import StdDebug
import Devices.mTaskDevice
import iTasks
+from Data.Tuple import appSnd
+from Text import class Text(indexOf), instance Text String
derive class iTask TCPSettings
derive gPrint MTaskMSGRecv
onDisconnect=onDisconnect} @! ()
where
onConnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool)
- onConnect _ (msgs,send,sendStopped) = (Ok "", Just (msgs,[],sendStopped), map encode send, False)
+ onConnect acc (msgs,send,sendStopped) = (Ok acc, Just (msgs,[],sendStopped), map encode send, False)
whileConnected :: (Maybe String) String ([MTaskMSGRecv], [MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool)
- whileConnected Nothing _ (_,[],_) = (Ok "", Nothing, [], False)
- whileConnected md _ (msgs,send,sendStopped)
- = (Ok "", Just (msgs++map decode (maybeToList md),[],sendStopped), map encode send, False)
+ //We stop
+ whileConnected _ _ (_,_,True) = (Ok "", Nothing, [], True)
+
+ //No new data and nothing to send
+ whileConnected Nothing acc (_,[],_) = (Ok acc, Nothing, [], False)
+
+ //New data and possibly something to send
+ whileConnected (Just newdata) acc (msgs,send,sendStopped)
+ # (acc, nd) = process (acc +++ newdata)
+ | isEmpty nd && isEmpty send = (Ok acc, Nothing, [], False)
+ = (Ok acc, Just (msgs++map decode nd,[],sendStopped), map encode send, False)
+
+ process :: String -> (String, [String])
+ process s = case indexOf "\n" s of
+ -1 = (s, [])
+ i = appSnd (\ss->[s % (0,i):ss]) (process (s % (i, size s)))
onDisconnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool))
onDisconnect _ (msgs,send,sendStopped) = (Ok "", Nothing)
ledtOff :: UserLED -> Main (ByteCode () Stmt)
ledtOff d = {main = ledOff (lit d) :. noOp}
+readDPin :: DigitalPin -> Main (ByteCode () Stmt)
+readDPin d = sds \pin=False In {main=pin =. digitalRead d :. noOp}
+
ledSelection :: Task UserLED
ledSelection = enterInformation "Select LED" []
+pinSelection :: Task DigitalPin
+pinSelection = enterInformation "Select digital pin" []
+
allmTasks :: Map String (Task (Main (ByteCode () Stmt)))
allmTasks = 'DM'.fromList
[("countAndLed", treturn countAndLed)
,("ledOn", ledSelection @ ledtOn)
,("ledOff", ledSelection @ ledtOff)
+ ,("readDPin", pinSelection @ readDPin)
,("blink", ledSelection @ blink)
,("blinkShare", treturn blinkShare)
]