ESPMegaPRO-v3-SDK/ESPMegaPRO-IRKit-SDK/src/main.cpp

75 lines
2.3 KiB
C++
Raw Normal View History

2024-01-10 17:15:00 +00:00
#include <ESPMegaProOS.hpp>
2024-01-10 17:07:34 +00:00
#include <IRReceiver.hpp>
/**
* @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();
2024-01-10 17:15:00 +00:00
for (int i = 0; i < CAPTURE_TIMEOUT; i++)
2024-01-10 17:07:34 +00:00
{
Serial.printf("Waiting for IR signal... (%d seconds left)\n", CAPTURE_TIMEOUT - i);
}
2024-01-10 17:15:00 +00:00
ir_data_t data = IRReceiver::end_long_receive();
timings_count[i - MIN_TEMP] = data.size;
2024-01-10 17:07:34 +00:00
// Copy the timings into the timings array
2024-01-10 17:15:00 +00:00
memcpy(timings[i - MIN_TEMP], data.data, sizeof(uint16_t) * data.size);
2024-01-10 17:07:34 +00:00
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");
}
2023-11-05 17:10:00 +00:00
void setup()
{
2024-01-10 17:07:34 +00:00
IRReceiver::begin(17);
espmega.begin();
2023-11-05 17:10:00 +00:00
}
void loop()
{
2024-01-10 17:10:44 +00:00
beginRoutine();
delay(10000);
2024-01-10 17:07:34 +00:00
}