38 memset(mtree, 0,
sizeof(mtree));
59 ERR(
"description string is NULL");
61 }
else if(parent != 0 &&
62 (parent > mi.total || mtree[parent-1].mfunc != NULL))
64 if(parent > mi.total)
ERR(
"wrong parent num");
65 else ERR(
"parent menu should be NULL function");
68 ERR(
"not enough menu space");
73 len = strlen((
char*)desc);
74 mtree[mi.total].desc = malloc(len+1);
75 if(mtree[mi.total].desc == NULL) {
76 ERRA(
"malloc fail - size(%d)", len+1);
79 strcpy((
char*)mtree[mi.total].desc, (
char*)desc);
81 mtree[mi.total].parent = parent;
82 mtree[mi.total].mfunc = mfunc;
97 printf(
"=== Menu Tree ===========================\r\n");
98 printf(
" Idx Exp Par Desc\r\n");
99 printf(
"-----------------------------------------\r\n");
101 printf(
" %-3d %c %-3d %s\r\n",
102 i+1, mtree[i].mfunc==NULL?
'v':
' ', mtree[i].parent, mtree[i].desc);
104 printf(
"=========================================\r\n");
119 static uint8 depth = 1, buf_len = 0;
122 if(recv_char ==
RET_NOK)
return;
124 if(isgraph(recv_char) == 0) {
134 for(i=0; i<depth; i++) PUTCHAR('>
');
137 case 0x08: //printf("<BS>\r\n");
144 case 0x7f: //printf("<DEL>\r\n");
145 memset(buf, 0, CMD_BUF_SIZE);
146 buf_len = 0; //printf("DEL: cur(%d), mfunc(%c), depth(%d)\r\n", mi.cur, mtree[mi.cur-1].mfunc==NULL?'N
':'Y
', depth);
148 if(mtree[mi.cur-1].mfunc)
149 mtree[mi.cur-1].mfunc(MC_END, buf);
150 mi.cur = mtree[mi.cur-1].parent;
155 case 0x1b: //printf("<ESC>\r\n");
159 } else if(buf_len < CMD_BUF_SIZE-1){
160 buf[buf_len++] = (uint8_t)recv_char; //buf[buf_len] = 0;
161 PUTCHAR(recv_char); //printf(" buf(%c, %s)\r\n", recv_char, buf);
163 printf("input buffer stuffed\r\n");
166 if(recv_char != 0x0d && recv_char != 0x7f) return; //LOGA("Command: %s", buf);
168 if(mi.cur == 0 || mtree[mi.cur-1].mfunc == NULL) // Out of the tem
171 if(str_check(isdigit, buf) == RET_OK) {//printf("digit(%d)\r\n", atoi(buf));
172 tmp8 = atoi((char*)buf);
173 if(depth > 1 && tmp8 == 0) { // If 0 entered, return to upper menu
175 if(mtree[mi.cur-1].mfunc)
176 mtree[mi.cur-1].mfunc(MC_END, buf);
177 mi.cur = mtree[mi.cur-1].parent;
180 } else printf("return tried despite root");
181 } else { // If not 0, search that menu
182 for(i=0; i<mi.total; i++) {
183 if(mi.cur == mtree[i].parent) {//printf("-i(%d)\r\n", i);
189 if(i < mi.total) { //DBGA("-set cur(%d)", tmp8);
192 if(mtree[mi.cur-1].mfunc) {
193 ret = mtree[mi.cur-1].mfunc(MC_START, buf);
195 mtree[mi.cur-1].mfunc(MC_END, buf);
204 } else printf("wrong number(%s)\r\n", buf);
206 } else printf("not digit(%s)\r\n", buf);
212 mtree[mi.cur-1].mfunc(MC_END, buf);
213 mi.cur = mtree[mi.cur-1].parent;
217 ret = mtree[mi.cur-1].mfunc(MC_DATA, buf);
218 if(ret != RET_OK) { //printf("process continue\r\n");
219 } else { //printf("process done\r\n");
220 mtree[mi.cur-1].mfunc(MC_END, buf);
221 mi.cur = mtree[mi.cur-1].parent;
228 printf("\r\n=== MENU ================================\r\n");
229 if(depth > 1) printf(" 0: Back\r\n");
230 for(i=0, cnt=0; i<mi.total; i++) {
231 if(mi.cur == mtree[i].parent) {
233 if(mtree[i].mfunc == NULL) {
235 printf(" +%d: %s\r\n", cnt, mtree[i].desc);
236 else printf("+%2d: %s\r\n", cnt, mtree[i].desc);
239 printf(" %d: %s\r\n", cnt, mtree[i].desc);
240 else printf(" %2d: %s\r\n", cnt, mtree[i].desc);
244 printf("=========================================\r\n");
247 memset(buf, 0, CMD_BUF_SIZE);
250 for(i=0; i<depth; i++) PUTCHAR('>
');