mTaskTaskStore :: Shared [String]
mTaskTaskStore = memoryShare "mTaskTasks" ["ledder", "ledon", "ledoff"]
+mTaskMap :: Map String (Main (ByteCode () Stmt))
+mTaskMap = 'DM'.fromList [("ledder", bc), ("ledon", bc2 LED1), ("ledoff", bc3 LED3)]
+
bc :: Main (ByteCode () Stmt)
bc = sds \x=1 In sds \pinnetje=1 In {main =
IF (digitalRead D3) (
listmTasks :: Task String
listmTasks = enterChoiceWithShared "Available mTasks" [ChooseFromList id] mTaskTaskStore
- sendmTask mTaskId ds = enterChoice "Choose Device" [ChooseFromDropdown (\t->t.deviceName)] ds <<@ Title mTaskId
- >>* [OnAction (Action "Send") (withValue $ sendToDevice mTaskId)]
-
- sendToDevice mTask device = Just $ viewInformation "" [] device
+ sendmTask mTaskId ds =
+ (enterChoice "Choose Device" [ChooseFromDropdown \t->t.deviceName] ds
+ -&&- enterInformation "Timeout, 0 for one-shot" [])
+ >>* [OnAction (Action "Send") (withValue $ Just o sendToDevice mTaskId)]
+
+ sendToDevice :: String (MTaskDevice, Int) -> Task ()
+ sendToDevice mTask (device, timeout) = get bcStateStore
+ @ toMessages timeout o toRealByteCode (unMain $ fromJust ('DM'.get mTask mTaskMap))
+ >>= \(msgs, st1)->set st1 bcStateStore
+ //@ map f
+ >>| upd (\(r,s,ss)->(r,s++msgs,ss)) (channels device)
+ @! ()
+ where
+ f (i,d) = (i, sharedStore ("mTaskSDS-" +++ toString i) (dd d))
+ dd [x,y] = toInt x*265 + toInt y
+
+// = (msgs, map f st.sdss)
+// where
+// upd (\(r,s,ss)->(r,s++[],ss)) (channels device) @! ()
+// # (msgs, st) = toMessages timeout (toRealByteCode (unMain bc))
+// = Just $ viewInformation "" [] device
+// = (msgs, map f st.sdss)
+// where
+// f (i,d) = (i, sharedStore ("mTaskSDS-" +++ toString i) (dd d))
+// dd [x,y] = toInt x*265 + toInt y
+// #
+// = Just $ viewInformation "" [] device
+ channels :: MTaskDevice -> Shared Channels
+ channels d = memoryShare (fromJust d.deviceConnected) ([], [], False)
layout = sequenceLayouts
[ arrangeWithSideBar 0 LeftSide 260 True
viewShares :: Task ()
viewShares = forever $
- enterChoiceWithShared "Shares" [ChooseFromList sdsvw] sdsShare
+ enterChoiceWithShared "Shares" [ChooseFromList id] sdsStore
>>* [OnValue $ withValue $ Just o updateShare]
>>* [OnAction (Action "Back") (const $ Just $ treturn ())]
where
sdsvw (k, v) = concat ["SDS ", toString k, ": ", toString v]
- updateShare (k, v) = (viewInformation "Key" [] k
- ||- updateInformation "Value" [] v)
+ updateShare s = viewInformation "" [] ()
+// updateShare (k, v) = (viewInformation "Key" [] k
+// ||- updateInformation "Value" [] v)
viewDevices :: [MTaskDevice] -> Task ()
viewDevice :: MTaskDevice -> Task ()
viewDevice d = (viewInformation "Device settings" [] d
||- (case d.deviceConnected of
- Just s = viewSharedInformation "Channels" [] (channels d.deviceName) @! ()
+ Just s = viewSharedInformation "Channels" [ViewAs dropEmpty] (channels d) @! ()
Nothing = viewInformation "No channels yet" [] "" @! ()
)) <<@ ArrangeHorizontal
-
- channels :: String -> Shared Channels
- channels s = sdsFocus s $ memoryStore "" $ Just ([], [], False)
-
- sdsShare :: Shared [(Int, Int)]
- sdsShare = sdsFocus "mTaskSDSs" $ memoryStore "" $ Just [(1, 1)]
+ where
+ dropEmpty (r,s,ss) = (filter ((=!=)MTEmpty) r,s,ss)
addDevice :: (Shared [MTaskDevice]) -> Task ()
addDevice devices = enterInformation "Device type and name" []
- >>= \(name, ty)->get randomInt @ ((+++) name o toString)
- >>= \realname->let ch = channels realname in case ty of
+ >>= \(name, ty)->get randomInt @ (\randint->{deviceConnected=Just (name +++ toString randint), deviceName=name, deviceTasks=[]})
+ >>= \dev->let ch = channels dev in case ty of
TCPDevice = enterInformation "Hostname and port" []
- >>= \(host, port)->cont realname name ||- syncNetworkChannel host port ch
+ >>= \(host, port)->cont dev ||- syncNetworkChannel host port ch
SerialDevice = accWorld getDevices
>>= \dl->(enterChoice "Device" [] dl -&&- updateInformation "Settings" [] zero)
- >>= \(device, settings)->cont realname name ||- syncSerialChannel device settings ch
+ >>= \(device, settings)->cont dev ||- syncSerialChannel device settings ch
where
- cont rn nm = (upd (\l->[dev rn nm:l]) devices >>| addDevice devices)
- dev rn nm = {deviceConnected=Just rn,deviceName=nm,deviceTasks=[]}
+ cont d = (upd (\l->[d:l]) devices >>| addDevice devices)
getDevices :: !*World -> *(![String], !*World)
getDevices w = case readDirectory "/dev" w of
syncNetworkChannel :: String Int (Shared ([MTaskMSGRecv], [MTaskMSGSend], Bool)) -> Task ()
-syncNetworkChannel server port channel
- = tcpconnect server port channel {ConnectionHandlers|onConnect=onConnect,whileConnected=whileConnected,onDisconnect=onDisconnect} @! ()
+syncNetworkChannel server port channel = catchAll
+ (tcpconnect server port channel {ConnectionHandlers|onConnect=onConnect,whileConnected=whileConnected,onDisconnect=onDisconnect} @! ())
+ (\v->traceValue v @! ())
where
onConnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool), [String], Bool)
onConnect _ (msgs,send,sendStopped)
= (Ok acc, Nothing, [], False)
whileConnected (Just newData) acc (msgs,send,sendStopped)
- | sendStopped = (Ok acc, Just (msgs ++ [decode newData],[],False), map encode send, False)
- = (Ok acc, Just (msgs ++ [decode newData],[],False), [], False)
+ = (Ok acc, Just (msgs ++ [decode newData],[],False), map encode send, False)
+ //| sendStopped = (Ok acc, Just (msgs ++ [decode newData],[],False), map encode send, False)
+// = (Ok acc, Just (msgs ++ [decode newData],[],False), [], False)
onDisconnect :: String ([MTaskMSGRecv],[MTaskMSGSend],Bool) -> (MaybeErrorString String, Maybe ([MTaskMSGRecv],[MTaskMSGSend],Bool))
onDisconnect l (msgs,send,sendStopped) = (Ok l, Nothing)