-derive class iTask SerTCP
-:: SerTCP = Serial | TCP
-
-mTaskTask :: (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task ()
-mTaskTask ch =
- (enterInformation "Choose" [] >>= \st->case st of
- Serial = deviceSelectorSerial >>= \(s,set)->syncSerialChannel s set decode encode ch
- TCP = deviceSelectorNetwork >>= \(p,h)->syncNetworkChannel h p "\n" decode encode ch
- ) ||-
- sendMsg msgs ch ||-
- (
- (
- consumeNetworkStream (processSDSs sdsShares messageShare) ch ||-
- viewSharedInformation "channels" [ViewWith lens] ch ||-
- viewSharedInformation "messages" [] messageShare ||-
- viewSh sdsShares ch
- ) >>* [OnAction ActionFinish (always shutDown)]
- )
- where
- messageShare :: Shared [String]
- messageShare = sharedStore "mTaskMessagesRecv" []
-
- processSDSs :: [(Int, Shared Int)] (Shared [String]) [MTaskMSGRecv] -> Task ()
- processSDSs _ _ [] = return ()
- processSDSs s y [x:xs] = updateSDSs s y x >>= \_->processSDSs s y xs
-
- updateSDSs :: [(Int, Shared Int)] (Shared [String]) MTaskMSGRecv -> Task ()
- updateSDSs _ m (MTMessage s) = upd (\l->take 20 [s:l]) m @! ()
- updateSDSs _ _ MTEmpty = return ()
- updateSDSs [(id, sh):xs] m n=:(MTPub i d)
- | id == i = set ((toInt d.[0])*265 + toInt d.[1]) sh @! ()
- = updateSDSs xs m n
-
- lens :: ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool) -> ([String], [String])
- lens (r,_,s,_) = (f r, map toString s)
- where
- f [] = []
- f [MTEmpty:xs] = f xs
- f [x:xs] = [toString x:f xs]
-
- viewSh :: [(Int, Shared Int)] (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task ()
- viewSh [] ch = return ()
- viewSh [(i, sh):xs] ch
- # sharename = "SDS-" +++ toString i
- = (
- viewSharedInformation ("SDS-" +++ toString i) [] sh ||-
- forever (
- enterInformation sharename []
- >>* [OnAction ActionOk
- (ifValue (\j->j>=1 && j <= 3)
- (\c->set c sh
- >>= \_->sendMsg (toSDSUpdate i c) ch
- @! ()
- )
- )]
- )
- ) ||- viewSh xs ch
-
- (msgs, sdsShares) = makeBytecode 500 bc
-
- bc :: Main (ByteCode () Stmt)
- bc = sds \x=1 In sds \pinnetje=1 In {main =
- IF (digitalRead D3 ==. lit True) (
- x =. x +. lit 1 :.
- pub x
- ) (
- noOp
- ) :.
- IF (pinnetje ==. lit 1) (
- digitalWrite D0 (lit True) :.
- digitalWrite D1 (lit False) :.
- digitalWrite D2 (lit False)
- ) (
- IF (pinnetje ==. lit 2) (
- digitalWrite D0 (lit False) :.
- digitalWrite D1 (lit True) :.
- digitalWrite D2 (lit False)
- ) (
- digitalWrite D0 (lit False) :.
- digitalWrite D1 (lit False) :.
- digitalWrite D2 (lit True)
- )
- )}
-
-makeBytecode :: Int (Main (ByteCode () Stmt)) -> ([MTaskMSGSend], [(Int, Shared Int)])
-makeBytecode timeout bc
-# (msgs, st) = toMessages timeout (toRealByteCode (unMain bc))
-# shares = map (\(i,d)->(i, sdsFocus (s i) (memoryStore (s i) (Just (dd d))))) st.sdss
-= (msgs, shares)
- where
- s i = "mTaskSDS-" +++ toString i
- dd [x,y] = (toInt x)*265+(toInt y)
+// connectDevice :: [MTaskDevice] -> Task ()
+// connectDevice [] = treturn ()
+// connectDevice [d:ds] = (case d.deviceConnected of
+// (Just sh) = viewSharedInformation "Buffers" [] sh @! ()
+// Nothing = viewInformation ("Connect " +++ d.deviceName) [] "" >>* [
+// OnAction (Action "connect") (const $ Just $ connect d)]
+// ) -|| connectDevice ds
+
+ deviceviewer :: [MTaskDevice] -> [MTaskDeviceStatus]
+ deviceviewer ds = [{MTaskDeviceStatus | name = d.deviceName,
+ connected = if (isNothing d.deviceConnected) False True,
+ tasks = d.deviceTasks}\\d<-ds]