/*
* AmznTopping_IR_Repeater.ino
* Capture SONY IR codes form Amazon Fire TV Remote and convert to Topping RC-15A Remote Codes
* Copyright 2021 Samuel A. Hurley (halfSpinDoctor)
* http://www.paradime.net [email protected]
*
* Based on IRremoteESP8266: SmartIRRepeater.ino, (C) 2019 David Conran (crankyoldgit)
*
* License: BSD-2-Clause
*
* Copyright 2021 Samuel A. Hurley
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <Arduino.h>
#include <IRsend.h>
#include <IRrecv.h>
#include <IRremoteESP8266.h>
#include <IRutils.h>
#define DECODE_SONY
// ==================== start of TUNEABLE PARAMETERS ====================
// The GPIO an IR detector/demodulator is connected to. Recommended: 14 (D5)
// Note: GPIO 16 won't work on the ESP8266 as it does not have interrupts.
const uint16_t kRecvPin = 13; // This must be set to 13 for the SparkFun board
// GPIO to use to control the IR LED circuit. Recommended: 4 (D2).
const uint16_t kIrLedPin = 4;
// The Serial connection baud rate.
// NOTE: Make sure you set your Serial Monitor to the same speed.
const uint32_t kBaudRate = 115200;
// As this program is a special purpose capture/resender, let's use a larger
// than expected buffer so we can handle very large IR messages.
const uint16_t kCaptureBufferSize = 1024; // 1024 == ~511 bits
// kTimeout is the Nr. of milli-Seconds of no-more-data before we consider a
// message ended.
const uint8_t kTimeout = 50; // Milli-Seconds
// kFrequency is the modulation frequency all UNKNOWN messages will be sent at.
// NOT USED
const uint16_t kFrequency = 38000; // in Hz. e.g. 38kHz.
// ==================== end of TUNEABLE PARAMETERS ====================
// The IR transmitter.
IRsend irsend(kIrLedPin);
// The IR receiver.
IRrecv irrecv(kRecvPin, kCaptureBufferSize, kTimeout, false);
// Somewhere to store the captured message.
decode_results results;
// This section of code runs only once at start-up.
void setup() {
irrecv.enableIRIn(); // Start up the IR receiver.
irsend.begin(); // Start up the IR sender.
Serial.begin(kBaudRate, SERIAL_8N1, SERIAL_TX_ONLY);
Serial.print("SmartIRRepeater is now running and waiting for IR input "
"on Pin ");
Serial.println(kRecvPin);
Serial.print("and will retransmit it on Pin ");
Serial.println(kIrLedPin);
}
// The repeating section of the code
void loop() {
// Check if an IR message has been received.
if (irrecv.decode(&results)) { // We have captured something.
// The capture has stopped at this point.
decode_type_t protocol = results.decode_type;
uint16_t size = results.bits;
bool success = true;
// Is it the SONY protocol?
if (protocol == decode_type_t::SONY) {
// Check for vol+ / vol- / mute result:
if (results.value == 0x240C) {
Serial.println("vol up");
irsend.sendNEC(0x11EE629D);
} else if (results.value == 0x640C) {
Serial.println("vol down");
irsend.sendNEC(0x11EE6897);
} else if (results.value == 0x140C) {
Serial.println("mute");
irsend.sendNEC(0x11EE609F);
} else {
serialPrintUint64(results.value, 16);
Serial.println(" - command not recognized.");
}
}
// Resume capturing IR messages. It was not restarted until after we sent
// the message so we didn't capture our own message.
irrecv.resume();
}
yield(); // Or delay(milliseconds); This ensures the ESP doesn't WDT reset.
}