This commit is contained in:
olikraus 2016-06-07 08:14:34 +05:30
parent 5d4e4d7e1d
commit b47cf07122
3 changed files with 43 additions and 4 deletions

View File

@ -234,20 +234,27 @@ uint8_t u8g2_UserInterfaceSelectionList(u8g2_t *u8g2, const char *title, uint8_t
u8g2_DrawSelectionList(u8g2, &u8sl, yy, sl);
} while( u8g2_NextPage(u8g2) );
#ifdef __unix__
utf8_show();
#endif
for(;;)
{
event = u8g2_GetMenuEvent(u8g2);
event = u8x8_GetMenuEvent(u8g2_GetU8x8(u8g2));
if ( event == U8X8_MSG_GPIO_MENU_SELECT )
return u8sl.current_pos;
else if ( event == U8X8_MSG_GPIO_MENU_HOME )
return start_pos;
else if ( event == U8X8_MSG_GPIO_MENU_NEXT )
{
puts("NEXT");
u8sl_Next(&u8sl);
break;
}
else if ( event == U8X8_MSG_GPIO_MENU_PREV )
{
u8sl_Prev(&u8sl);
break;
}
}
}

View File

@ -99,10 +99,40 @@ static uint8_t u8x8_find_first_diff(uint8_t a, uint8_t b)
--> State C
u8x8->debounce_last_pin_state != current_state
--> State A
*/
#ifdef __unix__
#include <stdio.h>
#include <stdlib.h>
uint8_t u8x8_GetMenuEvent(u8x8_t *u8x8)
{
int c;
c = getc(stdin);
switch(c)
{
case 'n':
return U8X8_MSG_GPIO_MENU_NEXT;
case 'p':
return U8X8_MSG_GPIO_MENU_PREV;
case 's':
return U8X8_MSG_GPIO_MENU_SELECT;
case 'h':
return U8X8_MSG_GPIO_MENU_HOME;
case 'x':
exit(0);
default:
puts("press n, p, s, h or x");
break;
}
return 0;
}
#else /* __unix__ */
#define U8X8_DEBOUNCE_WAIT 1
/* do debounce and return a GPIO msg which indicates the event */
/* returns 0, if there is no event */
@ -155,3 +185,5 @@ uint8_t u8x8_GetMenuEvent(u8x8_t *u8x8)
}
return result_msg;
}
#endif /* __unix__ */

View File

@ -19,7 +19,7 @@ int main(void)
u8g2_SetFont(&u8g2, u8g2_font_5x7_mf);
u8g2_SetFontDirection(&u8g2, 0);
u8g2_UserInterfaceSelectionList(&u8g2, "Title", 0, "abc\ndef\nghi");
u8g2_UserInterfaceSelectionList(&u8g2, "Title", 0, "abc\ndef\nghi\njkl");
utf8_show();