From: Mart Lubbers Date: Sun, 26 Feb 2017 14:33:46 +0000 (+0100) Subject: modularize more X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=b3d2bd33a99a2dbdc4907b6876a965c16c37314c;p=mTask.git modularize more --- diff --git a/Devices/mTaskDevice.dcl b/Devices/mTaskDevice.dcl index 6551eb3..457a1a6 100644 --- a/Devices/mTaskDevice.dcl +++ b/Devices/mTaskDevice.dcl @@ -36,3 +36,5 @@ class MTaskDuplex a where addDevice :: (Shared [MTaskDevice]) -> Task String //addDevice :: (Shared [MTaskDevice]) -> Task MTaskResource //addDevice :: (Shared [MTaskDevice]) -> Task () + +viewDevices :: [MTaskDevice] -> Task () diff --git a/Devices/mTaskDevice.icl b/Devices/mTaskDevice.icl index 2bd7121..b059b10 100644 --- a/Devices/mTaskDevice.icl +++ b/Devices/mTaskDevice.icl @@ -6,7 +6,7 @@ import iTasks import iTasksTTY import TTY import qualified Data.Map as DM -import Utils +import Utils.SDS import GenBimap import Devices.mTaskSerial @@ -47,5 +47,18 @@ addDevice devices = enterChoice "Device type" [] (map consName{|*|} deviceTypes) deviceSettings "SerialDevice" = getmTaskSerialDevice deviceSettings "TCPDevice" = getmTaskTCPDevice -deviceTypes :: [MTaskResource] -deviceTypes = conses{|*|} + deviceTypes :: [MTaskResource] + deviceTypes = conses{|*|} + +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 + ||- viewSharedInformation "Channels" [ViewAs dropEmpty] (channels d) @! () + ) <<@ ArrangeHorizontal + where + dropEmpty (r,s,ss) = (filter ((=!=)MTEmpty) r,s,ss) diff --git a/Shares/mTaskShare.dcl b/Shares/mTaskShare.dcl new file mode 100644 index 0000000..e3fdd42 --- /dev/null +++ b/Shares/mTaskShare.dcl @@ -0,0 +1,8 @@ +definition module Shares.mTaskShare + +:: MTaskShare = { + initValue :: Int, + withTask :: String, + identifier :: Int, + realShare :: String + } diff --git a/Shares/mTaskShare.icl b/Shares/mTaskShare.icl new file mode 100644 index 0000000..ad2e341 --- /dev/null +++ b/Shares/mTaskShare.icl @@ -0,0 +1,2 @@ +implementation module Shares.mTaskShare + diff --git a/Utils.dcl b/Utils.dcl deleted file mode 100644 index cda8a7a..0000000 --- a/Utils.dcl +++ /dev/null @@ -1,5 +0,0 @@ -definition module Utils - -import iTasks - -memoryShare :: String a -> Shared a | iTask a diff --git a/Utils.icl b/Utils.icl deleted file mode 100644 index 3a9be2c..0000000 --- a/Utils.icl +++ /dev/null @@ -1,8 +0,0 @@ -implementation module Utils - -import iTasks -import iTasks._Framework.Store -from Data.Func import $ - -memoryShare :: String a -> Shared a | iTask a -memoryShare s d = sdsFocus s $ memoryStore "" $ Just d diff --git a/Utils/SDS.dcl b/Utils/SDS.dcl new file mode 100644 index 0000000..88f1200 --- /dev/null +++ b/Utils/SDS.dcl @@ -0,0 +1,14 @@ +definition module Utils.SDS + +import Shares.mTaskShare +import Devices.mTaskDevice +import iTasks + +derive class iTask MTaskShare + +memoryShare :: String a -> Shared a | iTask a + +deviceStore :: Shared [MTaskDevice] +sdsStore :: Shared [MTaskShare] +bcStateStore :: Shared BCState +mTaskTaskStore :: Shared [String] diff --git a/Utils/SDS.icl b/Utils/SDS.icl new file mode 100644 index 0000000..f1184a8 --- /dev/null +++ b/Utils/SDS.icl @@ -0,0 +1,24 @@ +implementation module Utils.SDS + +import iTasks +import iTasks._Framework.Store +import Devices.mTaskDevice +import Shares.mTaskShare +from Data.Func import $ + +derive class iTask MTaskShare, BCState + +memoryShare :: String a -> Shared a | iTask a +memoryShare s d = sdsFocus s $ memoryStore "" $ Just d + +deviceStore :: Shared [MTaskDevice] +deviceStore = sharedStore "mTaskDevices" [] + +sdsStore :: Shared [MTaskShare] +sdsStore = memoryShare "mTaskShares" [] + +bcStateStore :: Shared BCState +bcStateStore = memoryShare "mTaskBCState" zero + +mTaskTaskStore :: Shared [String] +mTaskTaskStore = memoryShare "mTaskTasks" ["count", "ledon", "ledoff"] diff --git a/miTask.icl b/miTask.icl index 6c80f05..47778b2 100644 --- a/miTask.icl +++ b/miTask.icl @@ -6,6 +6,8 @@ from StdFunc import flip import iTasks import mTask import Devices.mTaskDevice +import Shares.mTaskShare +import Utils.SDS from Text import class Text(startsWith,concat,split,join), instance Text String @@ -22,32 +24,10 @@ import TTY, iTasksTTY derive class iTask UserLED -:: MTaskShare = { - initValue :: Int, - withTask :: String, - 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 = sharedStore "mTaskDevices" [] - -sdsStore :: Shared [MTaskShare] -sdsStore = memoryShare "mTaskShares" [] - -bcStateStore :: Shared BCState -bcStateStore = memoryShare "mTaskBCState" zero - -mTaskTaskStore :: Shared [String] -mTaskTaskStore = memoryShare "mTaskTasks" ["count", "ledon", "ledoff"] - mTaskMap :: Map String (Main (ByteCode () Stmt)) mTaskMap = 'DM'.fromList [("count", bc), ("ledon", bc2 LED1), ("ledoff", bc3 LED3)] @@ -76,7 +56,7 @@ bc3 :: UserLED -> Main (ByteCode () Stmt) bc3 d = {main = ledOff d} :: MTaskDeviceStatus = {connected :: Bool, name :: String, tasks :: [String]} -derive class iTask MTaskDeviceStatus, MTaskShare, BCState +derive class iTask MTaskDeviceStatus, BCState mTaskManager :: Task () mTaskManager = anyTask @@ -147,20 +127,6 @@ mTaskManager = anyTask // ||- 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 - ||- viewSharedInformation "Channels" [ViewAs dropEmpty] (channels d) @! () - ) <<@ ArrangeHorizontal - where - dropEmpty (r,s,ss) = (filter ((=!=)MTEmpty) r,s,ss) - - // addDevice :: (Shared [MTaskDevice]) -> Task SerTCP // addDevice devices = enterInformation "Device type" [] // >&^ \sh->whileUnchanged sh $ \mty->case mty of