X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=miTask.icl;h=1e62ea7f0217aa4923d0a4bfbec3973cb219b222;hb=58e526fc46f667943873621c9029d7e5dd7c158e;hp=738f8c2a11e559f4e7b88e324b2e5830d0b751aa;hpb=0781ce1e845d7ec4bd06a39105d5d0d68835c693;p=mTask.git diff --git a/miTask.icl b/miTask.icl index 738f8c2..1e62ea7 100644 --- a/miTask.icl +++ b/miTask.icl @@ -61,6 +61,9 @@ bcStateStore = memoryShare "mTaskBCState" zero 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) ( @@ -109,12 +112,37 @@ mTaskManager = anyTask 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 @@ -123,13 +151,14 @@ mTaskManager = anyTask 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 () @@ -141,28 +170,23 @@ mTaskManager = anyTask 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 @@ -321,8 +345,9 @@ serialDeviceBackgroundTask rw iworld 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) @@ -333,8 +358,9 @@ syncNetworkChannel server port channel = (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)