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).
This commit is contained in:
@@ -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::IdleState() {
|
||||
|
||||
}
|
||||
|
||||
void DisplayApp::Minutes(uint8_t m) {
|
||||
// TODO yeah, I know, race condition...
|
||||
minutes = m;
|
||||
DisplayApp::DisplayApp() {
|
||||
msgQueue = xQueueCreate(queueSize, itemSize);
|
||||
}
|
||||
|
||||
void DisplayApp::Hours(uint8_t h) {
|
||||
// TODO yeah, I know, race condition too...
|
||||
hours = h;
|
||||
}
|
||||
void DisplayApp::PushMessage(DisplayApp::Messages msg) {
|
||||
BaseType_t xHigherPriorityTaskWoken;
|
||||
xHigherPriorityTaskWoken = pdFALSE;
|
||||
xQueueSendFromISR( msgQueue, &msg, &xHigherPriorityTaskWoken );
|
||||
|
||||
void DisplayApp::SetTime(uint8_t minutes, uint8_t hours) {
|
||||
deltaSeconds = nrf_rtc_counter_get(portNRF_RTC_REG) / 1000;
|
||||
this->minutes = minutes;
|
||||
this->hours = hours;
|
||||
/* 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?
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user