Adam PIppin
3 years ago
19 changed files with 331 additions and 106 deletions
@ -0,0 +1,69 @@ |
|||
#include "watchos_consts.h" |
|||
#include "watchos_types.h" |
|||
#include "Events.h" |
|||
#include "Kernel.h" |
|||
|
|||
// temp
|
|||
#include <Arduino.h> |
|||
|
|||
EventQueue::EventQueue() |
|||
{ |
|||
for (int i = 0; i < EVENT_RING_SIZE; i++) |
|||
{ |
|||
m_events[i] = nullptr; |
|||
} |
|||
} |
|||
|
|||
int EventQueue::next(int n) |
|||
{ |
|||
if (n + 1 == EVENT_RING_SIZE) |
|||
return 0; |
|||
else |
|||
return n + 1; |
|||
} |
|||
|
|||
void EventQueue::push(Event* event) |
|||
{ |
|||
delay(500); |
|||
|
|||
if (m_full) |
|||
{ |
|||
// We're full
|
|||
Kernel::panic("Cannot enqueue event: ring buffer full"); |
|||
} |
|||
|
|||
// Write at m_next
|
|||
m_events[m_write] = event; |
|||
|
|||
// Move the next write position up
|
|||
m_write = next(m_write); |
|||
|
|||
// If the next position to write has looped back around to the next position
|
|||
// to read, then the ring is full.
|
|||
if (m_read == m_write) |
|||
{ |
|||
m_full = true; |
|||
} |
|||
} |
|||
|
|||
Event* EventQueue::pop() |
|||
{ |
|||
// If the next position to read and write match but the ring isn't full,
|
|||
// then the ring is empty
|
|||
if (m_read == m_write && !m_full) |
|||
{ |
|||
Kernel::panic("Cannot dequeue event: ring buffer empty"); |
|||
} |
|||
|
|||
Event* nextEvent = m_events[m_read]; |
|||
m_read = next(m_read); |
|||
// We can never be full if we just removed one
|
|||
m_full = false; |
|||
|
|||
return nextEvent; |
|||
} |
|||
|
|||
bool EventQueue::hasEvent() |
|||
{ |
|||
return m_read != m_write || m_full; |
|||
} |
@ -0,0 +1,30 @@ |
|||
#ifndef EVENT_H |
|||
#define EVENT_H |
|||
|
|||
#include "watchos_consts.h" |
|||
#include "watchos_types.h" |
|||
|
|||
struct Event |
|||
{ |
|||
byte source; |
|||
byte event; |
|||
byte param1; |
|||
byte param2; |
|||
}; |
|||
|
|||
class EventQueue |
|||
{ |
|||
Event* m_events[EVENT_RING_SIZE]; |
|||
int m_read = 0, m_write = 0; |
|||
bool m_full = false; |
|||
int next(int n); |
|||
|
|||
public: |
|||
EventQueue(); |
|||
void push(Event* event); |
|||
Event* pop(); |
|||
bool hasEvent(); |
|||
|
|||
}; |
|||
|
|||
#endif |
@ -0,0 +1,67 @@ |
|||
#include "watchos.h" |
|||
#include "Module_UI.h" |
|||
#include "watchos_fonts.h" |
|||
#include "Events.h" |
|||
|
|||
class Task_Clock : public Task |
|||
{ |
|||
private: |
|||
int hwnd; |
|||
Module_UI* ui; |
|||
byte hour, minute; |
|||
|
|||
public: |
|||
void initialize() |
|||
{ |
|||
ui = (Module_UI*)Kernel::get()->getModule(MODULE_UI); |
|||
hwnd = ui->createWindow((Task*)this, 0, 0); |
|||
} |
|||
void tick(unsigned int signal) |
|||
{ |
|||
bool dirty = false; |
|||
char msg[255]; |
|||
|
|||
while (this->hasEvent()) |
|||
{ |
|||
Event* e = this->popEvent(); |
|||
sprintf(msg, "event source %d id %d", e->source, e->event); |
|||
Kernel::debug(msg); |
|||
|
|||
if (e->source == MODULE_RTC && e->event == MODULE_RTC_EVENT_MINUTE) |
|||
{ |
|||
sprintf(msg, "old %d:%d new %d:%d", hour, minute, e->param1, e->param2); |
|||
Kernel::debug(msg); |
|||
if (e->param1 != hour || e->param2 != minute) |
|||
{ |
|||
Kernel::debug("Processed RTC event"); |
|||
hour = e->param1; |
|||
minute = e->param2; |
|||
dirty = true; |
|||
} |
|||
} |
|||
} |
|||
|
|||
if (dirty) |
|||
{ |
|||
Module_UI* ui = (Module_UI*)Kernel::get()->getModule(MODULE_UI); |
|||
ui->setDirty(hwnd); |
|||
} |
|||
} |
|||
|
|||
void suspend() |
|||
{ |
|||
} |
|||
|
|||
void draw(int hwnd, int x, int y, int width, int height) |
|||
{ |
|||
char time[6]; |
|||
sprintf(time, "%02d:%02d", hour, minute); |
|||
|
|||
Module_UI* ui = (Module_UI*)Kernel::get()->getModule(MODULE_UI); |
|||
ui->getGfx()->fillRect(x, y, width, height, GxEPD_WHITE); |
|||
ui->getGfx()->setFont(&DSEG7_Classic_Bold_53); |
|||
ui->getGfx()->setTextColor(GxEPD_BLACK); |
|||
ui->getGfx()->setCursor(0, y+height); |
|||
ui->getGfx()->print(time); |
|||
} |
|||
}; |
@ -1,54 +0,0 @@ |
|||
#include "watchos.h" |
|||
#include "Module_UI.h" |
|||
#include "Module_RTC.h" |
|||
#include "fonts.h" |
|||
|
|||
class TestTask : public Task |
|||
{ |
|||
private: |
|||
int hwnd; |
|||
Module_UI* ui; |
|||
int lastMinute = 0; |
|||
public: |
|||
void initialize() |
|||
{ |
|||
ui = (Module_UI*)Kernel::get()->getModule(MODULE_UI); |
|||
hwnd = ui->createWindow(&TestTask::draw, 0, 0); |
|||
} |
|||
void tick(unsigned int signal) |
|||
{ |
|||
// TODO: Replace once there's a signal for RTC events
|
|||
Module_RTC* rtc = (Module_RTC*)Kernel::get()->getModule(MODULE_RTC); |
|||
Module_UI* ui = (Module_UI*)Kernel::get()->getModule(MODULE_UI); |
|||
if (rtc->getMinute() != lastMinute) |
|||
{ |
|||
lastMinute = rtc->getMinute(); |
|||
ui->setDirty(hwnd); |
|||
} |
|||
} |
|||
|
|||
void suspend() |
|||
{ |
|||
} |
|||
|
|||
static void draw(int hwnd, int x, int y, int width, int height) |
|||
{ |
|||
Module_RTC* rtc = (Module_RTC*)Kernel::get()->getModule(MODULE_RTC); |
|||
char time[5]; |
|||
sprintf(time, "%02d:%02d", rtc->getHour(), rtc->getMinute()); |
|||
|
|||
Module_UI* ui = (Module_UI*)Kernel::get()->getModule(MODULE_UI); |
|||
ui->getGfx()->fillRect(x, y, width, height, GxEPD_WHITE); |
|||
ui->getGfx()->setFont(&DSEG7_Classic_Bold_53); |
|||
ui->getGfx()->setTextColor(GxEPD_BLACK); |
|||
ui->getGfx()->setCursor(0, y+height); |
|||
ui->getGfx()->print(time); |
|||
/*
|
|||
ui->getGfx()->drawRect(x, y, width, height, GxEPD_BLACK); |
|||
ui->getGfx()->setFont(&FreeMono12pt7b); |
|||
ui->getGfx()->setTextColor(GxEPD_BLACK); |
|||
ui->getGfx()->setCursor(x, y + height); |
|||
ui->getGfx()->print("Hello!"); |
|||
*/ |
|||
} |
|||
}; |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,13 +1,5 @@ |
|||
#include "consts.h" |
|||
// #include <Arduino.h>
|
|||
#include "Kernel.h" |
|||
|
|||
#define WATCHOS_DEBUG |
|||
|
|||
#define KERNEL_MAX_MODULES 8 |
|||
#define KERNEL_MAX_TASKS 16 |
|||
|
|||
#define MODULE_EAT 0x0001 |
|||
#define MODULE_EAT_MAGIC 0x4150 |
|||
#define MODULE_EAT_VERSION 1 |
|||
#define MODULE_EAT_MAX_ENTRIES 16 |
|||
#define MODULE_EAT_STATIC_OFFSET 4 + (MODULE_EAT_MAX_ENTRIES * 2) |
|||
#define EEPROM_SIZE 4096 |
|||
typedef unsigned char byte; |
|||
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,29 @@ |
|||
#ifndef CONSTS_H |
|||
#define CONSTS_H |
|||
|
|||
#define WATCHOS_DEBUG |
|||
|
|||
#define KERNEL_MAX_MODULES 8 |
|||
#define KERNEL_MAX_TASKS 16 |
|||
|
|||
#define EVENT_RING_SIZE 8 |
|||
|
|||
#define MODULE_EAT 0x0001 |
|||
#define MODULE_UI 0x0002 |
|||
#define MODULE_RTC 0x0004 |
|||
|
|||
#define MODULE_RTC_EVENT_MINUTE 0x0001 |
|||
|
|||
#define MODULE_EAT_MAGIC 0x4150 |
|||
#define MODULE_EAT_VERSION 1 |
|||
#define MODULE_EAT_MAX_ENTRIES 16 |
|||
#define MODULE_EAT_HEADER_LENGTH 4 |
|||
#define MODULE_EAT_TABLE_LENGTH (MODULE_EAT_MAX_ENTRIES * 2) |
|||
#define EEPROM_SIZE 4096 |
|||
|
|||
#define MODULE_UI_MAX_WINDOWS 32 |
|||
#define MODULE_UI_LAYOUT_MODE_NONE 0 |
|||
#define MODULE_UI_LAYOUT_MODE_SPLIT_VERTICAL 1 |
|||
#define MODULE_UI_LAYOUT_MODE_SPLIT_HORIZONTAL 2 |
|||
|
|||
#endif |
@ -0,0 +1,4 @@ |
|||
#ifndef TYPES_H |
|||
#define TYPES_H |
|||
typedef unsigned char byte; |
|||
#endif |
Loading…
Reference in new issue