2017-11-14 19:07:10 +00:00
|
|
|
/*! \file apps.h
|
|
|
|
\brief These are functions for working with applications and the task switcher.
|
2017-09-26 15:44:10 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2018-07-26 22:22:32 +00:00
|
|
|
//! We begin on the clock.
|
|
|
|
extern int appindex;
|
2018-07-29 19:40:05 +00:00
|
|
|
extern const struct app *applet;
|
2017-09-26 15:44:10 +00:00
|
|
|
|
2017-11-14 19:07:10 +00:00
|
|
|
//! Entry in the application table.
|
2017-09-26 15:44:10 +00:00
|
|
|
struct app {
|
2017-10-17 18:37:10 +00:00
|
|
|
char *name; //Shows when entering the app.
|
2017-09-26 15:44:10 +00:00
|
|
|
void (*init)(void); //Called exactly once at startup.
|
2018-07-29 16:59:24 +00:00
|
|
|
void (*draw)(int); //Called four times per second to draw display.
|
2017-11-14 19:07:10 +00:00
|
|
|
|
2017-09-27 20:10:24 +00:00
|
|
|
/* Called once when moving to the next applet. Returns zero (or is
|
|
|
|
NULL) if the application may move on, or returns non-zero if the
|
|
|
|
exit call is intercepted.
|
|
|
|
*/
|
2017-12-03 21:16:41 +00:00
|
|
|
int (*exit)(void);
|
|
|
|
|
2018-01-31 22:45:31 +00:00
|
|
|
/* I/O can work either by interrupts or by polling. The old
|
|
|
|
convention was to call getchar() to poll during the rendering
|
|
|
|
loop if you are checking to see if a button is held down, but to
|
|
|
|
take this interrupt callback when taking number entry, such as in
|
|
|
|
the calculator.
|
2018-01-27 22:08:55 +00:00
|
|
|
|
2018-02-08 22:21:58 +00:00
|
|
|
Called once per unique keypress. Return non-zero to immediately redraw.
|
2018-01-27 22:08:55 +00:00
|
|
|
*/
|
2018-02-08 22:21:58 +00:00
|
|
|
int (*keypress)(char ch);//A keypress has arrived.
|
2018-01-27 22:08:55 +00:00
|
|
|
|
2017-12-03 21:16:41 +00:00
|
|
|
/* Callbacks for packets being sent and received. Set to null if unused. */
|
2017-12-07 18:08:54 +00:00
|
|
|
void (*packetrx)(uint8_t *packet, int len); //A packet has arrived.
|
2017-12-03 21:16:41 +00:00
|
|
|
void (*packettx)(void); //A packet has been sent.
|
2017-09-26 15:44:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-11-14 19:07:10 +00:00
|
|
|
//! Draw the current application.
|
2018-07-29 16:59:24 +00:00
|
|
|
void app_draw(int forced);
|
2017-12-03 21:16:41 +00:00
|
|
|
//! Initializes the set of applications.
|
2017-09-26 16:59:02 +00:00
|
|
|
void app_init();
|
2017-11-14 19:07:10 +00:00
|
|
|
//! Move to the next application.
|
2017-09-26 16:59:02 +00:00
|
|
|
void app_next();
|
2017-11-14 19:07:10 +00:00
|
|
|
//! If this is *not* called, the watch forces home after three minutes.
|
2017-09-26 17:25:50 +00:00
|
|
|
void app_cleartimer();
|
2017-11-14 19:07:10 +00:00
|
|
|
//! Drop the power usage and return to the Clock.
|
2017-09-27 20:10:24 +00:00
|
|
|
void app_forcehome();
|
2017-12-07 18:08:54 +00:00
|
|
|
//! Provide an incoming packet.
|
|
|
|
void app_packetrx(uint8_t *packet, int len);
|
2018-04-05 19:32:05 +00:00
|
|
|
//! Callback after a packet has been sent.
|
|
|
|
void app_packettx();
|
2018-01-27 22:08:55 +00:00
|
|
|
|
|
|
|
//! Handles a keypress, if a handler is registered.
|
|
|
|
void app_keypress(char ch);
|
2018-01-28 22:22:54 +00:00
|
|
|
|
|
|
|
//! Sets an app by a pointer to its structure. Used for submenus.
|
|
|
|
void app_set(const struct app *newapplet);
|
2018-07-29 19:40:05 +00:00
|
|
|
//! Sets back to the indexed app. Does not work in the submenu.
|
|
|
|
void app_reset();
|