Basic Infrared Function

This commit is contained in:
Siwat Sirichai 2023-08-28 02:07:04 +07:00
parent 77e7330639
commit 58a79eb1ad
3 changed files with 49 additions and 0 deletions

View File

@ -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

25
src/daikin_ir.hpp Normal file
View File

@ -0,0 +1,25 @@
#ifndef DAIKIN_IR
#define DAIKIN_IR
#ifndef ESPMEGA
#include <ESPMegaPRO.h>
#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

View File

@ -5,6 +5,8 @@
#include <PubSubClientTools.h>
#include <Thread.h>
#include <StaticThreadController.h>
#include <IRremote.hpp>
#include <daikin_ir.hpp>
// 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();
}
}