Skip to content

Commit 99e26bd

Browse files
committed
LVGL use system tick
1 parent 61a4642 commit 99e26bd

7 files changed

Lines changed: 11 additions & 51 deletions

File tree

src/FreeRTOSConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
#define configENABLE_BACKWARD_COMPATIBILITY 1
7878

7979
/* Hook function related definitions. */
80-
#define configUSE_IDLE_HOOK 1
80+
#define configUSE_IDLE_HOOK 0
8181
#define configUSE_TICK_HOOK 0
8282
#define configCHECK_FOR_STACK_OVERFLOW 0
8383
#define configUSE_MALLOC_FAILED_HOOK 0

src/displayapp/screens/BatteryInfo.cpp

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ static void lv_update_task(struct _lv_task_t* task) {
99
user_data->UpdateScreen();
1010
}
1111

12-
static void lv_anim_task(struct _lv_task_t* task) {
13-
auto user_data = static_cast<BatteryInfo*>(task->user_data);
14-
user_data->UpdateAnim();
15-
}
16-
1712
BatteryInfo::BatteryInfo(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Battery& batteryController)
1813
: Screen(app), batteryController {batteryController} {
1914

@@ -24,12 +19,12 @@ BatteryInfo::BatteryInfo(Pinetime::Applications::DisplayApp* app, Pinetime::Cont
2419
lv_obj_set_size(charging_bar, 200, 15);
2520
lv_bar_set_range(charging_bar, 0, 100);
2621
lv_obj_align(charging_bar, nullptr, LV_ALIGN_CENTER, 0, 10);
27-
lv_bar_set_anim_time(charging_bar, 2000);
22+
lv_bar_set_anim_time(charging_bar, 1000);
2823
lv_obj_set_style_local_radius(charging_bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
2924
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, lv_color_hex(0x222222));
3025
lv_obj_set_style_local_bg_opa(charging_bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_OPA_100);
3126
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, lv_color_hex(0xFF0000));
32-
lv_bar_set_value(charging_bar, batteryPercent, LV_ANIM_OFF);
27+
lv_bar_set_value(charging_bar, batteryPercent, LV_ANIM_ON);
3328

3429
status = lv_label_create(lv_scr_act(), nullptr);
3530
lv_label_set_text_static(status, "Reading Battery status");
@@ -58,40 +53,15 @@ BatteryInfo::BatteryInfo(Pinetime::Applications::DisplayApp* app, Pinetime::Cont
5853
lv_obj_set_pos(backgroundLabel, 0, 0);
5954
lv_label_set_text_static(backgroundLabel, "");
6055

61-
taskUpdate = lv_task_create(lv_update_task, 500000, LV_TASK_PRIO_LOW, this);
62-
taskAnim = lv_task_create(lv_anim_task, 1000, LV_TASK_PRIO_LOW, this);
56+
taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_LOW, this);
6357
UpdateScreen();
6458
}
6559

6660
BatteryInfo::~BatteryInfo() {
6761
lv_task_del(taskUpdate);
68-
lv_task_del(taskAnim);
6962
lv_obj_clean(lv_scr_act());
7063
}
7164

72-
void BatteryInfo::UpdateAnim() {
73-
batteryPercent = batteryController.PercentRemaining();
74-
75-
if (batteryPercent >= 0) {
76-
if (batteryController.IsCharging() and batteryPercent < 100) {
77-
animation += 1;
78-
if (animation >= 100) {
79-
animation = 0;
80-
}
81-
82-
} else {
83-
if (animation > batteryPercent) {
84-
animation--;
85-
}
86-
if (animation < batteryPercent) {
87-
animation++;
88-
}
89-
}
90-
91-
lv_bar_set_value(charging_bar, animation, LV_ANIM_OFF);
92-
}
93-
}
94-
9565
void BatteryInfo::UpdateScreen() {
9666

9767
batteryController.Update();
@@ -123,9 +93,9 @@ void BatteryInfo::UpdateScreen() {
12393

12494
lv_obj_align(status, charging_bar, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);
12595
lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltage / 1000, batteryVoltage % 1000 / 10);
96+
lv_bar_set_value(charging_bar, batteryPercent, LV_ANIM_ON);
12697
}
12798

12899
bool BatteryInfo::Refresh() {
129-
130100
return running;
131101
}

src/displayapp/screens/BatteryInfo.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ namespace Pinetime {
2222
bool Refresh() override;
2323

2424
void UpdateScreen();
25-
void UpdateAnim();
2625

2726
private:
2827
Pinetime::Controllers::Battery& batteryController;
@@ -33,9 +32,7 @@ namespace Pinetime {
3332
lv_obj_t* status;
3433

3534
lv_task_t* taskUpdate;
36-
lv_task_t* taskAnim;
3735

38-
int8_t animation = 0;
3936
int8_t batteryPercent = -1;
4037
uint16_t batteryVoltage = 0;
4138
};

src/displayapp/screens/Tile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Tile::Tile(uint8_t screenID,
107107
lv_obj_set_pos(backgroundLabel, 0, 0);
108108
lv_label_set_text_static(backgroundLabel, "");
109109

110-
taskUpdate = lv_task_create(lv_update_task, 500000, LV_TASK_PRIO_MID, this);
110+
taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_MID, this);
111111
}
112112

113113
Tile::~Tile() {

src/displayapp/screens/settings/QuickSettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ QuickSettings::QuickSettings(Pinetime::Applications::DisplayApp* app,
110110
lv_obj_set_pos(backgroundLabel, 0, 0);
111111
lv_label_set_text_static(backgroundLabel, "");
112112

113-
taskUpdate = lv_task_create(lv_update_task, 500000, LV_TASK_PRIO_MID, this);
113+
taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_MID, this);
114114
}
115115

116116
QuickSettings::~QuickSettings() {

src/libs/lv_conf.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ typedef void* lv_img_decoder_user_data_t;
293293

294294
/* 1: use a custom tick source.
295295
* It removes the need to manually update the tick with `lv_tick_inc`) */
296-
#define LV_TICK_CUSTOM 0
296+
#define LV_TICK_CUSTOM 1
297297
#if LV_TICK_CUSTOM == 1
298-
#define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the system time function*/
299-
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current system time in ms*/
298+
#define LV_TICK_CUSTOM_INCLUDE "FreeRTOS.h" /*Header for the system time function*/
299+
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (xTaskGetTickCount()) /*Expression evaluating to current system time in ms*/
300300
#endif /*LV_TICK_CUSTOM*/
301301

302302
typedef void* lv_disp_drv_user_data_t; /*Type of user data in the display driver*/
@@ -759,4 +759,4 @@ typedef void* lv_obj_user_data_t;
759759

760760
/*--END OF LV_CONF_H--*/
761761

762-
#endif /*LV_CONF_H*/
762+
#endif /*LV_CONF_H*/

src/main.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,6 @@ void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action
175175
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
176176
}
177177

178-
extern "C" {
179-
void vApplicationIdleHook(void) {
180-
if (!isFactory)
181-
lv_tick_inc(1);
182-
}
183-
}
184-
185178
void DebounceTimerChargeCallback(TimerHandle_t xTimer) {
186179
xTimerStop(xTimer, 0);
187180
systemTask.PushMessage(Pinetime::System::Messages::OnChargingEvent);

0 commit comments

Comments
 (0)