summaryrefslogtreecommitdiff
path: root/src/DisplayApp
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2019-12-26 18:33:40 +0100
committerJF <jf@codingfield.com>2019-12-26 18:33:40 +0100
commit75e74904e82a18012436a3d496223d2d53111866 (patch)
tree9ddfc4d2cc6764d79ac8a301ec5255551b5464e8 /src/DisplayApp
parent9a379e180fd855dac2a9fe6b4532d95276edab0b (diff)
Use push button to go to sleep/wake up.
Use a queue to transmit messages between system and display task (sleep & wake up for now).
Diffstat (limited to 'src/DisplayApp')
-rw-r--r--src/DisplayApp/DisplayApp.cpp79
-rw-r--r--src/DisplayApp/DisplayApp.h17
2 files changed, 80 insertions, 16 deletions
diff --git a/src/DisplayApp/DisplayApp.cpp b/src/DisplayApp/DisplayApp.cpp
index ea92a29d..964db633 100644
--- a/src/DisplayApp/DisplayApp.cpp
+++ b/src/DisplayApp/DisplayApp.cpp
@@ -6,6 +6,7 @@
#include <nrf_font.h>
#include <hal/nrf_rtc.h>
#include "Components/Gfx/Gfx.h"
+#include <queue.h>
using namespace Pinetime::Applications;
@@ -21,10 +22,7 @@ void DisplayApp::Process(void *instance) {
app->InitHw();
while (1) {
-
app->Refresh();
-
- vTaskDelay(1000);
}
}
@@ -67,6 +65,56 @@ void DisplayApp::InitHw() {
}
void DisplayApp::Refresh() {
+ TickType_t queueTimeout;
+ switch(state) {
+ case States::Idle:
+ IdleState();
+ queueTimeout = portMAX_DELAY;
+ break;
+ case States::Running:
+ RunningState();
+ queueTimeout = 1000;
+ break;
+ }
+
+ Messages msg;
+ if(xQueueReceive( msgQueue, &msg, queueTimeout)) {
+ switch(msg) {
+ case Messages::GoToSleep:
+ nrf_gpio_pin_set(23);
+ vTaskDelay(100);
+ nrf_gpio_pin_set(22);
+ vTaskDelay(100);
+ nrf_gpio_pin_set(14);
+ state = States::Idle;
+ break;
+ case Messages::GoToRunning:
+ nrf_gpio_pin_clear(23);
+ nrf_gpio_pin_clear(22);
+ nrf_gpio_pin_clear(14);
+ state = States::Running;
+ break;
+ }
+ }
+}
+
+void DisplayApp::Minutes(uint8_t m) {
+ // TODO yeah, I know, race condition...
+ minutes = m;
+}
+
+void DisplayApp::Hours(uint8_t h) {
+ // TODO yeah, I know, race condition too...
+ hours = h;
+}
+
+void DisplayApp::SetTime(uint8_t minutes, uint8_t hours) {
+ deltaSeconds = nrf_rtc_counter_get(portNRF_RTC_REG) / 1000;
+ this->minutes = minutes;
+ this->hours = hours;
+}
+
+void DisplayApp::RunningState() {
uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
auto raw = systick_counter / 1000;
@@ -118,21 +166,24 @@ void DisplayApp::Refresh() {
gfx->DrawChar(&largeFont, minutesChar[1], &x, 78, 0xffff);
currentChar[3] = minutesChar[1];
}
-
}
-void DisplayApp::Minutes(uint8_t m) {
- // TODO yeah, I know, race condition...
- minutes = m;
+void DisplayApp::IdleState() {
+
}
-void DisplayApp::Hours(uint8_t h) {
- // TODO yeah, I know, race condition too...
- hours = h;
+DisplayApp::DisplayApp() {
+ msgQueue = xQueueCreate(queueSize, itemSize);
}
-void DisplayApp::SetTime(uint8_t minutes, uint8_t hours) {
- deltaSeconds = nrf_rtc_counter_get(portNRF_RTC_REG) / 1000;
- this->minutes = minutes;
- this->hours = hours;
+void DisplayApp::PushMessage(DisplayApp::Messages msg) {
+ BaseType_t xHigherPriorityTaskWoken;
+ xHigherPriorityTaskWoken = pdFALSE;
+ xQueueSendFromISR( msgQueue, &msg, &xHigherPriorityTaskWoken );
+
+ /* Now the buffer is empty we can switch context if necessary. */
+ if(xHigherPriorityTaskWoken) {
+ /* Actual macro used here is port specific. */
+ // TODO : should I do something here?
+ }
}
diff --git a/src/DisplayApp/DisplayApp.h b/src/DisplayApp/DisplayApp.h
index e89ff64f..b15c3580 100644
--- a/src/DisplayApp/DisplayApp.h
+++ b/src/DisplayApp/DisplayApp.h
@@ -5,6 +5,7 @@
#include <drivers/SpiMaster.h>
#include <Components/Gfx/Gfx.h>
#include <bits/unique_ptr.h>
+#include <queue.h>
extern const FONT_INFO lCD_70ptFontInfo;
@@ -12,6 +13,9 @@ namespace Pinetime {
namespace Applications {
class DisplayApp {
public:
+ enum class States {Idle, Running};
+ enum class Messages : uint8_t {GoToSleep, GoToRunning} ;
+ DisplayApp();
void Start();
void Minutes(uint8_t m);
@@ -19,6 +23,8 @@ namespace Pinetime {
void SetTime(uint8_t minutes, uint8_t hours);
+ void PushMessage(Messages msg);
+
private:
TaskHandle_t taskHandle;
static void Process(void* instance);
@@ -29,13 +35,20 @@ namespace Pinetime {
const FONT_INFO largeFont {lCD_70ptFontInfo.height, lCD_70ptFontInfo.startChar, lCD_70ptFontInfo.endChar, lCD_70ptFontInfo.spacePixels, lCD_70ptFontInfo.charInfo, lCD_70ptFontInfo.data};
void Refresh();
-
-
uint8_t seconds = 0;
uint8_t minutes = 0;
uint8_t hours = 0;
char currentChar[4];
uint32_t deltaSeconds = 0;
+
+ States state = States::Running;
+ void RunningState();
+ void IdleState();
+ QueueHandle_t msgQueue;
+
+ static constexpr uint8_t queueSize = 10;
+ static constexpr uint8_t itemSize = 1;
+
};
}
}