Skip to content

Commit

Permalink
Merge branch 'testing'
Browse files Browse the repository at this point in the history
  • Loading branch information
hfedcba committed Feb 24, 2019
2 parents 549fd53 + 03c8589 commit 3eadd86
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
30 changes: 24 additions & 6 deletions presence-light/PresenceLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ bool PresenceLight::init(Flows::PNodeInfo info)
settingsIterator = info->info->structValue->find("process-false");
if(settingsIterator != info->info->structValue->end()) _switchOffOnInFalse = settingsIterator->second->booleanValue;

settingsIterator = info->info->structValue->find("keep-on");
if(settingsIterator != info->info->structValue->end()) _keepOn = settingsIterator->second->booleanValue;

return true;
}
catch(const std::exception& ex)
Expand Down Expand Up @@ -221,6 +224,7 @@ void PresenceLight::timer()
setNodeData("onTo", std::make_shared<Flows::Variable>(-1));

_manuallyEnabled.store(false, std::memory_order_release);
_manuallyDisabled.store(false, std::memory_order_release);
setNodeData("manuallyEnabled", std::make_shared<Flows::Variable>(false));
}
else if(getLightState())
Expand All @@ -238,7 +242,7 @@ void PresenceLight::timer()
_lastLightEvent.store(BaseLib::HelperFunctions::getTime(), std::memory_order_release);

Flows::PVariable outputMessage = std::make_shared<Flows::Variable>(Flows::VariableType::tStruct);
bool lightState = onTo > time && (_enabled.load(std::memory_order_acquire) || _manuallyEnabled.load(std::memory_order_acquire));
bool lightState = onTo > time && (_enabled.load(std::memory_order_acquire) || _manuallyEnabled.load(std::memory_order_acquire)) && !_manuallyDisabled.load(std::memory_order_acquire);
outputMessage->structValue->emplace("payload", std::make_shared<Flows::Variable>(_booleanStateValue.load(std::memory_order_acquire) ? lightState : (lightState ? _stateValue.load(std::memory_order_acquire) : 0)));
output(0, outputMessage);

Expand Down Expand Up @@ -269,7 +273,7 @@ void PresenceLight::timer()
_lastLightEvent.store(BaseLib::HelperFunctions::getTime(), std::memory_order_release);

Flows::PVariable outputMessage = std::make_shared<Flows::Variable>(Flows::VariableType::tStruct);
bool lightState = onTo > time && (_enabled.load(std::memory_order_acquire) || _manuallyEnabled.load(std::memory_order_acquire));
bool lightState = onTo > time && (_enabled.load(std::memory_order_acquire) || _manuallyEnabled.load(std::memory_order_acquire)) && !_manuallyDisabled.load(std::memory_order_acquire);
outputMessage->structValue->emplace("payload", std::make_shared<Flows::Variable>(_booleanStateValue.load(std::memory_order_acquire) ? lightState : (lightState ? _stateValue.load(std::memory_order_acquire) : 0)));
output(0, outputMessage);

Expand Down Expand Up @@ -320,7 +324,9 @@ bool PresenceLight::getLightState()
auto onTo = _onTo.load(std::memory_order_acquire);
auto alwaysOnTo = _alwaysOnTo.load(std::memory_order_acquire);
auto alwaysOffTo = _alwaysOffTo.load(std::memory_order_acquire);
return ((_enabled.load(std::memory_order_acquire) || _manuallyEnabled.load(std::memory_order_acquire)) && onTo != -1 && BaseLib::HelperFunctions::getTime() < onTo &&
return ((_enabled.load(std::memory_order_acquire) || _manuallyEnabled.load(std::memory_order_acquire)) &&
!_manuallyDisabled.load(std::memory_order_acquire) &&
onTo != -1 && BaseLib::HelperFunctions::getTime() < onTo &&
(alwaysOffTo == -1 || (alwaysOffTo != 0 && (BaseLib::HelperFunctions::getTime() >= alwaysOffTo)))) ||
alwaysOnTo == 0 || (alwaysOnTo != -1 && BaseLib::HelperFunctions::getTime() < alwaysOnTo);
}
Expand Down Expand Up @@ -358,6 +364,10 @@ void PresenceLight::input(const Flows::PNodeInfo info, uint32_t index, const Flo
{
bool enabled = _enabled.load(std::memory_order_acquire);
if(enabled == inputValue) return;
if(!inputValue && _keepOn)
{
_manuallyEnabled.store(true, std::memory_order_release);
}
_enabled.store(inputValue, std::memory_order_release);
setNodeData("enabled", std::make_shared<Flows::Variable>(inputValue));
}
Expand Down Expand Up @@ -474,13 +484,12 @@ void PresenceLight::input(const Flows::PNodeInfo info, uint32_t index, const Flo
_stateValue.store(1, std::memory_order_release);
setNodeData("stateValue", input);
}
else if(input->type == Flows::VariableType::tInteger64 && input->integerValue64 > 0)
else if(input->type == Flows::VariableType::tInteger64)
{
_booleanStateValue.store(false, std::memory_order_release);
_stateValue.store(input->integerValue64, std::memory_order_release);
setNodeData("stateValue", input);
}
return;
}
else if(index == 6) //Toggle
{
Expand All @@ -492,10 +501,17 @@ void PresenceLight::input(const Flows::PNodeInfo info, uint32_t index, const Flo
setNodeData("stateValue", input);
}

if(!_booleanStateValue.load(std::memory_order_acquire) && input->type == Flows::VariableType::tBoolean)
{
_out->printWarning(R"(Warning: Got boolean input on "TG", but "SVAL" is set to a light profile (i. e. to an Integer).)");
return;
}

auto onTo = _onTo.load(std::memory_order_acquire);
if((!_booleanStateValue.load(std::memory_order_release) && inputValue) || onTo == -1)
if((!_booleanStateValue.load(std::memory_order_acquire) && inputValue) || onTo == -1)
{
_manuallyEnabled.store(true, std::memory_order_release);
_manuallyDisabled.store(false, std::memory_order_release);
setNodeData("manuallyEnabled", std::make_shared<Flows::Variable>(true));

auto onTime = _onTime;
Expand All @@ -508,6 +524,8 @@ void PresenceLight::input(const Flows::PNodeInfo info, uint32_t index, const Flo
}
else
{
_manuallyEnabled.store(false, std::memory_order_release);
_manuallyDisabled.store(true, std::memory_order_release);
_onTo.store(-1, std::memory_order_release);

setNodeData("manuallyEnabled", std::make_shared<Flows::Variable>(false));
Expand Down
3 changes: 3 additions & 0 deletions presence-light/PresenceLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class PresenceLight: public Flows::INode
uint32_t _alwaysOffTime = 21600000;
int64_t _lastInput = -1;
bool _switchOffOnInFalse = false;
bool _keepOn = false;
//}}}

std::atomic<int64_t> _lastLightEvent{-1};
Expand All @@ -67,7 +68,9 @@ class PresenceLight: public Flows::INode

std::atomic_bool _enabled{true};
std::atomic_bool _manuallyEnabled{false};
std::atomic_bool _manuallyDisabled{false};
std::atomic<int64_t> _onTo{-1};
int64_t _inBlockedUntil = 0;
std::atomic<int64_t> _alwaysOnTo{-1};
std::atomic<int64_t> _alwaysOffTo{-1};

Expand Down
3 changes: 2 additions & 1 deletion presence-light/locales/en-US/presence-light
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"always-on-time2": "Time in seconds",
"always-off-time": "Always off time",
"always-off-time2": "Time in seconds",
"process-false": "Switch light off immediately, when \"IN\" is set to false."
"process-false": "Switch light off immediately, when \"IN\" is set to \"false\".",
"keep-on": "Keep light on when \"EN\" is set to \"false\"."
},
"paletteHelp": "<p>This node automatically switches lights on or off depending on presence.</p>",
"help": "<p>This node automatically switches lights on or off depending on presence. A presence signal (<code>true</code>) on <code>IN</code> sets <code>S</code> to <code>SVAL</code> (<code>true</code> of a profile number greater <code>0</code>). <code>S</code> is reset to <code>false</code> or <code>0</code> after <code>On time</code>. An input of <code>true</code> on <code>ON</code> sets <code>S</code> to <code>SVAL</code> regardless of other inputs. <code>ON</code> is automatically reset after <code>Always on time</code>. When this happens, <code>RES</code> is set to true and <code>S</code> is set depending on <code>IN</code> and <code>On time</code>. An input of <code>true</code> on <code>OFF</code> sets <code>S</code> to <code>false</code> or <code>0</code> regardless of other inputs. <code>OFF</code> is automatically reset after <code>Always off time</code>. When this happens, <code>RES</code> is set to true and <code>S</code> is set depending on <code>IN</code> and <code>On time</code>. Setting <code>Always on time</code> or <code>Always off time</code> to <code>0</code>, disables the timer so the lights will stay on or off until <code>ON</code> or <code>OFF</code> are set to <code>false</code>. Setting <code>EN</code> to <code>false</code> disables processing of <code>IN</code> for example during daytime. <code>IN2</code> also sets <code>S</code> to <code>true</code> but an input of <code>false</code> to <code>IN2</code> immediately sets <code>S</code> to <code>false</code> or <code>0</code> and resets the <code>On time</code> timer. <code>TG</code> toggles <code>s</code> setting it to <code>SVAL</code> and starting the timer when it is <code>false</code> and immediately setting it to <code>false</code> resetting the timer when it is <code>true</code> or greater <code>0</code>. <code>TG</code> also works with profile (scene) numbers. <code>0</code> is recognized as the on/off profile toggling the last input scene number greater than 0. Any other number switches to that profile and also sets <code>SVAL</code>.</p><p>Note: The inputs are rate limited to one input per seconds to avoid too fast outputs.</p><p><code>On time</code>, <code>Always on time</code> and <code>Always off time</code> can also be set dynamically by setting <code>$message['onTime']</code>, <code>$message['alwaysOnTime']</code> or <code>$message['alwaysOffTime']</code></p>",
Expand Down
8 changes: 7 additions & 1 deletion presence-light/presence-light.hni
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<input type="checkbox" id="node-input-process-false" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-process-false" style="width: 60%;" data-i18n="presence-light.label.process-false"></label>
</div>
<div class="form-row">
<label style="width: 130px;">&nbsp;</label>
<input type="checkbox" id="node-input-keep-on" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-keep-on" style="width: 60%;" data-i18n="presence-light.label.keep-on"></label>
</div>
</script>
<script type="text/javascript">
RED.nodes.registerType('presence-light',{
Expand All @@ -42,7 +47,8 @@
"on-time": {value: "300",required:true,validate:RED.validators.number()},
"always-on-time": {value: "21600",required:true,validate:RED.validators.number()},
"always-off-time": {value: "21600",required:true,validate:RED.validators.number()},
"process-false": {value: false,required:false}
"process-false": {value: false,required:false},
"keep-on": {value: false,required:false}
},
inputs:7,
inputInfo: [
Expand Down
2 changes: 1 addition & 1 deletion timers/impulse/MyNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void MyNode::input(const Flows::PNodeInfo info, uint32_t index, const Flows::PVa
Flows::PVariable& input = message->structValue->at("payload");
if(*input)
{
if(!_lastInputState || (_allowRetrigger && BaseLib::HelperFunctions::getTime() > _delayTo.load(std::memory_order_acquire)))
if(!_lastInputState || _allowRetrigger)
{
_lastInputState = true;
setNodeData("lastInputState", std::make_shared<Flows::Variable>(true));
Expand Down
2 changes: 1 addition & 1 deletion variable/constant/constant.hni
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
name: {value:""},
payload: {value:"", validate: RED.validators.typedInput("payload")},
payloadType: {value:"int"},
outputonstartup: {value: true}
outputonstartup: {value: false}
},
inputs:0,
outputs:1,
Expand Down

0 comments on commit 3eadd86

Please sign in to comment.