嵌入式開發(fā)的一個(gè)騷操作!你用過嗎?
1 映射表在串口數(shù)據(jù)解析中的應(yīng)用
1.1 數(shù)據(jù)結(jié)構(gòu)
1.2 指令、函數(shù)映射表
1.3 串口解析函數(shù)實(shí)現(xiàn)
2 映射表在UI設(shè)計(jì)中的應(yīng)用
2.1 數(shù)據(jù)結(jié)構(gòu)
2.2 函數(shù)映射表
2.3 定義兩個(gè)變量保存當(dāng)前場(chǎng)景和上一個(gè)場(chǎng)景
2.4 按下Up按鍵 跳轉(zhuǎn)到指定場(chǎng)景current_stage的值根據(jù)映射表改變
2.5 場(chǎng)景改變后 根據(jù)映射表執(zhí)行相應(yīng)的函數(shù)Handler
typedef struct1.2 指令、函數(shù)映射表
{
char CMD[CMDLen];
unsigned char (*cmd_operate)(char *data);
}Usart_Tab;
static const Usart_Tab InstructionList[CMDMax]=1.3 串口解析函數(shù)實(shí)現(xiàn)
{
{"PWON",PowOn},
{"PWOFF",PowOff},
{"HDCP",HdcpOnOff},
{"/V",QueryKaVersion},
{"EDIDUpgrade",UpdataEDID},
{"Psave",Psave},
{"Precall",Precall},
{"Pclear",Pclear},
};
unsigned char DataAnalysis(char *buf){2 映射表在UI設(shè)計(jì)中的應(yīng)用2.1 數(shù)據(jù)結(jié)構(gòu)
unsigned char i,Result;
char *NEXT=NULL;
for(i=0;i<CMDMax;i++)
{
NEXT=StrCmp(buf,(char*)InstructionList[i].CMD);
if(NEXT!=NULL)
{
usartfuncp=InstructionList[i].cmd_operate;
Result=(*usartfuncp)(NEXT);
}
}
return Result;
}
菜單枚舉:
typedef enum
{
stage1=0,
stage2,
stage3,
stage4,
stage5,
stage6,
stage7,
stage8,
stage9,
}SCENE;
數(shù)據(jù)結(jié)構(gòu):
typedef struct {2.2 函數(shù)映射表
void (*current_operate)(); //當(dāng)前場(chǎng)景的處理函數(shù)
SCENE Index; //當(dāng)前場(chǎng)景的標(biāo)簽
SCENE Up; //按下Up鍵跳轉(zhuǎn)的場(chǎng)景
SCENE Down; //按下Down鍵跳轉(zhuǎn)的場(chǎng)景
SCENE Right; //按下Left鍵跳轉(zhuǎn)的場(chǎng)景
SCENE Left; //按下Right鍵跳轉(zhuǎn)的場(chǎng)景
}STAGE_TAB;
STAGE_TAB stage_tab[]={2.3 定義兩個(gè)變量保存當(dāng)前場(chǎng)景和上一個(gè)場(chǎng)景
#. operate Index Up Down Left Right
{Stage1_Handler, stage1, stage4, stage7, stage3, stage2},
{Stage2_Handler, stage2, stage5, stage8, stage1, stage3},
{Stage3_Handler, stage3, stage6, stage9, stage2, stage1},
{Stage4_Handler, stage4, stage7, stage1, stage6, stage5},
{Stage5_Handler, stage5, stage8, stage2, stage4, stage6},
{Stage6_Handler, stage6, stage9, stage3, stage5, stage4},
{Stage7_Handler, stage7, stage1, stage4, stage9, stage8},
{Stage8_Handler, stage8, stage2, stage5, stage7, stage9},
{Stage9_Handler, stage9, stage3, stage6, stage8, stage7},
};
char current_stage=stage1;2.4 按下Up按鍵 跳轉(zhuǎn)到指定場(chǎng)景current_stage的值根據(jù)映射表改變
char prev_stage=current_stage;
current_stage =stage_tab[current_stage].Up;2.5 場(chǎng)景改變后 根據(jù)映射表執(zhí)行相應(yīng)的函數(shù)Handler
if(current_stage!=prev_stage)
{
stage_tab[current_stage].current_operate();
prev_stage=current_stage;
}
文章來源:物聯(lián)網(wǎng)IoT技術(shù)
本文來源網(wǎng)絡(luò),免費(fèi)傳達(dá)知識(shí),版權(quán)歸原作者所有。如涉及作品版權(quán)問題,請(qǐng)聯(lián)系我進(jìn)行刪除。
*博客內(nèi)容為網(wǎng)友個(gè)人發(fā)布,僅代表博主個(gè)人觀點(diǎn),如有侵權(quán)請(qǐng)聯(lián)系工作人員刪除。