@prettywolf @bershwu 参照
无限级菜单,做了个12864菜单。
第一行、第二行 进二级菜单都可以正常返回;
第三行,进二级菜单,无法返回,有没有人遇到类似问题,帮忙看一下.
无法通过二级目录
返回一级目录
代码
#include "menu.h"
#include "12864.h"
#include <stdio.h>
#include <stdlib.h>
uint8_t ReadValue;//按键扫描值
/*菜单结构体*/
typedef struct menu
{
u8 range_from,range_to; //当前选择的项开始及结束符号
u8 itemCount;//项目总数
u8 selected;//当前选择项
u8 *menuItems[17];//菜单项目
struct menu **subMenus;//子菜单
struct menu *parent;//上级菜单,若是主菜单则为null
void (**func)();//选择相应按键后执行的函数
}Menu;
Menu MainMenu1 = {
0,3,4,0, //默认显示0-3项,总共4项,当前选择0项,
{
"◇ 8号柜 ◇",//"x10"表示一个小箭头
"◇ 2017-03-26 ◇",
"◇ sunday ◇",
"◇ 17:10:00 ◇",
}
};
Menu dis1Menu = {
0,3,1,0, //默认显示0-3项,总共4项,当前选择0项,
{
"请刷卡存包 x10",//"x10"表示一个小箭头
" 1 x10",
" 2 x10",
" 3 x10",
}
};
Menu dis2Menu = {
0,3,1,0, //默认显示0-3项,总共4项,当前选择0项,
{
"请刷卡取包 x10",//"x10"表示一个小箭头
" x10",
" x10",
" x10",
}
};
Menu dis3Menu = {
0,3,4,0, //默认显示0-3项,总共4项,当前选择0项,
{
"请按存包键刷卡 x10",//"x10"表示一个小箭头
"存包 x10",
"请按取包键刷卡 ",
"取包 x10",
}
};
Menu *currentMenu;//当前菜单
/*用于显示菜单*/
void displaymenu(u8 line)
{
int i;
line = 3-(currentMenu->range_to-line);
/*4次循环打印菜单*/
for(i = 0;i<4;i++)
Display_LCD_String(i,currentMenu->menuItems[i+currentMenu->range_from],5);
con_disp(line,1);
}
void func(void)
{
}
void initmenu(void)
{
currentMenu = &MainMenu1;
/*0*/
MainMenu1.subMenus = malloc(sizeof(&MainMenu1)*4);
MainMenu1.subMenus[0] = &dis1Menu;
MainMenu1.subMenus[1] = &dis2Menu;
MainMenu1.subMenus[2] = &dis3Menu;
MainMenu1.subMenus[3] = NULL;
MainMenu1.func = malloc(sizeof(&func)*4);
MainMenu1.func[0] = NULL;
MainMenu1.func[1] = NULL;
MainMenu1.func[2] = NULL;
MainMenu1.func[3] = NULL;
MainMenu1.parent = NULL;//mainmenu is top menu
/*1*/
dis1Menu.subMenus = malloc(sizeof(&dis1Menu)*4);
dis1Menu.subMenus[0] = NULL;
dis1Menu.subMenus[1] = NULL;
dis1Menu.subMenus[2] = NULL;
dis1Menu.subMenus[3] = NULL;
dis1Menu.func = malloc(sizeof(&func)*4);
dis1Menu.func[0] = NULL;
dis1Menu.func[1] = NULL;
dis1Menu.func[2] = NULL;
dis1Menu.func[3] = NULL;
dis1Menu.parent = &MainMenu1;//dis1menu parent menu is mainmenu1
/*2*/
dis2Menu.subMenus = malloc(sizeof(&dis1Menu)*4);
dis2Menu.subMenus[0] = NULL;
dis2Menu.subMenus[1] = NULL;
dis2Menu.subMenus[2] = NULL;
dis2Menu.subMenus[3] = NULL;
dis2Menu.func = malloc(sizeof(&func)*4);
dis2Menu.func[0] = NULL;
dis2Menu.func[1] = NULL;
dis2Menu.func[2] = NULL;
dis2Menu.func[3] = NULL;
dis2Menu.parent = &MainMenu1;//dis2menu parent menu is mainmenu1
}
void menutest(void)
{
initmenu();
displaymenu(currentMenu->selected);
while(1)
{
if(ReadValue != 0)
{
switch(ReadValue)
{
case key_sure://按键A(确认按键)
{
if(currentMenu->subMenus[currentMenu->selected] !=NULL)
{
currentMenu = currentMenu->subMenus[currentMenu->selected];
displaymenu(0);
}
break;
}
case key_up://按键B(上一行菜单)
{
if(currentMenu->selected == 0)
break;
else
{
currentMenu->selected--;
if(currentMenu->selected < currentMenu->range_from)
{
currentMenu->range_from = currentMenu->selected;
currentMenu->range_to = currentMenu->range_from+3;
}
displaymenu(currentMenu->selected);
}
break;
}
case key_down://按键C(下一行菜单 )
{
if(currentMenu->selected == currentMenu->itemCount-1)
break;
else
{
currentMenu->selected++;
if(currentMenu->selected > currentMenu->range_to)
{
currentMenu->range_to = currentMenu->selected;
currentMenu->range_from = currentMenu->range_to-3;
}
displaymenu(currentMenu->selected);
}
break;
}
case key_back://按键D(返回)
{
if(currentMenu->parent != NULL)
{
currentMenu = currentMenu->parent;
displaymenu(currentMenu->selected);
}
break;
}
default:
break;
}
ReadValue=0;
}
}
}
帮忙看一下
嗯,是的啊。
问题已解决
一周热门 更多>