——來自迪文開發(fā)者論壇
本期為大家推送迪文開發(fā)者論壇獲獎開源案例——基于T5L智能屏的萬能紅外控制器。工程師通過T5L串口與紅外傳感器模塊進(jìn)行通訊,賦予屏幕紅外遙控功能,使其能夠?qū)W習(xí)并模擬家電的紅外遙控信號,實(shí)現(xiàn)對空調(diào)、電視機(jī)、投影儀、功放機(jī)等紅外控制設(shè)備的精準(zhǔn)控制,并實(shí)時顯示設(shè)備狀態(tài)。該方案不僅提升了設(shè)備控制的效率和精確度,也為用戶帶來了更加便捷的交互體驗(yàn)。用戶通過屏幕,即可輕松管理和控制這些設(shè)備,顯著提升了家居和工業(yè)自動化領(lǐng)域的便捷性和智能化水平。
GUI工程設(shè)計 C51工程設(shè)計 T5L串口與紅外傳感器模塊進(jìn)行數(shù)據(jù)交互,實(shí)現(xiàn)通過屏幕控制空調(diào)的部分參考代碼如下:
INIT_CPU(); T2_Init(); UART4_Init(); EA=1;void Process(void){ OneMsHandle(); TenMsHandle();}bool uartHandle(u8 *Tdata,u16 len){ u8 writedata[2]={0,0}; u8 PressKeyI[] ="完成 "; u8 PreMacClose[]="請再按下關(guān)機(jī)鍵 "; if(!ReadYaoKongOper) return false; if(Tdata[0]!=0x68) return false; switch(Tdata[1]) { case 8://正常應(yīng)答,可以不管 break; case 0X0A://正常應(yīng)答,可以不管// default://返回已經(jīng)弄好的學(xué)習(xí)碼 memset(&IR_CmdPack,0,sizeof(IR_CmdPack)); IR_CmdPack.Tok=0x5a; IR_CmdPack.len=len; memcpy(IR_CmdPack.cmddata,Tdata,len);Write_Dgusii_Vp(0x5000,(u8*)&IR_CmdPack,sizeof(IR_CmdPack_s)/2);T5L_Flash(WRITE_MOD,0x5000,0x800+2048*(ReadYaoKongOper-1),sizeof(IR_CmdPack_s)/2); if(ReadYaoKongOper==1) { Write_Dgusii_Vp(0x2000,PreMacClose,strlen(PreMacClose)/2); SendLearnCodeId(7); ReadYaoKongOper=7; } else { ReadYaoKongOper=0;//操作完成 Write_Dgusii_Vp(0x1200,writedata,1);//寫顯示logo Write_Dgusii_Vp(0x2000,PressKeyI,strlen(PressKeyI)/2); }// UART4_SendStr(Tdata,len); break; } return true;}void RecordPageKeyPress(void){#if 1 u8 TouchKey[2]={0,0}; u8 writedata[2]={0,0};// u8 learnCode[]={0x68 ,0x08 ,0x00, 0xFF, 0x10 ,0x00 ,0x0F, 0x16}; u8 PressKeyI[]="請按下遙控按鍵"; u8 PreMachStart[]="請按下遙控開機(jī)鍵"; Read_Dgusii_Vp(0x1210,TouchKey,1); if(TouchKey[1]==0) return; if(!ReadYaoKongOper && TouchKey[1]<7) { //只有未學(xué)習(xí)的時候,操作學(xué)習(xí)碼 SendLearnCodeId(TouchKey[1]); if(TouchKey[1]<=8) writedata[1]=1<<(TouchKey[1]-1); Write_Dgusii_Vp(0x1200,writedata,1);//寫顯示logo ReadYaoKongOper=TouchKey[1]; if(ReadYaoKongOper!=1) Write_Dgusii_Vp(0x2000,PressKeyI,strlen(PressKeyI)/2); else Write_Dgusii_Vp(0x2000,PreMachStart,strlen(PreMachStart)/2); } TouchKey[1]=0; Write_Dgusii_Vp(0x1210,TouchKey,1);//關(guān)閉觸摸按鍵#endif}void CtrPageKeyPress(void){ u8 TouchKey[2]={0,0}; u8 sendcmd[]={0x68 ,0x08 ,0x00 ,0xFF ,0x12, 0x00 ,0x11, 0x16}; u8 MachStart[]="已開機(jī)"; u8 MachClose[]="已關(guān)機(jī)"; Read_Dgusii_Vp(0x1300,TouchKey,1); if(TouchKey[1]==0) return;// printf("CtrPageKeyPress\r\n"); if(TouchKey[1]<7) { memset(&IR_CmdPack,0,sizeof(IR_CmdPack));#if 0T5L_Flash(READ_MOD,0x5000,0x800+2048*(TouchKey[1]-1),sizeof(IR_CmdPack_s)/2); Read_Dgusii_Vp(0x5000,(u8*)&IR_CmdPack,sizeof(IR_CmdPack_s)/2); if(IR_CmdPack.Tok==0x5a) UART4_SendStr(IR_CmdPack.cmddata,IR_CmdPack.len);#else if(TouchKey[1]!=1) { sendcmd[5]=TouchKey[1]-1; sendcmd[6]=sendcmd[6]+sendcmd[5]; } else { if(MachineST) { MachineST=0; TouchKey[1]=7; sendcmd[5]=TouchKey[1]-1; sendcmd[6]=sendcmd[6]+sendcmd[5]; Write_Dgusii_Vp(0x2300,MachClose,strlen(MachClose)/2); } else { MachineST=1; sendcmd[5]=TouchKey[1]-1; sendcmd[6]=sendcmd[6]+sendcmd[5]; Write_Dgusii_Vp(0x2300,MachStart,strlen(MachStart)/2); } } UART4_SendStr(sendcmd,sizeof(sendcmd));#endif// printf("IR_CmdPack.Tok:%d",IR_CmdPack.Tok);// UART4_SendStr(&IR_CmdPack,10); } TouchKey[1]=0; Write_Dgusii_Vp(0x1300,TouchKey,1);//關(guān)閉觸摸按鍵 }
-
傳感器
+關(guān)注
關(guān)注
2550文章
51035瀏覽量
753061 -
紅外控制器
+關(guān)注
關(guān)注
0文章
7瀏覽量
983 -
智能屏幕
+關(guān)注
關(guān)注
0文章
65瀏覽量
3323
發(fā)布評論請先 登錄
相關(guān)推薦
評論