From: Mart Lubbers Date: Wed, 31 May 2017 12:05:31 +0000 (+0200) Subject: trying to get the sds lenses to work X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=54c127405f2b7e0085d1c6ff48b6b496f5917dcf;p=mTask.git trying to get the sds lenses to work --- diff --git a/Shares/mTaskShare.dcl b/Shares/mTaskShare.dcl index 1d38669..a3155fd 100644 --- a/Shares/mTaskShare.dcl +++ b/Shares/mTaskShare.dcl @@ -13,6 +13,8 @@ derive class iTask MTaskShare ,value :: BCValue } +instance == MTaskShare + //Constructor makeShare :: String Int BCValue -> MTaskShare diff --git a/Shares/mTaskShare.icl b/Shares/mTaskShare.icl index 481d3ad..edd84d0 100644 --- a/Shares/mTaskShare.icl +++ b/Shares/mTaskShare.icl @@ -6,6 +6,7 @@ import Utils.Devices import iTasks import mTask import Data.List +import Data.Tuple from Data.Func import $ from StdFunc import flip @@ -66,6 +67,8 @@ makeShare withTask identifier value = {MTaskShare ,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 @@ -90,33 +93,36 @@ cleanSharesTask taskid d = updateShares d id //TODO // up :: [String] MTaskShare -> MTaskShare // up ns s = {MTaskShare | s & withTask=[t\\t<-s.withTask|not (isMember t ns)]} +instance == MTaskShare where + (==) a b = a.identifier == b.identifier + getRealShare :: MTaskDevice MTaskShare -> Shared BCValue -getRealShare dev {identifier} = SDSSource {SDSSource +getRealShare dev share=:{identifier} = sdsFocus (Just identifier) $ SDSSource {SDSSource | name = "mTaskShareMap-" +++ toString identifier, read=rr, write=ww} where rr name iworld = case read deviceStore iworld of (Error e, iworld) = (Error e, iworld) (Ok devices, iworld) = case find ((==)dev) devices of Nothing = (Error $ exception "Device doesn't exist anymore", iworld) - Just {deviceShares} = case find (\s->s.identifier == identifier) deviceShares of + Just {deviceShares} = case find ((==)share) deviceShares of Nothing = (Error $ exception "Share doesn't exist", iworld) Just share = (Ok share.MTaskShare.value, iworld) // Also send messages ww name value iworld | not (trace_tn ("Update to: " +++ printToString value)) = undef - = case modify (\r->((), map (modFun value) r)) deviceStore iworld of + = case modify (tuple () o modifyValue value) deviceStore iworld of (Error e, iworld) = (Error e, iworld) (Ok _, iworld) = case sendMessagesIW [MTUpd identifier value] dev iworld of (Error e, iworld) = (Error e, iworld) - (Ok _, iworld) = (Ok $ const True, iworld) + (Ok _, iworld) = (Ok $ maybe True ((==) identifier), iworld) - //Selects the correct device - modFun value d - | d == dev = {d & deviceShares=map (modFun2 value) d.deviceShares} - = d + 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} - //Selects the correct share - modFun2 value share - | identifier == share.MTaskShare.identifier = {MTaskShare | share & value=value} - = share + filterMap :: (a -> Bool) (a -> a) [a] -> [a] + filterMap f t xs = [if (f x) (t x) x\\x<-xs] diff --git a/miTask.icl b/miTask.icl index cafbffa..8e43544 100644 --- a/miTask.icl +++ b/miTask.icl @@ -38,17 +38,15 @@ demo = viewSharedInformation "Devices" [] deviceStore cont :: MTaskDevice -> Task () cont dev = updateSharedInformation "Blinkyblink" [] (getRealShare dev (hd dev.deviceShares)) - >>| cont dev + >>* [OnAction ActionContinue (const $ Just $ cont dev)] mTaskManager :: Task () -mTaskManager = startupDevices >>| anyTask - [ viewmTasks @! () - , manageShares @! () - , whileUnchanged deviceStore $ manageDevices process - ] <<@ ApplyLayout (foldl1 sequenceLayouts - [arrangeWithSideBar 0 LeftSide 260 True - ,arrangeSplit Vertical True]) +mTaskManager = (>>|) startupDevices $ + viewmTasks ||- + ((manageShares ||- whileUnchanged deviceStore (manageDevices process)) + <<@ ArrangeSplit Vertical True) + <<@ ArrangeWithSideBar 0 LeftSide 260 True where viewmTasks :: Task String viewmTasks = enterChoiceWithShared "Available mTasks" [ChooseFromList id] mTaskTaskStore