mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-07-13 11:34:31 +02:00
mode-button: merge mode-button-event & mode-button-scheduler
This commit is contained in:
parent
1c4531d536
commit
8b2df7abd0
8 changed files with 66 additions and 57 deletions
|
@ -6,7 +6,7 @@ Mode button with multiple presses
|
||||||
Description
|
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.
|
you can trigger several actions by pressing the mode button several times.
|
||||||
|
|
||||||
The hardware needs to have a mode button, see
|
The hardware needs to have a mode button, see
|
||||||
|
@ -31,17 +31,17 @@ Copy this code to terminal to check:
|
||||||
Requirements and installation
|
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:
|
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
|
Configuration
|
||||||
-------------
|
-------------
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
# Make sure all configuration properties are up to date and this
|
# Make sure all configuration properties are up to date and this
|
||||||
# value is in sync with value in script 'global-functions'!
|
# value is in sync with value in script 'global-functions'!
|
||||||
:global GlobalConfigVersion 31;
|
:global GlobalConfigVersion 32;
|
||||||
|
|
||||||
# This is used for DNS and backup file.
|
# This is used for DNS and backup file.
|
||||||
:global Domain "example.com";
|
:global Domain "example.com";
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
# Make sure all configuration properties are up to date and this
|
# Make sure all configuration properties are up to date and this
|
||||||
# value is in sync with value in script 'global-functions'!
|
# value is in sync with value in script 'global-functions'!
|
||||||
# Comment or remove to disable change notifications.
|
# Comment or remove to disable change notifications.
|
||||||
:global GlobalConfigVersion 31;
|
:global GlobalConfigVersion 32;
|
||||||
|
|
||||||
# Copy configuration from global-config here and modify it.
|
# Copy configuration from global-config here and modify it.
|
||||||
|
|
||||||
|
|
|
@ -35,4 +35,5 @@
|
||||||
29="Added filter on log message text for 'log-forward'.";
|
29="Added filter on log message text for 'log-forward'.";
|
||||||
30="Implemented simple rate limit for 'log-forward' to prevent flooding.";
|
30="Implemented simple rate limit for 'log-forward' to prevent flooding.";
|
||||||
31="Switched Telegram notifications to fixed-width font, with opt-out.";
|
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/
|
# https://git.eworm.de/cgit/routeros-scripts/about/
|
||||||
|
|
||||||
# expected configuration version
|
# expected configuration version
|
||||||
:global ExpectedConfigVersion 31;
|
:global ExpectedConfigVersion 32;
|
||||||
|
|
||||||
# global variables not to be changed by user
|
# global variables not to be changed by user
|
||||||
:global GlobalFunctionsReady false;
|
:global GlobalFunctionsReady false;
|
||||||
|
|
54
mode-button
Normal file
54
mode-button
Normal file
|
@ -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
|
#!rsc by RouterOS
|
||||||
# RouterOS script: mode-button-event
|
# 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;
|
:global LogPrintExit;
|
||||||
|
|
||||||
:set ($ModeButton->"count") ($ModeButton->"count" + 1);
|
$LogPrintExit warning ("This script's functionality has been merged into 'mode-button'.") true;
|
||||||
|
|
||||||
: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 ];
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,34 +1,6 @@
|
||||||
#!rsc by RouterOS
|
#!rsc by RouterOS
|
||||||
# RouterOS script: mode-button-scheduler
|
# 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;
|
:global LogPrintExit;
|
||||||
|
|
||||||
:local Count ($ModeButton->"count");
|
$LogPrintExit warning ("This script's functionality has been merged into 'mode-button'.") true;
|
||||||
: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;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue