forked from xiaozhi/xiaozhi-esp32
add powersave to sensecap watcher
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "button.h"
|
||||
#include "config.h"
|
||||
#include "iot/thing_manager.h"
|
||||
#include "power_save_timer.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
#include "esp_check.h"
|
||||
@@ -17,7 +18,8 @@
|
||||
#include <driver/spi_common.h>
|
||||
#include <wifi_station.h>
|
||||
#include <iot_button.h>
|
||||
#include "esp_io_expander_tca95xx_16bit.h"
|
||||
#include <esp_io_expander_tca95xx_16bit.h>
|
||||
#include <esp_sleep.h>
|
||||
|
||||
#define TAG "sensecap_watcher"
|
||||
|
||||
@@ -31,6 +33,32 @@ private:
|
||||
LcdDisplay* display_;
|
||||
esp_io_expander_handle_t io_exp_handle;
|
||||
button_handle_t btns;
|
||||
PowerSaveTimer* power_save_timer_;
|
||||
esp_lcd_panel_io_handle_t panel_io_ = nullptr;
|
||||
esp_lcd_panel_handle_t panel_ = nullptr;
|
||||
|
||||
void InitializePowerSaveTimer() {
|
||||
power_save_timer_ = new PowerSaveTimer(-1, 60, 300);
|
||||
power_save_timer_->OnEnterSleepMode([this]() {
|
||||
ESP_LOGI(TAG, "Enabling sleep mode");
|
||||
auto display = GetDisplay();
|
||||
display->SetChatMessage("system", "");
|
||||
display->SetEmotion("sleepy");
|
||||
GetBacklight()->SetBrightness(10);
|
||||
});
|
||||
power_save_timer_->OnExitSleepMode([this]() {
|
||||
auto display = GetDisplay();
|
||||
display->SetChatMessage("system", "");
|
||||
display->SetEmotion("neutral");
|
||||
GetBacklight()->RestoreBrightness();
|
||||
});
|
||||
power_save_timer_->OnShutdownRequest([this]() {
|
||||
ESP_LOGI(TAG, "Shutting down");
|
||||
IoExpanderSetLevel(BSP_PWR_LCD, 0);
|
||||
IoExpanderSetLevel(BSP_PWR_SYSTEM, 0);
|
||||
});
|
||||
power_save_timer_->SetEnabled(true);
|
||||
}
|
||||
|
||||
void InitializeI2c() {
|
||||
// Initialize I2C peripheral
|
||||
@@ -102,6 +130,7 @@ private:
|
||||
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
|
||||
self->ResetWifiConfiguration();
|
||||
}
|
||||
self->power_save_timer_->WakeUp();
|
||||
app.ToggleChatState();
|
||||
}, this);
|
||||
iot_button_register_cb(btns, BUTTON_LONG_PRESS_START, [](void* button_handle, void* usr_data) {
|
||||
@@ -110,8 +139,8 @@ private:
|
||||
if (is_charging) {
|
||||
ESP_LOGI(TAG, "charging");
|
||||
} else {
|
||||
self->IoExpanderSetLevel(BSP_PWR_SYSTEM, 0);
|
||||
self->IoExpanderSetLevel(BSP_PWR_LCD, 0);
|
||||
self->IoExpanderSetLevel(BSP_PWR_SYSTEM, 0);
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
@@ -131,9 +160,6 @@ private:
|
||||
}
|
||||
|
||||
void Initializespd2010Display() {
|
||||
esp_lcd_panel_io_handle_t ret_io;
|
||||
esp_lcd_panel_handle_t ret_panel;
|
||||
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
const esp_lcd_panel_io_spi_config_t io_config = {
|
||||
.cs_gpio_num = BSP_LCD_SPI_CS,
|
||||
@@ -152,7 +178,7 @@ private:
|
||||
.use_qspi_interface = 1,
|
||||
},
|
||||
};
|
||||
esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)BSP_LCD_SPI_NUM, &io_config, &ret_io);
|
||||
esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)BSP_LCD_SPI_NUM, &io_config, &panel_io_);
|
||||
|
||||
ESP_LOGD(TAG, "Install LCD driver");
|
||||
const esp_lcd_panel_dev_config_t panel_config = {
|
||||
@@ -161,15 +187,14 @@ private:
|
||||
.bits_per_pixel = DRV_LCD_BITS_PER_PIXEL,
|
||||
.vendor_config = &vendor_config,
|
||||
};
|
||||
esp_lcd_new_panel_spd2010(ret_io, &panel_config, &ret_panel);
|
||||
|
||||
esp_lcd_panel_reset(ret_panel);
|
||||
esp_lcd_panel_init(ret_panel);
|
||||
esp_lcd_panel_mirror(ret_panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
esp_lcd_panel_disp_on_off(ret_panel, true);
|
||||
esp_lcd_new_panel_spd2010(panel_io_, &panel_config, &panel_);
|
||||
|
||||
esp_lcd_panel_reset(panel_);
|
||||
esp_lcd_panel_init(panel_);
|
||||
esp_lcd_panel_mirror(panel_, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
esp_lcd_panel_disp_on_off(panel_, true);
|
||||
|
||||
//TODO
|
||||
display_ = new SpiLcdDisplay(ret_io, ret_panel,
|
||||
display_ = new SpiLcdDisplay(panel_io_, panel_,
|
||||
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY,
|
||||
{
|
||||
.text_font = &font_puhui_30_4,
|
||||
@@ -188,6 +213,7 @@ private:
|
||||
public:
|
||||
SensecapWatcher(){
|
||||
ESP_LOGI(TAG, "Initialize Sensecap Watcher");
|
||||
InitializePowerSaveTimer();
|
||||
InitializeI2c();
|
||||
InitializeSpi();
|
||||
InitializeExpander();
|
||||
@@ -222,6 +248,13 @@ public:
|
||||
static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT);
|
||||
return &backlight;
|
||||
}
|
||||
|
||||
virtual void SetPowerSaveMode(bool enabled) override {
|
||||
if (!enabled) {
|
||||
power_save_timer_->WakeUp();
|
||||
}
|
||||
WifiBoard::SetPowerSaveMode(enabled);
|
||||
}
|
||||
};
|
||||
|
||||
DECLARE_BOARD(SensecapWatcher);
|
||||
|
||||
Reference in New Issue
Block a user