1.4.3: Low power popup & replace OledDisplay with Ssd1306Display
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
#include <esp_err.h>
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "display.h"
|
||||
#include "board.h"
|
||||
@ -9,6 +10,7 @@
|
||||
#include "font_awesome_symbols.h"
|
||||
#include "audio_codec.h"
|
||||
#include "settings.h"
|
||||
#include "assets/lang_config.h"
|
||||
|
||||
#define TAG "Display"
|
||||
|
||||
@ -146,6 +148,21 @@ void Display::Update() {
|
||||
battery_icon_ = icon;
|
||||
lv_label_set_text(battery_label_, battery_icon_);
|
||||
}
|
||||
|
||||
if (low_battery_popup_ != nullptr) {
|
||||
if (strcmp(icon, FONT_AWESOME_BATTERY_EMPTY) == 0) {
|
||||
if (lv_obj_has_flag(low_battery_popup_, LV_OBJ_FLAG_HIDDEN)) {
|
||||
lv_obj_clear_flag(low_battery_popup_, LV_OBJ_FLAG_HIDDEN);
|
||||
auto& app = Application::GetInstance();
|
||||
app.PlaySound(Lang::Sounds::P3_LOW_BATTERY);
|
||||
}
|
||||
} else {
|
||||
// Hide the low battery popup when the battery is not empty
|
||||
if (!lv_obj_has_flag(low_battery_popup_, LV_OBJ_FLAG_HIDDEN)) {
|
||||
lv_obj_add_flag(low_battery_popup_, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 升级固件时,不读取 4G 网络状态,避免占用 UART 资源
|
||||
|
||||
@ -43,6 +43,8 @@ protected:
|
||||
lv_obj_t *mute_label_ = nullptr;
|
||||
lv_obj_t *battery_label_ = nullptr;
|
||||
lv_obj_t* chat_message_label_ = nullptr;
|
||||
lv_obj_t* low_battery_popup_ = nullptr;
|
||||
|
||||
const char* battery_icon_ = nullptr;
|
||||
const char* network_icon_ = nullptr;
|
||||
bool muted_ = false;
|
||||
|
||||
@ -246,6 +246,18 @@ void LcdDisplay::SetupUI() {
|
||||
battery_label_ = lv_label_create(status_bar_);
|
||||
lv_label_set_text(battery_label_, "");
|
||||
lv_obj_set_style_text_font(battery_label_, fonts_.icon_font, 0);
|
||||
|
||||
low_battery_popup_ = lv_obj_create(screen);
|
||||
lv_obj_set_scrollbar_mode(low_battery_popup_, LV_SCROLLBAR_MODE_OFF);
|
||||
lv_obj_set_size(low_battery_popup_, LV_HOR_RES * 0.9, fonts_.text_font->line_height * 2);
|
||||
lv_obj_align(low_battery_popup_, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
lv_obj_set_style_bg_color(low_battery_popup_, lv_color_black(), 0);
|
||||
lv_obj_set_style_radius(low_battery_popup_, 10, 0);
|
||||
lv_obj_t* low_battery_label = lv_label_create(low_battery_popup_);
|
||||
lv_label_set_text(low_battery_label, Lang::Strings::BATTERY_NEED_CHARGE);
|
||||
lv_obj_set_style_text_color(low_battery_label, lv_color_white(), 0);
|
||||
lv_obj_center(low_battery_label);
|
||||
lv_obj_add_flag(low_battery_popup_, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
void LcdDisplay::SetEmotion(const char* emotion) {
|
||||
|
||||
@ -1,20 +1,18 @@
|
||||
#include "ssd1306_display.h"
|
||||
#include "oled_display.h"
|
||||
#include "font_awesome_symbols.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
#include <esp_lcd_panel_vendor.h>
|
||||
#include <esp_lvgl_port.h>
|
||||
#include "assets/lang_config.h"
|
||||
|
||||
#define TAG "Ssd1306Display"
|
||||
#define TAG "OledDisplay"
|
||||
|
||||
LV_FONT_DECLARE(font_awesome_30_1);
|
||||
|
||||
Ssd1306Display::Ssd1306Display(void* i2c_master_handle, int width, int height, bool mirror_x, bool mirror_y,
|
||||
const lv_font_t* text_font, const lv_font_t* icon_font)
|
||||
: text_font_(text_font), icon_font_(icon_font) {
|
||||
OledDisplay::OledDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
|
||||
int width, int height, bool mirror_x, bool mirror_y, DisplayFonts fonts)
|
||||
: panel_io_(panel_io), panel_(panel), fonts_(fonts) {
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
|
||||
@ -23,48 +21,6 @@ Ssd1306Display::Ssd1306Display(void* i2c_master_handle, int width, int height, b
|
||||
port_cfg.task_priority = 1;
|
||||
lvgl_port_init(&port_cfg);
|
||||
|
||||
// SSD1306 config
|
||||
esp_lcd_panel_io_i2c_config_t io_config = {
|
||||
.dev_addr = 0x3C,
|
||||
.on_color_trans_done = nullptr,
|
||||
.user_ctx = nullptr,
|
||||
.control_phase_bytes = 1,
|
||||
.dc_bit_offset = 6,
|
||||
.lcd_cmd_bits = 8,
|
||||
.lcd_param_bits = 8,
|
||||
.flags = {
|
||||
.dc_low_on_data = 0,
|
||||
.disable_control_phase = 0,
|
||||
},
|
||||
.scl_speed_hz = 400 * 1000,
|
||||
};
|
||||
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c_v2((i2c_master_bus_t*)i2c_master_handle, &io_config, &panel_io_));
|
||||
|
||||
ESP_LOGI(TAG, "Install SSD1306 driver");
|
||||
esp_lcd_panel_dev_config_t panel_config = {};
|
||||
panel_config.reset_gpio_num = -1;
|
||||
panel_config.bits_per_pixel = 1;
|
||||
|
||||
esp_lcd_panel_ssd1306_config_t ssd1306_config = {
|
||||
.height = static_cast<uint8_t>(height_),
|
||||
};
|
||||
panel_config.vendor_config = &ssd1306_config;
|
||||
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_ssd1306(panel_io_, &panel_config, &panel_));
|
||||
ESP_LOGI(TAG, "SSD1306 driver installed");
|
||||
|
||||
// Reset the display
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_));
|
||||
if (esp_lcd_panel_init(panel_) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to initialize display");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the display to on
|
||||
ESP_LOGI(TAG, "Turning display on");
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_, true));
|
||||
|
||||
ESP_LOGI(TAG, "Adding LCD screen");
|
||||
const lvgl_port_display_cfg_t display_cfg = {
|
||||
.io_handle = panel_io_,
|
||||
@ -103,7 +59,7 @@ Ssd1306Display::Ssd1306Display(void* i2c_master_handle, int width, int height, b
|
||||
}
|
||||
}
|
||||
|
||||
Ssd1306Display::~Ssd1306Display() {
|
||||
OledDisplay::~OledDisplay() {
|
||||
if (content_ != nullptr) {
|
||||
lv_obj_del(content_);
|
||||
}
|
||||
@ -126,15 +82,15 @@ Ssd1306Display::~Ssd1306Display() {
|
||||
lvgl_port_deinit();
|
||||
}
|
||||
|
||||
bool Ssd1306Display::Lock(int timeout_ms) {
|
||||
bool OledDisplay::Lock(int timeout_ms) {
|
||||
return lvgl_port_lock(timeout_ms);
|
||||
}
|
||||
|
||||
void Ssd1306Display::Unlock() {
|
||||
void OledDisplay::Unlock() {
|
||||
lvgl_port_unlock();
|
||||
}
|
||||
|
||||
void Ssd1306Display::SetChatMessage(const char* role, const char* content) {
|
||||
void OledDisplay::SetChatMessage(const char* role, const char* content) {
|
||||
DisplayLockGuard lock(this);
|
||||
if (chat_message_label_ == nullptr) {
|
||||
return;
|
||||
@ -151,11 +107,11 @@ void Ssd1306Display::SetChatMessage(const char* role, const char* content) {
|
||||
}
|
||||
}
|
||||
|
||||
void Ssd1306Display::SetupUI_128x64() {
|
||||
void OledDisplay::SetupUI_128x64() {
|
||||
DisplayLockGuard lock(this);
|
||||
|
||||
auto screen = lv_screen_active();
|
||||
lv_obj_set_style_text_font(screen, text_font_, 0);
|
||||
lv_obj_set_style_text_font(screen, fonts_.text_font, 0);
|
||||
lv_obj_set_style_text_color(screen, lv_color_black(), 0);
|
||||
|
||||
/* Container */
|
||||
@ -226,7 +182,7 @@ void Ssd1306Display::SetupUI_128x64() {
|
||||
|
||||
network_label_ = lv_label_create(status_bar_);
|
||||
lv_label_set_text(network_label_, "");
|
||||
lv_obj_set_style_text_font(network_label_, icon_font_, 0);
|
||||
lv_obj_set_style_text_font(network_label_, fonts_.icon_font, 0);
|
||||
|
||||
notification_label_ = lv_label_create(status_bar_);
|
||||
lv_obj_set_flex_grow(notification_label_, 1);
|
||||
@ -241,18 +197,30 @@ void Ssd1306Display::SetupUI_128x64() {
|
||||
|
||||
mute_label_ = lv_label_create(status_bar_);
|
||||
lv_label_set_text(mute_label_, "");
|
||||
lv_obj_set_style_text_font(mute_label_, icon_font_, 0);
|
||||
lv_obj_set_style_text_font(mute_label_, fonts_.icon_font, 0);
|
||||
|
||||
battery_label_ = lv_label_create(status_bar_);
|
||||
lv_label_set_text(battery_label_, "");
|
||||
lv_obj_set_style_text_font(battery_label_, icon_font_, 0);
|
||||
lv_obj_set_style_text_font(battery_label_, fonts_.icon_font, 0);
|
||||
|
||||
low_battery_popup_ = lv_obj_create(screen);
|
||||
lv_obj_set_scrollbar_mode(low_battery_popup_, LV_SCROLLBAR_MODE_OFF);
|
||||
lv_obj_set_size(low_battery_popup_, LV_HOR_RES * 0.9, fonts_.text_font->line_height * 2);
|
||||
lv_obj_align(low_battery_popup_, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
lv_obj_set_style_bg_color(low_battery_popup_, lv_color_black(), 0);
|
||||
lv_obj_set_style_radius(low_battery_popup_, 10, 0);
|
||||
lv_obj_t* low_battery_label = lv_label_create(low_battery_popup_);
|
||||
lv_label_set_text(low_battery_label, Lang::Strings::BATTERY_NEED_CHARGE);
|
||||
lv_obj_set_style_text_color(low_battery_label, lv_color_white(), 0);
|
||||
lv_obj_center(low_battery_label);
|
||||
lv_obj_add_flag(low_battery_popup_, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
void Ssd1306Display::SetupUI_128x32() {
|
||||
void OledDisplay::SetupUI_128x32() {
|
||||
DisplayLockGuard lock(this);
|
||||
|
||||
auto screen = lv_screen_active();
|
||||
lv_obj_set_style_text_font(screen, text_font_, 0);
|
||||
lv_obj_set_style_text_font(screen, fonts_.text_font, 0);
|
||||
|
||||
/* Container */
|
||||
container_ = lv_obj_create(screen);
|
||||
@ -294,15 +262,15 @@ void Ssd1306Display::SetupUI_128x32() {
|
||||
|
||||
network_label_ = lv_label_create(status_bar_);
|
||||
lv_label_set_text(network_label_, "");
|
||||
lv_obj_set_style_text_font(network_label_, icon_font_, 0);
|
||||
lv_obj_set_style_text_font(network_label_, fonts_.icon_font, 0);
|
||||
|
||||
mute_label_ = lv_label_create(status_bar_);
|
||||
lv_label_set_text(mute_label_, "");
|
||||
lv_obj_set_style_text_font(mute_label_, icon_font_, 0);
|
||||
lv_obj_set_style_text_font(mute_label_, fonts_.icon_font, 0);
|
||||
|
||||
battery_label_ = lv_label_create(status_bar_);
|
||||
lv_label_set_text(battery_label_, "");
|
||||
lv_obj_set_style_text_font(battery_label_, icon_font_, 0);
|
||||
lv_obj_set_style_text_font(battery_label_, fonts_.icon_font, 0);
|
||||
|
||||
status_label_ = lv_label_create(status_bar_);
|
||||
lv_obj_set_style_pad_left(status_label_, 2, 0);
|
||||
@ -1,12 +1,12 @@
|
||||
#ifndef SSD1306_DISPLAY_H
|
||||
#define SSD1306_DISPLAY_H
|
||||
#ifndef OLED_DISPLAY_H
|
||||
#define OLED_DISPLAY_H
|
||||
|
||||
#include "display.h"
|
||||
|
||||
#include <esp_lcd_panel_io.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
|
||||
class Ssd1306Display : public Display {
|
||||
class OledDisplay : public Display {
|
||||
private:
|
||||
esp_lcd_panel_io_handle_t panel_io_ = nullptr;
|
||||
esp_lcd_panel_handle_t panel_ = nullptr;
|
||||
@ -18,8 +18,7 @@ private:
|
||||
lv_obj_t* container_ = nullptr;
|
||||
lv_obj_t* side_bar_ = nullptr;
|
||||
|
||||
const lv_font_t* text_font_ = nullptr;
|
||||
const lv_font_t* icon_font_ = nullptr;
|
||||
DisplayFonts fonts_;
|
||||
|
||||
virtual bool Lock(int timeout_ms = 0) override;
|
||||
virtual void Unlock() override;
|
||||
@ -28,11 +27,11 @@ private:
|
||||
void SetupUI_128x32();
|
||||
|
||||
public:
|
||||
Ssd1306Display(void* i2c_master_handle, int width, int height, bool mirror_x, bool mirror_y,
|
||||
const lv_font_t* text_font, const lv_font_t* icon_font);
|
||||
~Ssd1306Display();
|
||||
OledDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, int width, int height, bool mirror_x, bool mirror_y,
|
||||
DisplayFonts fonts);
|
||||
~OledDisplay();
|
||||
|
||||
virtual void SetChatMessage(const char* role, const char* content) override;
|
||||
};
|
||||
|
||||
#endif // SSD1306_DISPLAY_H
|
||||
#endif // OLED_DISPLAY_H
|
||||
Reference in New Issue
Block a user