module miTask import StdDebug, StdMisc from StdFunc import flip 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 import qualified Data.Map as DM from Data.Func import $ import Data.Tuple import Data.List import System.Directory import iTasks._Framework.Store import iTasks._Framework.Serialization import TTY, iTasksTTY Start :: *World -> *World Start world = startEngine (mTaskManager >>* [OnAction (Action "Shutdown") (always $ shutDown)]) world mTaskManager :: Task () mTaskManager = startupDevices >>| anyTask [ viewmTasks @! () , whileUnchanged sdsStore manageShares , whileUnchanged deviceStore $ manageDevices process ] <<@ ApplyLayout (sequenceLayouts [ arrangeWithSideBar 0 LeftSide 260 True , arrangeSplit Vertical True ]) 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 = 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 ( ifValue (not o isEmpty o fst3) (\t->upd (appFst3 (const [])) ch >>| proc (fst3 t)))]) where proc :: [MTaskMSGRecv] -> Task () proc [] = treturn () proc [m:ms] = (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 @! () MTTaskAck i = deviceTaskAcked device i MTTaskDelAck i = deviceTaskDeleteAcked device i @! () MTEmpty = treturn () _ = traceValue (toString m) @! () ) >>| proc ms mapPar :: (a -> Task a) [a] -> Task () mapPar f l = foldr1 (\x y->f x ||- y) l <<@ ArrangeWithTabs @! () allAtOnce t = foldr1 (||-) t @! () //allAtOnce = (flip (@!) ()) o foldr1 (||-)