diff --git a/examples/LinkIR_demo/src/main.cpp b/examples/LinkIR_demo/src/main.cpp index c0d9a7d..68bb9b5 100644 --- a/examples/LinkIR_demo/src/main.cpp +++ b/examples/LinkIR_demo/src/main.cpp @@ -39,49 +39,52 @@ int main() { if (Common::didPress(KEY_A, a)) { Common::log("Sending..."); - linkIR->send((u16[]){ - // leader - 9000, 4500, - // address 0x04, LSB first (bits: 0,0,1,0,0,0,0,0) - 560, 560, // bit0: 0 - 560, 560, // bit1: 0 - 560, 1690, // bit2: 1 - 560, 560, // bit3: 0 - 560, 560, // bit4: 0 - 560, 560, // bit5: 0 - 560, 560, // bit6: 0 - 560, 560, // bit7: 0 - // inverted Address 0xFB, LSB first (bits: 1,1,0,1,1,1,1,1) - 560, 1690, // bit0: 1 - 560, 1690, // bit1: 1 - 560, 560, // bit2: 0 - 560, 1690, // bit3: 1 - 560, 1690, // bit4: 1 - 560, 1690, // bit5: 1 - 560, 1690, // bit6: 1 - 560, 1690, // bit7: 1 - // command 0x03, LSB first (bits: 1,1,0,0,0,0,0,0) - 560, 1690, // bit0: 1 - 560, 1690, // bit1: 1 - 560, 560, // bit2: 0 - 560, 560, // bit3: 0 - 560, 560, // bit4: 0 - 560, 560, // bit5: 0 - 560, 560, // bit6: 0 - 560, 560, // bit7: 0 - // inverted command 0xFC, LSB first (bits: 0,0,1,1,1,1,1,1) - 560, 560, // bit0: 0 - 560, 560, // bit1: 0 - 560, 1690, // bit2: 1 - 560, 1690, // bit3: 1 - 560, 1690, // bit4: 1 - 560, 1690, // bit5: 1 - 560, 1690, // bit6: 1 - 560, 1690, // bit7: 1 - // final burst - 560, - // terminator - 0}); + + linkIR->sendNEC(0x04, 0x03); + + // linkIR->send((u16[]){ + // // leader + // 9000, 4500, + // // address 0x04, LSB first (bits: 0,0,1,0,0,0,0,0) + // 560, 560, // bit0: 0 + // 560, 560, // bit1: 0 + // 560, 1690, // bit2: 1 + // 560, 560, // bit3: 0 + // 560, 560, // bit4: 0 + // 560, 560, // bit5: 0 + // 560, 560, // bit6: 0 + // 560, 560, // bit7: 0 + // // inverted Address 0xFB, LSB first (bits: 1,1,0,1,1,1,1,1) + // 560, 1690, // bit0: 1 + // 560, 1690, // bit1: 1 + // 560, 560, // bit2: 0 + // 560, 1690, // bit3: 1 + // 560, 1690, // bit4: 1 + // 560, 1690, // bit5: 1 + // 560, 1690, // bit6: 1 + // 560, 1690, // bit7: 1 + // // command 0x03, LSB first (bits: 1,1,0,0,0,0,0,0) + // 560, 1690, // bit0: 1 + // 560, 1690, // bit1: 1 + // 560, 560, // bit2: 0 + // 560, 560, // bit3: 0 + // 560, 560, // bit4: 0 + // 560, 560, // bit5: 0 + // 560, 560, // bit6: 0 + // 560, 560, // bit7: 0 + // // inverted command 0xFC, LSB first (bits: 0,0,1,1,1,1,1,1) + // 560, 560, // bit0: 0 + // 560, 560, // bit1: 0 + // 560, 1690, // bit2: 1 + // 560, 1690, // bit3: 1 + // 560, 1690, // bit4: 1 + // 560, 1690, // bit5: 1 + // 560, 1690, // bit6: 1 + // 560, 1690, // bit7: 1 + // // final burst + // 560, + // // terminator + // 0}); Common::log("DONE!"); Common::waitForKey(KEY_B); } diff --git a/lib/LinkIR.hpp b/lib/LinkIR.hpp index 5f1d204..bb158af 100644 --- a/lib/LinkIR.hpp +++ b/lib/LinkIR.hpp @@ -36,6 +36,11 @@ LINK_VERSION_TAG LINK_IR_VERSION = "vLinkIR/v8.0.0"; #define LINK_IR_SIGNAL_END 0 +#define LINK_IR_NEC_LEADER_MARK 9000 +#define LINK_IR_NEC_LEADER_SPACE 4500 +#define LINK_IR_NEC_PULSE 560 +#define LINK_IR_NEC_SPACE_1 1690 +#define LINK_IR_NEC_SPACE_0 560 #define LINK_IR_DEFAULT_TOLERANCE_PERCENTAGE 15 #define LINK_IR_DEFAULT_TIMER_ID 3 @@ -109,6 +114,22 @@ class LinkIR { return success; } + void sendNEC(u8 address, u8 command) { + u16 pulses[68]; + u32 i = 0; + + pulses[i++] = LINK_IR_NEC_LEADER_MARK; + pulses[i++] = LINK_IR_NEC_LEADER_SPACE; + addNECByte(pulses, i, address); + addNECByte(pulses, i, (u8)~address); + addNECByte(pulses, i, command); + addNECByte(pulses, i, (u8)~command); + pulses[i++] = LINK_IR_NEC_PULSE; + pulses[i++] = LINK_IR_SIGNAL_END; + + send(pulses); + } + /** * Sends a generic IR signal. * @param pulses An array of u16 numbers describing the signal. Even indices @@ -174,6 +195,14 @@ class LinkIR { volatile bool isEnabled = false; volatile bool irq = false; + void addNECByte(u16* pulses, u32& i, u8 value) { + for (u32 b = 0; b < 8; b++) { + pulses[i++] = LINK_IR_NEC_PULSE; + pulses[i++] = + (value >> b) & 1 ? LINK_IR_NEC_SPACE_1 : LINK_IR_NEC_SPACE_0; + } + } + void generate38kHzSignal(u32 microseconds); // defined in ASM (`LinkIR.cpp`) void waitMicroseconds(u32 microseconds); // defined in ASM (`LinkIR.cpp`)