Skip to content

Commit ef3ad04

Browse files
Release 2.0.0 (#7)
# Release 2.0.0 - Removed deprecated block "OnNewValue" (was replaced by "OnExpired") ## New features - New blocks "OnEvent" and "NotifyEvent" - Selectable which blocks to show in flow editor (to focus on specific use cases) - Check if persistent data to load provides all relevant parameters. Otherwise add default values ## Improvement - Added features "ADD", "SUBTRACT", "MULTIPLY", "DIVIDE", "FLOOR", "FALLING_EDGE" to logic operator block - Updated demo flows
1 parent d4924a3 commit ef3ad04

16 files changed

Lines changed: 800 additions & 380 deletions

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## Release 2.0.0
5+
- Removed deprecated block "OnNewValue" (was replaced by "OnExpired")
6+
7+
### New features
8+
- New blocks "OnEvent" and "NotifyEvent"
9+
- Selectable which blocks to show in flow editor (to focus on specific use cases)
10+
- Check if persistent data to load provides all relevant parameters. Otherwise add default values
11+
12+
### Improvement
13+
- Added features "ADD", "SUBTRACT", "MULTIPLY", "DIVIDE", "FLOOR", "FALLING_EDGE" to logic operator block
14+
- Updated demo flows
15+
416
## Release 1.4.0
517

618
### Improvement
177 Bytes
Binary file not shown.

CSK_Module_FlowConfig/project.mf.xml

Lines changed: 60 additions & 46 deletions
Large diffs are not rendered by default.

CSK_Module_FlowConfig/resources/CSK_Module_FlowConfig/FlowConfigDemo.bin

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

CSK_Module_FlowConfig/scripts/CSK_FlowConfig_FlowConfig.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
_G.availableAPIs = require('Communication/FlowConfig/helper/checkAPIs')
88

9-
require('Communication.FlowConfig.Features.FlowConfig_OnNewValue')
9+
require('Communication.FlowConfig.Features.FlowConfig_OnEvent')
10+
require('Communication.FlowConfig.Features.FlowConfig_NotifyEvent')
1011
require('Communication.FlowConfig.Features.FlowConfig_OnExpired')
1112
require('Communication.FlowConfig.Features.FlowConfig_ProcessLogic')

CSK_Module_FlowConfig/scripts/CSK_FlowConfig_LogicProcessing.lua

Lines changed: 102 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,90 @@ local function runOperator(instance)
1515
local result
1616
if parameters[instance]['logic'] == 'EQUAL' then
1717
result = tostring(parameters[instance]['values']['1']) == parameters[instance]['criteria']['1']
18+
19+
elseif parameters[instance]['logic'] == 'ADD' then
20+
if parameters[instance]['values']['1'] ~= '' and parameters[instance]['values']['2'] ~= '' then
21+
local val1 = tonumber(parameters[instance]['values']['1'])
22+
local val2 = tonumber(parameters[instance]['values']['2'])
23+
if val1 ~= nil and val2 ~= nil then
24+
result = true
25+
parameters[instance]['values']['1'] = val1 + val2
26+
end
27+
elseif parameters[instance]['values']['1'] ~= '' then
28+
local val1 = tonumber(parameters[instance]['values']['1'])
29+
local val2 = tonumber(parameters[instance]['criteria']['1'])
30+
if val1 ~= nil and val2 ~= nil then
31+
result = true
32+
parameters[instance]['values']['1'] = val1 + val2
33+
end
34+
end
35+
36+
elseif parameters[instance]['logic'] == 'SUBTRACT' then
37+
if parameters[instance]['values']['1'] ~= '' and parameters[instance]['values']['2'] ~= '' then
38+
local val1 = tonumber(parameters[instance]['values']['1'])
39+
local val2 = tonumber(parameters[instance]['values']['2'])
40+
if val1 ~= nil and val2 ~= nil then
41+
result = true
42+
parameters[instance]['values']['1'] = val1 + val2
43+
end
44+
elseif parameters[instance]['values']['1'] ~= '' then
45+
local val1 = tonumber(parameters[instance]['values']['1'])
46+
local val2 = tonumber(parameters[instance]['criteria']['1'])
47+
if val1 ~= nil and val2 ~= nil then
48+
result = true
49+
parameters[instance]['values']['1'] = val1 - val2
50+
end
51+
end
52+
53+
elseif parameters[instance]['logic'] == 'MULTIPLY' then
54+
if parameters[instance]['values']['1'] ~= '' and parameters[instance]['values']['2'] ~= '' then
55+
local val1 = tonumber(parameters[instance]['values']['1'])
56+
local val2 = tonumber(parameters[instance]['values']['2'])
57+
if val1 ~= nil and val2 ~= nil then
58+
result = true
59+
parameters[instance]['values']['1'] = val1 + val2
60+
end
61+
elseif parameters[instance]['values']['1'] ~= '' then
62+
local val1 = tonumber(parameters[instance]['values']['1'])
63+
local val2 = tonumber(parameters[instance]['criteria']['1'])
64+
if val1 ~= nil and val2 ~= nil then
65+
result = true
66+
parameters[instance]['values']['1'] = val1 * val2
67+
end
68+
end
69+
70+
elseif parameters[instance]['logic'] == 'DIVIDE' then
71+
if parameters[instance]['values']['1'] ~= '' and parameters[instance]['values']['2'] ~= '' then
72+
local val1 = tonumber(parameters[instance]['values']['1'])
73+
local val2 = tonumber(parameters[instance]['values']['2'])
74+
if val1 ~= nil and val2 ~= nil then
75+
result = true
76+
parameters[instance]['values']['1'] = val1 + val2
77+
end
78+
elseif parameters[instance]['values']['1'] ~= '' then
79+
local val1 = tonumber(parameters[instance]['values']['1'])
80+
local val2 = tonumber(parameters[instance]['criteria']['1'])
81+
if val1 ~= nil and val2 ~= nil then
82+
result = true
83+
parameters[instance]['values']['1'] = val1 / val2
84+
end
85+
end
86+
87+
elseif parameters[instance]['logic'] == 'FLOOR' then
88+
if parameters[instance]['values']['1'] ~= '' then
89+
local val1 = tonumber(parameters[instance]['values']['1'])
90+
if val1 ~= nil then
91+
local roundingValue = tonumber(parameters[instance]['criteria']['1'])
92+
if roundingValue ~= nil and roundingValue >= 1 then
93+
result = true
94+
parameters[instance]['values']['1'] = math.floor(val1*10^roundingValue+0.5)/10^roundingValue
95+
else
96+
result = true
97+
parameters[instance]['values']['1'] = math.floor(val1+0.5)
98+
end
99+
end
100+
end
101+
18102
elseif parameters[instance]['logic'] == 'AND' then
19103
if type(parameters[instance]['values']['1']) == 'boolean' and type(parameters[instance]['values']['2']) == 'boolean' then
20104
result = parameters[instance]['values']['1'] and parameters[instance]['values']['2']
@@ -61,6 +145,20 @@ local function runOperator(instance)
61145
if type(parameters[instance]['values']['1']) == 'number' then
62146
result = parameters[instance]['values']['1'] <= tonumber(parameters[instance]['criteria']['1'])
63147
end
148+
elseif parameters[instance]['logic'] == 'FALLING_EDGE' then
149+
if type(parameters[instance]['values']['1']) == 'boolean' then
150+
if parameters[instance]['values']['1'] == false then
151+
if parameters[instance]['values']['2'] == true then
152+
result = true
153+
else
154+
result = false
155+
end
156+
parameters[instance]['values']['2'] = false
157+
else
158+
result = false
159+
parameters[instance]['values']['2'] = true
160+
end
161+
end
64162
elseif parameters[instance]['logic'] == 'RISING_EDGE' then
65163
if type(parameters[instance]['values']['1']) == 'boolean' then
66164
if parameters[instance]['values']['1'] == true then
@@ -107,7 +205,7 @@ local function runOperator(instance)
107205
if result == nil then
108206
_G.logger:warning("CSK_FlowConfig: Error within operartor")
109207
else
110-
if parameters[instance]['logic'] == 'RISING_EDGE' then
208+
if parameters[instance]['logic'] == 'RISING_EDGE' or parameters[instance]['logic'] == 'FALLING_EDGE' then
111209
if result == true then
112210
Script.notifyEvent(parameters[instance]['event'], true)
113211
end
@@ -116,15 +214,15 @@ local function runOperator(instance)
116214
end
117215

118216
if result == true then
119-
if parameters[instance]['logic'] == 'EQUAL' or parameters[instance]['logic'] == 'GREATER' or parameters[instance]['logic'] == 'GREATER_EQUAL' or parameters[instance]['logic'] == 'SMALLER' or parameters[instance]['logic'] == 'SMALLER_EQUAL' or parameters[instance]['logic'] == 'WITHIN_RANGE' or parameters[instance]['logic'] == 'OUT_OF_RANGE' or parameters[instance]['logic'] == 'CHANGED' or parameters[instance]['logic'] == 'TO_NUMBER' or parameters[instance]['logic'] == 'TO_STRING' then
217+
if parameters[instance]['logic'] == 'EQUAL' or parameters[instance]['logic'] == 'GREATER' or parameters[instance]['logic'] == 'GREATER_EQUAL' or parameters[instance]['logic'] == 'SMALLER' or parameters[instance]['logic'] == 'SMALLER_EQUAL' or parameters[instance]['logic'] == 'WITHIN_RANGE' or parameters[instance]['logic'] == 'OUT_OF_RANGE' or parameters[instance]['logic'] == 'CHANGED' or parameters[instance]['logic'] == 'TO_NUMBER' or parameters[instance]['logic'] == 'TO_STRING' or parameters[instance]['logic'] == 'ADD' or parameters[instance]['logic'] == 'SUBTRACT' or parameters[instance]['logic'] == 'MULTIPLY' or parameters[instance]['logic'] == 'DIVIDE' or parameters[instance]['logic'] == 'FLOOR' then
120218
Script.notifyEvent(parameters[instance]['forwardEvent'], parameters[instance]['values']['1'])
121219
end
122220
end
123221
end
124222

125223
if parameters[instance]['logic'] ~= 'AND_PREV' and parameters[instance]['logic'] ~= 'OR_PREV' then
126224
parameters[instance]['values']['1'] = ''
127-
if parameters[instance]['logic'] ~= 'RISING_EDGE' then
225+
if parameters[instance]['logic'] ~= 'RISING_EDGE' and parameters[instance]['logic'] ~= 'FALLING_EDGE' then
128226
parameters[instance]['values']['2'] = ''
129227
end
130228
end
@@ -156,7 +254,7 @@ local function addLogicBlock(instance, logic, source1, source2, criteriaA, crite
156254
parameters[instance]['values']['1'] = ''
157255
parameters[instance]['values']['2'] = ''
158256

159-
if logic == 'RISING_EDGE' then
257+
if logic == 'RISING_EDGE' or logic == 'FALLING_EDGE' then
160258
parameters[instance]['values']['2'] = false
161259
end
162260

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
-- Block namespace
2+
local BLOCK_NAMESPACE = 'FlowConfig_FC.NotifyEvent'
3+
local nameOfModule = 'CSK_FlowConfig'
4+
5+
--*************************************************************
6+
--*************************************************************
7+
8+
-- Required to keep track of already allocated resource
9+
local instanceTable = {}
10+
local internalFunctions = {}
11+
12+
local function notifyEvent(handle, source)
13+
14+
-- Optionally check for specific parameter
15+
local eventName = Container.get(handle, 'EventName')
16+
17+
-- Check incoming value
18+
if source then
19+
local function forwardData(data1, data2, data3, data4)
20+
if data1 ~= nil and data2 ~= nil and data3 ~= nil and data4 ~= nil then
21+
Script.notifyEvent('FlowConfig_' .. eventName, data1, data2, data3, data4)
22+
elseif data1 ~= nil and data2 ~= nil and data3 ~= nil then
23+
Script.notifyEvent('FlowConfig_' .. eventName, data1, data2, data3)
24+
elseif data1 ~= nil and data2 ~= nil then
25+
Script.notifyEvent('FlowConfig_' .. eventName, data1, data2)
26+
elseif data1 ~= nil then
27+
Script.notifyEvent('FlowConfig_' .. eventName, data1)
28+
end
29+
end
30+
if not Script.isServedAsEvent('CSK_FlowConfig.' .. tostring(eventName)) then
31+
Script.serveEvent('CSK_FlowConfig.' .. tostring(eventName), 'FlowConfig_' .. eventName, 'auto:[?*],auto:[?*],auto:[?*],auto:[?*]')
32+
end
33+
internalFunctions[source] = forwardData
34+
Script.register(source, internalFunctions[source])
35+
end
36+
end
37+
Script.serveFunction(BLOCK_NAMESPACE .. '.notifyEvent', notifyEvent)
38+
39+
--*************************************************************
40+
--*************************************************************
41+
42+
local function create(eventName)
43+
44+
-- Check for multiple instances if same instance is already configured
45+
if instanceTable[eventName] ~= nil then
46+
_G.logger:warning(nameOfModule .. "Instance already in use, please choose another one")
47+
return nil
48+
else
49+
-- Otherwise create handle and store the restriced resource
50+
local handle = Container.create()
51+
instanceTable[eventName] = eventName
52+
Container.add(handle, 'EventName', eventName)
53+
54+
return handle
55+
end
56+
end
57+
Script.serveFunction(BLOCK_NAMESPACE .. '.create', create)
58+
59+
--- Function to reset instances if FlowConfig was cleared
60+
local function handleOnClearOldFlow()
61+
for key, value in pairs(internalFunctions) do
62+
Script.deregister(key, internalFunctions[key])
63+
end
64+
Script.releaseObject(instanceTable)
65+
Script.releaseObject(internalFunctions)
66+
instanceTable = {}
67+
internalFunctions = {}
68+
end
69+
Script.register('CSK_FlowConfig.OnClearOldFlow', handleOnClearOldFlow)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
-- Block namespace
2+
local BLOCK_NAMESPACE = "FlowConfig_FC.OnEvent"
3+
local nameOfModule = 'CSK_FlowConfig'
4+
5+
--*************************************************************
6+
--*************************************************************
7+
8+
-- Required to keep track of already allocated resource
9+
local instanceTable = {}
10+
11+
local function register(handle, _ , callback)
12+
13+
Container.remove(handle, "CB_Function")
14+
Container.add(handle, "CB_Function", callback)
15+
16+
local eventName = Container.get(handle, 'EventName')
17+
18+
local function localCallback()
19+
if callback ~= nil then
20+
Script.callFunction(callback, eventName)
21+
else
22+
_G.logger:warning(nameOfModule .. ": " .. BLOCK_NAMESPACE .. ".CB_Function missing!")
23+
end
24+
end
25+
Script.register('CSK_FlowConfig.OnNewFlowConfig', localCallback)
26+
27+
return true
28+
end
29+
Script.serveFunction(BLOCK_NAMESPACE ..".register", register)
30+
31+
--*************************************************************
32+
--*************************************************************
33+
34+
local function create(eventName)
35+
36+
-- Check if same instance is already configured
37+
if nil ~= instanceTable[eventName] then
38+
_G.logger:warning(nameOfModule .. ": Timer already in use, please choose another one")
39+
return nil
40+
else
41+
-- Otherwise create handle and store the restriced resource
42+
local handle = Container.create()
43+
instanceTable[eventName] = eventName
44+
Container.add(handle, 'EventName', eventName)
45+
Container.add(handle, "CB_Function", "")
46+
return(handle)
47+
end
48+
end
49+
Script.serveFunction(BLOCK_NAMESPACE .. ".create", create)
50+
51+
--- Function to reset instances if FlowConfig was cleared
52+
local function handleOnClearOldFlow()
53+
Script.releaseObject(instanceTable)
54+
instanceTable = {}
55+
end
56+
Script.register('CSK_FlowConfig.OnClearOldFlow', handleOnClearOldFlow)

CSK_Module_FlowConfig/scripts/Communication/FlowConfig/Features/FlowConfig_OnNewValue.lua

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)