C语言----基于旋转编码器按键的菜单结构( 二 )

< (pMenu->MN - 1))*pMenu->MF += 1;//当前标志位+1break;case ENTER:if (pMenu->Prev == Null) pMenu = pMenu->Next + *pMenu->MF;//跳转到下一深度elsepMenu = pMenu->Prev;//跳转到上一深度*(pMenu->MF + 1) += 1;//刷新当前标志位,否则切换深度后不显示当前选项break;}}// struct MenuItem*Next; 都不为空,使用此菜单功能函数,此函数跳转深度后会将跳转前的菜单成员的标志位清零//struct MenuItem*Prev;voidMFunc_MD(u8 key){switch (key){case LEFT:if (*pMenu->MF>0)*pMenu->MF -= 1;//当前标志位-1break;case RIGHT: if (*pMenu->MF < (pMenu->MN - 1))*pMenu->MF += 1;//当前标志位+1break;case ENTER: if (*pMenu->MF > (pMenu->MN - 2)){*pMenu->MF = 0;//清零当前标志位,下一次进入该选项从0开始显示*(pMenu->MF+1) = 0;//清零当前标志位,下一次进入该选项从0开始显示pMenu = pMenu->Prev + *pMenu->Prev->MF; //跳转到上一深度}else{pMenu = pMenu->Next + *pMenu->MF;//跳转到下一深度}*(pMenu->MF + 1) += 1;break;}}/****************** 显示功能函数的定义 *******************///同化标志位voidClearFlag(void){ClearF(MenuF.m1_Main);ClearF(MenuF.m2_Mode);ClearF(MenuF.m2_Water);ClearF(MenuF.m3_speed);ClearF(MenuF.m3_type);}void D_MenuCur(void) {printf("菜单游标位置: ");switch (MenuF.m1_Main[0]){case 0: printf("位置1\r\n");break;case 1: printf("位置2\r\n");break;default: break;}}void D_location1(void){printf("位置1: ");//比较m2_Mode[0]与m2_Mode[1]是否相等if(CompareF(MenuF.m2_Mode)){switch (MenuF.m2_Mode[0]){case 0: printf("布类");break;case 1: printf("速度");break;case 2: printf("返回上层");break;}}if (CompareF(MenuF.m3_speed)){switch (MenuF.m3_speed[0]){case 0: printf("最慢");break;case 1: printf("慢速");break;case 2: printf("中速");break;case 3: printf("快速");break;case 4: printf("最快");break;}}if (CompareF(MenuF.m3_type)){switch (MenuF.m3_type[0]){case 0: printf("牛仔");break;case 1: printf("帆布");break;case 2: printf("尼龙");break;case 3: printf("涤纶");break;case 4: printf("棉布");break;}}if (CompareF(MenuF.m1_Main)){if (MenuF.m1_Main[0] == 0){printf("模式");}}printf("\r\n");}void D_location2(void){printf("位置2: ");if (CompareF(MenuF.m2_Water)){switch (MenuF.m2_Water[0]){case 0: printf("最低");break;case 1: printf("低");break;case 2: printf("中等");break;case 3: printf("高");break;case 4: printf("最高");break;}}if (CompareF(MenuF.m1_Main)){if (MenuF.m1_Main[0] == 1){printf("水量");}}printf("\r\n");}//输出画面void printfGUI(void){printf("****************************\r\n");printf("\r\n");D_MenuCur();D_location1();D_location2();printf("\r\n");printf("****************************\r\n\r\n");}//打印标志位void printfLoc(void){printf("m1_Main = {x,x};\r\n",MenuF.m1_Main[0],MenuF.m1_Main[1]);printf("m2_Mode = {x,x};\r\n",MenuF.m2_Mode[0],MenuF.m2_Mode[1]);printf("m2_Water ={x,x};\r\n",MenuF.m2_Water[0], MenuF.m2_Water[1]);printf("m3_type = {x,x};\r\n",MenuF.m3_type[0],MenuF.m3_type[1]);printf("m3_speed ={x,x};\r\n",MenuF.m3_speed[0], MenuF.m3_speed[1]);printf("\r\n");}//画面初始化void GUI_Init(void){printf("****************************\r\n");printf("\r\n");printf("菜单游标位置: ");printf("位置1\r\n");printf("位置1: ");printf("模式\r\n");printf("位置2: ");printf("水量");printf("\r\n");printf("****************************\r\n\r\n");}int main(void){u8 temp = 0;pMenu = &m1_Main;GUI_Init();//初始化界面while (1){temp = _getch();switch (temp){case '1': (*(pMenu->Func))(LEFT);break;case '3': (*(pMenu->Func))(RIGHT);break;case '2': (*(pMenu->Func))(ENTER);break;default:break;}printfGUI();ClearFlag();//清零标志位printfLoc();//打印标志位}}
运行截图:

C语言----基于旋转编码器按键的菜单结构

文章插图

C语言----基于旋转编码器按键的菜单结构

文章插图
当按下键盘的‘1’、‘2’、‘3’,会打印出当前的标志位,并且显示位置上面会换成标志位对应的字符 。