ESPMegaPRO-v3-SDK/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/IRBlaster.cpp

39 lines
1.2 KiB
C++
Raw Normal View History

2024-01-10 10:10:51 +00:00
#include <IRBlaster.hpp>
void IRBlaster::send(uint16_t *data, size_t size)
{
rmt_item32_t *items = new rmt_item32_t[size];
for (size_t i = 0; i < size; i++)
{
items[i].duration0 = data[i] * 10;
items[i].level0 = 1;
items[i].duration1 = data[i] * 10;
items[i].level1 = 0;
}
ESP_ERROR_CHECK(rmt_write_items(channel, items, size, true));
delete[] items;
}
IRBlaster::IRBlaster(uint8_t pin, rmt_channel_t channel)
{
this->channel = channel;
rmt_config_t config;
config.rmt_mode = RMT_MODE_TX;
config.channel = channel;
config.gpio_num = gpio_num_t(pin);
config.mem_block_num = 1;
config.tx_config.loop_en = false;
config.tx_config.carrier_en = false;
config.tx_config.idle_output_en = true;
config.tx_config.idle_level = RMT_IDLE_LEVEL_LOW;
config.tx_config.carrier_freq_hz = 38000;
config.tx_config.carrier_level = RMT_CARRIER_LEVEL_HIGH;
config.clk_div = 80;
ESP_ERROR_CHECK(rmt_config(&config));
ESP_ERROR_CHECK(rmt_driver_install(channel, 0, 0));
}
IRBlaster::IRBlaster(uint8_t pin)
{
IRBlaster(pin, RMT_CHANNEL_0);
}