Skip to content

Commit 780a811

Browse files
committed
Automatic error detection
1 parent 9c175e2 commit 780a811

File tree

10 files changed

+121
-9
lines changed

10 files changed

+121
-9
lines changed

src/BootErrors.h

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
namespace Pinetime {
4+
namespace System {
5+
enum class BootErrors {
6+
None,
7+
TouchController,
8+
};
9+
}
10+
}

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ list(APPEND SOURCE_FILES
418418
displayapp/screens/BatteryInfo.cpp
419419
displayapp/screens/Steps.cpp
420420
displayapp/screens/Timer.cpp
421+
displayapp/screens/Error.cpp
421422

422423
## Settings
423424
displayapp/screens/settings/QuickSettings.cpp

src/displayapp/Apps.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ namespace Pinetime {
3030
SettingTimeFormat,
3131
SettingDisplay,
3232
SettingWakeUp,
33-
SettingSteps
33+
SettingSteps,
34+
Error,
3435
};
3536
}
3637
}

src/displayapp/DisplayApp.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "displayapp/screens/FlashLight.h"
2929
#include "displayapp/screens/BatteryInfo.h"
3030
#include "displayapp/screens/Steps.h"
31+
#include "displayapp/screens/Error.h"
3132

3233
#include "drivers/Cst816s.h"
3334
#include "drivers/St7789.h"
@@ -107,11 +108,16 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
107108
timerController {timerController} {
108109
}
109110

110-
void DisplayApp::Start() {
111+
void DisplayApp::Start(System::BootErrors error) {
111112
msgQueue = xQueueCreate(queueSize, itemSize);
112113

113-
// Start clock when smartwatch boots
114-
LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
114+
bootError = error;
115+
116+
if (error == System::BootErrors::TouchController) {
117+
LoadApp(Apps::Error, DisplayApp::FullRefreshDirections::None);
118+
} else {
119+
LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
120+
}
115121

116122
if (pdPASS != xTaskCreate(DisplayApp::Process, "displayapp", 800, this, 0, &taskHandle)) {
117123
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
@@ -325,6 +331,11 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
325331
motionController);
326332
break;
327333

334+
case Apps::Error:
335+
currentScreen = std::make_unique<Screens::Error>(this, bootError);
336+
ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None);
337+
break;
338+
328339
case Apps::FirmwareValidation:
329340
currentScreen = std::make_unique<Screens::FirmwareValidation>(this, validator);
330341
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);

src/displayapp/DisplayApp.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "displayapp/screens/Screen.h"
1616
#include "components/timer/TimerController.h"
1717
#include "Messages.h"
18+
#include "BootErrors.h"
1819

1920
namespace Pinetime {
2021

@@ -56,7 +57,7 @@ namespace Pinetime {
5657
Pinetime::Controllers::MotorController& motorController,
5758
Pinetime::Controllers::MotionController& motionController,
5859
Pinetime::Controllers::TimerController& timerController);
59-
void Start();
60+
void Start(System::BootErrors error);
6061
void PushMessage(Display::Messages msg);
6162

6263
void StartApp(Apps app, DisplayApp::FullRefreshDirections direction);
@@ -114,6 +115,8 @@ namespace Pinetime {
114115
Apps nextApp = Apps::None;
115116
DisplayApp::FullRefreshDirections nextDirection;
116117
TickType_t lastWakeTime;
118+
119+
System::BootErrors bootError;
117120
};
118121
}
119122
}

src/displayapp/screens/Error.cpp

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "Error.h"
2+
3+
using namespace Pinetime::Applications::Screens;
4+
5+
namespace {
6+
void ButtonEventCallback(lv_obj_t* obj, lv_event_t /*event*/) {
7+
auto* errorScreen = static_cast<Error*>(obj->user_data);
8+
errorScreen->ButtonEventHandler();
9+
}
10+
}
11+
12+
Error::Error(Pinetime::Applications::DisplayApp* app, System::BootErrors error)
13+
: Screen(app) {
14+
15+
lv_obj_t* warningLabel = lv_label_create(lv_scr_act(), nullptr);
16+
lv_obj_set_style_local_text_color(warningLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
17+
lv_label_set_text_static(warningLabel, "Warning");
18+
lv_obj_align(warningLabel, nullptr, LV_ALIGN_IN_TOP_MID, 0, 0);
19+
20+
lv_obj_t* causeLabel = lv_label_create(lv_scr_act(), nullptr);
21+
lv_label_set_long_mode(causeLabel, LV_LABEL_LONG_BREAK);
22+
lv_obj_set_width(causeLabel, LV_HOR_RES);
23+
lv_obj_align(causeLabel, warningLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
24+
25+
if (error == System::BootErrors::TouchController) {
26+
lv_label_set_text_static(causeLabel, "Touch controller error detected.");
27+
}
28+
29+
lv_obj_t* tipLabel = lv_label_create(lv_scr_act(), nullptr);
30+
lv_label_set_long_mode(tipLabel, LV_LABEL_LONG_BREAK);
31+
lv_obj_set_width(tipLabel, LV_HOR_RES);
32+
lv_label_set_text_static(tipLabel, "If you encounter problems and your device is under warranty, contact the devices seller.");
33+
lv_obj_align(tipLabel, causeLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
34+
35+
btnOk = lv_btn_create(lv_scr_act(), nullptr);
36+
btnOk->user_data = this;
37+
lv_obj_set_event_cb(btnOk, ButtonEventCallback);
38+
lv_obj_set_size(btnOk, LV_HOR_RES, 50);
39+
lv_obj_align(btnOk, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
40+
lv_obj_set_style_local_value_str(btnOk, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Proceed");
41+
lv_obj_set_style_local_bg_color(btnOk, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
42+
}
43+
44+
void Error::ButtonEventHandler() {
45+
running = false;
46+
}
47+
48+
Error::~Error() {
49+
lv_obj_clean(lv_scr_act());
50+
}
51+
52+
bool Error::Refresh() {
53+
return running;
54+
}

src/displayapp/screens/Error.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#pragma once
2+
3+
#include "Screen.h"
4+
#include "BootErrors.h"
5+
#include <lvgl/lvgl.h>
6+
7+
namespace Pinetime {
8+
namespace Applications {
9+
namespace Screens {
10+
class Error : public Screen {
11+
public:
12+
Error(DisplayApp* app, System::BootErrors error);
13+
~Error() override;
14+
15+
bool Refresh() override;
16+
void ButtonEventHandler();
17+
private:
18+
lv_obj_t* btnOk;
19+
};
20+
}
21+
}
22+
}

src/drivers/Cst816s.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ using namespace Pinetime::Drivers;
1717
Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaster}, twiAddress {twiAddress} {
1818
}
1919

20-
void Cst816S::Init() {
20+
bool Cst816S::Init() {
2121
nrf_gpio_cfg_output(pinReset);
2222
nrf_gpio_pin_set(pinReset);
2323
vTaskDelay(50);
@@ -44,13 +44,18 @@ void Cst816S::Init() {
4444
// There's mixed information about which register contains which information
4545
if (twiMaster.Read(twiAddress, 0xA7, &chipId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
4646
chipId = 0xFF;
47+
return false;
4748
}
4849
if (twiMaster.Read(twiAddress, 0xA8, &vendorId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
4950
vendorId = 0xFF;
51+
return false;
5052
}
5153
if (twiMaster.Read(twiAddress, 0xA9, &fwVersion, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
5254
fwVersion = 0xFF;
55+
return false;
5356
}
57+
58+
return chipId == 0xb4 && vendorId == 0 && fwVersion == 1;
5459
}
5560

5661
Cst816S::TouchInfos Cst816S::GetTouchInfo() {

src/drivers/Cst816s.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace Pinetime {
3131
Cst816S(Cst816S&&) = delete;
3232
Cst816S& operator=(Cst816S&&) = delete;
3333

34-
void Init();
34+
bool Init();
3535
TouchInfos GetTouchInfo();
3636
void Sleep();
3737
void Wakeup();

src/systemtask/SystemTask.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "drivers/TwiMaster.h"
2323
#include "drivers/Hrs3300.h"
2424
#include "main.h"
25+
#include "BootErrors.h"
2526

2627
#include <memory>
2728

@@ -106,6 +107,8 @@ void SystemTask::Process(void* instance) {
106107
}
107108

108109
void SystemTask::Work() {
110+
BootErrors bootError = BootErrors::None;
111+
109112
watchdog.Setup(7);
110113
watchdog.Start();
111114
NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason()));
@@ -124,7 +127,9 @@ void SystemTask::Work() {
124127
lcd.Init();
125128

126129
twiMaster.Init();
127-
touchPanel.Init();
130+
if (!touchPanel.Init()) {
131+
bootError = BootErrors::TouchController;
132+
}
128133
dateTimeController.Register(this);
129134
batteryController.Init();
130135
motorController.Init();
@@ -141,7 +146,7 @@ void SystemTask::Work() {
141146
settingsController.Init();
142147

143148
displayApp.Register(this);
144-
displayApp.Start();
149+
displayApp.Start(bootError);
145150

146151
displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
147152

0 commit comments

Comments
 (0)