2021-10-13 20:08:35 +00:00
|
|
|
#include "displayapp/DisplayAppRecovery.h"
|
2021-01-26 19:31:45 +00:00
|
|
|
#include <FreeRTOS.h>
|
|
|
|
#include <task.h>
|
|
|
|
#include <libraries/log/nrf_log.h>
|
2022-09-27 16:06:15 +00:00
|
|
|
#include "components/fs/FS.h"
|
2021-10-13 20:08:35 +00:00
|
|
|
#include "components/rle/RleDecoder.h"
|
|
|
|
#include "touchhandler/TouchHandler.h"
|
2021-01-26 19:31:45 +00:00
|
|
|
#include "displayapp/icons/infinitime/infinitime-nb.c"
|
2021-09-13 18:35:51 +00:00
|
|
|
#include "components/ble/BleController.h"
|
2021-01-26 19:31:45 +00:00
|
|
|
|
|
|
|
using namespace Pinetime::Applications;
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
DisplayApp::DisplayApp(Drivers::St7789& lcd,
|
2022-12-30 21:31:31 +00:00
|
|
|
Components::LittleVgl& /*lvgl*/,
|
2023-02-23 20:20:22 +00:00
|
|
|
const Drivers::Cst816S& /*touchPanel*/,
|
2023-02-23 20:16:44 +00:00
|
|
|
const Controllers::Battery& /*batteryController*/,
|
2021-04-18 17:28:14 +00:00
|
|
|
Controllers::Ble& bleController,
|
2022-12-30 21:31:31 +00:00
|
|
|
Controllers::DateTime& /*dateTimeController*/,
|
|
|
|
Drivers::WatchdogView& /*watchdog*/,
|
|
|
|
Pinetime::Controllers::NotificationManager& /*notificationManager*/,
|
|
|
|
Pinetime::Controllers::HeartRateController& /*heartRateController*/,
|
|
|
|
Controllers::Settings& /*settingsController*/,
|
|
|
|
Pinetime::Controllers::MotorController& /*motorController*/,
|
|
|
|
Pinetime::Controllers::MotionController& /*motionController*/,
|
|
|
|
Pinetime::Controllers::TimerController& /*timerController*/,
|
|
|
|
Pinetime::Controllers::AlarmController& /*alarmController*/,
|
|
|
|
Pinetime::Controllers::BrightnessController& /*brightnessController*/,
|
|
|
|
Pinetime::Controllers::TouchHandler& /*touchHandler*/,
|
|
|
|
Pinetime::Controllers::FS& /*filesystem*/)
|
2021-04-18 17:28:14 +00:00
|
|
|
: lcd {lcd}, bleController {bleController} {
|
2021-01-26 19:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayApp::Start() {
|
2021-06-12 08:58:28 +00:00
|
|
|
msgQueue = xQueueCreate(queueSize, itemSize);
|
2021-01-26 19:31:45 +00:00
|
|
|
if (pdPASS != xTaskCreate(DisplayApp::Process, "displayapp", 512, this, 0, &taskHandle))
|
|
|
|
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
|
|
|
|
}
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
void DisplayApp::Process(void* instance) {
|
|
|
|
auto* app = static_cast<DisplayApp*>(instance);
|
2021-01-26 19:31:45 +00:00
|
|
|
NRF_LOG_INFO("displayapp task started!");
|
|
|
|
|
|
|
|
// Send a dummy notification to unlock the lvgl display driver for the first iteration
|
|
|
|
xTaskNotifyGive(xTaskGetCurrentTaskHandle());
|
|
|
|
|
|
|
|
app->InitHw();
|
2021-05-14 09:40:46 +00:00
|
|
|
while (true) {
|
2021-01-26 19:31:45 +00:00
|
|
|
app->Refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayApp::InitHw() {
|
|
|
|
DisplayLogo(colorWhite);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayApp::Refresh() {
|
|
|
|
Display::Messages msg;
|
|
|
|
if (xQueueReceive(msgQueue, &msg, 200)) {
|
|
|
|
switch (msg) {
|
|
|
|
case Display::Messages::UpdateBleConnection:
|
2021-05-14 09:43:29 +00:00
|
|
|
if (bleController.IsConnected()) {
|
2021-01-26 19:31:45 +00:00
|
|
|
DisplayLogo(colorBlue);
|
2021-05-14 09:43:29 +00:00
|
|
|
} else {
|
2021-01-26 19:31:45 +00:00
|
|
|
DisplayLogo(colorWhite);
|
2021-05-14 09:43:29 +00:00
|
|
|
}
|
2021-01-26 19:31:45 +00:00
|
|
|
break;
|
|
|
|
case Display::Messages::BleFirmwareUpdateStarted:
|
|
|
|
DisplayLogo(colorGreen);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bleController.IsFirmwareUpdating()) {
|
2021-04-18 17:28:14 +00:00
|
|
|
uint8_t percent =
|
|
|
|
(static_cast<float>(bleController.FirmwareUpdateCurrentBytes()) / static_cast<float>(bleController.FirmwareUpdateTotalBytes())) *
|
|
|
|
100.0f;
|
2021-01-26 19:31:45 +00:00
|
|
|
switch (bleController.State()) {
|
|
|
|
case Controllers::Ble::FirmwareUpdateStates::Running:
|
|
|
|
DisplayOtaProgress(percent, colorWhite);
|
|
|
|
break;
|
|
|
|
case Controllers::Ble::FirmwareUpdateStates::Validated:
|
|
|
|
DisplayOtaProgress(100, colorGreenSwapped);
|
|
|
|
break;
|
|
|
|
case Controllers::Ble::FirmwareUpdateStates::Error:
|
|
|
|
DisplayOtaProgress(100, colorRedSwapped);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayApp::DisplayLogo(uint16_t color) {
|
|
|
|
Pinetime::Tools::RleDecoder rleDecoder(infinitime_nb, sizeof(infinitime_nb), color, colorBlack);
|
2021-04-18 17:28:14 +00:00
|
|
|
for (int i = 0; i < displayWidth; i++) {
|
2021-01-26 19:31:45 +00:00
|
|
|
rleDecoder.DecodeNext(displayBuffer, displayWidth * bytesPerPixel);
|
|
|
|
ulTaskNotifyTake(pdTRUE, 500);
|
2021-04-18 17:28:14 +00:00
|
|
|
lcd.DrawBuffer(0, i, displayWidth, 1, reinterpret_cast<const uint8_t*>(displayBuffer), displayWidth * bytesPerPixel);
|
2021-01-26 19:31:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayApp::DisplayOtaProgress(uint8_t percent, uint16_t color) {
|
|
|
|
const uint8_t barHeight = 20;
|
2021-04-18 17:28:14 +00:00
|
|
|
std::fill(displayBuffer, displayBuffer + (displayWidth * bytesPerPixel), color);
|
|
|
|
for (int i = 0; i < barHeight; i++) {
|
2021-01-26 19:31:45 +00:00
|
|
|
ulTaskNotifyTake(pdTRUE, 500);
|
|
|
|
uint16_t barWidth = std::min(static_cast<float>(percent) * 2.4f, static_cast<float>(displayWidth));
|
2021-04-18 17:28:14 +00:00
|
|
|
lcd.DrawBuffer(0, displayWidth - barHeight + i, barWidth, 1, reinterpret_cast<const uint8_t*>(displayBuffer), barWidth * bytesPerPixel);
|
2021-01-26 19:31:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayApp::PushMessage(Display::Messages msg) {
|
|
|
|
BaseType_t xHigherPriorityTaskWoken;
|
|
|
|
xHigherPriorityTaskWoken = pdFALSE;
|
|
|
|
xQueueSendFromISR(msgQueue, &msg, &xHigherPriorityTaskWoken);
|
|
|
|
if (xHigherPriorityTaskWoken) {
|
|
|
|
/* Actual macro used here is port specific. */
|
|
|
|
// TODO : should I do something here?
|
|
|
|
}
|
2021-06-06 18:20:55 +00:00
|
|
|
}
|
|
|
|
|
2022-12-30 21:31:31 +00:00
|
|
|
void DisplayApp::Register(Pinetime::System::SystemTask* /*systemTask*/) {
|
2021-06-06 18:20:55 +00:00
|
|
|
}
|