diff options
Diffstat (limited to '')
-rw-r--r-- | onkyo_ri.pde | 37 |
1 files changed, 37 insertions, 0 deletions
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!"); |