diff --git a/watchos/Kernel.cpp b/watchos/Kernel.cpp index cc6035c..e61685e 100644 --- a/watchos/Kernel.cpp +++ b/watchos/Kernel.cpp @@ -16,6 +16,7 @@ char scope[SCOPE_SIZE]; struct EventSubscription { + int handle; void (*callback)(Event* e); // module, event, param1, param2 Task* target; byte source_mask = 0; @@ -164,20 +165,45 @@ void Kernel::suspend() /** * Register a new task in the kernel */ -void Kernel::registerTask(Task* task) +int Kernel::registerTask(Task* task) { for (int i = 0; i < KERNEL_MAX_TASKS; i++) { if (m_task[i] == nullptr) { m_task[i] = task; - task->setId(i); // TODO: real pid - return; + task->setId(m_pid++); // TODO: real pid + return i; } } Kernel::panic("Exceeded KERNEL_MAX_TASKS!"); } +void Kernel::unregisterTask(int pid) +{ + for (int i = 0; i < KERNEL_MAX_TASKS; i++) + { + if (m_task[i] != nullptr && m_task[i]->getId() == pid) + { + delete m_task[i]; + m_task[i] = nullptr; + return; + } + } +} + +bool Kernel::isTaskRunning(int pid) +{ + for (int i = 0; i < KERNEL_MAX_TASKS; i++) + { + if (m_task[i] != nullptr && m_task[i]->getId() == pid) + { + return true; + } + } + return false; +} + /** * Register a new module in the kernel */ @@ -234,35 +260,49 @@ void Kernel::event(byte source, byte event, byte param1, byte param2) } } -void Kernel::subscribe(void (*callback)(Event* e), byte source_mask, byte event_mask) +int Kernel::subscribe(void (*callback)(Event* e), byte source_mask, byte event_mask) { for (int i = 0; i < KERNEL_MAX_EVENT_SUBSCRIPTIONS; i++) { if (m_event_subscription[i] == nullptr) { m_event_subscription[i] = new EventSubscription(); + m_event_subscription[i]->handle = ++m_handle; m_event_subscription[i]->callback = callback; m_event_subscription[i]->source_mask = source_mask; m_event_subscription[i]->event_mask = event_mask; - return; + return m_event_subscription[i]->handle; } } Kernel::panic("Exceeded KERNEL_MAX_EVENT_SUBSCRIPTIONS!"); } -void Kernel::subscribe(Task* task, byte source_mask, byte event_mask) +int Kernel::subscribe(Task* task, byte source_mask, byte event_mask) { for (int i = 0; i < KERNEL_MAX_EVENT_SUBSCRIPTIONS; i++) { if (m_event_subscription[i] == nullptr) { m_event_subscription[i] = new EventSubscription(); + m_event_subscription[i]->handle = ++m_handle; m_event_subscription[i]->target = task; m_event_subscription[i]->source_mask = source_mask; m_event_subscription[i]->event_mask = event_mask; - return; + return m_event_subscription[i]->handle; } } Kernel::panic("Exceeded KERNEL_MAX_EVENT_SUBSCRIPTIONS!"); +} + +void Kernel::unsubscribe(int handle) +{ + for (int i = 0; i < KERNEL_MAX_EVENT_SUBSCRIPTIONS; i++) + { + if (m_event_subscription[i] != nullptr && m_event_subscription[i]->handle == handle) + { + delete m_event_subscription[i]; + return; + } + } } \ No newline at end of file diff --git a/watchos/Module_Input.cpp b/watchos/Module_Input.cpp index ebeed1c..d707b36 100644 --- a/watchos/Module_Input.cpp +++ b/watchos/Module_Input.cpp @@ -86,6 +86,8 @@ void Module_Input::poll() } else { + if (m_button[i]->pressed) + Kernel::debug("Button released!"); m_button[i]->pressed = false; } } diff --git a/watchos/Task_Menu.cpp b/watchos/Task_Menu.cpp index a426463..b4f3a61 100644 --- a/watchos/Task_Menu.cpp +++ b/watchos/Task_Menu.cpp @@ -9,6 +9,7 @@ private: Module_UI* ui; Module_Menu* menu; bool m_waiting_for_menu = false; + int m_task_pid = -1; public: Task_Menu() @@ -66,7 +67,7 @@ public: Kernel::debug("Task_Menu::show"); menu->reset(); menu->addItem(0, "watchos", true); - menu->addItem(1, "Option 1"); + menu->addItem(1, "Set Time"); menu->addItem(2, "Option Two"); menu->addItem(3, "Option Tres"); menu->addItem(0, "config", true); @@ -76,4 +77,8 @@ public: menu->show(); } + void execute(int option) + { + } + }; \ No newline at end of file diff --git a/watchos/__vm/Compile.vmps.xml b/watchos/__vm/Compile.vmps.xml index b323bcd..1e42962 100644 --- a/watchos/__vm/Compile.vmps.xml +++ b/watchos/__vm/Compile.vmps.xml @@ -2,7 +2,7 @@ - +