added gracefull shutdown
[mTask.git] / Tasks / Examples.icl
1 implementation module Tasks.Examples
2
3 import qualified Data.Map as DM
4 import mTask
5
6 import Devices.mTaskDevice
7 import iTasks._Framework.Serialization
8
9 faculty :: Int -> Main (ByteCode () Stmt)
10 faculty i = sds \y=i In sds \x=1 In {main =
11 IF (y <=. lit 1) (
12 pub x :. retrn
13 ) (
14 x =. x *. y :.
15 y =. y -. lit 1
16 )}
17
18 countTo5 :: Main (ByteCode () Stmt)
19 countTo5 = sds \x=0 In {main =
20 x =. x +. lit 1 :.
21 pub x :.
22 IF ( x >. lit 5) (
23 retrn
24 ) (
25 noOp
26 )}
27
28 count :: Main (ByteCode () Stmt)
29 count = sds \x=0 In {main = x =. x +. lit 1 :. pub x :. noOp}
30
31 countAndLed :: Main (ByteCode () Stmt)
32 countAndLed = sds \x=1 In sds \pinnetje=1 In {main =
33 IF (digitalRead D3) (
34 x =. x +. lit 1 :.
35 pub x
36 ) (
37 noOp
38 ) :.
39 IF (pinnetje ==. lit 1) (
40 ledOn (lit LED1)
41 ) (
42 IF (pinnetje ==. lit 2) (
43 ledOn (lit LED2)
44 ) (
45 ledOn (lit LED3)
46 )
47 )}
48
49 blinkShare :: Main (ByteCode () Stmt)
50 blinkShare = sds \x=1 In sds \led=LED1 In {main =
51 IF (x ==. lit 1) (
52 ledOn led ) (
53 ledOff led ) :.
54 x =. lit 1 -. x :. noOp
55 }
56
57 blink :: UserLED -> Main (ByteCode () Stmt)
58 blink l = sds \x=1 In {main =
59 IF (x ==. lit 1) (
60 ledOn (lit l) ) (
61 ledOff (lit l) ) :.
62 x =. lit 1 -. x :. noOp
63 }
64
65 ledtOn :: UserLED -> Main (ByteCode () Stmt)
66 ledtOn d = {main = ledOn (lit d) :. noOp}
67
68 ledtOff :: UserLED -> Main (ByteCode () Stmt)
69 ledtOff d = {main = ledOff (lit d) :. noOp}
70
71 readDPin :: DigitalPin -> Main (ByteCode () Stmt)
72 readDPin d = sds \pin=False In {main=pin =. digitalRead d :. pub pin :. noOp}
73
74 ledSelection :: Task UserLED
75 ledSelection = enterInformation "Select LED" []
76
77 pinSelection :: Task DigitalPin
78 pinSelection = enterInformation "Select digital pin" []
79
80 allmTasks :: Map String (Task (Main (ByteCode () Stmt)))
81 allmTasks = 'DM'.fromList
82 [("countAndLed", treturn countAndLed)
83 ,("ledOn", ledSelection @ ledtOn)
84 ,("ledOff", ledSelection @ ledtOff)
85 ,("readDPin", pinSelection @ readDPin)
86 ,("blink", ledSelection @ blink)
87 ,("blinkShare", treturn blinkShare)
88 ,("count", treturn count)
89 ,("countTo5", treturn countTo5)
90 ,("faculty", enterInformation "Faculty" [] @ faculty)
91 ]