+ listmTasks :: Task String
+ listmTasks = enterChoiceWithShared "Available mTasks" [ChooseFromList id] mTaskTaskStore
+
+ 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
+ , arrangeSplit Vertical True
+ ]
+
+ viewShares :: Task ()
+ viewShares = forever $
+ 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 s = viewInformation "" [] ()
+// updateShare (k, v) = (viewInformation "Key" [] k
+// ||- updateInformation "Value" [] v)
+
+
+ viewDevices :: [MTaskDevice] -> Task ()
+ viewDevices ds = anyTask [
+ addDevice deviceStore <<@ Title "Add new device" @! ():
+ [viewDevice d <<@ Title d.deviceName\\d<-ds]]
+ <<@ ArrangeWithTabs @! ()
+
+ viewDevice :: MTaskDevice -> Task ()
+ viewDevice d = (viewInformation "Device settings" [] d
+ ||- (case d.deviceConnected of
+ Just s = viewSharedInformation "Channels" [ViewAs dropEmpty] (channels d) @! ()
+ Nothing = viewInformation "No channels yet" [] "" @! ()
+ )) <<@ ArrangeHorizontal
+ 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 @ (\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 dev ||- syncNetworkChannel host port ch
+ SerialDevice = accWorld getDevices
+ >>= \dl->(enterChoice "Device" [] dl -&&- updateInformation "Settings" [] zero)
+ >>= \(device, settings)->cont dev ||- syncSerialChannel device settings ch
+ where
+ cont d = (upd (\l->[d:l]) devices >>| addDevice devices)
+
+ getDevices :: !*World -> *(![String], !*World)
+ getDevices w = case readDirectory "/dev" w of
+ (Error (errcode, errmsg), w) = abort errmsg
+ (Ok entries, w) = (map ((+++) "/dev/") (filter isTTY entries), w)
+