diff --git a/main/boards/common/button.cc b/main/boards/common/button.cc index 8735cac3..723cc730 100644 --- a/main/boards/common/button.cc +++ b/main/boards/common/button.cc @@ -5,6 +5,16 @@ #define TAG "Button" +#if CONFIG_SOC_ADC_SUPPORTED +AdcButton::AdcButton(const button_adc_config_t& adc_config) : Button(nullptr) { + button_config_t btn_config = { + .long_press_time = 2000, + .short_press_time = 50, + }; + ESP_ERROR_CHECK(iot_button_new_adc_device(&btn_config, &adc_config, &button_handle_)); +} +#endif + Button::Button(button_handle_t button_handle) : button_handle_(button_handle) { } diff --git a/main/boards/common/button.h b/main/boards/common/button.h index 55341e86..4c7ef616 100644 --- a/main/boards/common/button.h +++ b/main/boards/common/button.h @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include class Button { @@ -18,7 +20,8 @@ public: void OnClick(std::function callback); void OnDoubleClick(std::function callback); void OnMultipleClick(std::function callback, uint8_t click_count = 3); -private: + +protected: gpio_num_t gpio_num_; button_handle_t button_handle_ = nullptr; @@ -30,4 +33,11 @@ private: std::function on_multiple_click_; }; +#if CONFIG_SOC_ADC_SUPPORTED +class AdcButton : public Button { +public: + AdcButton(const button_adc_config_t& adc_config); +}; +#endif + #endif // BUTTON_H_ diff --git a/main/boards/esp-box-lite/esp_box_lite_board.cc b/main/boards/esp-box-lite/esp_box_lite_board.cc index fa9b262f..9cafd2d2 100644 --- a/main/boards/esp-box-lite/esp_box_lite_board.cc +++ b/main/boards/esp-box-lite/esp_box_lite_board.cc @@ -111,10 +111,6 @@ private: void InitializeButtons() { /* Initialize ADC esp-box lite的前三个按钮采用是的adc按钮,而非gpio */ - 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) @@ -127,21 +123,18 @@ private: adc_cfg.button_index = BSP_ADC_BUTTON_PREV; adc_cfg.min = 2310; // middle is 2410mV adc_cfg.max = 2510; - ESP_ERROR_CHECK(iot_button_new_adc_device(&btn_config, &adc_cfg, &adc_button_[0])); - adc_button_[0] = new Button(adc_button_[0]); + adc_button_[0] = new AdcButton(adc_cfg); adc_cfg.button_index = BSP_ADC_BUTTON_ENTER; adc_cfg.min = 1880; // middle is 1980mV adc_cfg.max = 2080; - ESP_ERROR_CHECK(iot_button_new_adc_device(&btn_config, &adc_cfg, &adc_button_[1])); - adc_button_[1] = new Button(adc_button_[1]); + adc_button_[1] = new AdcButton(adc_cfg); adc_cfg.button_index = BSP_ADC_BUTTON_NEXT; adc_cfg.min = 720; // middle is 820mV adc_cfg.max = 920; - ESP_ERROR_CHECK(iot_button_new_adc_device(&btn_config, &adc_cfg, &adc_button_[2])); - adc_button_[2] = new Button(adc_button_[2]); + adc_button_[2] = new AdcButton(adc_cfg); auto volume_up_button = adc_button_[BSP_ADC_BUTTON_NEXT]; volume_up_button->OnClick([this]() {ChangeVol(10);}); diff --git a/main/idf_component.yml b/main/idf_component.yml index f43d97be..f9b7319f 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -11,7 +11,7 @@ dependencies: 78/esp_lcd_nv3023: "~1.0.0" 78/esp-wifi-connect: "~2.4.2" 78/esp-opus-encoder: "~2.3.2" - 78/esp-ml307: "~1.9.1" + 78/esp-ml307: "~2.0.0" 78/xiaozhi-fonts: "~1.3.2" espressif/led_strip: "^2.5.5" espressif/esp_codec_dev: "~1.3.2" diff --git a/main/ota.cc b/main/ota.cc index 5acd5283..cca90711 100644 --- a/main/ota.cc +++ b/main/ota.cc @@ -107,8 +107,6 @@ bool Ota::CheckVersion() { return false; } - ESP_LOGI(TAG, "OTA request success: %s", check_version_url_.c_str()); - has_activation_code_ = false; has_activation_challenge_ = false; cJSON *activation = cJSON_GetObjectItem(root, "activation");