.

Dependencies:   BLE_API TxIR mbed nRF51822

Fork of ir-puck by Nordic Pucks

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers IR.cpp Source File

IR.cpp

00001 #include "mbed.h"
00002 #include "IR.h"
00003 #include "TxIR.hpp"
00004 
00005 #define WORD(x, i) ((x)[(i)] << 8 | (x)[(i) + 1])
00006 
00007 TxIR txir(p14);
00008 Serial px(USBTX, USBRX);
00009 
00010 void fireIRCode(uint8_t* header, uint8_t* one, uint8_t* zero, uint8_t* ptrail, uint8_t* predata, uint8_t* code)
00011 {
00012     px.printf("Going to fire.\n");
00013     int raw_codes_length = 67;
00014     unsigned raw_codes[raw_codes_length];
00015     raw_codes[0] = WORD(header, 0);
00016     raw_codes[1] = WORD(header, 2);
00017     int offset = 2;
00018     for(int i = 0; i < 16 * 2; i += 2) {
00019         int bit = predata[i / 16] & 0x80;
00020         uint8_t* signal = bit ? one : zero;
00021         raw_codes[i + offset] = WORD(signal, 0);
00022         raw_codes[i + offset + 1] = WORD(signal, 2);
00023         predata[i / 16] <<= 1;
00024     }
00025     offset = 34;
00026     for(int i = 0; i <  16 * 2; i += 2) {
00027         int bit = code[i / 16] & 0x80;
00028         uint8_t* signal = bit ? one : zero;
00029         raw_codes[i + offset] = WORD(signal, 0);
00030         raw_codes[i + offset + 1] = WORD(signal, 2);
00031         code[i / 16] <<= 1;
00032     }
00033     raw_codes[66] = WORD(ptrail, 0);
00034 
00035     txir.txSeq(26, 67, raw_codes);
00036 
00037     px.printf("Wrote message :)\n");
00038 }