aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/mode-button.md12
-rw-r--r--global-config2
-rw-r--r--global-config-overlay2
-rw-r--r--global-config.changes1
-rw-r--r--global-functions2
-rw-r--r--mode-button54
-rw-r--r--mode-button-event20
-rw-r--r--mode-button-scheduler30
8 files changed, 66 insertions, 57 deletions
diff --git a/doc/mode-button.md b/doc/mode-button.md
index 6469e54..a44b571 100644
--- a/doc/mode-button.md
+++ b/doc/mode-button.md
@@ -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
-------------
diff --git a/global-config b/global-config
index 759356c..c90c4cb 100644
--- a/global-config
+++ b/global-config
@@ -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";
diff --git a/global-config-overlay b/global-config-overlay
index 0bc7cbb..246c013 100644
--- a/global-config-overlay
+++ b/global-config-overlay
@@ -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.
diff --git a/global-config.changes b/global-config.changes
index 4120695..aadc588 100644
--- a/global-config.changes
+++ b/global-config.changes
@@ -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'.";
};
diff --git a/global-functions b/global-functions
index 2dafe4b..38c6cde 100644
--- a/global-functions
+++ b/global-functions
@@ -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;
diff --git a/mode-button b/mode-button
new file mode 100644
index 0000000..242cb46
--- /dev/null
+++ b/mode-button
@@ -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 ];
+}
diff --git a/mode-button-event b/mode-button-event
index 7039852..b31ddc3 100644
--- a/mode-button-event
+++ b/mode-button-event
@@ -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;
diff --git a/mode-button-scheduler b/mode-button-scheduler
index 6c1f554..8844e49 100644
--- a/mode-button-scheduler
+++ b/mode-button-scheduler
@@ -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;