a fork to test out advertising process

Dependencies:   BLE_API TxIR mbed nRF51822

Fork of ir-puck by Nordic Pucks

Committer:
stiaje
Date:
Tue Jul 08 09:38:31 2014 +0000
Revision:
1:6ba27220d1da
Parent:
0:c94311378ec1
Rewrite all the things!; ; printing and advertising mostly.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sigveseb 0:c94311378ec1 1 #include "mbed.h"
sigveseb 0:c94311378ec1 2 #include "IR.h"
sigveseb 0:c94311378ec1 3 #include "TxIR.hpp"
sigveseb 0:c94311378ec1 4
sigveseb 0:c94311378ec1 5 #define WORD(x, i) ((x)[(i)] << 8 | (x)[(i) + 1])
sigveseb 0:c94311378ec1 6
sigveseb 0:c94311378ec1 7 TxIR txir(p14);
stiaje 1:6ba27220d1da 8
stiaje 1:6ba27220d1da 9 #define DEBUG 1
stiaje 1:6ba27220d1da 10 #ifdef DEBUG
stiaje 1:6ba27220d1da 11 Serial px(USBTX, USBRX);
stiaje 1:6ba27220d1da 12 #define LOG(args...) px.printf(args)
stiaje 1:6ba27220d1da 13 #else
stiaje 1:6ba27220d1da 14 #define LOG(args...)
stiaje 1:6ba27220d1da 15 #endif
sigveseb 0:c94311378ec1 16
sigveseb 0:c94311378ec1 17 void fireIRCode(uint8_t* header, uint8_t* one, uint8_t* zero, uint8_t* ptrail, uint8_t* predata, uint8_t* code) {
stiaje 1:6ba27220d1da 18 LOG("Going to fire.\n");
sigveseb 0:c94311378ec1 19 int raw_codes_length = 67;
sigveseb 0:c94311378ec1 20 unsigned raw_codes[raw_codes_length];
sigveseb 0:c94311378ec1 21 raw_codes[0] = WORD(header, 0);
sigveseb 0:c94311378ec1 22 raw_codes[1] = WORD(header, 2);
sigveseb 0:c94311378ec1 23 int offset = 2;
sigveseb 0:c94311378ec1 24 for(int i = 0; i < 16 * 2; i += 2) {
sigveseb 0:c94311378ec1 25 int bit = predata[i / 16] & 0x80;
sigveseb 0:c94311378ec1 26 uint8_t* signal = bit ? one : zero;
sigveseb 0:c94311378ec1 27 raw_codes[i + offset] = WORD(signal, 0);
sigveseb 0:c94311378ec1 28 raw_codes[i + offset + 1] = WORD(signal, 2);
sigveseb 0:c94311378ec1 29 predata[i / 16] <<= 1;
sigveseb 0:c94311378ec1 30 }
sigveseb 0:c94311378ec1 31 offset = 34;
sigveseb 0:c94311378ec1 32 for(int i = 0; i < 16 * 2; i += 2) {
sigveseb 0:c94311378ec1 33 int bit = code[i / 16] & 0x80;
sigveseb 0:c94311378ec1 34 uint8_t* signal = bit ? one : zero;
sigveseb 0:c94311378ec1 35 raw_codes[i + offset] = WORD(signal, 0);
sigveseb 0:c94311378ec1 36 raw_codes[i + offset + 1] = WORD(signal, 2);
sigveseb 0:c94311378ec1 37 code[i / 16] <<= 1;
sigveseb 0:c94311378ec1 38 }
sigveseb 0:c94311378ec1 39 raw_codes[67] = WORD(ptrail, 0);
sigveseb 0:c94311378ec1 40
sigveseb 0:c94311378ec1 41 txir.txSeq(26.32 / 1000000.0, 67, raw_codes);
sigveseb 0:c94311378ec1 42
stiaje 1:6ba27220d1da 43 LOG("Wrote message :)\n");
sigveseb 0:c94311378ec1 44 }