forked from xiaozhi/xiaozhi-esp32
修改神奇按钮2.4板子的LED和按键功能 (#203)
* 修改LED和按键功能 * Update magiclick_2p4_board.cc --------- Co-authored-by: Xiaoxia <terrence@tenclass.com>
This commit is contained in:
@@ -24,7 +24,9 @@
|
||||
#define BUILTIN_LED_NUM 2
|
||||
#define BUILTIN_LED_GPIO GPIO_NUM_38
|
||||
|
||||
#define BOOT_BUTTON_GPIO GPIO_NUM_21
|
||||
#define MAIN_BUTTON_GPIO GPIO_NUM_21
|
||||
#define LEFT_BUTTON_GPIO GPIO_NUM_0
|
||||
#define RIGHT_BUTTON_GPIO GPIO_NUM_47
|
||||
|
||||
// display
|
||||
#define DISPLAY_SDA_PIN GPIO_NUM_15
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "audio_codecs/es8311_audio_codec.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "led/single_led.h"
|
||||
#include "led/circular_strip.h"
|
||||
#include "iot/thing_manager.h"
|
||||
#include "config.h"
|
||||
#include <esp_lcd_panel_vendor.h>
|
||||
@@ -59,7 +59,9 @@ public:
|
||||
class magiclick_2p4 : public WifiBoard {
|
||||
private:
|
||||
i2c_master_bus_handle_t codec_i2c_bus_;
|
||||
Button boot_button_;
|
||||
Button main_button_;
|
||||
Button left_button_;
|
||||
Button right_button_;
|
||||
NV3023Display* display_;
|
||||
|
||||
void InitializeCodecI2c() {
|
||||
@@ -80,17 +82,45 @@ private:
|
||||
}
|
||||
|
||||
void InitializeButtons() {
|
||||
boot_button_.OnClick([this]() {
|
||||
main_button_.OnPressDown([this]() {
|
||||
Application::GetInstance().StartListening();
|
||||
});
|
||||
main_button_.OnPressUp([this]() {
|
||||
Application::GetInstance().StopListening();
|
||||
});
|
||||
|
||||
left_button_.OnClick([this]() {
|
||||
auto& app = Application::GetInstance();
|
||||
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
|
||||
ResetWifiConfiguration();
|
||||
}
|
||||
auto codec = GetAudioCodec();
|
||||
auto volume = codec->output_volume() - 10;
|
||||
if (volume < 0) {
|
||||
volume = 0;
|
||||
}
|
||||
codec->SetOutputVolume(volume);
|
||||
GetDisplay()->ShowNotification("音量 " + std::to_string(volume));
|
||||
});
|
||||
boot_button_.OnPressDown([this]() {
|
||||
Application::GetInstance().StartListening();
|
||||
|
||||
left_button_.OnLongPress([this]() {
|
||||
GetAudioCodec()->SetOutputVolume(0);
|
||||
GetDisplay()->ShowNotification("已静音");
|
||||
});
|
||||
boot_button_.OnPressUp([this]() {
|
||||
Application::GetInstance().StopListening();
|
||||
|
||||
right_button_.OnClick([this]() {
|
||||
auto codec = GetAudioCodec();
|
||||
auto volume = codec->output_volume() + 10;
|
||||
if (volume > 100) {
|
||||
volume = 100;
|
||||
}
|
||||
codec->SetOutputVolume(volume);
|
||||
GetDisplay()->ShowNotification("音量 " + std::to_string(volume));
|
||||
});
|
||||
|
||||
right_button_.OnLongPress([this]() {
|
||||
GetAudioCodec()->SetOutputVolume(100);
|
||||
GetDisplay()->ShowNotification("最大音量");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -155,7 +185,9 @@ private:
|
||||
|
||||
public:
|
||||
magiclick_2p4() :
|
||||
boot_button_(BOOT_BUTTON_GPIO) {
|
||||
main_button_(MAIN_BUTTON_GPIO),
|
||||
left_button_(LEFT_BUTTON_GPIO),
|
||||
right_button_(RIGHT_BUTTON_GPIO) {
|
||||
InitializeCodecI2c();
|
||||
InitializeButtons();
|
||||
InitializeLedPower();
|
||||
@@ -165,7 +197,7 @@ public:
|
||||
}
|
||||
|
||||
virtual Led* GetLed() override {
|
||||
static SingleLed led(BUILTIN_LED_GPIO);
|
||||
static CircularStrip led(BUILTIN_LED_GPIO, BUILTIN_LED_NUM);
|
||||
return &led;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user