Skip to content

Commit 36e2784

Browse files
authored
Merge pull request #263 from joaquimorg/0.16.0Update
Fix Issue #262 for 0.16.0 version
2 parents eb769fb + 3c413bd commit 36e2784

18 files changed

Lines changed: 289 additions & 126 deletions

src/FreeRTOSConfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
#define configTICK_RATE_HZ 1024
6464
#define configMAX_PRIORITIES ( 3 )
6565
#define configMINIMAL_STACK_SIZE ( 120 )
66-
#define configTOTAL_HEAP_SIZE ( 1024*15 )
66+
#define configTOTAL_HEAP_SIZE ( 1024*16 )
6767
#define configMAX_TASK_NAME_LEN ( 4 )
6868
#define configUSE_16_BIT_TICKS 0
6969
#define configIDLE_SHOULD_YIELD 1
@@ -96,7 +96,7 @@
9696
#define configUSE_TIMERS 1
9797
#define configTIMER_TASK_PRIORITY ( 0 )
9898
#define configTIMER_QUEUE_LENGTH 32
99-
#define configTIMER_TASK_STACK_DEPTH ( 200 )
99+
#define configTIMER_TASK_STACK_DEPTH ( 300 )
100100

101101
/* Tickless Idle configuration. */
102102
#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2

src/components/battery/BatteryController.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@ void Battery::Update() {
2323
isCharging = !nrf_gpio_pin_read(chargingPin);
2424
isPowerPresent = !nrf_gpio_pin_read(powerPresentPin);
2525

26+
if ( isReading ) return;
2627
// Non blocking read
27-
SaadcInit();
28-
nrfx_saadc_sample();
28+
samples = 0;
29+
isReading = true;
30+
SaadcInit();
31+
32+
nrfx_saadc_sample();
2933

3034
}
3135

36+
void Battery::adcCallbackStatic(nrfx_saadc_evt_t const *event) {
37+
instance->SaadcEventHandler(event);
38+
}
39+
3240
void Battery::SaadcInit() {
3341
nrfx_saadc_config_t adcConfig = NRFX_SAADC_DEFAULT_CONFIG;
3442
APP_ERROR_CHECK(nrfx_saadc_init(&adcConfig, adcCallbackStatic));
@@ -68,10 +76,13 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const * p_event) {
6876

6977
percentRemainingBuffer.insert(percentRemaining);
7078

71-
nrfx_saadc_uninit();
79+
samples++;
80+
if ( samples > percentRemainingSamples ) {
81+
nrfx_saadc_uninit();
82+
isReading = false;
83+
} else {
84+
nrfx_saadc_sample();
85+
}
7286
}
7387
}
7488

75-
void Battery::adcCallbackStatic(nrfx_saadc_evt_t const *event) {
76-
instance->SaadcEventHandler(event);
77-
}

src/components/battery/BatteryController.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ namespace Pinetime {
5252
float Voltage() const { return voltage; }
5353

5454
bool IsCharging() const { return isCharging; }
55-
bool IsPowerPresent() const { return isPowerPresent; }
55+
bool IsPowerPresent() const { return isPowerPresent; }
5656

5757
private:
5858
static Battery *instance;
5959
nrf_saadc_value_t saadc_value;
6060

61-
static constexpr uint8_t percentRemainingSamples = 10;
61+
static constexpr uint8_t percentRemainingSamples = 5;
6262
CircBuffer<percentRemainingSamples> percentRemainingBuffer {};
6363

6464
static constexpr uint32_t chargingPin = 12;
@@ -74,6 +74,9 @@ namespace Pinetime {
7474

7575
void SaadcEventHandler(nrfx_saadc_evt_t const * p_event);
7676
static void adcCallbackStatic(nrfx_saadc_evt_t const *event);
77+
78+
bool isReading = false;
79+
uint8_t samples = 0;
7780
};
7881
}
7982
}

src/displayapp/DisplayApp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "displayapp/screens/Twos.h"
2525
#include "displayapp/screens/FlashLight.h"
2626
#include "displayapp/screens/BatteryInfo.h"
27+
2728
#include "drivers/Cst816s.h"
2829
#include "drivers/St7789.h"
2930
#include "drivers/Watchdog.h"
@@ -131,7 +132,7 @@ void DisplayApp::Refresh() {
131132
// clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected : Screens::Clock::BleConnectionStates::NotConnected);
132133
break;
133134
case Messages::UpdateBatteryLevel:
134-
// clockScreen.SetBatteryPercentRemaining(batteryController.PercentRemaining());
135+
batteryController.Update();
135136
break;
136137
case Messages::NewNotification:
137138
LoadApp( Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down );
@@ -307,7 +308,6 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
307308
case Apps::Motion:
308309
currentScreen = std::make_unique<Screens::Motion>(this, motionController);
309310
break;
310-
311311
}
312312
currentApp = app;
313313
}

src/displayapp/lv_pinetime_theme.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ static void basic_init(void)
246246
lv_style_set_border_color(&style_table_cell, LV_STATE_DEFAULT, LV_PINETIME_GRAY);
247247
lv_style_set_border_width(&style_table_cell, LV_STATE_DEFAULT, 1);
248248
lv_style_set_border_side(&style_table_cell, LV_STATE_DEFAULT, LV_BORDER_SIDE_FULL);
249-
lv_style_set_pad_left(&style_table_cell, LV_STATE_DEFAULT, 12);
250-
lv_style_set_pad_right(&style_table_cell, LV_STATE_DEFAULT, 12);
251-
lv_style_set_pad_top(&style_table_cell, LV_STATE_DEFAULT, 12);
252-
lv_style_set_pad_bottom(&style_table_cell, LV_STATE_DEFAULT, 12);
249+
lv_style_set_pad_left(&style_table_cell, LV_STATE_DEFAULT, 5);
250+
lv_style_set_pad_right(&style_table_cell, LV_STATE_DEFAULT, 5);
251+
lv_style_set_pad_top(&style_table_cell, LV_STATE_DEFAULT, 2);
252+
lv_style_set_pad_bottom(&style_table_cell, LV_STATE_DEFAULT, 2);
253253

254254
style_init_reset(&style_pad_small);
255255
lv_style_int_t pad_small_value = 10;
@@ -356,6 +356,7 @@ static void theme_apply(lv_obj_t * obj, lv_theme_style_t name)
356356
lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN);
357357
list = lv_obj_get_style_list(obj, LV_OBJ_PART_MAIN);
358358
_lv_style_list_add_style(list, &style_bg);
359+
_lv_style_list_add_style(list, &style_label_white);
359360
break;
360361

361362
case LV_THEME_OBJ:
@@ -499,6 +500,7 @@ static void theme_apply(lv_obj_t * obj, lv_theme_style_t name)
499500
for(; idx <= LV_TABLE_CELL_STYLE_CNT; idx ++) {
500501
list = lv_obj_get_style_list(obj, idx);
501502
_lv_style_list_add_style(list, &style_table_cell);
503+
_lv_style_list_add_style(list, &style_label_white);
502504
}
503505
break;
504506

src/displayapp/screens/BatteryInfo.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void BatteryInfo::UpdateAnim() {
8484
batteryPercent = batteryController.PercentRemaining();
8585

8686
if ( batteryPercent >= 0 ) {
87-
if ( batteryController.IsCharging() ) {
87+
if ( batteryController.IsCharging() and batteryPercent < 100 ) {
8888
animation +=1;
8989
if (animation >= 100) {
9090
animation = 0;
@@ -111,12 +111,17 @@ void BatteryInfo::UpdateScreen() {
111111
batteryVoltage = batteryController.Voltage();
112112

113113
if ( batteryPercent >= 0 ) {
114-
if ( batteryController.IsCharging() ) {
115-
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC , LV_STATE_DEFAULT, lv_color_hex(0xFF0000));
114+
if ( batteryController.IsCharging() and batteryPercent < 100 ) {
115+
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC , LV_STATE_DEFAULT, LV_COLOR_RED);
116116
lv_label_set_text_static(status,"Battery charging");
117-
117+
} else if ( batteryPercent == 100 ) {
118+
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC , LV_STATE_DEFAULT, LV_COLOR_BLUE);
119+
lv_label_set_text_static(status,"Battery is fully charged");
120+
} else if ( batteryPercent < 10 ) {
121+
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC , LV_STATE_DEFAULT, LV_COLOR_YELLOW);
122+
lv_label_set_text_static(status,"Battery is low");
118123
} else {
119-
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC , LV_STATE_DEFAULT, lv_color_hex(0x00FF00));
124+
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC , LV_STATE_DEFAULT, LV_COLOR_GREEN);
120125
lv_label_set_text_static(status,"Battery discharging");
121126
}
122127

src/displayapp/screens/List.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void List::OnButtonEvent(lv_obj_t * object, lv_event_t event) {
116116
if ( event == LV_EVENT_RELEASED ) {
117117
for(int i = 0; i < MAXLISTITEMS; i++) {
118118
if ( apps[i] != Apps::None && object == itemApps[i] ) {
119-
app->StartApp(apps[i], DisplayApp::FullRefreshDirections::Down);
119+
app->StartApp(apps[i], DisplayApp::FullRefreshDirections::Up);
120120
running = false;
121121
return;
122122
}

src/displayapp/screens/SystemInfo.cpp

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp *app,
2626
[this]() -> std::unique_ptr<Screen> { return CreateScreen1(); },
2727
[this]() -> std::unique_ptr<Screen> { return CreateScreen2(); },
2828
[this]() -> std::unique_ptr<Screen> { return CreateScreen3(); },
29-
[this]() -> std::unique_ptr<Screen> { return CreateScreen4(); }
29+
[this]() -> std::unique_ptr<Screen> { return CreateScreen4(); },
30+
[this]() -> std::unique_ptr<Screen> { return CreateScreen5(); }
3031
},
3132
Screens::ScreenListModes::UpDown
3233
} {}
@@ -37,7 +38,9 @@ SystemInfo::~SystemInfo() {
3738
}
3839

3940
bool SystemInfo::Refresh() {
40-
screens.Refresh();
41+
if (running) {
42+
screens.Refresh();
43+
}
4144
return running;
4245
}
4346

@@ -50,27 +53,8 @@ bool SystemInfo::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
5053
return screens.OnTouchEvent(event);
5154
}
5255

53-
void SystemInfo::CreateContainer() {
54-
55-
if ( container1 ) {
56-
container1 = lv_cont_create(lv_scr_act(), nullptr);
57-
58-
lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
59-
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
60-
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
61-
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
62-
63-
lv_obj_set_pos(container1, 0, 0);
64-
lv_obj_set_width(container1, LV_HOR_RES - 10);
65-
lv_obj_set_height(container1, LV_VER_RES);
66-
lv_cont_set_layout(container1, LV_LAYOUT_CENTER);
67-
}
68-
}
69-
7056
std::unique_ptr<Screen> SystemInfo::CreateScreen1() {
71-
CreateContainer();
72-
73-
lv_obj_t * label = lv_label_create(container1, nullptr);
57+
lv_obj_t * label = lv_label_create(lv_scr_act(), nullptr);
7458
lv_label_set_recolor(label, true);
7559
lv_label_set_text_fmt(label,
7660
"#FFFF00 InfiniTime#\n\n"
@@ -81,12 +65,11 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen1() {
8165
Version::Major(), Version::Minor(), Version::Patch(),
8266
__DATE__, __TIME__);
8367
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
84-
return std::unique_ptr<Screen>(new Screens::Label(0, 4, app, label));
68+
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
69+
return std::unique_ptr<Screen>(new Screens::Label(0, 5, app, label));
8570
}
8671

8772
std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
88-
CreateContainer();
89-
9073
auto batteryPercent = static_cast<uint8_t>(batteryController.PercentRemaining());
9174
float batteryVoltage = batteryController.Voltage();
9275

@@ -126,7 +109,7 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
126109
batteryVoltageBytes[0] = static_cast<uint8_t>((batteryVoltage - batteryVoltageBytes[1]) * 100); //remove whole part of flt and shift 2 places over
127110
//
128111

129-
lv_obj_t * label = lv_label_create(container1, nullptr);
112+
lv_obj_t * label = lv_label_create(lv_scr_act(), nullptr);
130113
lv_label_set_recolor(label, true);
131114
lv_label_set_text_fmt(label,
132115
"#444444 Date# %02d/%02d/%04d\n"
@@ -140,16 +123,16 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
140123
uptimeDays, uptimeHours, uptimeMinutes, uptimeSeconds,
141124
batteryPercent, batteryVoltageBytes[1], batteryVoltageBytes[0], brightnessController.ToString(), resetReason
142125
);
126+
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
143127
return std::unique_ptr<Screen>(new Screens::Label(1, 4, app, label));
144128

145129
}
146130

147131
std::unique_ptr<Screen> SystemInfo::CreateScreen3() {
148132
lv_mem_monitor_t mon;
149133
lv_mem_monitor(&mon);
150-
CreateContainer();
151-
152-
lv_obj_t * label = lv_label_create(container1, nullptr);
134+
135+
lv_obj_t * label = lv_label_create(lv_scr_act(), nullptr);
153136
lv_label_set_recolor(label, true);
154137
auto& bleAddr = bleController.Address();
155138
lv_label_set_text_fmt(label,
@@ -169,13 +152,46 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen3() {
169152
(int)mon.free_biggest_size,
170153
0
171154
);
172-
173-
return std::unique_ptr<Screen>(new Screens::Label(2, 4, app, label));
155+
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
156+
return std::unique_ptr<Screen>(new Screens::Label(2, 5, app, label));
174157
}
175158

159+
160+
bool sortById(const TaskStatus_t &lhs, const TaskStatus_t &rhs) { return lhs.xTaskNumber < rhs.xTaskNumber; }
161+
176162
std::unique_ptr<Screen> SystemInfo::CreateScreen4() {
177-
CreateContainer();
178-
lv_obj_t * label = lv_label_create(container1, nullptr);
163+
TaskStatus_t tasksStatus[7];
164+
lv_obj_t * infoTask = lv_table_create(lv_scr_act(), NULL);
165+
lv_table_set_col_cnt(infoTask, 3);
166+
lv_table_set_row_cnt(infoTask, 8);
167+
lv_obj_set_pos(infoTask, 10, 10);
168+
169+
lv_table_set_cell_value(infoTask, 0, 0, "#");
170+
lv_table_set_col_width(infoTask, 0, 50);
171+
lv_table_set_cell_value(infoTask, 0, 1, "Task");
172+
lv_table_set_col_width(infoTask, 1, 80);
173+
lv_table_set_cell_value(infoTask, 0, 2, "Free");
174+
lv_table_set_col_width(infoTask, 2, 90);
175+
176+
auto nb = uxTaskGetSystemState(tasksStatus, 7, nullptr);
177+
std::sort(tasksStatus, tasksStatus + nb, sortById);
178+
for (uint8_t i = 0; i < nb; i++) {
179+
180+
lv_table_set_cell_value(infoTask, i + 1, 0, std::to_string(tasksStatus[i].xTaskNumber).c_str());
181+
lv_table_set_cell_value(infoTask, i + 1, 1, tasksStatus[i].pcTaskName);
182+
if (tasksStatus[i].usStackHighWaterMark < 20) {
183+
std::string str1 = std::to_string(tasksStatus[i].usStackHighWaterMark) + " low";
184+
lv_table_set_cell_value(infoTask, i + 1, 2, str1.c_str());
185+
} else {
186+
lv_table_set_cell_value(infoTask, i + 1, 2, std::to_string(tasksStatus[i].usStackHighWaterMark).c_str());
187+
}
188+
189+
}
190+
return std::unique_ptr<Screen>(new Screens::Label(3, 5, app, infoTask));
191+
}
192+
193+
std::unique_ptr<Screen> SystemInfo::CreateScreen5() {
194+
lv_obj_t * label = lv_label_create(lv_scr_act(), nullptr);
179195
lv_label_set_recolor(label, true);
180196
lv_label_set_text_static(label,
181197
"Software Licensed\n"
@@ -186,5 +202,6 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen4() {
186202
"#FFFF00 https://github.com/#\n"
187203
"#FFFF00 JF002/InfiniTime#");
188204
lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
189-
return std::unique_ptr<Screen>(new Screens::Label(3, 4, app, label));
205+
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
206+
return std::unique_ptr<Screen>(new Screens::Label(4, 5, app, label));
190207
}

src/displayapp/screens/SystemInfo.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,19 @@ namespace Pinetime {
3535
private:
3636
bool running = true;
3737

38-
lv_obj_t* container1;
39-
4038
Pinetime::Controllers::DateTime& dateTimeController;
4139
Pinetime::Controllers::Battery& batteryController;
4240
Pinetime::Controllers::BrightnessController& brightnessController;
4341
Pinetime::Controllers::Ble& bleController;
4442
Pinetime::Drivers::WatchdogView& watchdog;
4543

46-
ScreenList<4> screens;
44+
ScreenList<5> screens;
4745
std::unique_ptr<Screen> CreateScreen1();
4846
std::unique_ptr<Screen> CreateScreen2();
4947
std::unique_ptr<Screen> CreateScreen3();
5048
std::unique_ptr<Screen> CreateScreen4();
49+
std::unique_ptr<Screen> CreateScreen5();
5150

52-
void CreateContainer();
5351
};
5452
}
5553
}

src/displayapp/screens/Tile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ bool Tile::Refresh() {
128128

129129
void Tile::OnObjectEvent(lv_obj_t *obj, lv_event_t event, uint32_t buttonId) {
130130
if(event == LV_EVENT_VALUE_CHANGED) {
131-
app->StartApp(apps[buttonId], DisplayApp::FullRefreshDirections::Down);
131+
app->StartApp(apps[buttonId], DisplayApp::FullRefreshDirections::Up);
132132
running = false;
133133
}
134134
}

0 commit comments

Comments
 (0)