import iTasks
import iTasks._Framework.Serialization
import mTask
+import Devices.mTaskDevice
derive class iTask MTaskShareType, MTaskShare
:: MTaskShareType = MTaskWithShare String | MTaskLens String
:: MTaskShare =
{withTask :: [String]
+ ,withDevice :: [MTaskDevice]
,identifier :: Int
,realShare :: MTaskShareType
,value :: BCValue
manageShares :: [MTaskShare] -> Task ()
///makeShare :: String Int Dynamic -> Task MTaskShare
-makeShare :: String Int BCValue -> Task MTaskShare
+makeShare :: String MTaskDevice Int BCValue -> Task MTaskShare
updateShare :: Int BCValue -> Task ()
manageShares :: [MTaskShare] -> Task ()
manageShares shares = withShared Nothing $ \cs->forever $
- viewSharesGrid cs shares /*||- (viewSharedInformation "" [] cs*/ @! ()//)//||- editCurrentShare cs
+ (viewSharesGrid cs shares -|| updateShares shares <<@ ArrangeVertical)
+ @! ()
+updateShares :: [MTaskShare] -> Task BCValue
+updateShares shares = anyTask (map updateS shares) <<@ ArrangeWithTabs
+
+updateS :: MTaskShare -> Task BCValue
+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)
+ >>| treturn nv
+ )
+ <<@ ArrangeHorizontal
// >&^ \st->whileUnchanged st $ \msh->case msh of
// Nothing = viewShares shares
getSDSShare :: MTaskShare -> Shared BCValue
getSDSShare s=:{realShare=(MTaskWithShare id),value} = memoryShare id value
-makeShare :: String Int BCValue -> Task MTaskShare
-makeShare withTask identifier value = treturn
+makeShare :: String MTaskDevice Int BCValue -> Task MTaskShare
+makeShare withTask withDevice identifier value = treturn
{MTaskShare
|withTask=[withTask]
+ ,withDevice=[withDevice]
,identifier=identifier
,value=value
,realShare=MTaskWithShare $ "mTaskSDS-" +++ toString identifier
sendTaskToDevice wta mTask (device, timeout) =
get bcStateStore @ toMessages timeout mTask
>>= \(msgs, st1)->set st1 bcStateStore
- >>| toSDSRecords msgs st1
+ >>| toSDSRecords msgs st1 device
>>= \sdss->upd (mergeShares sdss) sdsStore
>>| sendMessages msgs device
>>| makeTask wta -1
where
sharename i = device.deviceChannels +++ "-" +++ toString i
- toSDSRecords :: [MTaskMSGSend] BCState -> Task [MTaskShare]
- toSDSRecords s st = sequence ""
- [makeShare wta sdsi sdsval
+ toSDSRecords :: [MTaskMSGSend] BCState MTaskDevice -> Task [MTaskShare]
+ toSDSRecords s st device = sequence ""
+ [makeShare wta device sdsi sdsval
\\{sdsi,sdspub,sdsval}<-st.sdss
, (MTSds sdsi` _)<-s
| sdsi == sdsi`]
:: MTaskMSGSend
= MTTask MTaskInterval String
| MTTaskDel Int
- | MTSds Int String
- | MTUpd Int String
+ | MTSds Int BCValue
+ | MTUpd Int BCValue
| MTSpec
:: MTaskInterval
instance serial ByteCode
toMessages :: MTaskInterval (Main (ByteCode a b)) BCState -> ([MTaskMSGSend], BCState)
-toSDSUpdate :: Int Int -> [MTaskMSGSend]
toByteVal :: BC -> String
toReadableByteCode :: (ByteCode a b) BCState -> (String, BCState)
encode :: MTaskMSGSend -> String
encode (MTTask to data) = "t" +++ toByteCode to +++ to16bit (size data) +++ data +++ "\n"
encode (MTTaskDel i) = "d" +++ to16bit i +++ "\n"
-encode (MTSds i v) = "s" +++ to16bit i +++ v +++ "\n"
-encode (MTUpd i v) = "u" +++ to16bit i +++ v +++ "\n"
+encode (MTSds i v) = "s" +++ to16bit i +++ toByteCode v +++ "\n"
+encode (MTUpd i v) = "u" +++ to16bit i +++ toByteCode v +++ "\n"
encode (MTSpec) = "c\n"
import StdDebug
| not (trace_tn $ printToString s.sdss) = undef
| not (trace_tn $ printToString newstate.sdss) = undef
| not (trace_tn $ printToString newsdss) = undef
-= ([MTSds sdsi $ toByteCode e\\{sdsi,sdsval=(BCValue e)}<-newsdss] ++
+= ([MTSds sdsi e\\{sdsi,sdsval=e}<-newsdss] ++
[MTTask interval bc], newstate)
instance == BCShare where (==) a b = a.sdsi == b.sdsi
-toSDSUpdate :: Int Int -> [MTaskMSGSend]
-toSDSUpdate i v = [MTUpd i (to16bit v)]
-
//Start = toMessages (OnInterval 500) $ toRealByteCode (unMain bc) zero
Start = fst $ toReadableByteCode (unMain $ countAndLed) zero
//Start = fst $ toReadableByteCode (unMain $ blink LED1) zero
delete tasks when deleting device
let tasks have a unique name
-add field in task that denotes to which device it belongs