mirror of
https://github.com/No-Chicken/Power-Pico.git
synced 2026-04-03 13:02:36 +08:00
更新界面
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
// Project name: PowerPico
|
// Project name: PowerPico
|
||||||
|
|
||||||
#include "../ui.h"
|
#include "../ui.h"
|
||||||
|
#include "BL24C02.h" // system settings
|
||||||
|
|
||||||
lv_obj_t * ui_SetPage = NULL;
|
lv_obj_t * ui_SetPage = NULL;
|
||||||
// backlight
|
// backlight
|
||||||
@@ -18,11 +19,15 @@ static lv_obj_t * ui_LabelKS = NULL;
|
|||||||
static lv_obj_t * ui_PanelLang = NULL;
|
static lv_obj_t * ui_PanelLang = NULL;
|
||||||
static lv_obj_t * ui_SwitchLang = NULL;
|
static lv_obj_t * ui_SwitchLang = NULL;
|
||||||
static lv_obj_t * ui_LabelLang = NULL;
|
static lv_obj_t * ui_LabelLang = NULL;
|
||||||
|
// chose rotation
|
||||||
|
static lv_obj_t * ui_PanelRotate = NULL;
|
||||||
|
static lv_obj_t * ui_LabelRotation = NULL;
|
||||||
|
static lv_obj_t * ui_LabelRotNum = NULL;
|
||||||
// about
|
// about
|
||||||
static lv_obj_t * ui_PanelAbout = NULL;
|
static lv_obj_t * ui_PanelAbout = NULL;
|
||||||
static lv_obj_t * ui_LabelAbout = NULL;
|
static lv_obj_t * ui_LabelAbout = NULL;
|
||||||
|
|
||||||
static lv_obj_t * panels[4]; // 存储所有 panel 的指针
|
static lv_obj_t * panels[5]; // 存储所有 panel 的指针
|
||||||
static int current_panel_index = 0; // 当前选中的 panel 索引
|
static int current_panel_index = 0; // 当前选中的 panel 索引
|
||||||
|
|
||||||
// event funtions
|
// event funtions
|
||||||
@@ -31,55 +36,79 @@ static int current_panel_index = 0; // 当前选中的 panel 索引
|
|||||||
void ui_set_page_key_handler(uint8_t key_id)
|
void ui_set_page_key_handler(uint8_t key_id)
|
||||||
{
|
{
|
||||||
int panel_count = sizeof(panels) / sizeof(panels[0]);
|
int panel_count = sizeof(panels) / sizeof(panels[0]);
|
||||||
if(key_id == KEYB_NUM) {
|
if(key_id == KEYB_NUM) { // key boot
|
||||||
PageManager_next();
|
PageManager_next();
|
||||||
}
|
} if (key_id == KEYL_NUM) { // key left
|
||||||
if (key_id == KEYL_NUM) {
|
|
||||||
lv_obj_clear_state(panels[current_panel_index], LV_STATE_CHECKED);
|
lv_obj_clear_state(panels[current_panel_index], LV_STATE_CHECKED);
|
||||||
current_panel_index = (current_panel_index - 1 + panel_count) % panel_count;
|
current_panel_index = (current_panel_index - 1 + panel_count) % panel_count;
|
||||||
lv_obj_add_state(panels[current_panel_index], LV_STATE_CHECKED);
|
lv_obj_add_state(panels[current_panel_index], LV_STATE_CHECKED);
|
||||||
lv_obj_scroll_to_view(panels[current_panel_index], LV_ANIM_ON);
|
lv_obj_scroll_to_view(panels[current_panel_index], LV_ANIM_ON);
|
||||||
} else if (key_id == KEYR_NUM) {
|
} else if (key_id == KEYR_NUM) { // key right
|
||||||
lv_obj_clear_state(panels[current_panel_index], LV_STATE_CHECKED);
|
lv_obj_clear_state(panels[current_panel_index], LV_STATE_CHECKED);
|
||||||
current_panel_index = (current_panel_index + 1) % panel_count;
|
current_panel_index = (current_panel_index + 1) % panel_count;
|
||||||
lv_obj_add_state(panels[current_panel_index], LV_STATE_CHECKED);
|
lv_obj_add_state(panels[current_panel_index], LV_STATE_CHECKED);
|
||||||
lv_obj_scroll_to_view(panels[current_panel_index], LV_ANIM_ON);
|
lv_obj_scroll_to_view(panels[current_panel_index], LV_ANIM_ON);
|
||||||
} else if (key_id == KEYY_NUM) {
|
} else { // key yes or key neg
|
||||||
if(current_panel_index == 0) { // Screen Brightness
|
switch(current_panel_index) {
|
||||||
|
// Screen Brightness
|
||||||
|
case 0:
|
||||||
|
if (key_id == KEYY_NUM) {
|
||||||
int16_t slider_value = lv_slider_get_value(ui_SliderBL);
|
int16_t slider_value = lv_slider_get_value(ui_SliderBL);
|
||||||
slider_value += 10;
|
slider_value += 10;
|
||||||
if(slider_value > 100) slider_value = 100;
|
if(slider_value > 100) slider_value = 100;
|
||||||
lv_slider_set_value(ui_SliderBL, slider_value, LV_ANIM_ON);
|
lv_slider_set_value(ui_SliderBL, slider_value, LV_ANIM_ON);
|
||||||
} else if(current_panel_index == 1) { // Key Sound
|
|
||||||
if(lv_obj_has_state(ui_SwitchKS, LV_STATE_CHECKED)) {
|
|
||||||
lv_obj_clear_state(ui_SwitchKS, LV_STATE_CHECKED);
|
|
||||||
} else {
|
|
||||||
lv_obj_add_state(ui_SwitchKS, LV_STATE_CHECKED);
|
|
||||||
}
|
|
||||||
} else if(current_panel_index == 2) { // Language
|
|
||||||
// do nothing
|
|
||||||
} else if(current_panel_index == 3) { // About
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
} else if (key_id == KEYN_NUM) {
|
} else if (key_id == KEYN_NUM) {
|
||||||
if(current_panel_index == 0) { // Screen Brightness
|
|
||||||
int16_t slider_value = lv_slider_get_value(ui_SliderBL);
|
int16_t slider_value = lv_slider_get_value(ui_SliderBL);
|
||||||
slider_value -= 10;
|
slider_value -= 10;
|
||||||
if(slider_value < 0) slider_value = 0;
|
if(slider_value < 0) slider_value = 10;
|
||||||
lv_slider_set_value(ui_SliderBL, slider_value, LV_ANIM_ON);
|
lv_slider_set_value(ui_SliderBL, slider_value, LV_ANIM_ON);
|
||||||
} else if(current_panel_index == 1) { // Key Sound
|
}
|
||||||
if(lv_obj_has_state(ui_SwitchKS, LV_STATE_CHECKED)) {
|
break;
|
||||||
lv_obj_clear_state(ui_SwitchKS, LV_STATE_CHECKED);
|
// key sound
|
||||||
} else {
|
case 1:
|
||||||
|
if (key_id == KEYY_NUM) {
|
||||||
lv_obj_add_state(ui_SwitchKS, LV_STATE_CHECKED);
|
lv_obj_add_state(ui_SwitchKS, LV_STATE_CHECKED);
|
||||||
|
} else if(key_id == KEYN_NUM) {
|
||||||
|
lv_obj_clear_state(ui_SwitchKS, LV_STATE_CHECKED);
|
||||||
}
|
}
|
||||||
} else if(current_panel_index == 2) { // Language
|
break;
|
||||||
// do nothing
|
|
||||||
} else if(current_panel_index == 3) { // About
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// language
|
||||||
|
case 2:
|
||||||
|
// do nothing
|
||||||
|
break;
|
||||||
|
|
||||||
|
// chose rotation
|
||||||
|
case 3:
|
||||||
|
if (key_id == KEYY_NUM) {
|
||||||
|
sys_settings.rotation = (sys_settings.rotation + 360 + 90) % 360;
|
||||||
|
lv_display_rotation_t rotation = sys_settings.rotation / 90;
|
||||||
|
lv_display_set_rotation(lv_display_get_default(), rotation);
|
||||||
|
ui_full_screen_refresh(ui_SetPage);
|
||||||
|
} else if(key_id == KEYN_NUM) {
|
||||||
|
sys_settings.rotation = (sys_settings.rotation + 360 - 90) % 360;
|
||||||
|
lv_display_rotation_t rotation = sys_settings.rotation / 90;
|
||||||
|
lv_display_set_rotation(lv_display_get_default(), rotation);
|
||||||
|
ui_full_screen_refresh(ui_SetPage);
|
||||||
|
}
|
||||||
|
if (sys_settings.rotation == 0) {
|
||||||
|
lv_label_set_text(ui_LabelRotNum, "< 0 >");
|
||||||
|
} else if (sys_settings.rotation == 90) {
|
||||||
|
lv_label_set_text(ui_LabelRotNum, "< 90 >");
|
||||||
|
} else if (sys_settings.rotation == 180) {
|
||||||
|
lv_label_set_text(ui_LabelRotNum, "< 180 >");
|
||||||
|
} else if (sys_settings.rotation == 270) {
|
||||||
|
lv_label_set_text(ui_LabelRotNum, "< 270 >");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
// about
|
||||||
|
case 4:
|
||||||
|
// do nothing
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// build funtions
|
// build funtions
|
||||||
@@ -164,11 +193,36 @@ void ui_SetPage_screen_init(void)
|
|||||||
lv_label_set_text(ui_LabelLang, "Enable Chinese");
|
lv_label_set_text(ui_LabelLang, "Enable Chinese");
|
||||||
lv_obj_set_style_text_font(ui_LabelLang, &lv_font_montserrat_16, LV_PART_MAIN | LV_STATE_DEFAULT);
|
lv_obj_set_style_text_font(ui_LabelLang, &lv_font_montserrat_16, LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||||
|
|
||||||
|
ui_PanelRotate = lv_obj_create(ui_SetPage);
|
||||||
|
lv_obj_set_width(ui_PanelRotate, 234);
|
||||||
|
lv_obj_set_height(ui_PanelRotate, 45);
|
||||||
|
lv_obj_set_x(ui_PanelRotate, 0);
|
||||||
|
lv_obj_set_y(ui_PanelRotate, 175);
|
||||||
|
lv_obj_set_align(ui_PanelRotate, LV_ALIGN_TOP_MID);
|
||||||
|
lv_obj_add_flag(ui_PanelRotate, LV_OBJ_FLAG_CHECKABLE); /// Flags
|
||||||
|
lv_obj_remove_flag(ui_PanelRotate, LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
||||||
|
lv_obj_set_style_bg_color(ui_PanelRotate, lv_color_hex(0x606060), LV_PART_MAIN | LV_STATE_CHECKED);
|
||||||
|
lv_obj_set_style_bg_opa(ui_PanelRotate, 255, LV_PART_MAIN | LV_STATE_CHECKED);
|
||||||
|
|
||||||
|
ui_LabelRotation = lv_label_create(ui_PanelRotate);
|
||||||
|
lv_obj_set_width(ui_LabelRotation, LV_SIZE_CONTENT); /// 1
|
||||||
|
lv_obj_set_height(ui_LabelRotation, LV_SIZE_CONTENT); /// 1
|
||||||
|
lv_obj_set_align(ui_LabelRotation, LV_ALIGN_LEFT_MID);
|
||||||
|
lv_label_set_text(ui_LabelRotation, "Chose Rotation");
|
||||||
|
lv_obj_set_style_text_font(ui_LabelRotation, &lv_font_montserrat_16, LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||||
|
|
||||||
|
ui_LabelRotNum = lv_label_create(ui_PanelRotate);
|
||||||
|
lv_obj_set_width(ui_LabelRotNum, LV_SIZE_CONTENT); /// 1
|
||||||
|
lv_obj_set_height(ui_LabelRotNum, LV_SIZE_CONTENT); /// 1
|
||||||
|
lv_obj_set_align(ui_LabelRotNum, LV_ALIGN_RIGHT_MID);
|
||||||
|
lv_label_set_text(ui_LabelRotNum, "< 180 >");
|
||||||
|
lv_obj_set_style_text_font(ui_LabelRotNum, &lv_font_montserrat_16, LV_PART_MAIN | LV_STATE_DEFAULT);
|
||||||
|
|
||||||
ui_PanelAbout = lv_obj_create(ui_SetPage);
|
ui_PanelAbout = lv_obj_create(ui_SetPage);
|
||||||
lv_obj_set_width(ui_PanelAbout, 234);
|
lv_obj_set_width(ui_PanelAbout, 234);
|
||||||
lv_obj_set_height(ui_PanelAbout, 100);
|
lv_obj_set_height(ui_PanelAbout, 100);
|
||||||
lv_obj_set_x(ui_PanelAbout, 0);
|
lv_obj_set_x(ui_PanelAbout, 0);
|
||||||
lv_obj_set_y(ui_PanelAbout, 175);
|
lv_obj_set_y(ui_PanelAbout, 225);
|
||||||
lv_obj_set_align(ui_PanelAbout, LV_ALIGN_TOP_MID);
|
lv_obj_set_align(ui_PanelAbout, LV_ALIGN_TOP_MID);
|
||||||
lv_obj_add_flag(ui_PanelAbout, LV_OBJ_FLAG_CHECKABLE); /// Flags
|
lv_obj_add_flag(ui_PanelAbout, LV_OBJ_FLAG_CHECKABLE); /// Flags
|
||||||
lv_obj_remove_flag(ui_PanelAbout, LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
lv_obj_remove_flag(ui_PanelAbout, LV_OBJ_FLAG_SCROLLABLE); /// Flags
|
||||||
@@ -185,7 +239,8 @@ void ui_SetPage_screen_init(void)
|
|||||||
panels[0] = ui_PanelBL;
|
panels[0] = ui_PanelBL;
|
||||||
panels[1] = ui_PanelKS;
|
panels[1] = ui_PanelKS;
|
||||||
panels[2] = ui_PanelLang;
|
panels[2] = ui_PanelLang;
|
||||||
panels[3] = ui_PanelAbout;
|
panels[3] = ui_PanelRotate;
|
||||||
|
panels[4] = ui_PanelAbout;
|
||||||
lv_obj_add_state(panels[current_panel_index], LV_STATE_CHECKED);
|
lv_obj_add_state(panels[current_panel_index], LV_STATE_CHECKED);
|
||||||
lv_obj_scroll_to_view(panels[current_panel_index], LV_ANIM_ON);
|
lv_obj_scroll_to_view(panels[current_panel_index], LV_ANIM_ON);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include "../ui.h"
|
#include "../ui.h"
|
||||||
#include "ui_mainPage.h"
|
#include "ui_mainPage.h"
|
||||||
#include "data_queue.h"
|
#include "data_queue.h"
|
||||||
|
#include "math.h"
|
||||||
|
#include "BL24C02.h" // system settings
|
||||||
|
|
||||||
lv_obj_t * ui_HomeScreen = NULL;
|
lv_obj_t * ui_HomeScreen = NULL;
|
||||||
static lv_obj_t * ui_ButVal = NULL;
|
static lv_obj_t * ui_ButVal = NULL;
|
||||||
@@ -25,12 +27,25 @@ static uint8_t timecount = 0;
|
|||||||
|
|
||||||
// other funtions
|
// other funtions
|
||||||
|
|
||||||
static void full_screen_refresh(void) {
|
#include "key.h"
|
||||||
// 标记整个屏幕为脏区域
|
void ui_main_page_key_handler(uint8_t key_id)
|
||||||
lv_obj_invalidate(ui_HomeScreen);
|
{
|
||||||
|
if(key_id == KEYB_NUM) {
|
||||||
// 或者立即刷新整个屏幕
|
PageManager_next();
|
||||||
lv_refr_now(NULL);
|
} else if (key_id == KEYL_NUM) {
|
||||||
|
// rotation - 90 degrees
|
||||||
|
// rotation – LV_DISPLAY_ROTATION_0/90/180/270
|
||||||
|
sys_settings.rotation = (sys_settings.rotation + 360 - 90) % 360;
|
||||||
|
lv_display_rotation_t rotation = sys_settings.rotation / 90;
|
||||||
|
lv_display_set_rotation(lv_display_get_default(), rotation);
|
||||||
|
ui_full_screen_refresh(ui_HomeScreen);
|
||||||
|
} else if (key_id == KEYR_NUM) {
|
||||||
|
// rotation + 90 degrees
|
||||||
|
sys_settings.rotation = (sys_settings.rotation + 360 + 90) % 360;
|
||||||
|
lv_display_rotation_t rotation = sys_settings.rotation / 90;
|
||||||
|
lv_display_set_rotation(lv_display_get_default(), rotation);
|
||||||
|
ui_full_screen_refresh(ui_HomeScreen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_val_cur_label(float voltage, float current)
|
static void set_val_cur_label(float voltage, float current)
|
||||||
@@ -40,14 +55,14 @@ static void set_val_cur_label(float voltage, float current)
|
|||||||
sprintf(buf, "%.2f", voltage);
|
sprintf(buf, "%.2f", voltage);
|
||||||
lv_label_set_text(ui_LabelValt, buf);
|
lv_label_set_text(ui_LabelValt, buf);
|
||||||
// current
|
// current
|
||||||
if (current >= 1000000.0) {
|
if (fabs(current) >= 1000000.0) {
|
||||||
current = current / 1000000.0;
|
current = current / 1000000.0;
|
||||||
sprintf(buf, "%.2f", current); // 保留 2 位小数
|
sprintf(buf, "%.2f", current); // 保留 2 位小数
|
||||||
lv_label_set_text(ui_LabelCur, buf);
|
lv_label_set_text(ui_LabelCur, buf);
|
||||||
lv_label_set_text(ui_LabelUnitCur, "A");
|
lv_label_set_text(ui_LabelUnitCur, "A");
|
||||||
} else if(current >= 1000.0) {
|
} else if(fabs(current) >= 1000.0) {
|
||||||
current = current / 1000.0;
|
current = current / 1000.0;
|
||||||
if(current >= 100.0) {
|
if(fabs(current) >= 100.0) {
|
||||||
sprintf(buf, "%.1f", current);
|
sprintf(buf, "%.1f", current);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -56,7 +71,7 @@ static void set_val_cur_label(float voltage, float current)
|
|||||||
lv_label_set_text(ui_LabelCur, buf);
|
lv_label_set_text(ui_LabelCur, buf);
|
||||||
lv_label_set_text(ui_LabelUnitCur, "mA");
|
lv_label_set_text(ui_LabelUnitCur, "mA");
|
||||||
} else {
|
} else {
|
||||||
if(current >= 100.0) {
|
if(fabs(current) >= 100.0) {
|
||||||
sprintf(buf, "%.1f", current);
|
sprintf(buf, "%.1f", current);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -67,14 +82,14 @@ static void set_val_cur_label(float voltage, float current)
|
|||||||
}
|
}
|
||||||
// set power
|
// set power
|
||||||
float power = voltage * current; // in uW
|
float power = voltage * current; // in uW
|
||||||
if(power >= 1000000.0) {
|
if(fabs(power) >= 1000000.0) {
|
||||||
power = power / 1000000.0;
|
power = power / 1000000.0;
|
||||||
sprintf(buf, "%.2f", power);
|
sprintf(buf, "%.2f", power);
|
||||||
lv_label_set_text(ui_LabelEnerge, buf);
|
lv_label_set_text(ui_LabelEnerge, buf);
|
||||||
lv_label_set_text(ui_LabelUnitEnerge, "W");
|
lv_label_set_text(ui_LabelUnitEnerge, "W");
|
||||||
} else if(power >= 1000.0) {
|
} else if(fabs(power) >= 1000.0) {
|
||||||
power = power / 1000.0;
|
power = power / 1000.0;
|
||||||
if(power >= 100.0) {
|
if(fabs(power) >= 100.0) {
|
||||||
sprintf(buf, "%.1f", power);
|
sprintf(buf, "%.1f", power);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -83,7 +98,7 @@ static void set_val_cur_label(float voltage, float current)
|
|||||||
lv_label_set_text(ui_LabelEnerge, buf);
|
lv_label_set_text(ui_LabelEnerge, buf);
|
||||||
lv_label_set_text(ui_LabelUnitEnerge, "mW");
|
lv_label_set_text(ui_LabelUnitEnerge, "mW");
|
||||||
} else {
|
} else {
|
||||||
if(power >= 100.0) {
|
if(fabs(power) >= 100.0) {
|
||||||
sprintf(buf, "%.1f", power);
|
sprintf(buf, "%.1f", power);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -106,7 +121,7 @@ static void _flush_timer_cb()
|
|||||||
timecount++;
|
timecount++;
|
||||||
if(timecount >= 2) { // 1s
|
if(timecount >= 2) { // 1s
|
||||||
timecount = 0;
|
timecount = 0;
|
||||||
full_screen_refresh();
|
ui_full_screen_refresh(ui_HomeScreen);
|
||||||
}
|
}
|
||||||
float voltage = 0.0;
|
float voltage = 0.0;
|
||||||
float current = 0.0;
|
float current = 0.0;
|
||||||
@@ -240,11 +255,3 @@ void ui_main_screen_destroy(void)
|
|||||||
timecount = 0;
|
timecount = 0;
|
||||||
lv_timer_del(_flush_timer);
|
lv_timer_del(_flush_timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "key.h"
|
|
||||||
void ui_main_page_key_handler(uint8_t key_id)
|
|
||||||
{
|
|
||||||
if(key_id == KEYB_NUM) {
|
|
||||||
PageManager_next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -40,6 +40,16 @@ Page_t pages[] = {
|
|||||||
#error "LV_COLOR_DEPTH should be 16bit to match SquareLine Studio's settings"
|
#error "LV_COLOR_DEPTH should be 16bit to match SquareLine Studio's settings"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
///////////////////// help funtions ////////////////////
|
||||||
|
|
||||||
|
void ui_full_screen_refresh(lv_obj_t * screen) {
|
||||||
|
// 标记整个屏幕为脏区域
|
||||||
|
lv_obj_invalidate(screen);
|
||||||
|
// 或者立即刷新整个屏幕
|
||||||
|
lv_refr_now(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////// Timer //////////////////////
|
/////////////////////// Timer //////////////////////
|
||||||
/**
|
/**
|
||||||
* Main timer for Refreshing the screens
|
* Main timer for Refreshing the screens
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ extern "C" {
|
|||||||
#include "./PageManager.h"
|
#include "./PageManager.h"
|
||||||
|
|
||||||
void ui_init(void);
|
void ui_init(void);
|
||||||
|
void ui_full_screen_refresh(lv_obj_t * screen);
|
||||||
|
|
||||||
// FONTS
|
// FONTS
|
||||||
LV_FONT_DECLARE(ui_font_HeiTi32);
|
LV_FONT_DECLARE(ui_font_HeiTi32);
|
||||||
|
|||||||
Reference in New Issue
Block a user