fix(fb_room): latch ha_all_on/off on rising edge, not level
Node-RED sends ha_all_on and ha_all_off as short NVL pulses (same as zigbee_swN). Level-sensitive IF switches.ha_all_on caused all outputs to drop when the pulse cleared (~1s flash then off). Use R_TRIG plus all_on_latch: ALL ON edge latches room on until ALL OFF edge. Document behaviour and Node-RED sparse merge in integration guide. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -14,12 +14,20 @@ VAR
|
||||
l4: fb_light;
|
||||
l5: fb_light;
|
||||
l6: fb_light;
|
||||
r_trig_all_on: R_TRIG;
|
||||
r_trig_all_off: R_TRIG;
|
||||
all_on_latch: BOOL := FALSE; // Latched room-wide ON until ha_all_off rising edge
|
||||
END_VAR
|
||||
|
||||
(* === IMPLEMENTATION === *)
|
||||
// =====================================================
|
||||
// fb_room - Implementation (per redesign)
|
||||
// =====================================================
|
||||
// Per-light: ha_lN_on/off and zigbee_swN use R_TRIG in fb_light (NVL pulses).
|
||||
// Room-wide: ha_all_on / ha_all_off are also rising-edge pulses from Node-RED;
|
||||
// latch all_on_latch so outputs stay on after the pulse ends (do not use level
|
||||
// on switches.ha_all_on — a FALSE NVL bit would drop back to per-light state).
|
||||
// =====================================================
|
||||
|
||||
// Light 1..6 (relay_status = previous cycle output for Option C)
|
||||
l1(ha_on := switches.ha_l1_on, ha_off := switches.ha_l1_off, zigbee_sw := switches.zigbee_sw1, relay_status := relay_status.l_1);
|
||||
@@ -40,15 +48,17 @@ lights.l_5 := l5.light_output;
|
||||
l6(ha_on := switches.ha_l6_on, ha_off := switches.ha_l6_off, zigbee_sw := switches.zigbee_sw6, relay_status := relay_status.l_6);
|
||||
lights.l_6 := l6.light_output;
|
||||
|
||||
// Global Commands (overwrite outputs per redesign)
|
||||
IF switches.ha_all_off THEN
|
||||
lights.l_1 := FALSE;
|
||||
lights.l_2 := FALSE;
|
||||
lights.l_3 := FALSE;
|
||||
lights.l_4 := FALSE;
|
||||
lights.l_5 := FALSE;
|
||||
lights.l_6 := FALSE;
|
||||
ELSIF switches.ha_all_on THEN
|
||||
// Room-wide commands (rising edge + latch)
|
||||
r_trig_all_on(CLK := switches.ha_all_on);
|
||||
r_trig_all_off(CLK := switches.ha_all_off);
|
||||
|
||||
IF r_trig_all_on.Q THEN
|
||||
all_on_latch := TRUE;
|
||||
ELSIF r_trig_all_off.Q THEN
|
||||
all_on_latch := FALSE;
|
||||
END_IF;
|
||||
|
||||
IF all_on_latch THEN
|
||||
lights.l_1 := TRUE;
|
||||
lights.l_2 := TRUE;
|
||||
lights.l_3 := TRUE;
|
||||
|
||||
Reference in New Issue
Block a user