suu pen
/
HonyBeePropoIR_TestProgram
IRC Helicopter "HonyBee" Propo decode test program
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /** 00002 * HonyBee Propo Decode test program 00003 * 130623 00004 * 00005 * Writer:suupen 00006 * 00007 * <circuit diagram> 00008 * VU(mbed) 00009 * | 00010 * |Vcc 00011 * --- (PL-IRM2161) IR Reciver 00012 * | |Vout 00013 * | |--- p5(mbed) 00014 * | | 00015 * --- 00016 * |GND 00017 * | 00018 * GND(mbed) 00019 * 00020 * <PC termnal soft> 00021 * tera term 00022 * baudrate:38400[bps] 00023 * data:8[bit] 00024 * parity:none 00025 * stopbit:1[bit] 00026 */ 00027 00028 00029 //#define PROPO_RAW_DATA // ari: zyusin data hyoji nasi:HonyBee kaiseki data hyoji 00030 //#define HONYBEE_NORMALIZE // ari: HonyBee data seikika hyoji nasi: HonyBee data tujyo hyoji 00031 00032 #include "mbed.h" 00033 #include "ReceiverIR.h" 00034 00035 #ifndef PROPO_RAW_DATA 00036 #include "CodecHonyBee.h" 00037 #include "DecodeHonyBee.h" 00038 #endif // PROPO_RAW_DATA 00039 00040 void display_format(RemoteIR::Format format); 00041 void display_binary(uint8_t *buf, uint8_t cnt); 00042 00043 Serial pc(USBTX,USBRX); 00044 00045 00046 ReceiverIR ir_rx(p5); 00047 00048 RemoteIR::Format format; 00049 00050 #ifndef PROPO_RAW_DATA 00051 DecodeHonyBee HonyBee; 00052 CodecHonyBee::honyBeePropo_t HonyBeeData; 00053 00054 #ifdef HONYBEE_NORMALIZE 00055 CodecHonyBee::normalizePropo_t normalize; 00056 #endif // HONYBEE_NORMALIZE 00057 00058 #endif // PROPO_RAW_DATA 00059 00060 00061 uint8_t buf[32]; 00062 int bitcount; 00063 00064 DigitalOut myled(LED1); 00065 DigitalOut led2(LED2); 00066 DigitalIn irtest(p20); 00067 00068 00069 int main(){ 00070 pc.baud(38400); 00071 while(1){ 00072 00073 myled =~myled; 00074 led2 = irtest; 00075 00076 00077 00078 #ifdef PROPO_RAW_DATA 00079 if (ir_rx.getState() == ReceiverIR::Received) { 00080 bitcount = ir_rx.getData(&format, buf, sizeof(buf) * 8); 00081 00082 display_format(format); 00083 display_binary(buf, ((bitcount + 7) / 8)); 00084 } 00085 else{ 00086 #if 0 00087 switch(ir_rx.getState()){ 00088 00089 case ReceiverIR::Idle: 00090 printf("Idele\n"); 00091 break; 00092 case ReceiverIR::Receiving: 00093 printf("Receiveing\n"); 00094 break; 00095 case ReceiverIR::Received: 00096 printf("Received\n"); 00097 break; 00098 } 00099 #endif 00100 } 00101 #endif // PROPO_RAW_DATA 00102 00103 #ifndef PROPO_RAW_DATA 00104 if (ir_rx.getState() == ReceiverIR::Received) { 00105 bitcount = ir_rx.getData(&format, buf, sizeof(buf) * 8); 00106 #ifdef HONYBEE_NORMALIZE 00107 bool ans = HonyBee.normalize(buf, &normalize); 00108 if(ans == true){ 00109 printf("count = %02x band = %1d slottle = %f trim = %f ladder = %f elevator = %f\n",normalize.count,normalize.band,normalize.slottle,normalize.trim,normalize.ladder, normalize.elevator); 00110 } 00111 else{ 00112 printf("NG\n"); 00113 } 00114 #else // ~HONYBEE_NORMALIZE 00115 bool ans = HonyBee.decode(buf, &HonyBeeData); 00116 if(ans == true){ 00117 printf("count = %02x band = %02x slottle = %03d trim = %03d ladder = %03d \n",HonyBeeData.count,HonyBeeData.band,HonyBeeData.slottle,HonyBeeData.trim,HonyBeeData.ladder); 00118 } 00119 else{ 00120 printf("NG\n"); 00121 } 00122 #endif// HONYBEE_NORMALIZE 00123 00124 } 00125 #endif // PROPO_RAW_DATA 00126 00127 } 00128 00129 } 00130 00131 /** 00132 * Display a format of a data. 00133 */ 00134 void display_format(RemoteIR::Format format) { 00135 switch (format) { 00136 case RemoteIR::UNKNOWN: 00137 pc.printf("????????"); 00138 break; 00139 case RemoteIR::NEC: 00140 pc.printf("NEC "); 00141 break; 00142 case RemoteIR::NEC_REPEAT: 00143 pc.printf("NEC (R)"); 00144 break; 00145 case RemoteIR::AEHA: 00146 pc.printf("AEHA "); 00147 break; 00148 case RemoteIR::AEHA_REPEAT: 00149 pc.printf("AEHA (R)"); 00150 break; 00151 case RemoteIR::SONY: //HONEY_BEE: 00152 pc.printf("SONY or HONEY_BEE "); 00153 break; 00154 00155 #ifdef Swift_PROTCOL 00156 case RemoteIR::Swift: 00157 pc.printf("Swift "); 00158 break; 00159 #endif // Swift_PROPO 00160 default: 00161 pc.printf("unknown "); 00162 break; 00163 } 00164 } 00165 00166 void display_binary(uint8_t *buf, uint8_t cnt){ 00167 uint8_t i; 00168 uint8_t bitcnt; 00169 uint8_t dat; 00170 uint16_t checkbit; 00171 00172 for(i = 0; i < cnt; i++){ 00173 checkbit = 0x0080; 00174 dat = *(buf + i); 00175 printf("%02x:",dat); 00176 for(bitcnt = 0; bitcnt < 8; bitcnt++){ 00177 if( checkbit & dat){printf("1");} 00178 else {printf("0");} 00179 00180 checkbit = checkbit >> 1; 00181 if(bitcnt == 3){printf(" ");} 00182 } 00183 printf(" "); 00184 } 00185 printf("\n"); 00186 } 00187 00188 00189
Generated on Fri Jul 15 2022 02:33:45 by 1.7.2