From cb7038ee63429bda8b8ddc5287faf73023a7bd8e Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 11 Jan 2024 00:07:34 +0700 Subject: [PATCH] batch IR Capture --- ESPMegaPRO-IRKit-SDK/platformio.ini | 3 +- ESPMegaPRO-IRKit-SDK/src/main.cpp | 94 +++++++++++++++++++++-------- ESPMegaPRO-IRKit-SDK/src/main.cpp.d | 73 ---------------------- ESPMegaPRO-IRKit-SDK/src/test.txt | 1 - ESPMegaPRO-IRKit-SDK/src/test2.txt | 1 - 5 files changed, 69 insertions(+), 103 deletions(-) delete mode 100644 ESPMegaPRO-IRKit-SDK/src/main.cpp.d delete mode 100644 ESPMegaPRO-IRKit-SDK/src/test.txt delete mode 100644 ESPMegaPRO-IRKit-SDK/src/test2.txt diff --git a/ESPMegaPRO-IRKit-SDK/platformio.ini b/ESPMegaPRO-IRKit-SDK/platformio.ini index d8c8aa2..a31e5aa 100644 --- a/ESPMegaPRO-IRKit-SDK/platformio.ini +++ b/ESPMegaPRO-IRKit-SDK/platformio.ini @@ -12,6 +12,5 @@ platform = espressif32 board = wt32-eth01 framework = arduino -lib_deps = siwats/ESPMegaPROR3@^1.3.0 - z3t0/IRremote@^4.2.0 +lib_deps = siwats/ESPMegaPROR3@^2.0.2 monitor_speed = 115200 \ No newline at end of file diff --git a/ESPMegaPRO-IRKit-SDK/src/main.cpp b/ESPMegaPRO-IRKit-SDK/src/main.cpp index adbf209..34b836d 100644 --- a/ESPMegaPRO-IRKit-SDK/src/main.cpp +++ b/ESPMegaPRO-IRKit-SDK/src/main.cpp @@ -1,32 +1,74 @@ -#include -// Infrared Transciever -#define IR_RECIEVE_PIN 35 -#define IR_SEND_PIN 17 -//#define MARK_EXCESS_MICROS 20 -#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}; -#include +#include +#include + +/** + * @brief This program helps construct an ir timing table for a air conditioner + * + * Each run of this program will generate a new table, for a specific mode and fan speed + * 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() { - Serial.begin(115200); - // IrReceiver.begin(IR_RECIEVE_PIN); - IrSender.begin(IR_SEND_PIN); + IRReceiver::begin(17); + espmega.begin(); } void loop() { - // if (IrReceiver.decode()) - // { - // 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); -} + espmega.loop(); +} \ No newline at end of file diff --git a/ESPMegaPRO-IRKit-SDK/src/main.cpp.d b/ESPMegaPRO-IRKit-SDK/src/main.cpp.d deleted file mode 100644 index 0aa18dc..0000000 --- a/ESPMegaPRO-IRKit-SDK/src/main.cpp.d +++ /dev/null @@ -1,73 +0,0 @@ -#include -/* -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 - -} \ No newline at end of file diff --git a/ESPMegaPRO-IRKit-SDK/src/test.txt b/ESPMegaPRO-IRKit-SDK/src/test.txt deleted file mode 100644 index aee3f2d..0000000 --- a/ESPMegaPRO-IRKit-SDK/src/test.txt +++ /dev/null @@ -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} \ No newline at end of file diff --git a/ESPMegaPRO-IRKit-SDK/src/test2.txt b/ESPMegaPRO-IRKit-SDK/src/test2.txt deleted file mode 100644 index ac2ee0c..0000000 --- a/ESPMegaPRO-IRKit-SDK/src/test2.txt +++ /dev/null @@ -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, \ No newline at end of file