mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-08-17 16:21:15 +02:00
mode-button: move code into function
This commit is contained in:
parent
50e1c45880
commit
400516295e
1 changed files with 56 additions and 51 deletions
|
@ -8,10 +8,12 @@
|
||||||
# act on multiple mode and reset button presses
|
# act on multiple mode and reset button presses
|
||||||
# https://git.eworm.de/cgit/routeros-scripts/about/doc/mode-button.md
|
# https://git.eworm.de/cgit/routeros-scripts/about/doc/mode-button.md
|
||||||
|
|
||||||
:local 0 [ :jobname ];
|
|
||||||
:global GlobalFunctionsReady;
|
:global GlobalFunctionsReady;
|
||||||
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
||||||
|
|
||||||
|
:local Main do={
|
||||||
|
:local ScriptName [ :tostr $1 ];
|
||||||
|
|
||||||
:global ModeButton;
|
:global ModeButton;
|
||||||
|
|
||||||
:global LogPrintExit2;
|
:global LogPrintExit2;
|
||||||
|
@ -21,7 +23,7 @@
|
||||||
:local Scheduler [ /system/scheduler/find where name="_ModeButtonScheduler" ];
|
:local Scheduler [ /system/scheduler/find where name="_ModeButtonScheduler" ];
|
||||||
|
|
||||||
:if ([ :len $Scheduler ] = 0) do={
|
:if ([ :len $Scheduler ] = 0) do={
|
||||||
$LogPrintExit2 info $0 ("Creating scheduler _ModeButtonScheduler, counting presses...") false;
|
$LogPrintExit2 info $ScriptName ("Creating scheduler _ModeButtonScheduler, counting presses...") false;
|
||||||
:global ModeButtonScheduler do={
|
:global ModeButtonScheduler do={
|
||||||
:global ModeButton;
|
:global ModeButton;
|
||||||
|
|
||||||
|
@ -50,7 +52,7 @@
|
||||||
|
|
||||||
:if ([ :len $Code ] > 0) do={
|
:if ([ :len $Code ] > 0) do={
|
||||||
:if ([ $ValidateSyntax $Code ] = true) do={
|
:if ([ $ValidateSyntax $Code ] = true) do={
|
||||||
$LogPrintExit2 info $0 ("Acting on " . $Count . " mode-button presses: " . $Code) false;
|
$LogPrintExit2 info $ScriptName ("Acting on " . $Count . " mode-button presses: " . $Code) false;
|
||||||
|
|
||||||
:for I from=1 to=$Count do={
|
:for I from=1 to=$Count do={
|
||||||
$LEDInvert;
|
$LEDInvert;
|
||||||
|
@ -64,15 +66,18 @@
|
||||||
|
|
||||||
[ :parse $Code ];
|
[ :parse $Code ];
|
||||||
} else={
|
} else={
|
||||||
$LogPrintExit2 warning $0 ("The code for " . $Count . " mode-button presses failed syntax validation!") false;
|
$LogPrintExit2 warning $ScriptName ("The code for " . $Count . " mode-button presses failed syntax validation!") false;
|
||||||
}
|
}
|
||||||
} else={
|
} else={
|
||||||
$LogPrintExit2 info $0 ("No action defined for " . $Count . " mode-button presses.") false;
|
$LogPrintExit2 info $ScriptName ("No action defined for " . $Count . " mode-button presses.") false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/system/scheduler/add name="_ModeButtonScheduler" \
|
/system/scheduler/add name="_ModeButtonScheduler" \
|
||||||
on-event=":global ModeButtonScheduler; \$ModeButtonScheduler;" interval=3s;
|
on-event=":global ModeButtonScheduler; \$ModeButtonScheduler;" interval=3s;
|
||||||
} else={
|
} else={
|
||||||
$LogPrintExit2 debug $0 ("Updating scheduler _ModeButtonScheduler...") false;
|
$LogPrintExit2 debug $ScriptName ("Updating scheduler _ModeButtonScheduler...") false;
|
||||||
/system/scheduler/set $Scheduler start-time=[ /system/clock/get time ];
|
/system/scheduler/set $Scheduler start-time=[ /system/clock/get time ];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$Main [ :jobname ];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue