X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=miTask.icl;h=2b9d4e0856294ae711d28ad23be0396cfe7f3b68;hb=7ab8606c3d22a2bc2743eae7a398407c84d502f2;hp=4bef60020d83c59a9c2e3819b3f7dd809148cf88;hpb=7fec7868123d56d410e807042cb3e031ebda12b9;p=mTask.git diff --git a/miTask.icl b/miTask.icl index 4bef600..2b9d4e0 100644 --- a/miTask.icl +++ b/miTask.icl @@ -7,6 +7,7 @@ import iTasks import mTask import Devices.mTaskDevice import Shares.mTaskShare +import Tasks.Examples import Utils.SDS from Text import class Text(startsWith,concat,split,join), instance Text String @@ -19,69 +20,37 @@ import Data.List import System.Directory import iTasks._Framework.Store +import iTasks._Framework.Serialization import TTY, iTasksTTY -derive class iTask UserLED - Start :: *World -> *World Start world = startEngine (mTaskManager >>* [OnAction (Action "Shutdown") (always $ shutDown)]) world -mTaskMap :: Map String (Main (ByteCode () Stmt)) -mTaskMap = 'DM'.fromList [("count", bc), ("ledon", bc2 LED1), ("ledoff", bc3 LED3)] - -bc :: Main (ByteCode () Stmt) -bc = sds \x=1 In sds \pinnetje=1 In {main = - IF (digitalRead D3) ( - x =. x +. lit 1 :. - pub x - ) ( - noOp - ) :. - IF (pinnetje ==. lit 1) ( - ledOn LED1 - ) ( - IF (pinnetje ==. lit 2) ( - ledOn LED2 - ) ( - ledOn LED3 - ) - )} - -bc2 :: UserLED -> Main (ByteCode () Stmt) -bc2 d = {main = ledOn d} - -bc3 :: UserLED -> Main (ByteCode () Stmt) -bc3 d = {main = ledOff d} - mTaskManager :: Task () -mTaskManager = anyTask +mTaskManager = startupDevices >>| anyTask [ viewmTasks @! () - , whileUnchanged sdsStore viewShares + , whileUnchanged sdsStore manageShares , whileUnchanged deviceStore $ manageDevices process - ] <<@ ApplyLayout layout - where - layout = sequenceLayouts + ] <<@ ApplyLayout (sequenceLayouts [ arrangeWithSideBar 0 LeftSide 260 True , arrangeSplit Vertical True - ] - - viewmTasks = listmTasks + ]) + where + viewmTasks :: Task String + viewmTasks = enterChoiceWithShared "Available mTasks" [ChooseFromList id] mTaskTaskStore >&^ \sh->whileUnchanged sh $ \mi->forever (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 - -&&- enterInformation "Timeout, 0 for one-shot" []) - >>* [OnAction (Action "Send") (withValue $ Just o sendToDevice mTaskMap mTaskId)] + ds = fromJust ('DM'.get mTaskTask allmTasks) + >>= \bc->(enterChoice "Choose Device" [ChooseFromDropdown \t->t.deviceName] ds + -&&- enterInformation "Timeout" [] + ) >>* [OnAction (Action "Send") (withValue $ Just o sendToDevice mTaskTask bc)] + @! () + ) process :: MTaskDevice (Shared Channels) -> Task () process device ch = forever (watch ch >>* [OnValue ( @@ -90,14 +59,14 @@ mTaskManager = anyTask where proc :: [MTaskMSGRecv] -> Task () proc [] = treturn () - proc [m:ms] = (case m of + proc [MTEmpty:ms] = proc ms + proc [m:ms] = traceValue (toString m) >>| (case m of // MTSDSAck i = traceValue (toString m) @! () // MTSDSDelAck i = traceValue (toString m) @! () - MTPub i val = getSDSRecord i >>= set (toInt val.[0]*256 + toInt val.[1]) o getSDSStore @! () + MTPub i val = updateShare i val MTTaskAck i = deviceTaskAcked device i MTTaskDelAck i = deviceTaskDeleteAcked device i @! () - MTEmpty = treturn () - _ = traceValue (toString m) @! () + _ = treturn () ) >>| proc ms mapPar :: (a -> Task a) [a] -> Task ()