2021-10-13 20:08:35 +00:00
|
|
|
#include "displayapp/screens/FirmwareUpdate.h"
|
2020-11-15 15:49:36 +00:00
|
|
|
#include <lvgl/lvgl.h>
|
|
|
|
#include "components/ble/BleController.h"
|
2021-10-13 20:08:35 +00:00
|
|
|
#include "displayapp/DisplayApp.h"
|
2020-05-02 12:16:57 +00:00
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
FirmwareUpdate::FirmwareUpdate(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Ble& bleController)
|
|
|
|
: Screen(app), bleController {bleController} {
|
2020-05-02 12:16:57 +00:00
|
|
|
|
2020-10-04 11:53:11 +00:00
|
|
|
titleLabel = lv_label_create(lv_scr_act(), nullptr);
|
2022-03-20 14:47:25 +00:00
|
|
|
lv_label_set_text_static(titleLabel, "Firmware update");
|
2020-10-04 11:53:11 +00:00
|
|
|
lv_obj_align(titleLabel, nullptr, LV_ALIGN_IN_TOP_MID, 0, 50);
|
2020-05-02 12:16:57 +00:00
|
|
|
|
2020-10-04 11:53:11 +00:00
|
|
|
bar1 = lv_bar_create(lv_scr_act(), nullptr);
|
2020-05-02 12:16:57 +00:00
|
|
|
lv_obj_set_size(bar1, 200, 30);
|
2020-10-04 11:53:11 +00:00
|
|
|
lv_obj_align(bar1, nullptr, LV_ALIGN_CENTER, 0, 0);
|
2022-04-09 11:47:43 +00:00
|
|
|
lv_bar_set_range(bar1, 0, 1000);
|
2020-05-02 12:16:57 +00:00
|
|
|
lv_bar_set_value(bar1, 0, LV_ANIM_OFF);
|
|
|
|
|
2020-10-04 11:53:11 +00:00
|
|
|
percentLabel = lv_label_create(lv_scr_act(), nullptr);
|
2022-03-20 14:47:25 +00:00
|
|
|
lv_label_set_text_static(percentLabel, "Waiting...");
|
2022-04-09 11:47:43 +00:00
|
|
|
lv_label_set_recolor(percentLabel, true);
|
2020-05-02 12:16:57 +00:00
|
|
|
lv_obj_set_auto_realign(percentLabel, true);
|
|
|
|
lv_obj_align(percentLabel, bar1, LV_ALIGN_OUT_TOP_MID, 0, 60);
|
2021-07-19 13:26:12 +00:00
|
|
|
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
|
2021-07-22 19:57:45 +00:00
|
|
|
startTime = xTaskGetTickCount();
|
2020-05-02 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FirmwareUpdate::~FirmwareUpdate() {
|
2021-07-19 13:26:12 +00:00
|
|
|
lv_task_del(taskRefresh);
|
2020-05-02 12:16:57 +00:00
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
|
|
|
|
2021-07-19 13:26:12 +00:00
|
|
|
void FirmwareUpdate::Refresh() {
|
2021-04-18 17:28:14 +00:00
|
|
|
switch (bleController.State()) {
|
2020-06-01 07:22:54 +00:00
|
|
|
default:
|
|
|
|
case Pinetime::Controllers::Ble::FirmwareUpdateStates::Idle:
|
2021-07-22 19:57:45 +00:00
|
|
|
// This condition makes sure that the app is exited if somehow it got
|
|
|
|
// launched without a firmware update. This should never happen.
|
|
|
|
if (state != States::Error) {
|
|
|
|
if (xTaskGetTickCount() - startTime > (60 * 1024)) {
|
|
|
|
UpdateError();
|
|
|
|
state = States::Error;
|
|
|
|
}
|
|
|
|
} else if (xTaskGetTickCount() - startTime > (5 * 1024)) {
|
|
|
|
running = false;
|
|
|
|
}
|
|
|
|
break;
|
2020-06-01 07:22:54 +00:00
|
|
|
case Pinetime::Controllers::Ble::FirmwareUpdateStates::Running:
|
2022-04-09 11:47:43 +00:00
|
|
|
if (state != States::Running) {
|
2020-06-01 07:22:54 +00:00
|
|
|
state = States::Running;
|
2022-04-09 11:47:43 +00:00
|
|
|
}
|
2021-07-19 13:26:12 +00:00
|
|
|
DisplayProgression();
|
2021-07-22 19:57:45 +00:00
|
|
|
break;
|
2020-06-01 07:22:54 +00:00
|
|
|
case Pinetime::Controllers::Ble::FirmwareUpdateStates::Validated:
|
2021-04-18 17:28:14 +00:00
|
|
|
if (state != States::Validated) {
|
2020-06-01 07:22:54 +00:00
|
|
|
UpdateValidated();
|
|
|
|
state = States::Validated;
|
|
|
|
}
|
2021-07-22 19:57:45 +00:00
|
|
|
break;
|
2020-06-01 07:22:54 +00:00
|
|
|
case Pinetime::Controllers::Ble::FirmwareUpdateStates::Error:
|
2021-04-18 17:28:14 +00:00
|
|
|
if (state != States::Error) {
|
2020-06-01 07:22:54 +00:00
|
|
|
UpdateError();
|
|
|
|
state = States::Error;
|
|
|
|
}
|
2021-07-22 19:57:45 +00:00
|
|
|
if (xTaskGetTickCount() - startTime > (5 * 1024)) {
|
|
|
|
running = false;
|
|
|
|
}
|
|
|
|
break;
|
2020-06-01 07:22:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 13:26:12 +00:00
|
|
|
void FirmwareUpdate::DisplayProgression() const {
|
2022-04-09 11:47:43 +00:00
|
|
|
const uint32_t current = bleController.FirmwareUpdateCurrentBytes();
|
|
|
|
const uint32_t total = bleController.FirmwareUpdateTotalBytes();
|
|
|
|
const int16_t permille = current / (total / 1000);
|
|
|
|
|
|
|
|
lv_label_set_text_fmt(percentLabel, "%d %%", permille / 10);
|
2020-05-02 12:16:57 +00:00
|
|
|
|
2022-04-09 11:47:43 +00:00
|
|
|
lv_bar_set_value(bar1, permille, LV_ANIM_OFF);
|
2020-05-02 12:16:57 +00:00
|
|
|
}
|
|
|
|
|
2020-06-01 07:22:54 +00:00
|
|
|
void FirmwareUpdate::UpdateValidated() {
|
2022-03-20 14:47:25 +00:00
|
|
|
lv_label_set_text_static(percentLabel, "#00ff00 Image Ok!#");
|
2020-06-01 07:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FirmwareUpdate::UpdateError() {
|
2022-03-20 14:47:25 +00:00
|
|
|
lv_label_set_text_static(percentLabel, "#ff0000 Error!#");
|
2021-07-22 19:57:45 +00:00
|
|
|
startTime = xTaskGetTickCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FirmwareUpdate::OnButtonPushed() {
|
|
|
|
return true;
|
2020-06-01 07:22:54 +00:00
|
|
|
}
|