example code IRBlaster
Greenchips IR Blaster gives the easiest way to use various IR format and it is being tested and supported on mbed platform. It supports remote control format as followings.
- NEC
- NEC with Simple Repeat
- Toshia
- Toshiba with Simple Repeat,
- Philips-RC5
- Sony(12bits)
- Sony(15bits)
- Sony(20bits)
- Misubish
- JVC
main.cpp@0:7896055e7ec5, 2014-09-11 (annotated)
- Committer:
- DavidJoo
- Date:
- Thu Sep 11 01:29:42 2014 +0000
- Revision:
- 0:7896055e7ec5
IRBlaster Initial code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DavidJoo | 0:7896055e7ec5 | 1 | #include "mbed.h" |
DavidJoo | 0:7896055e7ec5 | 2 | #include "IR_Blaster.h" |
DavidJoo | 0:7896055e7ec5 | 3 | |
DavidJoo | 0:7896055e7ec5 | 4 | Serial pc(SERIAL_TX, SERIAL_RX); |
DavidJoo | 0:7896055e7ec5 | 5 | Serial IrBlaster(PA_9, PA_10); |
DavidJoo | 0:7896055e7ec5 | 6 | |
DavidJoo | 0:7896055e7ec5 | 7 | #define MAX_BUF_SIZE 12 |
DavidJoo | 0:7896055e7ec5 | 8 | #define PAYLOAD_LEN 8 |
DavidJoo | 0:7896055e7ec5 | 9 | |
DavidJoo | 0:7896055e7ec5 | 10 | char IrTxBuffer[MAX_BUF_SIZE] = {0,}; |
DavidJoo | 0:7896055e7ec5 | 11 | |
DavidJoo | 0:7896055e7ec5 | 12 | /* |
DavidJoo | 0:7896055e7ec5 | 13 | * UART Packet Structure |
DavidJoo | 0:7896055e7ec5 | 14 | |
DavidJoo | 0:7896055e7ec5 | 15 | ------------------------------------------------ |
DavidJoo | 0:7896055e7ec5 | 16 | | SOP | Payload Size | Command | Payload | EOP | |
DavidJoo | 0:7896055e7ec5 | 17 | | (1) | (1) | (1) | (0~128) | (1) | |
DavidJoo | 0:7896055e7ec5 | 18 | ------------------------------------------------ |
DavidJoo | 0:7896055e7ec5 | 19 | * |
DavidJoo | 0:7896055e7ec5 | 20 | */ |
DavidJoo | 0:7896055e7ec5 | 21 | |
DavidJoo | 0:7896055e7ec5 | 22 | // Sample UART data structure when user data is "0x6A" |
DavidJoo | 0:7896055e7ec5 | 23 | // NEC custom code : 0x04,0xFB |
DavidJoo | 0:7896055e7ec5 | 24 | char NEC_SR_Sample[12] = {0xFE,0x8,0x1, 0x01,0x04,0xFB,0x00,0x00,0x6A,0x00,0x00, 0xEF}; |
DavidJoo | 0:7896055e7ec5 | 25 | char NEC_Sample[12] = {0xFE,0x8,0x1, 0x02,0x04,0xFB,0x00,0x00,0x6A,0x00,0x00, 0xEF}; |
DavidJoo | 0:7896055e7ec5 | 26 | // TOSHIBA custom code : 0x07, 0x07 |
DavidJoo | 0:7896055e7ec5 | 27 | char TOSHIBA_Sample[12]= {0xFE,0x8,0x1, 0x03,0x07,0x07,0x00,0x00,0x6A,0x00,0x00, 0xEF}; |
DavidJoo | 0:7896055e7ec5 | 28 | char TOSHIBA_SR_Sample[12]= {0xFE,0x8,0x1, 0x04,0x07,0x07,0x00,0x00,0x6A,0x00,0x00, 0xEF}; |
DavidJoo | 0:7896055e7ec5 | 29 | // PHILIPS System code : 0x15 |
DavidJoo | 0:7896055e7ec5 | 30 | char PHILIPS_RC5_Sample[12]={0xFE,0x8,0x1, 0x05,0x15,0x00,0x00,0x00,0x6A,0x00,0x00, 0xEF}; |
DavidJoo | 0:7896055e7ec5 | 31 | // SONY custom code : 0x12 |
DavidJoo | 0:7896055e7ec5 | 32 | char SONY_12BITS_Sample[12]={0xFE,0x8,0x1, 0x06,0x12,0x00,0x00,0x00,0x6A,0x00,0x00, 0xEF}; |
DavidJoo | 0:7896055e7ec5 | 33 | char SONY_16BITS_Sample[12]={0xFE,0x8,0x1, 0x07,0x42,0x00,0x00,0x00,0x6A,0x00,0x00, 0xEF}; |
DavidJoo | 0:7896055e7ec5 | 34 | char SONY_20BITS_Sample[12]={0xFE,0x8,0x1, 0x08,0x34,0x00,0x00,0x00,0x6A,0x00,0x00, 0xEF}; |
DavidJoo | 0:7896055e7ec5 | 35 | char MISUBISHI_Sample[12]= {0xFE,0x8,0x1, 0x09,0x12,0x00,0x00,0x00,0x6A,0x00,0x00, 0xEF}; |
DavidJoo | 0:7896055e7ec5 | 36 | char JVC_Sample[12]= {0xFE,0x8,0x1, 0x0A,0x12,0x00,0x00,0x00,0x6A,0x00,0x00, 0xEF}; |
DavidJoo | 0:7896055e7ec5 | 37 | |
DavidJoo | 0:7896055e7ec5 | 38 | |
DavidJoo | 0:7896055e7ec5 | 39 | DigitalOut myled(LED1); |
DavidJoo | 0:7896055e7ec5 | 40 | |
DavidJoo | 0:7896055e7ec5 | 41 | int main() { |
DavidJoo | 0:7896055e7ec5 | 42 | int i = 1; |
DavidJoo | 0:7896055e7ec5 | 43 | int j = 0; |
DavidJoo | 0:7896055e7ec5 | 44 | |
DavidJoo | 0:7896055e7ec5 | 45 | pc.baud(115200); |
DavidJoo | 0:7896055e7ec5 | 46 | IrBlaster.baud(115200); |
DavidJoo | 0:7896055e7ec5 | 47 | IrBlaster.format(8, Serial::None, 1); |
DavidJoo | 0:7896055e7ec5 | 48 | |
DavidJoo | 0:7896055e7ec5 | 49 | IrBlaster.printf("Hello World !\n"); |
DavidJoo | 0:7896055e7ec5 | 50 | while(1) |
DavidJoo | 0:7896055e7ec5 | 51 | { |
DavidJoo | 0:7896055e7ec5 | 52 | wait(2); |
DavidJoo | 0:7896055e7ec5 | 53 | //Send IR data through UART to IR Blaster |
DavidJoo | 0:7896055e7ec5 | 54 | IrTxBuffer[0] = SOP; |
DavidJoo | 0:7896055e7ec5 | 55 | IrTxBuffer[1] = PAYLOAD_LEN; |
DavidJoo | 0:7896055e7ec5 | 56 | IrTxBuffer[2] = COMMAND_START_IROUT; |
DavidJoo | 0:7896055e7ec5 | 57 | IrTxBuffer[3] = NEC; |
DavidJoo | 0:7896055e7ec5 | 58 | IrTxBuffer[4] = 0x04; |
DavidJoo | 0:7896055e7ec5 | 59 | IrTxBuffer[5] = 0xFB; |
DavidJoo | 0:7896055e7ec5 | 60 | IrTxBuffer[8] = 0x6A; |
DavidJoo | 0:7896055e7ec5 | 61 | IrTxBuffer[11] = EOP; |
DavidJoo | 0:7896055e7ec5 | 62 | for(j=0; j<12; j++) |
DavidJoo | 0:7896055e7ec5 | 63 | IrBlaster.putc(IrTxBuffer[j]); |
DavidJoo | 0:7896055e7ec5 | 64 | pc.printf("This program runs since %d seconds.\n", i++); |
DavidJoo | 0:7896055e7ec5 | 65 | myled = !myled; |
DavidJoo | 0:7896055e7ec5 | 66 | } |
DavidJoo | 0:7896055e7ec5 | 67 | |
DavidJoo | 0:7896055e7ec5 | 68 | } |
DavidJoo | 0:7896055e7ec5 | 69 |