#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() { IRReceiver::begin(17); espmega.begin(); } void loop() { beginRoutine(); delay(10000); }