aboutsummaryrefslogtreecommitdiffstats
path: root/mode-button
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2020-10-23 21:24:59 +0200
committerGravatar Christian Hesse <mail@eworm.de>2020-10-23 21:24:59 +0200
commit2e4658e49a5a2e575ff6b9c0fdadb66f65142d94 (patch)
tree6898ca76e3f23803cea645225e07d7a6ebedd94e /mode-button
parent55e114c190318274f06a9749810470e6c4e8dfea (diff)
mode-button: act on led with type on or off only
Diffstat (limited to 'mode-button')
-rw-r--r--mode-button17
1 files changed, 12 insertions, 5 deletions
diff --git a/mode-button b/mode-button
index 2493208..c189ad2 100644
--- a/mode-button
+++ b/mode-button
@@ -19,14 +19,21 @@
:global ModeButtonScheduler do={
:global ModeButton;
- :global IfThenElse;
:global LogPrintExit;
:global ModeButtonScheduler;
+ :local LEDInvert do={
+ :global IfThenElse;
+
+ :local LED [ / system leds find where leds="user-led" type~"^(on|off)\$" interface=[] ];
+ :if ([ :len $LED ] = 0) do={
+ :return false;
+ }
+ / system leds set type=[ $IfThenElse ([ get $LED type ] = "on") "off" "on" ] $LED;
+ }
+
:local Count ($ModeButton->"count");
:local Code ($ModeButton->[ :tostr $Count ]);
- :local LEDState [ / system leds get [ find where leds="user-led" ] type ];
- :local LEDInvert [ $IfThenElse ($LEDState = "on") "off" "on" ];
:set ($ModeButton->"count") 0;
:set ModeButtonScheduler;
@@ -36,12 +43,12 @@
$LogPrintExit info ("Acting on " . $Count . " mode-button presses: " . $Code) false;
:for I from=1 to=$Count do={
- / system leds set type=$LEDInvert [ find where leds="user-led" type=$LEDState interface=[] ];
+ $LEDInvert;
:if ([ / system routerboard settings get silent-boot ] = false) do={
:beep length=200ms;
}
:delay 200ms;
- / system leds set type=$LEDState [ find where leds="user-led" type=$LEDInvert interface=[] ];
+ $LEDInvert;
:delay 200ms;
}