テスト
Dependencies: RemoteIR TB6612FNG2 mbed
Fork of RemoteIR_TestProgram by
Revision 6:9bddde38e25e, committed 2015-12-23
- Comitter:
- mbed_Cookbook_SE
- Date:
- Wed Dec 23 16:59:17 2015 +0000
- Parent:
- 5:40750d5779ca
- Commit message:
- ??
Changed in this revision
diff -r 40750d5779ca -r 9bddde38e25e RemoteIR.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RemoteIR.lib Wed Dec 23 16:59:17 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/shintamainjp/code/RemoteIR/#268cc2ab63bd
diff -r 40750d5779ca -r 9bddde38e25e TB6612FNG2.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TB6612FNG2.lib Wed Dec 23 16:59:17 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/jksoft/code/TB6612FNG2/#051a7ecff13e
diff -r 40750d5779ca -r 9bddde38e25e extlib/TextLCD.lib --- a/extlib/TextLCD.lib Wed Oct 13 10:51:41 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/simon/code/TextLCD/#a53b3e2d6f1e
diff -r 40750d5779ca -r 9bddde38e25e main.cpp --- a/main.cpp Wed Oct 13 10:51:41 2010 +0000 +++ b/main.cpp Wed Dec 23 16:59:17 2015 +0000 @@ -1,33 +1,14 @@ -/** - * RemoteIR library - Test program. - * - * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) - * http://shinta.main.jp/ - */ - -#include <mbed.h> +#include "mbed.h" #include "ReceiverIR.h" #include "TransmitterIR.h" -#include "TextLCD.h" - -#define TEST_LOOP_BACK 0 - -ReceiverIR ir_rx(p15); -TransmitterIR ir_tx(p21); -TextLCD lcd(p24, p26, p27, p28, p29, p30); -BusOut led(LED4, LED3, LED2, LED1); -Ticker ledTicker; +#include "TB6612.h" -/** - * Receive. - * - * @param format Pointer to a format. - * @param buf Pointer to a buffer. - * @param bufsiz Size of the buffer. - * - * @return Bit length of the received data. - */ +ReceiverIR ir_rx(p14); +TransmitterIR ir_tx(p23); +TB6612 MOTOR_A(p21,p19,p20); // PWM IN1 IN2 +TB6612 MOTOR_B(p22,p29,p30); // PWM IN1 IN2 + int receive(RemoteIR::Format *format, uint8_t *buf, int bufsiz, int timeout = 100) { int cnt = 0; while (ir_rx.getState() != ReceiverIR::Received) { @@ -39,15 +20,6 @@ return ir_rx.getData(format, buf, bufsiz * 8); } -/** - * Transmit. - * - * @param format Format. - * @param buf Pointer to a buffer. - * @param bitlength Bit length of the data. - * - * @return Bit length of the received data. - */ int transmit(RemoteIR::Format format, uint8_t *buf, int bitlength, int timeout = 100) { int cnt = 0; while (ir_tx.getState() != TransmitterIR::Idle) { @@ -59,148 +31,91 @@ return ir_tx.setData(format, buf, bitlength); } -/** - * Display a current status. - */ -void display_status(char *status, int bitlength) { - lcd.locate(8, 0); - lcd.printf("%-5.5s:%02d", status, bitlength); +int SearchCode( uint8_t *code ,uint8_t **buf , int size) +{ + int ret = -1; + for(int i=0;i<5;i++) + { + if(memcmp( code , buf[i] , size ) == 0 ){ + ret = i; + break; + } + } + return(ret); } -/** - * Display a format of a data. - */ -void display_format(RemoteIR::Format format) { - lcd.locate(0, 0); - switch (format) { - case RemoteIR::UNKNOWN: - lcd.printf("????????"); - break; - case RemoteIR::NEC: - lcd.printf("NEC "); - break; - case RemoteIR::NEC_REPEAT: - lcd.printf("NEC (R)"); - break; - case RemoteIR::AEHA: - lcd.printf("AEHA "); - break; - case RemoteIR::AEHA_REPEAT: - lcd.printf("AEHA (R)"); - break; - case RemoteIR::SONY: - lcd.printf("SONY "); - break; - } -} +void RegistrationCode(uint8_t *forward ,uint8_t *back ,uint8_t *left ,uint8_t *right ,uint8_t *stop) +{ + uint8_t buf[32]; + int bitlength; + RemoteIR::Format format; + uint8_t *ir_buf[5] = {forward,back,left,right,stop}; + + memset(buf, 0x00, sizeof(buf)); + + for(int i=0;i<5;i++) + { + bitlength = -1; + while(bitlength < 0) + { + bitlength = receive(&format, buf, sizeof(buf)); + if (bitlength < 0) { + continue; + } + + if( SearchCode(buf,ir_buf,sizeof(buf)) != -1 ) + { + bitlength = -1; + continue; + } -/** - * Display a data. - * - * @param buf Pointer to a buffer. - * @param bitlength Bit length of a data. - */ -void display_data(uint8_t *buf, int bitlength) { - lcd.locate(0, 1); - const int n = bitlength / 8 + (((bitlength % 8) != 0) ? 1 : 0); - for (int i = 0; i < n; i++) { - lcd.printf("%02X", buf[i]); - } - for (int i = 0; i < 8 - n; i++) { - lcd.printf("--"); + memcpy( ir_buf[i] , buf , sizeof(buf)); + } } } -void ledfunc(void) { - led = led + 1; -} - -/** - * Entry point. - */ int main(void) { - - ledTicker.attach(&ledfunc, 0.5); + + uint8_t forward[32],back[32],left[32],right[32],stop[32]; + uint8_t *ir_buf[5] = {forward,back,left,right,stop}; - /* - * Splash. - */ - lcd.cls(); - lcd.locate(0, 0); - lcd.printf("RemoteIR "); - lcd.locate(0, 1); - lcd.printf("Program example."); - wait(3); + RegistrationCode( forward ,back ,left ,right ,stop); - /* - * Initialize. - */ - led = 0; - lcd.cls(); - lcd.locate(0, 0); - lcd.printf("Press a button "); - lcd.locate(0, 1); - lcd.printf("on a controller."); - - /* - * Execute. - */ while (1) { - uint8_t buf1[32]; - uint8_t buf2[32]; + uint8_t buf[32]; int bitlength1; - int bitlength2; RemoteIR::Format format; - memset(buf1, 0x00, sizeof(buf1)); - memset(buf2, 0x00, sizeof(buf2)); + memset(buf, 0x00, sizeof(buf)); - { - bitlength1 = receive(&format, buf1, sizeof(buf1)); - if (bitlength1 < 0) { - continue; - } - display_status("RECV", bitlength1); - display_data(buf1, bitlength1); - display_format(format); - } - -#if TEST_LOOP_BACK - wait_ms(100); - - { - bitlength1 = transmit(format, buf1, bitlength1); - if (bitlength1 < 0) { - continue; - } - display_status("TRAN", bitlength1); - display_data(buf1, bitlength1); - display_format(format); + bitlength1 = receive(&format, buf, sizeof(buf)); + if (bitlength1 < 0) { + continue; } - - wait_ms(100); - + switch(SearchCode(buf,ir_buf,sizeof(buf))) { - bitlength2 = receive(&format, buf2, sizeof(buf2)); - if (bitlength2 < 0) { - continue; - } - display_status("RECV", bitlength2); - display_data(buf2, bitlength2); - display_format(format); + case 0: // forward + MOTOR_A = 100; + MOTOR_B = 100; + break; + case 1: // back + MOTOR_A = -100; + MOTOR_B = -100; + break; + case 2: // left + MOTOR_A = 100; + MOTOR_B = -100; + break; + case 3: // right + MOTOR_A = -100; + MOTOR_B = 100; + break; + case 4: // stop + MOTOR_A = 0; + MOTOR_B = 0; + break; + default: + break; } - - wait_ms(100); - - { - for (int i = 0; i < sizeof(buf1); i++) { - if (buf1[i] != buf2[i]) { - display_status("CPERR", bitlength2); - wait(1); - continue; - } - } - } -#endif } } \ No newline at end of file
diff -r 40750d5779ca -r 9bddde38e25e mylib/RemoteIR.lib --- a/mylib/RemoteIR.lib Wed Oct 13 10:51:41 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/shintamainjp/code/RemoteIR/#268cc2ab63bd