implement menu on LCD
Stefan Schuermans authored 12 years ago
|
1) #include "config.h"
2) #include "eth.h"
|
added debug output functions
Stefan Schuermans authored 12 years ago
|
3) #include "format.h"
|
implement menu on LCD
Stefan Schuermans authored 12 years ago
|
4) #include "lcd.h"
5) #include "macros.h"
6) #include "menu.h"
7) #include "switches.h"
8)
9) /// last value of rotary knob
10) static unsigned int menu_cur_rot_val = 0;
11)
12) /// current screen
13) static int menu_cur_screen = 0;
14)
15) /// current content on screen
16) static char menu_cur_content[16];
17)
18) /**
19) * @brief update screen content
20) * @param[in] str new content to display
21) */
22) static void menu_update_content(const char *str)
23) {
24) unsigned int i;
25)
26) // update only characters that changed (LCD is slow)
27) for (i = 0; str[i] != 0 && i < 16; ++i) {
28) if (menu_cur_content[i] != str[i]) {
29) menu_cur_content[i] = str[i];
30) lcd_chr(1, i, str[i]);
31) }
32) }
33) // clear rest of line
34) for (; i < 16; ++i) {
35) if (menu_cur_content[i] != ' ') {
36) menu_cur_content[i] = ' ';
37) lcd_chr(1, i, ' ');
38) }
39) }
40) }
41)
42) /// start screen
43) static void menu_screen_start(void)
44) {
45) menu_update_content("turn knob...");
46) }
47)
48) /// switches screen
49) static void menu_screen_switches(void)
50) {
51) char buf[11];
52)
53) buf[0] = switches_get_state(sw_0) ? '0' : ' ';
54) buf[1] = switches_get_state(sw_1) ? '1' : ' ';
55) buf[2] = switches_get_state(sw_2) ? '2' : ' ';
56) buf[3] = switches_get_state(sw_3) ? '3' : ' ';
57) buf[4] = switches_get_state(sw_east) ? 'E' : ' ';
58) buf[5] = switches_get_state(sw_north) ? 'N' : ' ';
59) buf[6] = switches_get_state(sw_south) ? 'S' : ' ';
60) buf[7] = switches_get_state(sw_west) ? 'W' : ' ';
61) buf[8] = switches_get_state(sw_center) ? 'C' : ' ';
62) buf[9] = switches_get_state(sw_rot_a) ? 'a' : ' ';
63) buf[10] = switches_get_state(sw_rot_b) ? 'b' : ' ';
64) buf[11] = 0;
65)
66) menu_update_content(buf);
67) }
68)
69) /// ethernet screen
70) static void menu_screen_eth(void)
71) {
72) char buf[] = "RX 0000 TX 0000";
73)
|
added debug output functions
Stefan Schuermans authored 12 years ago
|
74) format_uint2dec(eth_rx_get_cnt(), 4, &buf[3]);
75) format_uint2dec(eth_tx_get_cnt(), 4, &buf[11]);
|
implement menu on LCD
Stefan Schuermans authored 12 years ago
|
76)
77) menu_update_content(buf);
78) }
79)
80) /// MAC address screen
81) static void menu_screen_mac(void)
82) {
83) unsigned int i;
84) char buf[] = "000000000000";
85)
86) for (i = 0; i < 6; ++i)
|
added debug output functions
Stefan Schuermans authored 12 years ago
|
87) format_uint2hex(config_mac.mac[i], 2, &buf[i * 2]);
|
implement menu on LCD
Stefan Schuermans authored 12 years ago
|
88)
89) menu_update_content(buf);
90) }
91)
92) /// IP address screen
93) static void menu_screen_ip(void)
94) {
95) unsigned int i;
96) char buf[] = "000.000.000.000";
97)
98) for (i = 0; i < 4; ++i)
|
added debug output functions
Stefan Schuermans authored 12 years ago
|
99) format_uint2dec(config_ip.ip[i], 3, &buf[i * 4]);
|
implement menu on LCD
Stefan Schuermans authored 12 years ago
|
100)
101) menu_update_content(buf);
102) }
103)
104) /// subnet mask screen
105) static void menu_screen_netmask(void)
106) {
107) unsigned int i;
108) char buf[] = "000.000.000.000";
109)
110) for (i = 0; i < 4; ++i)
|
added debug output functions
Stefan Schuermans authored 12 years ago
|
111) format_uint2dec(config_ip.mask[i], 3, &buf[i * 4]);
|
implement menu on LCD
Stefan Schuermans authored 12 years ago
|
112)
113) menu_update_content(buf);
114) }
115)
116) /// gateway IP screen
117) static void menu_screen_gateway(void)
118) {
119) unsigned int i;
120) char buf[] = "000.000.000.000";
121)
122) for (i = 0; i < 4; ++i)
|
added debug output functions
Stefan Schuermans authored 12 years ago
|
123) format_uint2dec(config_ip.gw[i], 3, &buf[i * 4]);
|