#include "watchos.h" #include "Module_UI.h" #include "Module_Storage.h" class Task_Test : public IRunnable, public IDrawable, public Task, public EventListener { Module_UI* ui = nullptr; Module_Storage* storage = nullptr; kernel_handle_t window_handle; int m_counter = 0; public: void start() { watchos::subscribe(this, 0xffffffffffffffffu, 0xffffu); storage = static_cast(watchos::module(WATCHOS_MODULE_STORAGE)); if (storage->allocate((byte)64, 2)) { watchos::debug("Initialized counter"); storage->write((byte)64, 0, 0); storage->write((byte)64, 1, 0); } else { read(); } ui = static_cast(watchos::module(WATCHOS_MODULE_UI)); window_handle = ui->createWindow(this, ui->getRoot()); ui->setAbsolutePosition(window_handle, 0, 96, 200, 104); } void tick() { Event* e; while (this->hasEvent()) { e = this->getEvent(); if (e->source == WATCHOS_MODULE_INPUT && e->event == WATCHOS_EVENT_TYPE_INPUT_PRESSED) { watchos::debug("Got event: src %#020llx evt %#06x param1 %#04x param2 %#04x", e->source, e->event, e->param1, e->param2); m_counter++; write(); ui->setDirty(window_handle); } this->popEvent(); } } void draw(kernel_handle_t handle) { ui->fill(COLOUR_SECONDARY); char msg[8]; sprintf(msg, "%d", m_counter); ui->print(0, ui->getHeight(), msg); } void read() { m_counter = (storage->read((byte)64, 0) << 8) | storage->read((byte)64, 1); } void write() { storage->write((byte)64, 0, (byte)(m_counter >> 8)); storage->write((byte)64, 1, (byte)(m_counter)); } };