summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2021-04-23 23:55:16 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2021-04-24 00:00:44 -0400
commit557ff6a9818d5383c9b544ad45612b850334e1e0 (patch)
tree5b3ed5966efacf13f9c1d27a919372324d837f7d
parent14c6bb798d6bebc80f07e863236adbaf8d156a9c (diff)
downloadrockbox-557ff6a981.tar.gz
rockbox-557ff6a981.tar.bz2
rockbox-557ff6a981.zip
lua print_button script
also allow splash_scroller to be used as static text display Change-Id: Idc8c9e60ada920e2d1abd5301b59bd235e21a1c2
-rwxr-xr-xapps/plugins/lua/rbdefines_helper.pl2
-rw-r--r--apps/plugins/lua/rockaux.c44
-rw-r--r--apps/plugins/lua_scripts/print_buttons.lua70
3 files changed, 95 insertions, 21 deletions
diff --git a/apps/plugins/lua/rbdefines_helper.pl b/apps/plugins/lua/rbdefines_helper.pl
index eca09187fa..e788855e87 100755
--- a/apps/plugins/lua/rbdefines_helper.pl
+++ b/apps/plugins/lua/rbdefines_helper.pl
@@ -47,7 +47,7 @@ if ($def_type eq "rb_defines") {
'^PLAYLIST_(INSERT|PREPEND|REPLACE)',
'^TOUCHSCREEN_(POINT|BUTTON)$',
'^SYS_CHARGER_(DIS|)CONNECTED$',
- '^SYS_(TIMEOUT|POWEROFF)$',
+ '^SYS_(TIMEOUT|POWEROFF|BATTERY_UPDATE)$',
'^SYS_USB_(DIS|)CONNECTED$',
'^HOME_DIR$',
'^PLUGIN_DIR$',
diff --git a/apps/plugins/lua/rockaux.c b/apps/plugins/lua/rockaux.c
index 25bace3451..73fe458889 100644
--- a/apps/plugins/lua/rockaux.c
+++ b/apps/plugins/lua/rockaux.c
@@ -133,28 +133,32 @@ int splash_scroller(int timeout, const char* str)
}
rb->lcd_update();
-
- action = rb->get_action(CONTEXT_STD, timeout);
- switch(action)
+ if (timeout >= TIMEOUT_BLOCK)
{
- case ACTION_STD_OK:
- case ACTION_STD_CANCEL:
- cycles--;
- /* Fall Through */
- case ACTION_NONE:
- cycles--;
- break;
- case ACTION_STD_PREV:
- timeout = TIMEOUT_BLOCK; /* disable timeout */
- if(firstline > 0)
- firstline--;
- break;
- case ACTION_STD_NEXT:
- timeout = TIMEOUT_BLOCK; /* disable timeout */
- if (linesdisp == max_lines)
- firstline++;
- break;
+ action = rb->get_action(CONTEXT_STD, timeout);
+ switch(action)
+ {
+ case ACTION_STD_OK:
+ case ACTION_STD_CANCEL:
+ cycles--;
+ /* Fall Through */
+ case ACTION_NONE:
+ cycles--;
+ break;
+ case ACTION_STD_PREV:
+ timeout = TIMEOUT_BLOCK; /* disable timeout */
+ if(firstline > 0)
+ firstline--;
+ break;
+ case ACTION_STD_NEXT:
+ timeout = TIMEOUT_BLOCK; /* disable timeout */
+ if (linesdisp == max_lines)
+ firstline++;
+ break;
+ }
}
+ else
+ break;
}
return action;
}
diff --git a/apps/plugins/lua_scripts/print_buttons.lua b/apps/plugins/lua_scripts/print_buttons.lua
new file mode 100644
index 0000000000..1b488ddd64
--- /dev/null
+++ b/apps/plugins/lua_scripts/print_buttons.lua
@@ -0,0 +1,70 @@
+-- bilgus 4/2021
+require "buttons"
+local BUTTON_NONE = 0
+
+local function decode_ord_btn(btn)
+ local btntxt = ""
+ for k, v in pairs(rb.buttons) do
+ if btn > BUTTON_NONE and v ~= BUTTON_NONE and bit.band(btn, v) == v then
+ if #btntxt > 0 then
+ btntxt = btntxt .. " | "
+ end
+ btntxt = btntxt .. k
+ end
+ end
+ if btntxt == "" then return nil end
+ return btntxt
+end
+
+local _, w, h = rb.font_getstringsize("W", rb.FONT_UI)
+local max_lines = rb.LCD_HEIGHT / h - 1
+
+button_text = {}
+for k, v in pairs(rb.buttons) do
+ button_text[v] = k
+end
+
+--Add the system button codes to the button_text table
+for k, v in pairs(rb) do
+ if string.find(k or "", "SYS_", 1, true) and type(v) == "number" then
+ button_text[v] = k
+ end
+end
+
+local s = {[1] = "Buttons Found:"}
+for k, v in pairs(button_text) do
+ table.insert(s, tostring(k) .. " : " .. tostring(v))
+end
+rb.splash_scroller(rb.HZ, table.concat(s, "\n"))
+
+button_text[BUTTON_NONE] = " "
+
+local lastbtn = BUTTON_NONE
+local lastkey = BUTTON_NONE
+local s_t = {"Press same button 3x to exit"}
+local keyrpt = 0
+
+repeat
+
+ local btn
+ if lastbtn == BUTTON_NONE then
+ btn = rb.button_get(true)
+ else
+ btn = rb.button_get_w_tmo(rb.HZ)
+ end
+
+ if btn ~= lastkey then
+ table.insert(s_t, 1, (button_text[btn] or decode_ord_btn(btn) or "unknown " .. tostring (btn)))
+ end
+
+ if btn == lastbtn then keyrpt = keyrpt + 1 end
+ if button_text[btn] then lastbtn = btn end
+ lastkey = btn
+
+ rb.splash_scroller(-2, table.concat(s_t, "\n"))
+
+ if #s_t > max_lines then
+ table.remove(s_t)
+ end
+
+until keyrpt >= 2