platform for developing on SQFMI's Watchy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

114 lines
3.4 KiB

#ifndef _WATCHOS2_h
#define _WATCHOS2_h
#include <Arduino.h>
#include "watchos_config.h"
#include "watchos_consts.h"
#include "watchos_hw.h"
#include "watchos_types.h"
#include "Event.h"
#include "EventListener.h"
#include "Kernel.h"
#include "Task.h"
#include "IRunnable.h"
#include "IDrawable.h"
/// <summary>
/// General watchos interface for use in code
/// </summary>
class watchos
{
private:
/// <summary>
/// kernel() only ever instantiates one instance of the kernel, this is that instance.
/// </summary>
static Kernel* s_kernel;
public:
/// <summary>
/// Call from your .ino's setup() method after registering tasks and modules
/// </summary>
/// <remarks>
/// This will check the wake-up reason and determine whether we need to initialize tasks,
/// and finally call start() on all registered tasks.
/// </remarks>
static void setup();
/// <summary>
/// Call from your .ino's tick() method
/// </summary>
/// <remarks>
/// Give's the kernel a chance to run any tasks that need it
/// </remarks>
static void tick();
/// <summary>
/// Initialize the system
/// </summary>
/// <remarks>
/// Currently initializes the serial interface and Wire library
/// </remarks>
static void initialize();
/// <summary>
/// Fetch an instance of the kernel
/// </summary>
/// <returns>The same instance of the kernel with every call</returns>
static Kernel* kernel();
/// <summary>
/// Trigger a kernel panic
/// </summary>
/// <remarks>
/// Prints the passed formatted string then either:
/// if WATCHOS_DEBUG is set: goes into an infinite loop to wait for reset
/// if WATCHOS_DEBUG is not set: resets the system after a few seconds
/// </remarks>
static void panic(char* fmt...);
/// <summary>
/// Print debugging output
/// </summary>
/// <remarks>
/// Only when WATCHOS_DEBUG is set, will print the passed formatted string to
/// the serial console.
/// </remarks>
static void debug(char* fmt...);
/// <summary>
/// Fetch an instance of an event by handle
/// </summary>
static Event* event(kernel_handle_t event);
/// <summary>
/// Fetch an instance of a task by handle
/// </summary>
static Task* task(kernel_handle_t task);
/// <summary>
/// Fetch an instance of a task by a well-known handle
/// </summary>
static Task* module(well_known_handle_t handle);
/// <summary>
/// Increase the reference count for the passed handle
/// </summary>
static void reference(kernel_handle_t handle);
/// <summary>
/// Decrease the reference count for the passed handle
/// </summary>
static void release(kernel_handle_t handle);
/// <summary>
/// Register a new task with the kernel
/// </summary>
/// <param name="task">an instance of a task</param>
/// <returns>handle for the newly registered task</returns>
static kernel_handle_t run(Task* task);
/// <summary>
/// Subscribe a task to a set of events
/// </summary>
/// <param name="task">task to receive events; must implement EventListener</param>
/// <param name="source_mask">bitmask of which well known handles / modules we should receive events from</param>
/// <param name="event_mask">bitmask of which events we should receive</param>
/// <returns>handle for the event subscription; release to unsubscribe</returns>
static kernel_handle_t subscribe(Task* task, well_known_handle_t source_mask, uint16_t event_mask);
};
#endif