Automatic error detection

This commit is contained in:
Riku Isokoski 2021-08-18 15:23:30 +03:00
parent 9c175e2f0c
commit 780a811f05
10 changed files with 121 additions and 9 deletions

10
src/BootErrors.h Normal file
View file

@ -0,0 +1,10 @@
#pragma once
namespace Pinetime {
namespace System {
enum class BootErrors {
None,
TouchController,
};
}
}

View file

@ -418,6 +418,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/BatteryInfo.cpp displayapp/screens/BatteryInfo.cpp
displayapp/screens/Steps.cpp displayapp/screens/Steps.cpp
displayapp/screens/Timer.cpp displayapp/screens/Timer.cpp
displayapp/screens/Error.cpp
## Settings ## Settings
displayapp/screens/settings/QuickSettings.cpp displayapp/screens/settings/QuickSettings.cpp

View file

@ -30,7 +30,8 @@ namespace Pinetime {
SettingTimeFormat, SettingTimeFormat,
SettingDisplay, SettingDisplay,
SettingWakeUp, SettingWakeUp,
SettingSteps SettingSteps,
Error,
}; };
} }
} }

View file

@ -28,6 +28,7 @@
#include "displayapp/screens/FlashLight.h" #include "displayapp/screens/FlashLight.h"
#include "displayapp/screens/BatteryInfo.h" #include "displayapp/screens/BatteryInfo.h"
#include "displayapp/screens/Steps.h" #include "displayapp/screens/Steps.h"
#include "displayapp/screens/Error.h"
#include "drivers/Cst816s.h" #include "drivers/Cst816s.h"
#include "drivers/St7789.h" #include "drivers/St7789.h"
@ -107,11 +108,16 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
timerController {timerController} { timerController {timerController} {
} }
void DisplayApp::Start() { void DisplayApp::Start(System::BootErrors error) {
msgQueue = xQueueCreate(queueSize, itemSize); msgQueue = xQueueCreate(queueSize, itemSize);
// Start clock when smartwatch boots bootError = error;
LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
if (error == System::BootErrors::TouchController) {
LoadApp(Apps::Error, DisplayApp::FullRefreshDirections::None);
} else {
LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
}
if (pdPASS != xTaskCreate(DisplayApp::Process, "displayapp", 800, this, 0, &taskHandle)) { if (pdPASS != xTaskCreate(DisplayApp::Process, "displayapp", 800, this, 0, &taskHandle)) {
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
@ -325,6 +331,11 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
motionController); motionController);
break; break;
case Apps::Error:
currentScreen = std::make_unique<Screens::Error>(this, bootError);
ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None);
break;
case Apps::FirmwareValidation: case Apps::FirmwareValidation:
currentScreen = std::make_unique<Screens::FirmwareValidation>(this, validator); currentScreen = std::make_unique<Screens::FirmwareValidation>(this, validator);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);

View file

@ -15,6 +15,7 @@
#include "displayapp/screens/Screen.h" #include "displayapp/screens/Screen.h"
#include "components/timer/TimerController.h" #include "components/timer/TimerController.h"
#include "Messages.h" #include "Messages.h"
#include "BootErrors.h"
namespace Pinetime { namespace Pinetime {
@ -56,7 +57,7 @@ namespace Pinetime {
Pinetime::Controllers::MotorController& motorController, Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::MotionController& motionController, Pinetime::Controllers::MotionController& motionController,
Pinetime::Controllers::TimerController& timerController); Pinetime::Controllers::TimerController& timerController);
void Start(); void Start(System::BootErrors error);
void PushMessage(Display::Messages msg); void PushMessage(Display::Messages msg);
void StartApp(Apps app, DisplayApp::FullRefreshDirections direction); void StartApp(Apps app, DisplayApp::FullRefreshDirections direction);
@ -114,6 +115,8 @@ namespace Pinetime {
Apps nextApp = Apps::None; Apps nextApp = Apps::None;
DisplayApp::FullRefreshDirections nextDirection; DisplayApp::FullRefreshDirections nextDirection;
TickType_t lastWakeTime; TickType_t lastWakeTime;
System::BootErrors bootError;
}; };
} }
} }

View file

@ -0,0 +1,54 @@
#include "Error.h"
using namespace Pinetime::Applications::Screens;
namespace {
void ButtonEventCallback(lv_obj_t* obj, lv_event_t /*event*/) {
auto* errorScreen = static_cast<Error*>(obj->user_data);
errorScreen->ButtonEventHandler();
}
}
Error::Error(Pinetime::Applications::DisplayApp* app, System::BootErrors error)
: Screen(app) {
lv_obj_t* warningLabel = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(warningLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
lv_label_set_text_static(warningLabel, "Warning");
lv_obj_align(warningLabel, nullptr, LV_ALIGN_IN_TOP_MID, 0, 0);
lv_obj_t* causeLabel = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_long_mode(causeLabel, LV_LABEL_LONG_BREAK);
lv_obj_set_width(causeLabel, LV_HOR_RES);
lv_obj_align(causeLabel, warningLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
if (error == System::BootErrors::TouchController) {
lv_label_set_text_static(causeLabel, "Touch controller error detected.");
}
lv_obj_t* tipLabel = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_long_mode(tipLabel, LV_LABEL_LONG_BREAK);
lv_obj_set_width(tipLabel, LV_HOR_RES);
lv_label_set_text_static(tipLabel, "If you encounter problems and your device is under warranty, contact the devices seller.");
lv_obj_align(tipLabel, causeLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
btnOk = lv_btn_create(lv_scr_act(), nullptr);
btnOk->user_data = this;
lv_obj_set_event_cb(btnOk, ButtonEventCallback);
lv_obj_set_size(btnOk, LV_HOR_RES, 50);
lv_obj_align(btnOk, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
lv_obj_set_style_local_value_str(btnOk, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Proceed");
lv_obj_set_style_local_bg_color(btnOk, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
}
void Error::ButtonEventHandler() {
running = false;
}
Error::~Error() {
lv_obj_clean(lv_scr_act());
}
bool Error::Refresh() {
return running;
}

View file

@ -0,0 +1,22 @@
#pragma once
#include "Screen.h"
#include "BootErrors.h"
#include <lvgl/lvgl.h>
namespace Pinetime {
namespace Applications {
namespace Screens {
class Error : public Screen {
public:
Error(DisplayApp* app, System::BootErrors error);
~Error() override;
bool Refresh() override;
void ButtonEventHandler();
private:
lv_obj_t* btnOk;
};
}
}
}

View file

@ -17,7 +17,7 @@ using namespace Pinetime::Drivers;
Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaster}, twiAddress {twiAddress} { Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaster}, twiAddress {twiAddress} {
} }
void Cst816S::Init() { bool Cst816S::Init() {
nrf_gpio_cfg_output(pinReset); nrf_gpio_cfg_output(pinReset);
nrf_gpio_pin_set(pinReset); nrf_gpio_pin_set(pinReset);
vTaskDelay(50); vTaskDelay(50);
@ -44,13 +44,18 @@ void Cst816S::Init() {
// There's mixed information about which register contains which information // There's mixed information about which register contains which information
if (twiMaster.Read(twiAddress, 0xA7, &chipId, 1) == TwiMaster::ErrorCodes::TransactionFailed) { if (twiMaster.Read(twiAddress, 0xA7, &chipId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
chipId = 0xFF; chipId = 0xFF;
return false;
} }
if (twiMaster.Read(twiAddress, 0xA8, &vendorId, 1) == TwiMaster::ErrorCodes::TransactionFailed) { if (twiMaster.Read(twiAddress, 0xA8, &vendorId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
vendorId = 0xFF; vendorId = 0xFF;
return false;
} }
if (twiMaster.Read(twiAddress, 0xA9, &fwVersion, 1) == TwiMaster::ErrorCodes::TransactionFailed) { if (twiMaster.Read(twiAddress, 0xA9, &fwVersion, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
fwVersion = 0xFF; fwVersion = 0xFF;
return false;
} }
return chipId == 0xb4 && vendorId == 0 && fwVersion == 1;
} }
Cst816S::TouchInfos Cst816S::GetTouchInfo() { Cst816S::TouchInfos Cst816S::GetTouchInfo() {

View file

@ -31,7 +31,7 @@ namespace Pinetime {
Cst816S(Cst816S&&) = delete; Cst816S(Cst816S&&) = delete;
Cst816S& operator=(Cst816S&&) = delete; Cst816S& operator=(Cst816S&&) = delete;
void Init(); bool Init();
TouchInfos GetTouchInfo(); TouchInfos GetTouchInfo();
void Sleep(); void Sleep();
void Wakeup(); void Wakeup();

View file

@ -22,6 +22,7 @@
#include "drivers/TwiMaster.h" #include "drivers/TwiMaster.h"
#include "drivers/Hrs3300.h" #include "drivers/Hrs3300.h"
#include "main.h" #include "main.h"
#include "BootErrors.h"
#include <memory> #include <memory>
@ -106,6 +107,8 @@ void SystemTask::Process(void* instance) {
} }
void SystemTask::Work() { void SystemTask::Work() {
BootErrors bootError = BootErrors::None;
watchdog.Setup(7); watchdog.Setup(7);
watchdog.Start(); watchdog.Start();
NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason())); NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason()));
@ -124,7 +127,9 @@ void SystemTask::Work() {
lcd.Init(); lcd.Init();
twiMaster.Init(); twiMaster.Init();
touchPanel.Init(); if (!touchPanel.Init()) {
bootError = BootErrors::TouchController;
}
dateTimeController.Register(this); dateTimeController.Register(this);
batteryController.Init(); batteryController.Init();
motorController.Init(); motorController.Init();
@ -141,7 +146,7 @@ void SystemTask::Work() {
settingsController.Init(); settingsController.Init();
displayApp.Register(this); displayApp.Register(this);
displayApp.Start(); displayApp.Start(bootError);
displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel); displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);