Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Changelog
All notable changes to this project will be documented in this file.

## 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

## Release 1.4.0

### Improvement
Expand Down
Binary file modified CSK_Module_FlowConfig/pages/CSK_Module_FlowConfig.msdd
Binary file not shown.
106 changes: 60 additions & 46 deletions CSK_Module_FlowConfig/project.mf.xml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion CSK_Module_FlowConfig/scripts/CSK_FlowConfig_FlowConfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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

require('Communication.FlowConfig.Features.FlowConfig_OnNewValue')
require('Communication.FlowConfig.Features.FlowConfig_OnEvent')
require('Communication.FlowConfig.Features.FlowConfig_NotifyEvent')
require('Communication.FlowConfig.Features.FlowConfig_OnExpired')
require('Communication.FlowConfig.Features.FlowConfig_ProcessLogic')
106 changes: 102 additions & 4 deletions CSK_Module_FlowConfig/scripts/CSK_FlowConfig_LogicProcessing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,90 @@ local function runOperator(instance)
local result
if parameters[instance]['logic'] == 'EQUAL' then
result = tostring(parameters[instance]['values']['1']) == parameters[instance]['criteria']['1']

elseif parameters[instance]['logic'] == 'ADD' then
if parameters[instance]['values']['1'] ~= '' and parameters[instance]['values']['2'] ~= '' then
local val1 = tonumber(parameters[instance]['values']['1'])
local val2 = tonumber(parameters[instance]['values']['2'])
if val1 ~= nil and val2 ~= nil then
result = true
parameters[instance]['values']['1'] = val1 + val2
end
elseif parameters[instance]['values']['1'] ~= '' then
local val1 = tonumber(parameters[instance]['values']['1'])
local val2 = tonumber(parameters[instance]['criteria']['1'])
if val1 ~= nil and val2 ~= nil then
result = true
parameters[instance]['values']['1'] = val1 + val2
end
end

elseif parameters[instance]['logic'] == 'SUBTRACT' then
if parameters[instance]['values']['1'] ~= '' and parameters[instance]['values']['2'] ~= '' then
local val1 = tonumber(parameters[instance]['values']['1'])
local val2 = tonumber(parameters[instance]['values']['2'])
if val1 ~= nil and val2 ~= nil then
result = true
parameters[instance]['values']['1'] = val1 + val2
end
elseif parameters[instance]['values']['1'] ~= '' then
local val1 = tonumber(parameters[instance]['values']['1'])
local val2 = tonumber(parameters[instance]['criteria']['1'])
if val1 ~= nil and val2 ~= nil then
result = true
parameters[instance]['values']['1'] = val1 - val2
end
end

elseif parameters[instance]['logic'] == 'MULTIPLY' then
if parameters[instance]['values']['1'] ~= '' and parameters[instance]['values']['2'] ~= '' then
local val1 = tonumber(parameters[instance]['values']['1'])
local val2 = tonumber(parameters[instance]['values']['2'])
if val1 ~= nil and val2 ~= nil then
result = true
parameters[instance]['values']['1'] = val1 + val2
end
elseif parameters[instance]['values']['1'] ~= '' then
local val1 = tonumber(parameters[instance]['values']['1'])
local val2 = tonumber(parameters[instance]['criteria']['1'])
if val1 ~= nil and val2 ~= nil then
result = true
parameters[instance]['values']['1'] = val1 * val2
end
end

elseif parameters[instance]['logic'] == 'DIVIDE' then
if parameters[instance]['values']['1'] ~= '' and parameters[instance]['values']['2'] ~= '' then
local val1 = tonumber(parameters[instance]['values']['1'])
local val2 = tonumber(parameters[instance]['values']['2'])
if val1 ~= nil and val2 ~= nil then
result = true
parameters[instance]['values']['1'] = val1 + val2
end
elseif parameters[instance]['values']['1'] ~= '' then
local val1 = tonumber(parameters[instance]['values']['1'])
local val2 = tonumber(parameters[instance]['criteria']['1'])
if val1 ~= nil and val2 ~= nil then
result = true
parameters[instance]['values']['1'] = val1 / val2
end
end

elseif parameters[instance]['logic'] == 'FLOOR' then
if parameters[instance]['values']['1'] ~= '' then
local val1 = tonumber(parameters[instance]['values']['1'])
if val1 ~= nil then
local roundingValue = tonumber(parameters[instance]['criteria']['1'])
if roundingValue ~= nil and roundingValue >= 1 then
result = true
parameters[instance]['values']['1'] = math.floor(val1*10^roundingValue+0.5)/10^roundingValue
else
result = true
parameters[instance]['values']['1'] = math.floor(val1+0.5)
end
end
end

elseif parameters[instance]['logic'] == 'AND' then
if type(parameters[instance]['values']['1']) == 'boolean' and type(parameters[instance]['values']['2']) == 'boolean' then
result = parameters[instance]['values']['1'] and parameters[instance]['values']['2']
Expand Down Expand Up @@ -61,6 +145,20 @@ local function runOperator(instance)
if type(parameters[instance]['values']['1']) == 'number' then
result = parameters[instance]['values']['1'] <= tonumber(parameters[instance]['criteria']['1'])
end
elseif parameters[instance]['logic'] == 'FALLING_EDGE' then
if type(parameters[instance]['values']['1']) == 'boolean' then
if parameters[instance]['values']['1'] == false then
if parameters[instance]['values']['2'] == true then
result = true
else
result = false
end
parameters[instance]['values']['2'] = false
else
result = false
parameters[instance]['values']['2'] = true
end
end
elseif parameters[instance]['logic'] == 'RISING_EDGE' then
if type(parameters[instance]['values']['1']) == 'boolean' then
if parameters[instance]['values']['1'] == true then
Expand Down Expand Up @@ -107,7 +205,7 @@ local function runOperator(instance)
if result == nil then
_G.logger:warning("CSK_FlowConfig: Error within operartor")
else
if parameters[instance]['logic'] == 'RISING_EDGE' then
if parameters[instance]['logic'] == 'RISING_EDGE' or parameters[instance]['logic'] == 'FALLING_EDGE' then
if result == true then
Script.notifyEvent(parameters[instance]['event'], true)
end
Expand All @@ -116,15 +214,15 @@ local function runOperator(instance)
end

if result == true then
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
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
Script.notifyEvent(parameters[instance]['forwardEvent'], parameters[instance]['values']['1'])
end
end
end

if parameters[instance]['logic'] ~= 'AND_PREV' and parameters[instance]['logic'] ~= 'OR_PREV' then
parameters[instance]['values']['1'] = ''
if parameters[instance]['logic'] ~= 'RISING_EDGE' then
if parameters[instance]['logic'] ~= 'RISING_EDGE' and parameters[instance]['logic'] ~= 'FALLING_EDGE' then
parameters[instance]['values']['2'] = ''
end
end
Expand Down Expand Up @@ -156,7 +254,7 @@ local function addLogicBlock(instance, logic, source1, source2, criteriaA, crite
parameters[instance]['values']['1'] = ''
parameters[instance]['values']['2'] = ''

if logic == 'RISING_EDGE' then
if logic == 'RISING_EDGE' or logic == 'FALLING_EDGE' then
parameters[instance]['values']['2'] = false
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
-- Block namespace
local BLOCK_NAMESPACE = 'FlowConfig_FC.NotifyEvent'
local nameOfModule = 'CSK_FlowConfig'

--*************************************************************
--*************************************************************

-- Required to keep track of already allocated resource
local instanceTable = {}
local internalFunctions = {}

local function notifyEvent(handle, source)

-- Optionally check for specific parameter
local eventName = Container.get(handle, 'EventName')

-- Check incoming value
if source then
local function forwardData(data1, data2, data3, data4)
if data1 ~= nil and data2 ~= nil and data3 ~= nil and data4 ~= nil then
Script.notifyEvent('FlowConfig_' .. eventName, data1, data2, data3, data4)
elseif data1 ~= nil and data2 ~= nil and data3 ~= nil then
Script.notifyEvent('FlowConfig_' .. eventName, data1, data2, data3)
elseif data1 ~= nil and data2 ~= nil then
Script.notifyEvent('FlowConfig_' .. eventName, data1, data2)
elseif data1 ~= nil then
Script.notifyEvent('FlowConfig_' .. eventName, data1)
end
end
if not Script.isServedAsEvent('CSK_FlowConfig.' .. tostring(eventName)) then
Script.serveEvent('CSK_FlowConfig.' .. tostring(eventName), 'FlowConfig_' .. eventName, 'auto:[?*],auto:[?*],auto:[?*],auto:[?*]')
end
internalFunctions[source] = forwardData
Script.register(source, internalFunctions[source])
end
end
Script.serveFunction(BLOCK_NAMESPACE .. '.notifyEvent', notifyEvent)

--*************************************************************
--*************************************************************

local function create(eventName)

-- Check for multiple instances if same instance is already configured
if instanceTable[eventName] ~= nil then
_G.logger:warning(nameOfModule .. "Instance already in use, please choose another one")
return nil
else
-- Otherwise create handle and store the restriced resource
local handle = Container.create()
instanceTable[eventName] = eventName
Container.add(handle, 'EventName', eventName)

return handle
end
end
Script.serveFunction(BLOCK_NAMESPACE .. '.create', create)

--- Function to reset instances if FlowConfig was cleared
local function handleOnClearOldFlow()
for key, value in pairs(internalFunctions) do
Script.deregister(key, internalFunctions[key])
end
Script.releaseObject(instanceTable)
Script.releaseObject(internalFunctions)
instanceTable = {}
internalFunctions = {}
end
Script.register('CSK_FlowConfig.OnClearOldFlow', handleOnClearOldFlow)
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
-- Block namespace
local BLOCK_NAMESPACE = "FlowConfig_FC.OnEvent"
local nameOfModule = 'CSK_FlowConfig'

--*************************************************************
--*************************************************************

-- Required to keep track of already allocated resource
local instanceTable = {}

local function register(handle, _ , callback)

Container.remove(handle, "CB_Function")
Container.add(handle, "CB_Function", callback)

local eventName = Container.get(handle, 'EventName')

local function localCallback()
if callback ~= nil then
Script.callFunction(callback, eventName)
else
_G.logger:warning(nameOfModule .. ": " .. BLOCK_NAMESPACE .. ".CB_Function missing!")
end
end
Script.register('CSK_FlowConfig.OnNewFlowConfig', localCallback)

return true
end
Script.serveFunction(BLOCK_NAMESPACE ..".register", register)

--*************************************************************
--*************************************************************

local function create(eventName)

-- Check if same instance is already configured
if nil ~= instanceTable[eventName] then
_G.logger:warning(nameOfModule .. ": Timer already in use, please choose another one")
return nil
else
-- Otherwise create handle and store the restriced resource
local handle = Container.create()
instanceTable[eventName] = eventName
Container.add(handle, 'EventName', eventName)
Container.add(handle, "CB_Function", "")
return(handle)
end
end
Script.serveFunction(BLOCK_NAMESPACE .. ".create", create)

--- Function to reset instances if FlowConfig was cleared
local function handleOnClearOldFlow()
Script.releaseObject(instanceTable)
instanceTable = {}
end
Script.register('CSK_FlowConfig.OnClearOldFlow', handleOnClearOldFlow)

This file was deleted.

Loading