ir-puck
Dependencies: IRSender Puck mbed
Fork of ir-puck by
Revision 13:f016a0bc4a7d, committed 2014-08-01
- Comitter:
- sigveseb
- Date:
- Fri Aug 01 12:37:29 2014 +0000
- Parent:
- 6:da2de3a0a9d9
- Child:
- 14:b00d0c5ba8e3
- Commit message:
- Start changing IR bt interface
Changed in this revision
IR.cpp | Show diff for this revision Revisions of this file |
IR.h | Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/IR.cpp Wed Jul 23 13:06:57 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -#include "mbed.h" -#include "IR.h" -#include "TxIR.hpp" - -#define WORD(x, i) ((x)[(i)] << 8 | (x)[(i) + 1]) - -TxIR txir(p14); -Serial px(USBTX, USBRX); - -#define SCR_1 1260, 420 -#define SCR_0 420, 1260 - -#define SCR_RAW_CODE_DOWN SCR_1, SCR_1, SCR_1, SCR_1, SCR_0, SCR_0, SCR_0, SCR_0, SCR_0, SCR_1, SCR_0, SCR_0 -#define SCR_RAW_CODE_MIDDLE SCR_1, SCR_1, SCR_1, SCR_1, SCR_0, SCR_0, SCR_0, SCR_0, SCR_0, SCR_0, SCR_1, SCR_0 -#define SCR_RAW_CODE_UP SCR_1, SCR_1, SCR_1, SCR_1, SCR_0, SCR_0, SCR_0, SCR_0, SCR_0, SCR_0, SCR_0, SCR_1 -#define SCR_PAUSE 0, 20 * 1680 - -unsigned screen_down_raw_codes[50] = { - SCR_RAW_CODE_DOWN, - SCR_PAUSE, - SCR_RAW_CODE_DOWN -}; - -unsigned screen_middle_raw_codes[50] = { - SCR_RAW_CODE_MIDDLE, - SCR_PAUSE, - SCR_RAW_CODE_MIDDLE -}; - -unsigned screen_up_raw_codes[50] = { - SCR_RAW_CODE_UP, - SCR_PAUSE, - SCR_RAW_CODE_UP -}; - - - -void fireIRCode(uint8_t* header, uint8_t* one, uint8_t* zero, uint8_t* ptrail, uint8_t* predata, uint8_t* code) -{ - - if(code[0] == 17) { - switch(code[1]) { - case 17: txir.txSeq(26, 50, screen_up_raw_codes); break; - case 18: txir.txSeq(26, 50, screen_middle_raw_codes); break; - case 19: txir.txSeq(26, 50, screen_down_raw_codes); break; - } - return; - } - - px.printf("Going to fire.\n"); - int raw_codes_length = 67; - unsigned raw_codes[raw_codes_length]; - raw_codes[0] = WORD(header, 0); - raw_codes[1] = WORD(header, 2); - int offset = 2; - for(int i = 0; i < 16 * 2; i += 2) { - int bit = predata[i / 16] & 0x80; - uint8_t* signal = bit ? one : zero; - raw_codes[i + offset] = WORD(signal, 0); - raw_codes[i + offset + 1] = WORD(signal, 2); - predata[i / 16] <<= 1; - } - offset = 34; - for(int i = 0; i < 16 * 2; i += 2) { - int bit = code[i / 16] & 0x80; - uint8_t* signal = bit ? one : zero; - raw_codes[i + offset] = WORD(signal, 0); - raw_codes[i + offset + 1] = WORD(signal, 2); - code[i / 16] <<= 1; - } - raw_codes[66] = WORD(ptrail, 0); - - px.printf("Full sequence received: [%i", raw_codes[0]); - for (int i=1; i<67; i++) { - px.printf(", %i", raw_codes[i]); - } - px.printf("]\n"); - - txir.txSeq(26, 67, raw_codes); - - - px.printf("Wrote message :)\n"); -} \ No newline at end of file
--- a/IR.h Wed Jul 23 13:06:57 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -#ifndef __IR_H__ -#define __IR_H__ - -void fireIRCode(uint8_t* header, uint8_t* one, uint8_t* zero, uint8_t* ptrail, uint8_t* predata, uint8_t* code); - -#endif \ No newline at end of file
--- a/main.cpp Wed Jul 23 13:06:57 2014 +0000 +++ b/main.cpp Fri Aug 01 12:37:29 2014 +0000 @@ -1,40 +1,62 @@ #include "mbed.h" -#include "IR.h" +#include "TxIR.hpp" #define LOG_LEVEL_VERBOSE #include "Puck.h" Puck* puck = &Puck::getPuck(); +TxIR txir(p14); + const UUID IR_SERVICE_UUID = stringToUUID("bftj ir "); -const UUID HEADER_UUID = stringToUUID("bftj ir header "); -const UUID ONE_UUID = stringToUUID("bftj ir one "); -const UUID ZERO_UUID = stringToUUID("bftj ir zero "); -const UUID PTRAIL_UUID = stringToUUID("bftj ir ptrail "); -const UUID PREDATA_UUID = stringToUUID("bftj ir predata "); -const UUID CODE_UUID = stringToUUID("bftj ir code "); +const UUID COMMAND_UUID = stringToUUID("bftj ir command "); +const UUID DATA_UUID = stringToUUID("bftj ir data "); +const UUID PERIOD_UUID = stringToUUID("bftj ir period "); + +unsigned int dataBuffer[100]; +uint8_t period = 26; +int receiveIndex; + +#define COMMAND_BEGIN_CODE_TRANSMISSION 0 +#define COMMAND_END_CODE_TRANSMISSION 1 -void onIRCodeWrite(uint8_t* value) { - LOG_INFO("Going to fire IR code...\n"); - fireIRCode(puck->getCharacteristicValue(HEADER_UUID), - puck->getCharacteristicValue(ONE_UUID), - puck->getCharacteristicValue(ZERO_UUID), - puck->getCharacteristicValue(PTRAIL_UUID), - puck->getCharacteristicValue(PREDATA_UUID), - puck->getCharacteristicValue(CODE_UUID)); - LOG_INFO("Fire complete!\n"); +void onCommandWrite(uint8_t* value) { + LOG_VERBOSE("Got command: %i\n", value[0]); + switch(value[0]) { + case COMMAND_BEGIN_CODE_TRANSMISSION: + receiveIndex = 0; + break; + case COMMAND_END_CODE_TRANSMISSION: + LOG_INFO("Going to fire IR code...\n"); + txir.txSeq(period, 200, dataBuffer); + LOG_INFO("Fire complete!\n"); + break; + } +} + + +void onDataWrite(uint8_t* value) { + LOG_VERBOSE("Got data, index: %i\n", receiveIndex); + for(int i = 0; i < 20 && receiveIndex < 100; i += 2) { + dataBuffer[receiveIndex++] = (value[i] << 8) | value[i + 1]; + } +} + + +void onPeriodWrite(uint8_t* value) { + period = value[0]; + LOG_VERBOSE("Period is now: %i\n", period); } int main() { - puck->addCharacteristic(IR_SERVICE_UUID, HEADER_UUID, 4); - puck->addCharacteristic(IR_SERVICE_UUID, ONE_UUID, 4); - puck->addCharacteristic(IR_SERVICE_UUID, ZERO_UUID, 4); - puck->addCharacteristic(IR_SERVICE_UUID, PTRAIL_UUID, 2); - puck->addCharacteristic(IR_SERVICE_UUID, PREDATA_UUID, 2); - puck->addCharacteristic(IR_SERVICE_UUID, CODE_UUID, 2); + puck->addCharacteristic(IR_SERVICE_UUID, COMMAND_UUID, 1); + puck->addCharacteristic(IR_SERVICE_UUID, DATA_UUID, 20); + puck->addCharacteristic(IR_SERVICE_UUID, PERIOD_UUID, 1); puck->init(0xABBA); - puck->onCharacteristicWrite(CODE_UUID, onIRCodeWrite); + puck->onCharacteristicWrite(COMMAND_UUID, onCommandWrite); + puck->onCharacteristicWrite(DATA_UUID, onDataWrite); + puck->onCharacteristicWrite(PERIOD_UUID, onPeriodWrite); while (puck->drive()); } \ No newline at end of file