Last active
May 10, 2024 23:56
-
-
Save JarrettR/2864aeaf5060cac33a3ab2423c8de4bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://github.com/mswietlicki/Lirc_remotes/blob/master/benq.config | |
#include <stdio.h> | |
#include "freertos/FreeRTOS.h" | |
#include "freertos/task.h" | |
#include "driver/rmt.h" | |
#include "driver/gpio.h" | |
#include "esp_system.h" | |
#include "esp_log.h" | |
#define RMT_IO (GPIO_NUM_18) | |
#define ON_OFF_CONTROL (GPIO_NUM_19) | |
#define PIN_INDICATOR (GPIO_NUM_5) | |
static const char* TAG = "ir_transmitter"; | |
#define ZERO_BIT {{{ 604, 1, 511, 0 }}} | |
#define ONE_BIT {{{ 604, 1, 1622, 0 }}} | |
#define RMT_END {{{ 0, 1, 0, 0 }}} | |
#define PACKET_HEADER {{{ 9077, 1, 4504, 0 }}} | |
#define PACKET_TAIL {{{ 604, 1, 108167, 0 }}} | |
#define PACKET_ZERO_NIBBLE ZERO_BIT,ZERO_BIT,ZERO_BIT,ZERO_BIT | |
//0x000CF20D | |
static const rmt_item32_t on_key[] = { | |
PACKET_HEADER, | |
PACKET_ZERO_NIBBLE, | |
PACKET_ZERO_NIBBLE, | |
PACKET_ZERO_NIBBLE, | |
//C | |
ONE_BIT, | |
ONE_BIT, | |
ZERO_BIT, | |
ZERO_BIT, | |
//F | |
ONE_BIT, | |
ONE_BIT, | |
ONE_BIT, | |
ONE_BIT, | |
//2 | |
ZERO_BIT, | |
ZERO_BIT, | |
ONE_BIT, | |
ZERO_BIT, | |
//0 | |
PACKET_ZERO_NIBBLE, | |
//D | |
ONE_BIT, | |
ONE_BIT, | |
ZERO_BIT, | |
ONE_BIT, | |
//End | |
PACKET_TAIL, | |
RMT_END | |
}; | |
static const rmt_item32_t tail_key[] = { | |
{{{ 9000, 1, 2273, 0 }}}, | |
{{{ 538, 1, 2254, 0 }}}, | |
RMT_END | |
}; | |
//0x000C728D | |
static const rmt_item32_t off_key[] = { | |
PACKET_HEADER, | |
PACKET_ZERO_NIBBLE, | |
PACKET_ZERO_NIBBLE, | |
PACKET_ZERO_NIBBLE, | |
//C | |
ONE_BIT, | |
ONE_BIT, | |
ZERO_BIT, | |
ZERO_BIT, | |
//7 | |
ZERO_BIT, | |
ONE_BIT, | |
ONE_BIT, | |
ONE_BIT, | |
//2 | |
ZERO_BIT, | |
ZERO_BIT, | |
ONE_BIT, | |
ZERO_BIT, | |
//0 | |
PACKET_ZERO_NIBBLE, | |
//D | |
ONE_BIT, | |
ONE_BIT, | |
ZERO_BIT, | |
ONE_BIT, | |
//End | |
PACKET_TAIL, | |
RMT_END | |
}; | |
static void send_on() | |
{ | |
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, on_key, sizeof(on_key) / sizeof(on_key[0]), true)); | |
vTaskDelay(44/portTICK_RATE_MS); | |
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, tail_key, sizeof(tail_key) / sizeof(tail_key[0]), true)); | |
} | |
static void send_off() | |
{ | |
//Off needs to be pressed twice | |
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, off_key, sizeof(off_key) / sizeof(off_key[0]), true)); | |
vTaskDelay(2000/portTICK_RATE_MS); | |
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, off_key, sizeof(off_key) / sizeof(off_key[0]), true)); | |
} | |
void app_main(void) | |
{ | |
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(RMT_IO, RMT_CHANNEL_0); | |
// set count to 1us | |
config.clk_div = 80; | |
config.tx_config.carrier_en = true; | |
config.tx_config.carrier_freq_hz = 38000; | |
config.tx_config.carrier_duty_percent = 35; | |
ESP_ERROR_CHECK(rmt_config(&config)); | |
ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0)); | |
gpio_set_direction(ON_OFF_CONTROL, GPIO_MODE_INPUT); | |
gpio_set_pull_mode(ON_OFF_CONTROL, GPIO_PULLUP_ONLY); | |
gpio_set_direction(PIN_INDICATOR, GPIO_MODE_OUTPUT); | |
while (1) { | |
gpio_set_level(PIN_INDICATOR, 1); | |
if (gpio_get_level(ON_OFF_CONTROL) == 1) { | |
send_on(); | |
} else { | |
send_off(); | |
} | |
vTaskDelay(1); | |
gpio_set_level(PIN_INDICATOR, 0); | |
vTaskDelay(2000/portTICK_RATE_MS); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment