integrate IRBlaster into climate card

This commit is contained in:
Siwat Sirichai 2024-01-10 19:43:07 +07:00
parent 618f0b51e8
commit 81aa0c64f9
6 changed files with 60 additions and 50 deletions

View file

@ -1,11 +1,23 @@
#include <IRBlaster.hpp>
#include <Arduino.h>
void IRBlaster::send(uint16_t *data, size_t size)
/**
* @brief Destroy the IRBlaster object
*/
IRBlaster::~IRBlaster()
{
ESP_ERROR_CHECK(rmt_driver_uninstall(channel));
}
/**
* @brief Send an IR signal
*
* @param data The microseconds timing array produced by IRReceiver
* @param size The number of elements in the array
*/
void IRBlaster::send(const uint16_t *data, const size_t size)
{
// Send a raw IR signal
rmt_item32_t *items = new rmt_item32_t[size / 2 + size % 2];
Serial.println("Converting IR data");
// data is in microseconds, we need to convert it to ticks
// If the number of elements is odd, we need to add a 0 at the end
for (size_t i = 0, j = 0; i < size; i += 2, j++)
@ -20,12 +32,18 @@ void IRBlaster::send(uint16_t *data, size_t size)
items[j].duration1 = 0;
}
}
Serial.println("Sending IR data");
ESP_ERROR_CHECK(rmt_write_items(channel, items, size / 2 + size % 2, true));
delete[] items;
}
IRBlaster::IRBlaster(uint8_t pin, rmt_channel_t channel)
/**
* @brief Construct a new IRBlaster object
*
* @param pin The pin to use for IR transmission
* @param channel The RMT channel to use
*/
IRBlaster::IRBlaster(const uint8_t pin, rmt_channel_t channel)
{
this->channel = channel;
gpio_num_t gpio = gpio_num_t(pin);
@ -37,7 +55,13 @@ IRBlaster::IRBlaster(uint8_t pin, rmt_channel_t channel)
ESP_ERROR_CHECK(rmt_driver_install(channel, 0, 0));
}
IRBlaster::IRBlaster(uint8_t pin)
/**
* @brief Construct a new IRBlaster object
* @note This constructor uses RMT_CHANNEL_0
*
* @param pin The pin to use for IR transmission
*/
IRBlaster::IRBlaster(const uint8_t pin)
{
IRBlaster(pin, RMT_CHANNEL_0);
}