BlinkenArea - GitList
Repositories
Blog
Wiki
mips_sys
Code
Commits
Branches
Tags
Search
Tree:
902aa40
Branches
Tags
master
mips_sys
fw
menu.c
replace email address in headers with blinkenarea address
Stefan Schuermans
commited
902aa40
at 2012-05-21 17:42:50
menu.c
Blame
History
Raw
/* MIPS I system * Copyright 2011-2012 Stefan Schuermans <stefan@blinkenarea.org> * Copyleft GNU public license V2 or later * http://www.gnu.org/copyleft/gpl.html */ #include "config.h" #include "eth.h" #include "format.h" #include "lcd.h" #include "macros.h" #include "menu.h" #include "switches.h" /// last value of rotary knob static int menu_cur_rot_cnt = 0; /// current screen static int menu_cur_screen = 0; /// current content on screen static char menu_cur_content[16]; /** * @brief update screen content * @param[in] str new content to display */ static void menu_update_content(const char *str) { unsigned int i; // update only characters that changed (LCD is slow) for (i = 0; str[i] != 0 && i < 16; ++i) { if (menu_cur_content[i] != str[i]) { menu_cur_content[i] = str[i]; lcd_chr(1, i, str[i]); } } // clear rest of line for (; i < 16; ++i) { if (menu_cur_content[i] != ' ') { menu_cur_content[i] = ' '; lcd_chr(1, i, ' '); } } } /// start screen static void menu_screen_start(void) { menu_update_content("turn knob..."); } /// switches screen static void menu_screen_switches(void) { char buf[12]; buf[0] = switches_get_state(sw_0) ? '0' : ' '; buf[1] = switches_get_state(sw_1) ? '1' : ' '; buf[2] = switches_get_state(sw_2) ? '2' : ' '; buf[3] = switches_get_state(sw_3) ? '3' : ' '; buf[4] = switches_get_state(sw_east) ? 'E' : ' '; buf[5] = switches_get_state(sw_north) ? 'N' : ' '; buf[6] = switches_get_state(sw_south) ? 'S' : ' '; buf[7] = switches_get_state(sw_west) ? 'W' : ' '; buf[8] = switches_get_state(sw_center) ? 'C' : ' '; buf[9] = switches_get_state(sw_rot_a) ? 'a' : ' '; buf[10] = switches_get_state(sw_rot_b) ? 'b' : ' '; buf[11] = 0; menu_update_content(buf); } /// ethernet screen static void menu_screen_eth(void) { char buf[] = "RX 0000 TX 0000"; format_uint2dec(eth_rx_get_cnt(), 4, &buf[3]); format_uint2dec(eth_tx_get_cnt(), 4, &buf[11]); menu_update_content(buf); } /// MAC address screen static void menu_screen_mac(void) { unsigned int i; char buf[] = "000000000000"; for (i = 0; i < 6; ++i) format_uint2hex(config_mac.mac[i], 2, &buf[i * 2]); menu_update_content(buf); } /// IP address screen static void menu_screen_ip(void) { unsigned int i; char buf[] = "000.000.000.000"; for (i = 0; i < 4; ++i) format_uint2dec(config_ip.ip[i], 3, &buf[i * 4]); menu_update_content(buf); } /// subnet mask screen static void menu_screen_netmask(void) { unsigned int i; char buf[] = "000.000.000.000"; for (i = 0; i < 4; ++i) format_uint2dec(config_ip.mask[i], 3, &buf[i * 4]); menu_update_content(buf); } /// gateway IP screen static void menu_screen_gateway(void) { unsigned int i; char buf[] = "000.000.000.000"; for (i = 0; i < 4; ++i) format_uint2dec(config_ip.gw[i], 3, &buf[i * 4]); menu_update_content(buf); } /// available screens static struct menu_screen { const char *title; ///< title of screen void (*update)(void); ///< function to update screen content } menu_screens[] = { { "MIPS I", menu_screen_start }, { "switches", menu_screen_switches }, { "ethernet", menu_screen_eth }, { "MAC address", menu_screen_mac }, { "IP address", menu_screen_ip }, { "subnet mask", menu_screen_netmask }, { "gateway IP", menu_screen_gateway }, }; /// initialize void menu_init(void) { lcd_init(); menu_cur_screen = 0; lcd_str(0, menu_screens[0].title); menu_screens[0].update(); } /// task procedure - call as often as possible void menu_task(void) { // get new screen to show int new_rot_cnt = switches_get_rot_cnt(); int delta = (new_rot_cnt - menu_cur_rot_cnt) / 4; // 1 click is 4 steps menu_cur_rot_cnt += delta * 4; int new_screen = menu_cur_screen + delta; if (new_screen < 0) new_screen = count(menu_screens) - (-new_screen % count(menu_screens)); new_screen = new_screen % count(menu_screens); // screen changed -> show new title if (new_screen != menu_cur_screen) { menu_cur_screen = new_screen; lcd_str(0, menu_screens[menu_cur_screen].title); } // update current screen menu_screens[menu_cur_screen].update(); }