1
+ #include " DisplayAppRecovery.h"
2
+ #include " DisplayAppRecovery.h"
3
+ #include < FreeRTOS.h>
4
+ #include < task.h>
5
+ #include < libraries/log/nrf_log.h>
6
+ #include < components/rle/RleDecoder.h>
7
+ #include " displayapp/icons/infinitime/infinitime-nb.c"
8
+
9
+ using namespace Pinetime ::Applications;
10
+
11
+ DisplayApp::DisplayApp (Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Drivers::Cst816S &touchPanel,
12
+ Controllers::Battery &batteryController, Controllers::Ble &bleController,
13
+ Controllers::DateTime &dateTimeController, Drivers::WatchdogView &watchdog,
14
+ System::SystemTask &systemTask,
15
+ Pinetime::Controllers::NotificationManager& notificationManager,
16
+ Pinetime::Controllers::HeartRateController& heartRateController):
17
+ lcd{lcd}, bleController{bleController} {
18
+ msgQueue = xQueueCreate (queueSize, itemSize);
19
+
20
+ }
21
+
22
+ void DisplayApp::Start () {
23
+ if (pdPASS != xTaskCreate (DisplayApp::Process, " displayapp" , 512 , this , 0 , &taskHandle))
24
+ APP_ERROR_HANDLER (NRF_ERROR_NO_MEM);
25
+ }
26
+
27
+ void DisplayApp::Process (void *instance) {
28
+ auto *app = static_cast <DisplayApp *>(instance);
29
+ NRF_LOG_INFO (" displayapp task started!" );
30
+
31
+ // Send a dummy notification to unlock the lvgl display driver for the first iteration
32
+ xTaskNotifyGive (xTaskGetCurrentTaskHandle ());
33
+
34
+ app->InitHw ();
35
+ while (1 ) {
36
+ app->Refresh ();
37
+ }
38
+ }
39
+
40
+ void DisplayApp::InitHw () {
41
+ DisplayLogo (colorWhite);
42
+ }
43
+
44
+ void DisplayApp::Refresh () {
45
+ Display::Messages msg;
46
+ if (xQueueReceive (msgQueue, &msg, 200 )) {
47
+ switch (msg) {
48
+ case Display::Messages::UpdateBleConnection:
49
+ if (bleController.IsConnected ())
50
+ DisplayLogo (colorBlue);
51
+ else
52
+ DisplayLogo (colorWhite);
53
+ break ;
54
+ case Display::Messages::BleFirmwareUpdateStarted:
55
+ DisplayLogo (colorGreen);
56
+ break ;
57
+ default :
58
+ break ;
59
+ }
60
+ }
61
+
62
+ if (bleController.IsFirmwareUpdating ()) {
63
+ uint8_t percent = (static_cast <float >(bleController.FirmwareUpdateCurrentBytes ()) /
64
+ static_cast <float >(bleController.FirmwareUpdateTotalBytes ())) * 100 .0f ;
65
+ switch (bleController.State ()) {
66
+ case Controllers::Ble::FirmwareUpdateStates::Running:
67
+ DisplayOtaProgress (percent, colorWhite);
68
+ break ;
69
+ case Controllers::Ble::FirmwareUpdateStates::Validated:
70
+ DisplayOtaProgress (100 , colorGreenSwapped);
71
+ break ;
72
+ case Controllers::Ble::FirmwareUpdateStates::Error:
73
+ DisplayOtaProgress (100 , colorRedSwapped);
74
+ break ;
75
+ default :
76
+ break ;
77
+ }
78
+ }
79
+ }
80
+
81
+ void DisplayApp::DisplayLogo (uint16_t color) {
82
+ Pinetime::Tools::RleDecoder rleDecoder (infinitime_nb, sizeof (infinitime_nb), color, colorBlack);
83
+ for (int i = 0 ; i < displayWidth; i++) {
84
+ rleDecoder.DecodeNext (displayBuffer, displayWidth * bytesPerPixel);
85
+ ulTaskNotifyTake (pdTRUE, 500 );
86
+ lcd.BeginDrawBuffer (0 , i, displayWidth, 1 );
87
+ lcd.NextDrawBuffer (reinterpret_cast <const uint8_t *>(displayBuffer), displayWidth * bytesPerPixel);
88
+ }
89
+ }
90
+
91
+ void DisplayApp::DisplayOtaProgress (uint8_t percent, uint16_t color) {
92
+ const uint8_t barHeight = 20 ;
93
+ std::fill (displayBuffer, displayBuffer+(displayWidth * bytesPerPixel), color);
94
+ for (int i = 0 ; i < barHeight; i++) {
95
+ ulTaskNotifyTake (pdTRUE, 500 );
96
+ uint16_t barWidth = std::min (static_cast <float >(percent) * 2 .4f , static_cast <float >(displayWidth));
97
+ lcd.BeginDrawBuffer (0 , displayWidth - barHeight + i, barWidth, 1 );
98
+ lcd.NextDrawBuffer (reinterpret_cast <const uint8_t *>(displayBuffer), barWidth * bytesPerPixel);
99
+ }
100
+ }
101
+
102
+ void DisplayApp::PushMessage (Display::Messages msg) {
103
+ BaseType_t xHigherPriorityTaskWoken;
104
+ xHigherPriorityTaskWoken = pdFALSE;
105
+ xQueueSendFromISR (msgQueue, &msg, &xHigherPriorityTaskWoken);
106
+ if (xHigherPriorityTaskWoken) {
107
+ /* Actual macro used here is port specific. */
108
+ // TODO : should I do something here?
109
+ }
110
+ }
0 commit comments