-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcc.hs
24 lines (19 loc) · 836 Bytes
/
cc.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import System.RaspberryPi.Events
-- This file is just a testbench for testing the library code
edgeToNumber :: Edge -> Int
edgeToNumber Rising = 100
edgeToNumber Falling = -7
g Rising = Just 10
g Falling = Nothing
main = let inputs = [InputAction Immediate $ f g (getGpioEdge 7)]
initial = 0
update msg state = msg
outputs = [OutputAction Immediate print]
in topLevel inputs update initial outputs
-- This should probably be in Events.hs (or something more general even),
-- but I don't have a good name for it. It's a pretty common pattern though.
f :: (a -> Maybe b) -> IO a -> IO b
f verify action = do val <- action
let reaction = verify val
case reaction of (Just v) -> return v
Nothing -> f verify action