Add LED for user feedback
This commit is contained in:
parent
86e2d3a6b8
commit
0d8f93c791
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,6 +2,8 @@ build/
|
||||
sdkconfig
|
||||
sdkconfig.old
|
||||
|
||||
managed_components/
|
||||
|
||||
.vscode/
|
||||
|
||||
cmake-build-*/
|
||||
|
||||
@ -2,4 +2,5 @@ idf_component_register(SRCS "esp_tunnel.cpp"
|
||||
"app_networking.cpp"
|
||||
"app_serial.cpp"
|
||||
"app_config.cpp"
|
||||
"app_led.cpp"
|
||||
INCLUDE_DIRS ".")
|
||||
|
||||
64
main/app_led.cpp
Normal file
64
main/app_led.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
//
|
||||
// Created by erki on 26/06/23.
|
||||
//
|
||||
|
||||
#include "app_led.hpp"
|
||||
|
||||
#include "led_strip.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
led_strip_handle_t s_strip;
|
||||
bool s_tx_on = false;
|
||||
bool s_rx_on = false;
|
||||
|
||||
void s_updateStrip()
|
||||
{
|
||||
const int red = s_tx_on ? 10 : 0;
|
||||
const int blue = s_rx_on ? 10 : 0;
|
||||
|
||||
led_strip_set_pixel(s_strip, 0, red, 10, blue);
|
||||
led_strip_refresh(s_strip);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Led
|
||||
{
|
||||
|
||||
void setupLed(const gpio_num_t gpio)
|
||||
{
|
||||
led_strip_config_t config = {
|
||||
.strip_gpio_num = gpio,
|
||||
.max_leds = 1,
|
||||
.led_pixel_format = LED_PIXEL_FORMAT_GRB,
|
||||
.led_model = LED_MODEL_WS2812,
|
||||
.flags = { 0 }
|
||||
};
|
||||
|
||||
led_strip_rmt_config_t rmt_config = {
|
||||
.clk_src = RMT_CLK_SRC_DEFAULT,
|
||||
.resolution_hz = 10 * 1000 * 1000,
|
||||
.mem_block_symbols = 0,
|
||||
.flags = { 0 }
|
||||
};
|
||||
|
||||
ESP_ERROR_CHECK(led_strip_new_rmt_device(&config, &rmt_config, &s_strip));
|
||||
led_strip_clear(s_strip);
|
||||
s_updateStrip();
|
||||
}
|
||||
|
||||
void flashRx()
|
||||
{
|
||||
s_rx_on = !s_rx_on;
|
||||
s_updateStrip();
|
||||
}
|
||||
|
||||
void flashTx()
|
||||
{
|
||||
s_tx_on = !s_tx_on;
|
||||
s_updateStrip();
|
||||
}
|
||||
|
||||
}
|
||||
13
main/app_led.hpp
Normal file
13
main/app_led.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <driver/gpio.h>
|
||||
|
||||
namespace Led
|
||||
{
|
||||
|
||||
void setupLed(const gpio_num_t gpio);
|
||||
void flashRx();
|
||||
void flashTx();
|
||||
|
||||
} // namespace Led
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include "app_networking.hpp"
|
||||
#include "app_serial.hpp"
|
||||
#include "app_config.hpp"
|
||||
#include "app_led.hpp"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
@ -36,6 +37,8 @@ void s_sendUartData(std::size_t len)
|
||||
uart_read_bytes(CONFIG_ESPTNL_UART, tx_buffer.data(), len, 0);
|
||||
|
||||
xTimerStop(s_timer, 0);
|
||||
Led::flashTx();
|
||||
|
||||
Networking::sendData(tx_buffer, len);
|
||||
}
|
||||
|
||||
@ -65,9 +68,13 @@ std::size_t s_uartBytesWaiting()
|
||||
{
|
||||
std::size_t uart_free = 0;
|
||||
uart_get_tx_buffer_free_size(CONFIG_ESPTNL_UART, &uart_free);
|
||||
|
||||
if (uart_free >= event.rx_length)
|
||||
{
|
||||
ESP_LOGD(LOG_TAG, "ESP-NOW event: wrote %ull bytes to UART RX.", uart_free);
|
||||
|
||||
Led::flashRx();
|
||||
|
||||
const auto& esp_rx_buffer = Networking::getRxBuffer();
|
||||
uart_write_bytes(CONFIG_ESPTNL_UART, esp_rx_buffer.data(), event.rx_length);
|
||||
}
|
||||
@ -151,6 +158,8 @@ extern "C" void app_main(void)
|
||||
xQueueAddToSet(s_esp_now_queue, s_queue_set);
|
||||
xQueueAddToSet(s_uart_queue, s_queue_set);
|
||||
|
||||
Led::setupLed(GPIO_NUM_8);
|
||||
|
||||
ESP_LOGI(LOG_TAG, "Setup completed. Sending hello.");
|
||||
|
||||
Networking::sendHello();
|
||||
|
||||
2
main/idf_component.yml
Normal file
2
main/idf_component.yml
Normal file
@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
espressif/led_strip: "^2.0.0"
|
||||
Loading…
x
Reference in New Issue
Block a user