Using menu with rotary encoder
"Markus Dolze" <[email protected]> Tue, 14 Feb 2012 08:50:52 +0100
| Newsgroups | gmane.comp.sysutils.lcdproc |
|---|---|
| Message-ID | <[email protected]> |
Hi, a few weeks ago I got a cheap rotary / torque encoder and I wondered if I can use the LCDproc menu with it. There was some discussion about this years ago (http://lists.omnipotent.net/pipermail/lcdproc/2006-January/010369.html) but I didn't find any final result. Anyway, hooking up a rotary encoder to the parallel port is no good so I made a little AVR project (another subject of its own). Unfortunately the menu system currently requires a menu/escape key and enter key to function properly. Therefore I made a small change that: a) Changes the order of precedence of the menu and enter key while you are in the menu. b) If the enter key is the same as the menu key adds a 'back' action to the end of each menu that brings you back one level or exit the menu. Unfortunately it is not possible to have an 'escape' key with this setup so there is no way to cancel input. But this makes menus work with only two keys! I thought of using some time based mechanism to simulate an 'escape' event, but that seems to be difficult within LCDd. Patch attached. Your opinion? Do you think it is useful? Regards, Markus _______________________________________________ LCDproc mailing list [email protected] http://lists.omnipotent.net/mailman/listinfo/lcdproc
rotary.diff
(application/octet-stream, 3.8 KB)
Index: server/menu.c
===================================================================
RCS file: /cvsroot/lcdproc/lcdproc/server/menu.c,v
retrieving revision 1.41
diff -u -r1.41 menu.c
--- server/menu.c 5 Jan 2011 23:34:37 -0000 1.41
+++ server/menu.c 14 Feb 2012 00:48:59 -0000
@@ -42,6 +42,7 @@
extern Menu *custom_main_menu;
+extern bool add_back_action;
/**
@@ -209,7 +210,13 @@
if (new_menu != NULL) {
new_menu->data.menu.contents = LL_new();
new_menu->data.menu.association = NULL;
- }
+
+ if (add_back_action) {
+ MenuItem *back;
+ back = menuitem_create_action("back2", NULL, "back", NULL, MENURESULT_CLOSE);
+ menu_add_item(new_menu, back);
+ }
+ }
return new_menu;
}
@@ -245,8 +252,15 @@
if ((menu == NULL) || (item == NULL))
return;
- /* Add the item to the menu */
- LL_Push(menu->data.menu.contents, item);
+ if (add_back_action) {
+ /* Add the item before the 'back' entry which is the last */
+ menu_find_item(menu, "back2", false);
+ LL_InsertNode(menu->data.menu.contents, item);
+ }
+ else {
+ /* Add the item to the end of the menu */
+ LL_Push(menu->data.menu.contents, item);
+ }
item->parent = menu;
}
@@ -387,7 +401,7 @@
screen_add_widget(s, w);
w->text = strdup(menu->text);
w->x = 1;
- }
+ }
/* Create widgets for each subitem in the menu */
for (subitem = LL_GetFirst(menu->data.menu.contents), itemnr = 0;
@@ -724,7 +738,7 @@
// wrap araound to 1st menu entry
menu->data.menu.selector_pos = 0;
menu->data.menu.scroll = 0;
- }
+ }
return MENURESULT_NONE;
case MENUTOKEN_LEFT:
if (!(keymask & MENUTOKEN_LEFT))
@@ -785,7 +799,7 @@
return MENURESULT_NONE;
case MENUTOKEN_OTHER:
/* TODO: move to the selected number and enter it */
- default:
+ default:
return MENURESULT_NONE;
}
return MENURESULT_ERROR;
Index: server/menuscreens.c
===================================================================
RCS file: /cvsroot/lcdproc/lcdproc/server/menuscreens.c,v
retrieving revision 1.32
diff -u -r1.32 menuscreens.c
--- server/menuscreens.c 5 Jan 2011 23:34:37 -0000 1.32
+++ server/menuscreens.c 14 Feb 2012 00:48:59 -0000
@@ -48,6 +48,7 @@
char *left_key;
char *right_key;
static unsigned int keymask; /* mask of defined menu keys */
+bool add_back_action = false;
Screen *menuscreen = NULL;
MenuItem *active_menuitem = NULL;
@@ -143,6 +144,9 @@
screenlist_add(menuscreen);
+ if (is_menu_key(enter_key))
+ add_back_action = true;
+
/* Build menu */
menuscreen_create_menu();
@@ -175,19 +179,19 @@
/* Forget menu's key reservations */
input_release_client_keys(NULL);
- if (menu_key != NULL)
+ if (menu_key != NULL)
free(menu_key);
- if (enter_key != NULL)
+ if (enter_key != NULL)
free(enter_key);
- if (up_key != NULL)
+ if (up_key != NULL)
free(up_key);
- if (down_key != NULL)
+ if (down_key != NULL)
free(down_key);
if (left_key != NULL)
free(left_key);
if (right_key != NULL)
free(right_key);
- keymask = 0;
+ keymask = 0;
return 0;
}
@@ -398,12 +402,12 @@
debug(RPT_DEBUG, "%s(\"%s\")", __FUNCTION__, key);
- if ((menu_key != NULL) && (strcmp(key, menu_key) == 0)) {
- token = MENUTOKEN_MENU;
- }
- else if ((enter_key != NULL) && (strcmp(key, enter_key) == 0)) {
+ if ((enter_key != NULL) && (strcmp(key, enter_key) == 0)) {
token = MENUTOKEN_ENTER;
}
+ else if ((menu_key != NULL) && (strcmp(key, menu_key) == 0)) {
+ token = MENUTOKEN_MENU;
+ }
else if ((up_key != NULL) && (strcmp(key, up_key) == 0)) {
token = MENUTOKEN_UP;
}
@@ -613,7 +617,7 @@
menu_add_item(test_menu, test_item);
test_item = menuitem_create_ip("", NULL, "IPv6", NULL, 1, "1080:0:0:0:8:800:200C:417A");
menu_add_item(test_menu, test_item);
-
+
test_item = menuitem_create_ring("", NULL, "Charset", NULL, testiso, 0);
menu_add_item(test_menu, test_item);
}