mode-button: merge mode-button-event & mode-button-scheduler
This commit is contained in:
parent
1c4531d536
commit
8b2df7abd0
|
@ -6,7 +6,7 @@ Mode button with multiple presses
|
|||
Description
|
||||
-----------
|
||||
|
||||
These scripts extend the functionality of mode button. Instead of just one
|
||||
This script extend the functionality of mode button. Instead of just one
|
||||
you can trigger several actions by pressing the mode button several times.
|
||||
|
||||
The hardware needs to have a mode button, see
|
||||
|
@ -31,17 +31,17 @@ Copy this code to terminal to check:
|
|||
Requirements and installation
|
||||
-----------------------------
|
||||
|
||||
Just install the scripts:
|
||||
Just install the script:
|
||||
|
||||
$ScriptInstallUpdate mode-button-event,mode-button-scheduler;
|
||||
$ScriptInstallUpdate mode-button;
|
||||
|
||||
Then configure the mode button to run `mode-button-event`:
|
||||
Then configure the mode button to run `mode-button`:
|
||||
|
||||
/ system routerboard mode-button set enabled=yes on-event="/ system script run mode-button-event;";
|
||||
/ system routerboard mode-button set enabled=yes on-event="/ system script run mode-button;";
|
||||
|
||||
To use the reset button instead:
|
||||
|
||||
/ system routerboard reset-button set enabled=yes on-event="/ system script run mode-button-event;";
|
||||
/ system routerboard reset-button set enabled=yes on-event="/ system script run mode-button;";
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
# Make sure all configuration properties are up to date and this
|
||||
# value is in sync with value in script 'global-functions'!
|
||||
:global GlobalConfigVersion 31;
|
||||
:global GlobalConfigVersion 32;
|
||||
|
||||
# This is used for DNS and backup file.
|
||||
:global Domain "example.com";
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
# Make sure all configuration properties are up to date and this
|
||||
# value is in sync with value in script 'global-functions'!
|
||||
# Comment or remove to disable change notifications.
|
||||
:global GlobalConfigVersion 31;
|
||||
:global GlobalConfigVersion 32;
|
||||
|
||||
# Copy configuration from global-config here and modify it.
|
||||
|
||||
|
|
|
@ -35,4 +35,5 @@
|
|||
29="Added filter on log message text for 'log-forward'.";
|
||||
30="Implemented simple rate limit for 'log-forward' to prevent flooding.";
|
||||
31="Switched Telegram notifications to fixed-width font, with opt-out.";
|
||||
32="Merged mode (& reset) button scripts in single new script 'mode-button'.";
|
||||
};
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
# https://git.eworm.de/cgit/routeros-scripts/about/
|
||||
|
||||
# expected configuration version
|
||||
:global ExpectedConfigVersion 31;
|
||||
:global ExpectedConfigVersion 32;
|
||||
|
||||
# global variables not to be changed by user
|
||||
:global GlobalFunctionsReady false;
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
#!rsc by RouterOS
|
||||
# RouterOS script: mode-button
|
||||
# Copyright (c) 2018-2020 Christian Hesse <mail@eworm.de>
|
||||
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
||||
#
|
||||
# act on multiple mode and reset button presses
|
||||
# https://git.eworm.de/cgit/routeros-scripts/about/doc/mode-button.md
|
||||
|
||||
:global ModeButton;
|
||||
|
||||
:global LogPrintExit;
|
||||
|
||||
:set ($ModeButton->"count") ($ModeButton->"count" + 1);
|
||||
|
||||
:local Scheduler [ / system scheduler find where name="ModeButtonScheduler" ];
|
||||
|
||||
:if ([ :len $Scheduler ] = 0) do={
|
||||
$LogPrintExit info ("Creating scheduler ModeButtonScheduler, counting presses...") false;
|
||||
:global ModeButtonScheduler do={
|
||||
:global ModeButton;
|
||||
|
||||
:global LogPrintExit;
|
||||
:global ModeButtonScheduler;
|
||||
|
||||
:local Count ($ModeButton->"count");
|
||||
:local Code ($ModeButton->[ :tostr $Count ]);
|
||||
|
||||
:set ($ModeButton->"count") 0;
|
||||
:set ModeButtonScheduler;
|
||||
/ system scheduler remove ModeButtonScheduler;
|
||||
|
||||
:if ([ :len $Code ] > 0) do={
|
||||
$LogPrintExit info ("Acting on " . $Count . " mode-button presses: " . $Code) false;
|
||||
|
||||
:if ([ / system routerboard settings get silent-boot ] = false) do={
|
||||
:for I from=1 to=$Count do={
|
||||
:beep length=200ms;
|
||||
:delay 200ms;
|
||||
}
|
||||
} else={
|
||||
:delay 1s;
|
||||
}
|
||||
|
||||
[ :parse $Code ];
|
||||
} else={
|
||||
$LogPrintExit info ("No action defined for " . $Count . " mode-button presses.") false;
|
||||
}
|
||||
}
|
||||
/ system scheduler add name="ModeButtonScheduler" \
|
||||
on-event=":global ModeButtonScheduler; \$ModeButtonScheduler;" interval=3s;
|
||||
} else={
|
||||
$LogPrintExit debug ("Updating scheduler ModeButtonScheduler...") false;
|
||||
/ system scheduler set $Scheduler start-time=[ /system clock get time ];
|
||||
}
|
|
@ -1,24 +1,6 @@
|
|||
#!rsc by RouterOS
|
||||
# RouterOS script: mode-button-event
|
||||
# Copyright (c) 2018-2020 Christian Hesse <mail@eworm.de>
|
||||
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
||||
#
|
||||
# run on mode-button event and count button presses
|
||||
# https://git.eworm.de/cgit/routeros-scripts/about/doc/mode-button.md
|
||||
|
||||
:global ModeButton;
|
||||
|
||||
:global LogPrintExit;
|
||||
|
||||
:set ($ModeButton->"count") ($ModeButton->"count" + 1);
|
||||
|
||||
:local Scheduler [ / system scheduler find where name="mode-button-scheduler" ];
|
||||
|
||||
:if ([ :len $Scheduler ] = 0) do={
|
||||
$LogPrintExit info ("Creating mode-button scheduler, counting presses...") false;
|
||||
/ system scheduler add name="mode-button-scheduler" \
|
||||
on-event="/ system script run mode-button-scheduler;" interval=3s;
|
||||
} else={
|
||||
$LogPrintExit debug ("Updating mode-button-scheduler...") false;
|
||||
/ system scheduler set $Scheduler start-time=[ /system clock get time ];
|
||||
}
|
||||
$LogPrintExit warning ("This script's functionality has been merged into 'mode-button'.") true;
|
||||
|
|
|
@ -1,34 +1,6 @@
|
|||
#!rsc by RouterOS
|
||||
# RouterOS script: mode-button-scheduler
|
||||
# Copyright (c) 2018-2020 Christian Hesse <mail@eworm.de>
|
||||
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
||||
#
|
||||
# act on multiple mode-button presses from scheduler
|
||||
# https://git.eworm.de/cgit/routeros-scripts/about/doc/mode-button.md
|
||||
|
||||
:global ModeButton;
|
||||
|
||||
:global LogPrintExit;
|
||||
|
||||
:local Count ($ModeButton->"count");
|
||||
:local Code ($ModeButton->[ :tostr $Count ]);
|
||||
|
||||
:set ($ModeButton->"count") 0;
|
||||
/ system scheduler remove mode-button-scheduler;
|
||||
|
||||
:if ([ :len $Code ] > 0) do={
|
||||
$LogPrintExit info ("Acting on " . $Count . " mode-button presses: " . $Code) false;
|
||||
|
||||
:if ([ / system routerboard settings get silent-boot ] = false) do={
|
||||
:for I from=1 to=$Count do={
|
||||
:beep length=200ms;
|
||||
:delay 200ms;
|
||||
}
|
||||
} else={
|
||||
:delay 1s;
|
||||
}
|
||||
|
||||
[ :parse $Code ];
|
||||
} else={
|
||||
$LogPrintExit info ("No action defined for " . $Count . " mode-button presses.") false;
|
||||
}
|
||||
$LogPrintExit warning ("This script's functionality has been merged into 'mode-button'.") true;
|
||||
|
|
Loading…
Reference in New Issue