,value=value
}
-if` i t e = if i t e
-
-updateShareFromPublish :: MTaskDevice Int BCValue -> Task [MTaskShare]
-updateShareFromPublish dev ident val = updateShares dev $ map $ up ident val
- where
- up :: Int BCValue MTaskShare -> MTaskShare
- up i v s = if (s.identifier == i) {MTaskShare | s & value=val} s
-
import GenPrint, StdMisc, StdDebug, TTY
derive gPrint MTaskDevice, MTaskShare, Maybe, MTaskResource, MTaskTask, TaskId, TTYSettings, TCPSettings, DateTime
derive gPrint Parity, BaudRate, ByteSize
Nothing = (Error $ exception "Device doesn't exist anymore", iworld)
Just {deviceShares} = case find ((==)share) deviceShares of
Nothing = (Error $ exception "Share doesn't exist", iworld)
- Just share = (Ok share.MTaskShare.value, iworld)
+ Just s = (Ok s.MTaskShare.value, iworld)
// Also send messages
ww name value iworld
(Ok _, iworld) = (Ok $ maybe True ((==) identifier), iworld)
modifyValue :: BCValue [MTaskDevice] -> [MTaskDevice]
- modifyValue v ds = filterMap ((==)dev) deviceUpdate ds
- where
- deviceUpdate d = {MTaskDevice | d
- & deviceShares=filterMap ((==)share) shareUpd d.deviceShares}
- shareUpd s = {MTaskShare | s & value=v}
-
- filterMap :: (a -> Bool) (a -> a) [a] -> [a]
- filterMap f t xs = [if (f x) (t x) x\\x<-xs]
+ modifyValue v ds = filterMap ((==)dev) (updateShare identifier v) ds
+
+filterMap :: (a -> Bool) (a -> a) [a] -> [a]
+filterMap f t xs = [if (f x) (t x) x\\x<-xs]
+
+getDeviceStoreForShare :: Int -> Shared [MTaskDevice]
+getDeviceStoreForShare ident = sdsFocus (Just ident) $ sdsFocus () deviceStore
+
+updateShareFromPublish :: MTaskDevice Int BCValue -> Task [MTaskDevice]
+updateShareFromPublish dev ident val
+ = upd (filterMap ((==)dev) (updateShare ident val)) $ getDeviceStoreForShare ident
+
+updateShare :: Int BCValue MTaskDevice -> MTaskDevice
+updateShare ident val dev = {MTaskDevice | dev & deviceShares=filterMap
+ (\s->s.identifier==ident)
+ (\s->{MTaskShare | s & value=val})
+ dev.deviceShares}
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" $ 'DM'.keys allmTasks
-
-getSDSRecord :: Int -> Task MTaskShare
-getSDSRecord i = get sdsStore @ \l->hd [s\\s<-l | s.identifier == i]