batch IR Capture

This commit is contained in:
Siwat Sirichai 2024-01-11 00:07:34 +07:00
parent ec411bf7bb
commit cb7038ee63
5 changed files with 69 additions and 103 deletions

View File

@ -12,6 +12,5 @@
platform = espressif32 platform = espressif32
board = wt32-eth01 board = wt32-eth01
framework = arduino framework = arduino
lib_deps = siwats/ESPMegaPROR3@^1.3.0 lib_deps = siwats/ESPMegaPROR3@^2.0.2
z3t0/IRremote@^4.2.0
monitor_speed = 115200 monitor_speed = 115200

View File

@ -1,32 +1,74 @@
#include <ESPMegaPRO.h> #include <ESPMegaProOS.h>
// Infrared Transciever #include <IRReceiver.hpp>
#define IR_RECIEVE_PIN 35
#define IR_SEND_PIN 17 /**
//#define MARK_EXCESS_MICROS 20 * @brief This program helps construct an ir timing table for a air conditioner
#define RAW_BUFFER_LENGTH 1024 *
uint16_t rawTicks[] = {2404, 597, 1204, 596, 603, 597, 1203, 598, 603, 597, 1203, 597, 603, 597, 603, 597, 1203, 596, 604, 597, 604, 596, 603, 597, 603, 25810, 2402, 597, 1204, 596, 604, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 603, 597, 1203, 597, 603, 597, 603, 597, 603, 598, 602, 25804, 2404, 596, 1204, 597, 603, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 603, 597, 1204, 596, 603, 597, 603, 597, 603, 597, 604, 25803, 2404, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 603, 598, 1202, 598, 602, 597, 603, 598, 602, 598, 602, 25805, 2403, 597, 1203, 597, 603, 597, 1203, 597, 603, 598, 1202, 597, 603, 597, 603, 597, 1203, 597, 603, 598, 602, 598, 602, 598, 602, 25804, 2404, 597, 1202, 598, 602, 598, 1202, 598, 602, 598, 1202, 599, 602, 598, 601, 598, 1203, 597, 602, 599, 602, 598, 602, 598, 602, 25804, 2403, 598, 1202, 599, 601, 599, 1202, 598, 601, 598, 1202, 599, 601, 599, 602, 598, 1202, 598, 602, 598, 602, 597, 603, 598, 602, 25805, 2403, 598, 1201, 599, 601, 599, 1202, 598, 602, 598, 1202, 598, 602, 599, 601, 598, 1203, 597, 602, 599, 602, 598, 602, 597, 603}; * Each run of this program will generate a new table, for a specific mode and fan speed
#include <IRremote.hpp> * It will iterate through all the temperature settings, and record the timing for each temperature
* It will then print the timing table as a C++ 2D array, which can be copied into your main program
* The first dimension is the temperature, the second dimension is the timing
*/
#define MIN_TEMP 16
#define MAX_TEMP 30
#define MAX_TIMINGS 1000 // 1000 timings should be enough for any remote
#define CAPTURE_TIMEOUT 5 // seconds
uint16_t timings[MAX_TEMP - MIN_TEMP + 1][MAX_TIMINGS] = {0};
uint16_t timings_count[MAX_TEMP - MIN_TEMP + 1] = {0};
ESPMegaPRO espmega = ESPMegaPRO();
void beginRoutine()
{
Serial.println("Beginning IR capture routine");
for (int i = MIN_TEMP; i <= MAX_TEMP; i++)
{
Serial.printf("Please press the button on your remote for %d degrees\n", i);
IRReceiver::start_long_receive();
for (int i = 0; i < CAPTURE_TIMEOUT, i++)
{
Serial.printf("Waiting for IR signal... (%d seconds left)\n", CAPTURE_TIMEOUT - i);
}
ir_data_t data = IRReceiver::end_receive();
timing_count[i - MIN_TEMP] = data.count;
// Copy the timings into the timings array
memcpy(timings[i - MIN_TEMP], data.data, sizeof(uint16_t) * data.count);
free(data.data);
}
Serial.println("Generating C++ code for the timings, please wait...");
// Find the maximum number of timings
int max_timings = 0;
for (int i = 0; i < MAX_TEMP - MIN_TEMP + 1; i++)
{
if (timings_count[i] > max_timings)
{
max_timings = timings_count[i];
}
}
// Print the timings
Serial.println("Done!, please copy the following into your main program");
Serial.printf("uint16_t timings[%d][%d] = {\n", MAX_TEMP - MIN_TEMP + 1, max_timings);
for (int i = 0; i < MAX_TEMP - MIN_TEMP + 1; i++)
{
Serial.printf(" {");
for (int j = 0; j < timings_count[i]; j++)
{
Serial.printf("%d%s", timings[i][j], j == timings_count[i] - 1 ? "" : ", ");
}
Serial.println(i == MAX_TEMP - MIN_TEMP ? "}" : "},");
}
Serial.println("};");
Serial.println("Stopping IR capture routine");
}
void setup() void setup()
{ {
Serial.begin(115200); IRReceiver::begin(17);
// IrReceiver.begin(IR_RECIEVE_PIN); espmega.begin();
IrSender.begin(IR_SEND_PIN);
} }
void loop() void loop()
{ {
// if (IrReceiver.decode()) espmega.loop();
// {
// Serial.println();
// IrReceiver.printIRSendUsage(&Serial);
// IrReceiver.compensateAndPrintIRResultAsCArray(&Serial, false);
// Serial.println();
// Serial.println();
// IrReceiver.resume();
// }
//IrSender.sendRaw(ir_code_a,sizeof(ir_code_a)/sizeof(ir_code_a[0]),NEC_KHZ);
// IrSender.sendRaw(ir_code_b,sizeof(ir_code_b)/sizeof(ir_code_b[0]),NEC_KHZ);
IrSender.sendRaw(rawTicks,sizeof(rawTicks)/sizeof(rawTicks[0]),NEC_KHZ);
//IrSender.sendSony(0x1, 0x15, 2, 12);
delay(500);
} }

View File

@ -1,73 +0,0 @@
#include <ESPMegaPRO.h>
/*
Author: AnalysIR
Revision: 1.0
This code is provided to overcome an issue with Arduino IR libraries
It allows you to capture raw timings for signals longer than 255 marks & spaces.
Typical use case is for long Air conditioner signals.
You can use the output to plug back into IRremote, to resend the signal.
This Software was written by AnalysIR.
Usage: Free to use, subject to conditions posted on blog below.
Please credit AnalysIR and provide a link to our website/blog, where possible.
Copyright AnalysIR 2014
Please refer to the blog posting for conditions associated with use.
http://www.analysir.com/blog/2014/03/19/air-conditioners-problems-recording-long-infrared-remote-control-signals-arduino/
Connections:
IR Receiver Arduino
V+ -> +5v
GND -> GND
Signal Out -> Digital Pin 2
(If using a 3V Arduino, you may connect V+ to +3V)
*/
void rxIR_Interrupt_Handler();
#define LEDPIN 17
//you may increase this value on Arduinos with greater than 2k SRAM
#define maxLen 800
volatile unsigned int irBuffer[maxLen]; //stores timings - volatile because changed by ISR
volatile unsigned int x = 0; //Pointer thru irBuffer - volatile because changed by ISR
void setup() {
Serial.begin(115200); //change BAUD rate as required
attachInterrupt(digitalPinToInterrupt(35), rxIR_Interrupt_Handler, CHANGE);//set up ISR for receiving IR signal
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(F("Press the button on the remote now - once only"));
delay(5000); // pause 5 secs
if (x) { //if a signal is captured
digitalWrite(LEDPIN, HIGH);//visual indicator that signal received
Serial.println();
Serial.print(F("Raw: (")); //dump raw header format - for library
Serial.print((x - 1));
Serial.print(F(") "));
detachInterrupt(0);//stop interrupts & capture until finshed here
for (int i = 1; i < x; i++) { //now dump the times
if (!(i & 0x1)) Serial.print(F("-"));
Serial.print(irBuffer[i] - irBuffer[i - 1]);
Serial.print(F(", "));
}
x = 0;
Serial.println();
Serial.println();
digitalWrite(LEDPIN, LOW);//end of visual indicator, for this time
attachInterrupt(0, rxIR_Interrupt_Handler, CHANGE);//re-enable ISR for receiving IR signal
}
}
void rxIR_Interrupt_Handler() {
if (x > maxLen) return; //ignore if irBuffer is already full
irBuffer[x++] = micros(); //just continually record the time-stamp of signal transitions
}

View File

@ -1 +0,0 @@
{438, 430, 435, 430, 436, 430, 435, 430, 436, 430, 435, 25095, 3467, 1727, 436, 1295, 436, 430, 435, 430, 436, 430, 435, 1295, 436, 430, 436, 430, 436, 429, 435, 431, 436, 1294, 436, 429, 436, 1295, 437, 1294, 437, 429, 436, 1295, 437, 1294, 436, 1295, 436, 1296, 435, 1295, 436, 430, 436, 429, 436, 1295, 436, 432, 434, 429, 436, 429, 436, 430, 436, 429, 436, 431, 434, 431, 435, 430, 436, 430, 436, 429, 436, 1295, 436, 429, 436, 1296, 435, 430, 436, 430, 436, 429, 436, 1295, 436, 1295, 435, 430, 436, 430, 436, 429, 436, 430, 436, 1295, 436, 429, 436, 430, 435, 430, 436, 430, 435, 430, 436, 429, 436, 430, 436, 430, 435, 429, 437, 429, 436, 430, 436, 1295, 436, 1295, 435, 1296, 436, 430, 435, 430, 435, 1296, 436, 1295, 436, 1296, 435, 35481, 3466, 1728, 436, 1296, 435, 429, 436, 430, 436, 429, 436, 1295, 436, 429, 436, 430, 436, 430, 435, 430, 436, 1295, 436, 429, 436, 1295, 436, 1295, 436, 430, 436, 1295, 436, 1295, 436, 1295, 436, 1295, 436, 1295, 436, 429, 436, 430, 436, 1295, 436, 429, 436, 429, 436, 430, 436, 430, 436, 429, 436, 430, 435, 430, 436, 430, 435, 430, 436, 430, 435, 430, 436, 1294, 437, 430, 436, 429, 436, 429, 436, 430, 436, 1295, 436, 429, 437, 429, 436, 430, 435, 431, 435, 429, 436, 430, 436, 430, 436, 429, 436, 430, 435, 430, 436, 430, 436, 429, 435, 430, 437, 1295, 435, 430, 436, 430, 435, 431, 435, 429, 437, 429, 436, 1295, 436, 429, 436, 429, 437, 1295, 436, 1295, 436, 429, 436, 35481, 3466, 1728, 436, 1295, 436, 429, 436, 430, 436, 430, 435, 1296, 436, 429, 436, 429, 436, 430, 436, 429, 436, 1295, 436, 430, 436, 1294, 437, 1296, 435, 429, 436, 1294, 437, 1295, 436, 1295, 436, 1296, 435, 1295, 436, 430, 436, 429, 436, 1295, 435, 431, 435, 430, 436, 430, 435, 430, 436, 430, 435, 430, 436, 430, 435, 430, 436, 430, 435, 430, 436, 429, 437, 429, 436, 429, 437, 429, 436, 429, 436, 430, 435, 430, 436, 429, 436, 1296, 435, 430, 436, 430, 436, 1295, 436, 1295, 436, 1294, 437, 429, 436, 431, 434, 430, 436, 430, 436, 1295, 436, 429, 436, 1295, 436, 1295, 436, 430, 435, 430, 436, 430, 435, 430, 436, 430, 435, 430, 436, 429, 436, 429, 437, 430, 436, 429, 436, 1295, 435, 1296, 436, 1295, 436, 1295, 436, 1295, 436, 1295, 436, 1295, 436, 430, 435, 430, 436, 430, 435, 429, 437, 429, 436, 430, 436, 429, 436, 430, 436, 429, 436, 430, 435, 431, 435, 429, 436, 430, 436, 429, 436, 430, 436, 430, 435, 430, 436, 429, 436, 1295, 436, 1296, 435, 430, 436, 430, 436, 430, 435, 430, 435, 430, 436, 430, 436, 429, 436, 429, 436, 430, 436, 429, 436, 1296, 435, 1295, 437, 429, 436, 429, 437, 429, 436, 429, 437, 429, 436, 430, 435, 430, 436, 429, 436, 430, 436, 429, 436, 430, 436, 429, 436, 429, 436, 430, 436, 430, 437, 427, 437, 430, 435, 1296, 436, 429, 436, 1295, 436, 430, 435, 430, 436, 430, 436, 1295, 435, 1296, 435, 430, 436, 430, 435, 430, 436, 430, 436, 429, 436, 430, 435, 430, 436, 430, 435, 430, 436, 429, 436, 430, 436, 1295, 436, 430, 436, 430, 435, 430, 435, 430, 436, 1295, 436, 430, 436, 430, 435, 430, 435, 1295, 436, 1295, 436, 430, 436, 429, 436}

View File

@ -1 +0,0 @@
2404, 597, 1204, 596, 603, 597, 1203, 598, 603, 597, 1203, 597, 603, 597, 603, 597, 1203, 596, 604, 597, 604, 596, 603, 597, 603, 25810, 2402, 597, 1204, 596, 604, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 603, 597, 1203, 597, 603, 597, 603, 597, 603, 598, 602, 25804, 2404, 596, 1204, 597, 603, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 603, 597, 1204, 596, 603, 597, 603, 597, 603, 597, 604, 25803, 2404, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 1203, 597, 603, 597, 603, 598, 1202, 598, 602, 597, 603, 598, 602, 598, 602, 25805, 2403, 597, 1203, 597, 603, 597, 1203, 597, 603, 598, 1202, 597, 603, 597, 603, 597, 1203, 597, 603, 598, 602, 598, 602, 598, 602, 25804, 2404, 597, 1202, 598, 602, 598, 1202, 598, 602, 598, 1202, 599, 602, 598, 601, 598, 1203, 597, 602, 599, 602, 598, 602, 598, 602, 25804, 2403, 598, 1202, 599, 601, 599, 1202, 598, 601, 598, 1202, 599, 601, 599, 602, 598, 1202, 598, 602, 598, 602, 597, 603, 598, 602, 25805, 2403, 598, 1201, 599, 601, 599, 1202, 598, 602, 598, 1202, 598, 602, 599, 601, 598, 1203, 597, 602, 599, 602, 598, 602, 597, 603,