refactoors
[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 pinShare :: Main (ByteCode () Stmt)
10 pinShare = sds \p=True In {main =
11 d0 =. p :. noOp
12 }
13
14 faculty :: Int -> Main (ByteCode () Stmt)
15 faculty i = sds \y=i In sds \x=1 In {main =
16 IF (y <=. lit 1) (
17 pub x :. retrn
18 ) (
19 x =. x *. y :.
20 y =. y -. lit 1
21 )}
22
23 count :: Main (ByteCode () Stmt)
24 count = sds \x=0 In {main = x =. x +. lit 1 :. pub x :. noOp}
25
26 countAndLed :: Main (ByteCode () Stmt)
27 countAndLed = sds \x=1 In sds \pinnetje=1 In {main =
28 IF (digitalRead D3) (
29 x =. x +. lit 1 :.
30 pub x
31 ) (
32 noOp
33 ) :.
34 IF (pinnetje ==. lit 1) (
35 ledOn (lit LED1)
36 ) (
37 IF (pinnetje ==. lit 2) (
38 ledOn (lit LED2)
39 ) (
40 ledOn (lit LED3)
41 )
42 )}
43
44 blinkShare :: Main (ByteCode () Stmt)
45 blinkShare = sds \x=1 In sds \led=LED1 In {main =
46 IF (x ==. lit 1) (
47 ledOn led ) (
48 ledOff led ) :.
49 x =. lit 1 -. x :. noOp
50 }
51
52 blink :: UserLED -> Main (ByteCode () Stmt)
53 blink l = sds \x=1 In {main =
54 IF (x ==. lit 1) (
55 ledOn (lit l) ) (
56 ledOff (lit l) ) :.
57 x =. lit 1 -. x :. noOp
58 }
59
60 ledtOn :: UserLED -> Main (ByteCode () Stmt)
61 ledtOn d = {main = ledOn (lit d) :. noOp}
62
63 ledtOff :: UserLED -> Main (ByteCode () Stmt)
64 ledtOff d = {main = ledOff (lit d) :. noOp}
65
66 readDPin :: DigitalPin -> Main (ByteCode () Stmt)
67 readDPin d = sds \pin=False In {main=pin =. digitalRead d :. pub pin :. noOp}
68
69 ledSelection :: Task UserLED
70 ledSelection = enterInformation "Select LED" []
71
72 pinSelection :: Task DigitalPin
73 pinSelection = enterInformation "Select digital pin" []
74
75 allmTasks :: Map String (Task (Main (ByteCode () Stmt)))
76 allmTasks = 'DM'.fromList
77 [("countAndLed", treturn countAndLed)
78 ,("ledOn", ledSelection @ ledtOn)
79 ,("ledOff", ledSelection @ ledtOff)
80 ,("readDPin", pinSelection @ readDPin)
81 ,("blink", ledSelection @ blink)
82 ,("blinkShare", treturn blinkShare)
83 ,("count", treturn count)
84 ,("faculty", enterInformation "Faculty" [] @ faculty)
85 ,("pinShare", treturn pinShare)
86 ]