Upgrade components

This commit is contained in:
Terrence
2025-05-07 04:55:51 +08:00
parent b00c5b50c3
commit fd6235750d
10 changed files with 209 additions and 165 deletions

View File

@@ -8,7 +8,9 @@
#include "config.h"
#include "iot/thing_manager.h"
#include "assets/lang_config.h"
#include <esp_log.h>
#include <button_adc.h>
#include <esp_lcd_panel_vendor.h>
#include <driver/i2c_master.h>
#include <driver/spi_common.h>
@@ -86,7 +88,7 @@ private:
ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));
}
void changeVol(int val) {
void ChangeVol(int val) {
auto codec = GetAudioCodec();
auto volume = codec->output_volume() + val;
if (volume > 100) {
@@ -109,7 +111,11 @@ private:
void InitializeButtons() {
/* Initialize ADC esp-box lite的前三个按钮采用是的adc按钮而非gpio */
button_adc_config_t adc_cfg;
button_config_t btn_config = {
.long_press_time = 2000,
.short_press_time = 50,
};
button_adc_config_t adc_cfg = {};
adc_cfg.adc_channel = ADC_CHANNEL_0; // ADC1 channel 0 is GPIO1
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
const adc_oneshot_unit_init_cfg_t init_config1 = {
@@ -121,27 +127,31 @@ private:
adc_cfg.button_index = BSP_ADC_BUTTON_PREV;
adc_cfg.min = 2310; // middle is 2410mV
adc_cfg.max = 2510;
adc_button_[0] = new Button(adc_cfg);
ESP_ERROR_CHECK(iot_button_new_adc_device(&btn_config, &adc_cfg, &adc_button_[0]));
adc_button_[0] = new Button(adc_button_[0]);
adc_cfg.button_index = BSP_ADC_BUTTON_ENTER;
adc_cfg.min = 1880; // middle is 1980mV
adc_cfg.max = 2080;
adc_button_[1] = new Button(adc_cfg);
ESP_ERROR_CHECK(iot_button_new_adc_device(&btn_config, &adc_cfg, &adc_button_[1]));
adc_button_[1] = new Button(adc_button_[1]);
adc_cfg.button_index = BSP_ADC_BUTTON_NEXT;
adc_cfg.min = 720; // middle is 820mV
adc_cfg.max = 920;
adc_button_[2] = new Button(adc_cfg);
ESP_ERROR_CHECK(iot_button_new_adc_device(&btn_config, &adc_cfg, &adc_button_[2]));
adc_button_[2] = new Button(adc_button_[2]);
auto volume_up_button = adc_button_[BSP_ADC_BUTTON_NEXT];
volume_up_button->OnClick([this]() {changeVol(10);});
volume_up_button->OnClick([this]() {ChangeVol(10);});
volume_up_button->OnLongPress([this]() {
GetAudioCodec()->SetOutputVolume(100);
GetDisplay()->ShowNotification(Lang::Strings::MAX_VOLUME);
});
auto volume_down_button = adc_button_[BSP_ADC_BUTTON_PREV];
volume_down_button->OnClick([this]() {changeVol(-10);});
volume_down_button->OnClick([this]() {ChangeVol(-10);});
volume_down_button->OnLongPress([this]() {
GetAudioCodec()->SetOutputVolume(0);
GetDisplay()->ShowNotification(Lang::Strings::MUTED);