:: SerTCP = SerialDevice | TCPDevice
:: MTaskDevice = {
deviceConnected :: Maybe String,
- deviceName :: String
+ deviceName :: String,
+ deviceTasks :: [(String, Int)]
+ }
+:: MTaskShare = {
+ identifier :: Int,
+ realShare :: String
}
Start :: *World -> *World
Start world = startEngine (mTaskManager
>>* [OnAction (Action "Shutdown") (always $ shutDown)]) world
+memoryShare :: String a -> Shared a | iTask a
+memoryShare s d = sdsFocus s $ memoryStore "" $ Just d
+
+deviceStore :: Shared [MTaskDevice]
+deviceStore = memoryShare "mTaskDevices" []
+
+sdsStore :: Shared [MTaskShare]
+sdsStore = memoryShare "mTaskShares" []
+
+bcStateStore :: Shared BCState
+bcStateStore = memoryShare "mTaskBCState" zero
+
+mTaskTaskStore :: Shared [String]
+mTaskTaskStore = memoryShare "mTaskTasks" ["ledder", "ledon", "ledoff"]
+
bc :: Main (ByteCode () Stmt)
bc = sds \x=1 In sds \pinnetje=1 In {main =
IF (digitalRead D3) (
bc3 :: UserLED -> Main (ByteCode () Stmt)
bc3 d = {main = ledOff d}
-:: MTaskDeviceStatus = {connected :: Bool, name :: String}
-derive class iTask MTaskDeviceStatus, MTaskDevice
+:: MTaskDeviceStatus = {connected :: Bool, name :: String, tasks :: [(String, Int)]}
+derive class iTask MTaskDeviceStatus, MTaskDevice, MTaskShare, BCState
mTaskManager :: Task ()
mTaskManager = anyTask
isValue (Value _ _) = True
isValue _ = False
- viewmTasks = enterChoice "Available mTasks" [ChooseFromList id] ["ledder", "ledon", "ledoff"]
- >>= viewInformation "" []
+ viewmTasks = listmTasks
+ >&^ \sh->whileUnchanged sh $ \mi->case mi of
+ Nothing = viewInformation "No task selected" [] ()
+ Just mTaskTask = get deviceStore
+ >>= \devices->case devices of
+ [] = viewInformation "No devices yet" [] ()
+ ds = sendmTask mTaskTask ds @! ()
+ where
+ 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
+
+
layout = sequenceLayouts
[ arrangeWithSideBar 0 LeftSide 260 True
]
viewShares :: Task ()
- viewShares = forever (
+ viewShares = forever $
enterChoiceWithShared "Shares" [ChooseFromList sdsvw] sdsShare
>>* [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)
- >>= \nv->upd
viewDevices :: [MTaskDevice] -> Task ()
>>= \(device, settings)->cont realname name ||- 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}
+ dev rn nm = {deviceConnected=Just rn,deviceName=nm,deviceTasks=[]}
getDevices :: !*World -> *(![String], !*World)
getDevices w = case readDirectory "/dev" w of
deviceviewer :: [MTaskDevice] -> [MTaskDeviceStatus]
deviceviewer ds = [{MTaskDeviceStatus | name = d.deviceName,
- connected = if (isNothing d.deviceConnected) False True}\\d<-ds]
+ connected = if (isNothing d.deviceConnected) False True,
+ tasks = d.deviceTasks}\\d<-ds]
- deviceStore :: Shared [MTaskDevice]
- deviceStore = sdsFocus "mTaskDevices" $ memoryStore "" (Just [])
-
// showTabbed :: [MTaskDevice] -> Task ()
// showTabbed [] = viewInformation "" [] "No devices yet" @! ()
// showTabbed [l:ls] = foldr (\e es->manageDevice e ||- es) (manageDevice l) ls