Skip to content

Commit 3eadd86

Browse files
committed
Merge branch 'testing'
2 parents 549fd53 + 03c8589 commit 3eadd86

File tree

6 files changed

+38
-10
lines changed

6 files changed

+38
-10
lines changed

presence-light/PresenceLight.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ bool PresenceLight::init(Flows::PNodeInfo info)
6060
settingsIterator = info->info->structValue->find("process-false");
6161
if(settingsIterator != info->info->structValue->end()) _switchOffOnInFalse = settingsIterator->second->booleanValue;
6262

63+
settingsIterator = info->info->structValue->find("keep-on");
64+
if(settingsIterator != info->info->structValue->end()) _keepOn = settingsIterator->second->booleanValue;
65+
6366
return true;
6467
}
6568
catch(const std::exception& ex)
@@ -221,6 +224,7 @@ void PresenceLight::timer()
221224
setNodeData("onTo", std::make_shared<Flows::Variable>(-1));
222225

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

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

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

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

@@ -320,7 +324,9 @@ bool PresenceLight::getLightState()
320324
auto onTo = _onTo.load(std::memory_order_acquire);
321325
auto alwaysOnTo = _alwaysOnTo.load(std::memory_order_acquire);
322326
auto alwaysOffTo = _alwaysOffTo.load(std::memory_order_acquire);
323-
return ((_enabled.load(std::memory_order_acquire) || _manuallyEnabled.load(std::memory_order_acquire)) && onTo != -1 && BaseLib::HelperFunctions::getTime() < onTo &&
327+
return ((_enabled.load(std::memory_order_acquire) || _manuallyEnabled.load(std::memory_order_acquire)) &&
328+
!_manuallyDisabled.load(std::memory_order_acquire) &&
329+
onTo != -1 && BaseLib::HelperFunctions::getTime() < onTo &&
324330
(alwaysOffTo == -1 || (alwaysOffTo != 0 && (BaseLib::HelperFunctions::getTime() >= alwaysOffTo)))) ||
325331
alwaysOnTo == 0 || (alwaysOnTo != -1 && BaseLib::HelperFunctions::getTime() < alwaysOnTo);
326332
}
@@ -358,6 +364,10 @@ void PresenceLight::input(const Flows::PNodeInfo info, uint32_t index, const Flo
358364
{
359365
bool enabled = _enabled.load(std::memory_order_acquire);
360366
if(enabled == inputValue) return;
367+
if(!inputValue && _keepOn)
368+
{
369+
_manuallyEnabled.store(true, std::memory_order_release);
370+
}
361371
_enabled.store(inputValue, std::memory_order_release);
362372
setNodeData("enabled", std::make_shared<Flows::Variable>(inputValue));
363373
}
@@ -474,13 +484,12 @@ void PresenceLight::input(const Flows::PNodeInfo info, uint32_t index, const Flo
474484
_stateValue.store(1, std::memory_order_release);
475485
setNodeData("stateValue", input);
476486
}
477-
else if(input->type == Flows::VariableType::tInteger64 && input->integerValue64 > 0)
487+
else if(input->type == Flows::VariableType::tInteger64)
478488
{
479489
_booleanStateValue.store(false, std::memory_order_release);
480490
_stateValue.store(input->integerValue64, std::memory_order_release);
481491
setNodeData("stateValue", input);
482492
}
483-
return;
484493
}
485494
else if(index == 6) //Toggle
486495
{
@@ -492,10 +501,17 @@ void PresenceLight::input(const Flows::PNodeInfo info, uint32_t index, const Flo
492501
setNodeData("stateValue", input);
493502
}
494503

504+
if(!_booleanStateValue.load(std::memory_order_acquire) && input->type == Flows::VariableType::tBoolean)
505+
{
506+
_out->printWarning(R"(Warning: Got boolean input on "TG", but "SVAL" is set to a light profile (i. e. to an Integer).)");
507+
return;
508+
}
509+
495510
auto onTo = _onTo.load(std::memory_order_acquire);
496-
if((!_booleanStateValue.load(std::memory_order_release) && inputValue) || onTo == -1)
511+
if((!_booleanStateValue.load(std::memory_order_acquire) && inputValue) || onTo == -1)
497512
{
498513
_manuallyEnabled.store(true, std::memory_order_release);
514+
_manuallyDisabled.store(false, std::memory_order_release);
499515
setNodeData("manuallyEnabled", std::make_shared<Flows::Variable>(true));
500516

501517
auto onTime = _onTime;
@@ -508,6 +524,8 @@ void PresenceLight::input(const Flows::PNodeInfo info, uint32_t index, const Flo
508524
}
509525
else
510526
{
527+
_manuallyEnabled.store(false, std::memory_order_release);
528+
_manuallyDisabled.store(true, std::memory_order_release);
511529
_onTo.store(-1, std::memory_order_release);
512530

513531
setNodeData("manuallyEnabled", std::make_shared<Flows::Variable>(false));

presence-light/PresenceLight.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class PresenceLight: public Flows::INode
5555
uint32_t _alwaysOffTime = 21600000;
5656
int64_t _lastInput = -1;
5757
bool _switchOffOnInFalse = false;
58+
bool _keepOn = false;
5859
//}}}
5960

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

6869
std::atomic_bool _enabled{true};
6970
std::atomic_bool _manuallyEnabled{false};
71+
std::atomic_bool _manuallyDisabled{false};
7072
std::atomic<int64_t> _onTo{-1};
73+
int64_t _inBlockedUntil = 0;
7174
std::atomic<int64_t> _alwaysOnTo{-1};
7275
std::atomic<int64_t> _alwaysOffTo{-1};
7376

presence-light/locales/en-US/presence-light

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"always-on-time2": "Time in seconds",
1010
"always-off-time": "Always off time",
1111
"always-off-time2": "Time in seconds",
12-
"process-false": "Switch light off immediately, when \"IN\" is set to false."
12+
"process-false": "Switch light off immediately, when \"IN\" is set to \"false\".",
13+
"keep-on": "Keep light on when \"EN\" is set to \"false\"."
1314
},
1415
"paletteHelp": "<p>This node automatically switches lights on or off depending on presence.</p>",
1516
"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>",

presence-light/presence-light.hni

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
<input type="checkbox" id="node-input-process-false" style="display: inline-block; width: auto; vertical-align: top;">
3232
<label for="node-input-process-false" style="width: 60%;" data-i18n="presence-light.label.process-false"></label>
3333
</div>
34+
<div class="form-row">
35+
<label style="width: 130px;">&nbsp;</label>
36+
<input type="checkbox" id="node-input-keep-on" style="display: inline-block; width: auto; vertical-align: top;">
37+
<label for="node-input-keep-on" style="width: 60%;" data-i18n="presence-light.label.keep-on"></label>
38+
</div>
3439
</script>
3540
<script type="text/javascript">
3641
RED.nodes.registerType('presence-light',{
@@ -42,7 +47,8 @@
4247
"on-time": {value: "300",required:true,validate:RED.validators.number()},
4348
"always-on-time": {value: "21600",required:true,validate:RED.validators.number()},
4449
"always-off-time": {value: "21600",required:true,validate:RED.validators.number()},
45-
"process-false": {value: false,required:false}
50+
"process-false": {value: false,required:false},
51+
"keep-on": {value: false,required:false}
4652
},
4753
inputs:7,
4854
inputInfo: [

timers/impulse/MyNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void MyNode::input(const Flows::PNodeInfo info, uint32_t index, const Flows::PVa
188188
Flows::PVariable& input = message->structValue->at("payload");
189189
if(*input)
190190
{
191-
if(!_lastInputState || (_allowRetrigger && BaseLib::HelperFunctions::getTime() > _delayTo.load(std::memory_order_acquire)))
191+
if(!_lastInputState || _allowRetrigger)
192192
{
193193
_lastInputState = true;
194194
setNodeData("lastInputState", std::make_shared<Flows::Variable>(true));

variable/constant/constant.hni

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
name: {value:""},
3232
payload: {value:"", validate: RED.validators.typedInput("payload")},
3333
payloadType: {value:"int"},
34-
outputonstartup: {value: true}
34+
outputonstartup: {value: false}
3535
},
3636
inputs:0,
3737
outputs:1,

0 commit comments

Comments
 (0)