From ae455ef0bca4ea7a7119dac1ed28f5aab9bae265 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 18 Nov 2011 22:06:49 +0100 Subject: add logic for sending ir signals --- onkyo_ri.pde | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/onkyo_ri.pde b/onkyo_ri.pde index 9f8c607..a23c920 100644 --- a/onkyo_ri.pde +++ b/onkyo_ri.pde @@ -30,6 +30,43 @@ uint64_t listenForIR(ir_t *proto); int getPulseLength(); int getPulseLengthInRange(int expected); +void sendToggle(int pin, int delayTime[]) { + digitalWrite(pin, LOW); + delayMicroseconds(delayTime[0] * 10); + digitalWrite(pin, HIGH); + delayMicroseconds(delayTime[1] * 10); +} + +void send(ir_t *proto, uint64_t value, int pin, bool inverted) { + bool low = inverted; + int i; + uint8_t bit; + + for (i = 0; i < ARRAY_LEN(proto->header); i++) { + digitalWrite(pin, low ? LOW : HIGH); + delayMicroseconds(proto->header[i] * 10); + low = !low; + } + + for (i = proto->prebits - 1; i >= 0; i--) { + bit = (proto->pre >> i) & 1; + sendToggle(pin, proto->values[bit]); + } + + for (i = proto->bits - 1; i >= 0; i--) { + bit = (value >> i) & 1; + sendToggle(pin, proto->values[bit]); + } + + for (i = 0; i < ARRAY_LEN(proto->trail); i++) { + digitalWrite(pin, low ? LOW : HIGH); + delayMicroseconds(proto->trail[i] * 10); + low = !low; + } + + digitalWrite(pin, low ? LOW : HIGH); +} + void setup(void) { Serial.begin(9600); Serial.println("Ready to decode IR!"); -- cgit v1.2.3