Adam PIppin
3 years ago
19 changed files with 266 additions and 71 deletions
@ -1,26 +1,34 @@ |
|||
#include "watchos.h" |
|||
#include "EventListener.h" |
|||
|
|||
EventListener::EventListener() |
|||
{ |
|||
m_event_queue = new Queue(); |
|||
} |
|||
|
|||
bool EventListener::hasEvent() |
|||
{ |
|||
return !m_event_queue->isEmpty(); |
|||
} |
|||
|
|||
Event* EventListener::popEvent() |
|||
Event* EventListener::getEvent() |
|||
{ |
|||
kernel_handle_t handle = m_event_queue->peek(); |
|||
// Fetch and immediately release, the event queue still holds the reference.
|
|||
Event* e = watchos::event(handle); |
|||
return e; |
|||
} |
|||
|
|||
void EventListener::pushEvent(kernel_handle_t handle) |
|||
void EventListener::popEvent() |
|||
{ |
|||
// Once we're done with the event, remove from the event queue and release
|
|||
// the reference it holds.
|
|||
kernel_handle_t handle = m_event_queue->pop(); |
|||
watchos::release(handle); |
|||
} |
|||
|
|||
class IEventListener |
|||
void EventListener::pushEvent(kernel_handle_t handle) |
|||
{ |
|||
private: |
|||
Queue<Event*> m_events; |
|||
protected: |
|||
bool hasEvent(); |
|||
Event* popEvent(); |
|||
public: |
|||
void pushEvent(kernel_handle_t handle); |
|||
uint32_t getEventSourceMask(); |
|||
uint16_t getEventTypeMask(); |
|||
}; |
|||
watchos::reference(handle); |
|||
m_event_queue->push(handle); |
|||
} |
@ -1,22 +1,21 @@ |
|||
#ifndef _EVENTLISTENER_h |
|||
#define _EVENTLISTENER_h |
|||
|
|||
#include "watchos.h" |
|||
#include "watchos_consts.h" |
|||
#include "Queue.h" |
|||
#include "Events.h" |
|||
#include "Event.h" |
|||
|
|||
class EventListener |
|||
{ |
|||
private: |
|||
Queue<kernel_handle_t> m_event_queue; |
|||
Queue* m_event_queue; |
|||
protected: |
|||
bool hasEvent(); |
|||
Event* popEvent(); |
|||
void releaseEvent(kernel_handle_t handle); |
|||
Event* getEvent(); |
|||
void popEvent(); |
|||
public: |
|||
EventListener(); |
|||
void pushEvent(kernel_handle_t handle); |
|||
uint32_t getEventSourceMask(); |
|||
uint16_t getEventTypeMask(); |
|||
}; |
|||
|
|||
#endif |
@ -0,0 +1,21 @@ |
|||
#ifndef _MODULE_UI_h |
|||
#define _MODULE_UI_h |
|||
|
|||
#include <Arduino.h> |
|||
#include "watchos_consts.h" |
|||
#include "watchos_hw.h" |
|||
#include "watchos_types.h" |
|||
|
|||
#include "Task.h" |
|||
#include "IRunnable.h" |
|||
|
|||
#define MODULE_UI_MAX_WINDOWS 32 |
|||
|
|||
struct UiWindow; |
|||
|
|||
class Module_UI : public Task, public IRunnable |
|||
{ |
|||
UiWindow* m_window[MODULE_UI_MAX_WINDOWS]; |
|||
}; |
|||
|
|||
#endif |
@ -1,21 +1,22 @@ |
|||
#ifndef _QUEUE_h |
|||
#define _QUEUE_h |
|||
|
|||
#include "watchos_types.h" |
|||
|
|||
#define QUEUE_RING_SIZE 8 |
|||
|
|||
template<typename T> |
|||
class Queue |
|||
{ |
|||
private: |
|||
T* m_item[QUEUE_RING_SIZE]; |
|||
kernel_handle_t m_item[QUEUE_RING_SIZE]; |
|||
int m_read = 0, m_write = 0; |
|||
bool m_full = false; |
|||
int next(int n); |
|||
public: |
|||
Queue(); |
|||
void push(T* item); |
|||
T* pop(); |
|||
T* peek(); |
|||
void push(kernel_handle_t item); |
|||
kernel_handle_t pop(); |
|||
kernel_handle_t peek(); |
|||
bool isEmpty(); |
|||
}; |
|||
|
|||
|
@ -1,4 +0,0 @@ |
|||
#include "Queue.h" |
|||
#include "Queue.cpp" |
|||
|
|||
template class Queue<int>; |
@ -1,12 +1,22 @@ |
|||
#include "watchos.h" |
|||
#include "Task.h" |
|||
#include "IRunnable.h" |
|||
|
|||
class Task_Test : public IRunnable, public Task |
|||
class Task_Test : public IRunnable, public Task, public EventListener |
|||
{ |
|||
public: |
|||
Task_Test() |
|||
{ |
|||
watchos::subscribe(this, 0xffffffffffffffffu, 0xffffu); |
|||
} |
|||
void tick() |
|||
{ |
|||
watchos::debug("Tick!"); |
|||
Event* e; |
|||
while (this->hasEvent()) |
|||
{ |
|||
e = this->getEvent(); |
|||
|
|||
watchos::debug("Got event: src %#020llx evt %#06x param1 %#04x param2 %#04x", e->source, e->event, e->param1, e->param2); |
|||
|
|||
this->popEvent(); |
|||
} |
|||
} |
|||
}; |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue