From: Mart Lubbers Date: Thu, 11 May 2017 09:45:29 +0000 (+0200) Subject: have device logic go in withDevices X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=4f5bec7a819e8a8ee9ee30b761c2159df0a7d8a4;p=mTask.git have device logic go in withDevices --- diff --git a/CleanSerial b/CleanSerial index 3a3cc11..948f49f 160000 --- a/CleanSerial +++ b/CleanSerial @@ -1 +1 @@ -Subproject commit 3a3cc117a5b3e9cfe8c1d0272b8af431156f118f +Subproject commit 948f49f132f17f55b2ac49c2771df13d9aac3b48 diff --git a/Devices/mTaskDevice.dcl b/Devices/mTaskDevice.dcl index cae6519..618020b 100644 --- a/Devices/mTaskDevice.dcl +++ b/Devices/mTaskDevice.dcl @@ -35,11 +35,12 @@ instance == MTaskDevice class MTaskDuplex a where synFun :: a (Shared Channels) -> Task () +withDevice :: (MTaskDevice -> Task a) String -> Task a | iTask a + 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 a99097d..ad848d2 100644 --- a/Devices/mTaskDevice.icl +++ b/Devices/mTaskDevice.icl @@ -30,6 +30,12 @@ startupDevices :: Task [MTaskDevice] startupDevices = upd (map reset) deviceStore where reset d = {d & deviceTask=Nothing, deviceTasks=[], deviceError=Nothing} +withDevice :: (MTaskDevice -> Task a) String -> Task a | iTask a +withDevice f s = get deviceStore + >>= \ds->case 'DL'.find (\d->d.deviceName == s) ds of + Nothing = throw "Device not available" + Just d = f d + makeDevice :: String MTaskResource -> Task MTaskDevice makeDevice name res = get randomInt @ \rand->{MTaskDevice |deviceChannels=name +++ toString rand @@ -115,9 +121,6 @@ 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.icl b/Shares/mTaskShare.icl index 7ae47e1..ee6282b 100644 --- a/Shares/mTaskShare.icl +++ b/Shares/mTaskShare.icl @@ -24,7 +24,7 @@ updateS sh = flip (<<@) (Title $ toString sh.identifier) $ forever $ viewSharedInformation "Current value" [] (getSDSShare sh) ||- ( updateSharedInformation "New value" [] (getSDSShare sh) - >>= \nv->allTasks (map getDevice sh.withDevice) + >>= \nv->allTasks (map (withDevice treturn) sh.withDevice) >>= \devs->allTasks (map (sendMessages [MTUpd sh.identifier nv]) devs) >>| treturn nv ) diff --git a/Utils/Devices.dcl b/Utils/Devices.dcl index d816d3f..8480ce2 100644 --- a/Utils/Devices.dcl +++ b/Utils/Devices.dcl @@ -3,5 +3,4 @@ definition module Utils.Devices import iTasks import Devices.mTaskDevice -getDeviceByName :: String -> Task MTaskDevice channels :: MTaskDevice -> Shared Channels diff --git a/Utils/Devices.icl b/Utils/Devices.icl index 6a8052e..68eab35 100644 --- a/Utils/Devices.icl +++ b/Utils/Devices.icl @@ -5,10 +5,6 @@ import mTask import Utils.SDS import Data.List -getDeviceByName :: String -> Task MTaskDevice -getDeviceByName nm = get deviceStore @ find (\d->d.deviceChannels == nm) - >>= maybe (throw "Help, device not found") treturn - channels :: MTaskDevice -> Shared Channels channels d = memoryShare d.deviceChannels ([], [], False) diff --git a/client/task.c b/client/task.c index 050784c..9206a13 100644 --- a/client/task.c +++ b/client/task.c @@ -83,7 +83,6 @@ struct task *task_next(struct task *t) void task_delete(uint8_t c) { debug("Going to delete task: %i", c); - debug("mem_task: %p", mem_task); struct task *t = task_head(); while(t != NULL){ if(t->taskid == c){ @@ -105,5 +104,4 @@ void task_delete(uint8_t c) //Decrement the spacepointer mem_task -= end-start; } - debug("mem_task: %p", mem_task); } diff --git a/miTask.icl b/miTask.icl index 9a486af..b0378c1 100644 --- a/miTask.icl +++ b/miTask.icl @@ -37,7 +37,7 @@ mTaskManager = startupDevices >>| anyTask [ viewmTasks @! () , whileUnchanged sdsStore manageShares , whileUnchanged deviceStore $ manageDevices process - ] <<@ ApplyLayout (foldr1 sequenceLayouts + ] <<@ ApplyLayout (sequenceLayouts [arrangeWithSideBar 0 LeftSide 260 True ,arrangeSplit Vertical True]) where