diff --git a/main/application.cc b/main/application.cc index 8ffd4efa..84568c11 100644 --- a/main/application.cc +++ b/main/application.cc @@ -699,4 +699,21 @@ void Application::UpdateIotStates() { void Application::Reboot() { ESP_LOGI(TAG, "Rebooting..."); esp_restart(); -} \ No newline at end of file +} + +void Application::WakeWordInvoke(const std::string& wake_word) { + if (device_state_ == kDeviceStateIdle) { + ToggleChatState(); + Schedule([this, wake_word]() { + if (protocol_) { + protocol_->SendWakeWordDetected(wake_word); + } + }); + } else if (device_state_ == kDeviceStateSpeaking) { + AbortSpeaking(kAbortReasonNone); + } else if (device_state_ == kDeviceStateListening) { + if (protocol_) { + protocol_->CloseAudioChannel(); + } + } +} diff --git a/main/application.h b/main/application.h index c7321c16..b66cdf3b 100644 --- a/main/application.h +++ b/main/application.h @@ -63,6 +63,7 @@ public: void StopListening(); void UpdateIotStates(); void Reboot(); + void WakeWordInvoke(const std::string& wake_word); private: Application(); diff --git a/main/boards/bread-compact-esp32/config.h b/main/boards/bread-compact-esp32/config.h index aef02003..0c477e3c 100644 --- a/main/boards/bread-compact-esp32/config.h +++ b/main/boards/bread-compact-esp32/config.h @@ -30,6 +30,7 @@ #define BOOT_BUTTON_GPIO GPIO_NUM_0 #define TOUCH_BUTTON_GPIO GPIO_NUM_5 +#define ASR_BUTTON_GPIO GPIO_NUM_19 #define BUILTIN_LED_GPIO GPIO_NUM_2 #define DISPLAY_SDA_PIN GPIO_NUM_4 diff --git a/main/boards/bread-compact-esp32/esp32_bread_board.cc b/main/boards/bread-compact-esp32/esp32_bread_board.cc index 34dc95f1..1096b267 100644 --- a/main/boards/bread-compact-esp32/esp32_bread_board.cc +++ b/main/boards/bread-compact-esp32/esp32_bread_board.cc @@ -21,6 +21,8 @@ class CompactWifiBoard : public WifiBoard { private: Button boot_button_; Button touch_button_; + Button asr_button_; + i2c_master_bus_handle_t display_i2c_bus_; void InitializeDisplayI2c() { @@ -59,6 +61,12 @@ private: gpio_set_level(BUILTIN_LED_GPIO, 1); app.ToggleChatState(); }); + + asr_button_.OnClick([this]() { + std::string wake_word="你好小智"; + Application::GetInstance().WakeWordInvoke(wake_word); + }); + touch_button_.OnPressDown([this]() { gpio_set_level(BUILTIN_LED_GPIO, 1); Application::GetInstance().StartListening(); @@ -77,7 +85,7 @@ private: } public: - CompactWifiBoard() : boot_button_(BOOT_BUTTON_GPIO), touch_button_(TOUCH_BUTTON_GPIO) + CompactWifiBoard() : boot_button_(BOOT_BUTTON_GPIO), touch_button_(TOUCH_BUTTON_GPIO), asr_button_(ASR_BUTTON_GPIO) { InitializeDisplayI2c(); InitializeButtons();