From 58a79eb1ad8ca8ee2205dbeaecd52ff8cf6f2c48 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Mon, 28 Aug 2023 02:07:04 +0700 Subject: [PATCH] Basic Infrared Function --- platformio.ini | 1 + src/daikin_ir.hpp | 25 +++++++++++++++++++++++++ src/main.cpp | 23 +++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 src/daikin_ir.hpp diff --git a/platformio.ini b/platformio.ini index 7110682..74c99c5 100644 --- a/platformio.ini +++ b/platformio.ini @@ -17,4 +17,5 @@ lib_deps = siwats/espmegapror3@^1.0.2 ivanseidel/ArduinoThread@^2.1.1 arduino-libraries/Arduino_BuiltIn@^1.0.0 dersimn/PubSubClientTools@^0.6 + z3t0/IRremote@^4.2.0 monitor_speed = 115200 \ No newline at end of file diff --git a/src/daikin_ir.hpp b/src/daikin_ir.hpp new file mode 100644 index 0000000..2ccf596 --- /dev/null +++ b/src/daikin_ir.hpp @@ -0,0 +1,25 @@ +#ifndef DAIKIN_IR +#define DAIKIN_IR +#ifndef ESPMEGA +#include +#endif + +extern const uint16_t daikin_ir_code_cool[3][10][750] = { + // Fan Speed Low + { + {0}, // 16C + {0} // 17C + }, + // Fan Speed MED + { + {0}, // 16C + {0} // 17C + }}; + +extern const uint16_t daikin_ir_code_fan[3][750] = { + {0}, // LOW + {0}, // MED + {0} // HIGH +}; +extern const uint16_t daikin_ir_code_off[750] = {0}; +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index dc16c34..e5bca59 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include // Network Connectivity #define HOSTNAME "espmega-pro-r3" @@ -38,6 +40,12 @@ const float pwm_linear_scaling_c[PWM_COUNT] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #define PWM_CYCLE_VALUES_COUNT 3 const int PWM_CYCLE_VALUES[PWM_CYCLE_VALUES_COUNT] = {50, 125, 255}; +// Infrared Transciever +#define IR_RECIEVER_PIN 4 +#define IR_TRANSMITTER_PIN 15 +#define MARK_EXCESS_MICROS 20 +#define RAW_BUFFER_LENGTH 750 + // Forward declaration void virtual_interrupt_loop(); void virtual_interrupt_callback(int pin, int state); @@ -49,6 +57,7 @@ void pwm_state_callback(String topic, String message); void pwm_value_callback(String topic, String message); void state_request_callback(String topic, String message); void io_begin(); +void ir_loop(); void publish_pwm_states(); void publish_pwm_state(int id); @@ -80,6 +89,9 @@ void setup() Serial.println("ESPMega R3 Initializing . . ."); ESPMega_begin(); io_begin(); + Serial.println("Initializing Infrared . . ."); + IrReceiver.begin(IR_RECIEVER_PIN); + IrSender.begin(IR_TRANSMITTER_PIN); network_begin(); Serial.println("Initializing MQTT . . ."); mqtt_connect(); @@ -93,6 +105,7 @@ void loop() virtual_interrupt_loop(); mqtt_client.loop(); ESPMega_loop(); + ir_loop(); thread_controller.run(); } @@ -353,4 +366,14 @@ void state_request_callback(String topic, String message) { publish_input_states(); publish_pwm_states(); +} + +void ir_loop() { + if (IrReceiver.decode()) { + IrReceiver.printIRResultAsCVariables(&Serial); + Serial.println(); + IrReceiver.printIRResultRawFormatted(&Serial, true); + Serial.println(); + Serial.println(); + } } \ No newline at end of file