From c518754bec4758cce7d899463f9c68612c3bf4e4 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Tue, 21 Mar 2017 16:11:50 +0100 Subject: [PATCH] update device name instead of record --- Devices/mTaskDevice.dcl | 1 + Devices/mTaskDevice.icl | 4 ++++ Shares/mTaskShare.dcl | 5 ++--- Shares/mTaskShare.icl | 31 ++++--------------------------- Tasks/mTaskTask.icl | 2 +- todo.txt | 1 - 6 files changed, 12 insertions(+), 32 deletions(-) diff --git a/Devices/mTaskDevice.dcl b/Devices/mTaskDevice.dcl index 103da32..cae6519 100644 --- a/Devices/mTaskDevice.dcl +++ b/Devices/mTaskDevice.dcl @@ -39,6 +39,7 @@ startupDevices :: Task [MTaskDevice] connectDevice :: (MTaskDevice (Shared Channels) -> Task ()) MTaskDevice -> Task () manageDevices :: (MTaskDevice (Shared Channels) -> Task ()) [MTaskDevice] -> Task () sendMessages :: [MTaskMSGSend] -> (MTaskDevice -> Task Channels) +getDevice :: String -> Task MTaskDevice withDevices :: MTaskDevice (MTaskDevice -> MTaskDevice) -> Task () diff --git a/Devices/mTaskDevice.icl b/Devices/mTaskDevice.icl index 5e3f6dc..a99097d 100644 --- a/Devices/mTaskDevice.icl +++ b/Devices/mTaskDevice.icl @@ -7,6 +7,7 @@ import iTasks import iTasksTTY import TTY import qualified Data.Map as DM +import qualified Data.List as DL import Utils.SDS import Utils.Devices @@ -114,6 +115,9 @@ deviceTaskAcked dev i ackFirst [t:ts] = if (t.ident == -1) [{t & ident=i}:ts] [t:ackFirst ts] +getDevice :: String -> Task MTaskDevice +getDevice n = get deviceStore @ fromJust o 'DL'.find (\s->s.deviceName == n) + deviceTaskDelete :: MTaskDevice MTaskTask -> Task () deviceTaskDelete dev task = sendMessages [MTTaskDel task.ident] dev @! () diff --git a/Shares/mTaskShare.dcl b/Shares/mTaskShare.dcl index 3dee1e8..0e73a82 100644 --- a/Shares/mTaskShare.dcl +++ b/Shares/mTaskShare.dcl @@ -10,7 +10,7 @@ derive class iTask MTaskShareType, MTaskShare :: MTaskShareType = MTaskWithShare String | MTaskLens String :: MTaskShare = {withTask :: [String] - ,withDevice :: [MTaskDevice] + ,withDevice :: [String] ,identifier :: Int ,realShare :: MTaskShareType ,value :: BCValue @@ -18,7 +18,6 @@ derive class iTask MTaskShareType, MTaskShare manageShares :: [MTaskShare] -> Task () -///makeShare :: String Int Dynamic -> Task MTaskShare -makeShare :: String MTaskDevice Int BCValue -> Task MTaskShare +makeShare :: String String Int BCValue -> Task MTaskShare updateShare :: Int BCValue -> Task () diff --git a/Shares/mTaskShare.icl b/Shares/mTaskShare.icl index ed4b5e3..60fb0a8 100644 --- a/Shares/mTaskShare.icl +++ b/Shares/mTaskShare.icl @@ -7,6 +7,7 @@ import iTasks import mTask import Data.List from Data.Func import $ +from StdFunc import flip derive class iTask MTaskShareType, MTaskShare @@ -22,36 +23,12 @@ updateS sh = flip (<<@) (Title $ toString sh.identifier) $ forever $ viewSharedInformation "Current value" [] (getSDSShare sh) ||- ( updateSharedInformation "New value" [] (getSDSShare sh) - >>= \nv->allTasks (map (sendMessages [MTUpd sh.identifier nv]) sh.withDevice) + >>= \nv->allTasks (map getDevice sh.withDevice) + >>= \devs->allTasks (map (sendMessages [MTUpd sh.identifier nv]) devs) >>| treturn nv ) <<@ ArrangeHorizontal -// >&^ \st->whileUnchanged st $ \msh->case msh of -// Nothing = viewShares shares -// Just sh = forever ( -// viewSharedInformation "View value" [] (getSDSShare sh) >>| treturn sh -// >>* [OnAction (Action "Update") (withValue (Just o updateInformation "New value" []))] -// >>= updateShare sh -// ) -// -// ) @! () - - -//viewShares :: [MTaskShare] -> Task BCValue -//viewShares shares = anyTask (map viewShare shares) -// -//viewAndDelete :: [MTaskShare] -> Task () -//viewAndDelete shares -// = enterChoice "Choose share to update" [ChooseFromGrid id] shares @! () - -//updateShare :: MTaskShare a -> Task MTaskShare | toByteCode, iTask a -//updateShare sh=:{withTask,identifier} a = getDeviceByName withTask -// >>= sendMessages [MTUpd identifier $ toString $ toByteCode a] -// >>| treturn sh -// -from StdFunc import flip - viewSharesGrid :: (Shared (Maybe MTaskShare)) [MTaskShare] -> Task [BCValue] viewSharesGrid _ [] = viewInformation "No shares yet" [] [] viewSharesGrid cs sh = (allTasks [watch (getSDSShare m)\\m<-sh] <<@ NoUserInterface) @@ -67,7 +44,7 @@ viewShare m = viewSharedInformation "" [] (getSDSShare m) getSDSShare :: MTaskShare -> Shared BCValue getSDSShare s=:{realShare=(MTaskWithShare id),value} = memoryShare id value -makeShare :: String MTaskDevice Int BCValue -> Task MTaskShare +makeShare :: String String Int BCValue -> Task MTaskShare makeShare withTask withDevice identifier value = treturn {MTaskShare |withTask=[withTask] diff --git a/Tasks/mTaskTask.icl b/Tasks/mTaskTask.icl index 52191b5..845c077 100644 --- a/Tasks/mTaskTask.icl +++ b/Tasks/mTaskTask.icl @@ -28,7 +28,7 @@ sendTaskToDevice wta mTask (device, timeout) = toSDSRecords :: [MTaskMSGSend] BCState MTaskDevice -> Task [MTaskShare] toSDSRecords s st device = sequence "" - [makeShare wta device sdsi sdsval + [makeShare wta device.deviceName sdsi sdsval \\{sdsi,sdspub,sdsval}<-st.sdss , (MTSds sdsi` _)<-s | sdsi == sdsi`] diff --git a/todo.txt b/todo.txt index e580bcd..4647ddd 100644 --- a/todo.txt +++ b/todo.txt @@ -1,3 +1,2 @@ delete tasks when deleting device let tasks have a unique name -withDevice field should only contain name -- 2.20.1