Imayan chan
/
FRDM_tocos_x2_FIXED
TFT2P0327 MONO-WIRELESS TWELITE-DIP 2pcs control
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "S6D0151_TFT.h" 00003 #include "Consolas12.h" 00004 #include "Prototype24x34_T.h" 00005 00006 S6D0151_TFT TFT(PTD2, NC, PTD1, PTD6, PTD7,"TFT"); // mosi, miso, sclk, cs, reset 00007 00008 DigitalOut myled(LED2); 00009 Serial tocos(PTE0,PTE1); 00010 //Serial pc(USBTX,USBRX); 00011 00012 PwmOut bkl(PTD4); 00013 00014 int main() { 00015 char recv_str[64]; 00016 char ad1_str[5]={'\0'}; 00017 char ad1h_str[5]={'\0'}; 00018 char tmp_str[10]={'\0'}; 00019 char v_id_str[10]={'\0'}; 00020 char v_lg_str[10]={'\0'}; 00021 00022 int ad1,ad1h,v_lqi,v_bat; 00023 int lm61; 00024 char child1[]="810CD3F0"; 00025 int vpos_offset; 00026 00027 tocos.baud(115200); 00028 bkl.period_ms(1); 00029 bkl = 1; // 00030 00031 // TFT.claim(stdout); // send stdout to the TFT display 00032 TFT.set_orientation(2); 00033 00034 TFT.background(Black); // set background to black 00035 TFT.foreground(White); 00036 TFT.cls(); 00037 TFT.set_font((unsigned char *) Consolas9x16 ); 00038 TFT.locate( 0, 0); TFT.printf("ZigBee Temp"); 00039 00040 TFT.set_font( (unsigned char *) Prototype24x34 ); 00041 TFT.locate( 63, 18+0 ); TFT.printf("."); 00042 TFT.locate( 63, 18+80); TFT.printf("."); 00043 00044 while(1) { 00045 while( tocos.getc() != 0x3A ); // 0x3A=":" 00046 for(int i=0;i<49;i++){ 00047 recv_str[i] = tocos.getc(); 00048 } 00049 recv_str[49]=NULL; 00050 // 78811501B781003BB6782A05000B291B000033FFFFFFFFA3 00051 // 012345678901234567890123456789012345678901234567 00052 strncpy( ad1_str , recv_str+36 , 2 ); 00053 strncpy( ad1h_str , recv_str+44 , 2 ); 00054 strncpy( v_id_str , recv_str+10 , 8 ); 00055 strncpy( v_lg_str , recv_str+18 , 2 ); 00056 strncpy( tmp_str , recv_str+8 , 2 ); 00057 v_lqi=strtol(tmp_str,NULL,16); 00058 strncpy( tmp_str , recv_str+26 , 4 ); 00059 v_bat=strtol(tmp_str,NULL,16); 00060 tmp_str[2]=NULL; 00061 ad1 = strtol(ad1_str,NULL,16); 00062 ad1h= strtol(ad1h_str,NULL,16) & 0x03; 00063 ad1 = (ad1 * 4 + ad1h) * 4; 00064 lm61= ad1 - 600 ; 00065 myled = 0; 00066 00067 if( strcmp(v_id_str,child1)==0 ){ 00068 vpos_offset=0; 00069 } else { 00070 vpos_offset=80; 00071 } 00072 TFT.foreground( White ); 00073 TFT.set_font( (unsigned char *) Prototype24x34 ); 00074 TFT.locate( 0,18+vpos_offset); 00075 TFT.printf("% 2d",lm61/10); 00076 TFT.locate( 82,18+vpos_offset); 00077 if(lm61<0){ 00078 TFT.printf("%d",(-1*lm61 % 10) ); 00079 } else { 00080 TFT.printf("%d",(lm61 % 10) ); 00081 } 00082 TFT.set_font( (unsigned char *) Consolas9x16 ); 00083 TFT.foreground( Yellow ); 00084 TFT.locate( 0, 0+vpos_offset);TFT.printf("%s(%2d%%)",v_id_str,(int)((float)v_lqi/255*100) ); 00085 TFT.foreground( Cyan ); 00086 TFT.locate( 0, 54+vpos_offset);TFT.printf("VBAT=%4.2fV",(float)v_bat/1000 ); 00087 00088 myled = 1; 00089 } 00090 }
Generated on Sat Jul 16 2022 15:37:05 by 1.7.2