Add screen.[ch] and unit tests

This commit is contained in:
Pim van Pelt
2017-11-26 14:18:43 +01:00
parent 79bb900def
commit 3e2e9d4e5b
11 changed files with 344 additions and 46 deletions

28
include/screen.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef __SCREEN_H
#define __SCREEN_H
#include "mgos.h"
#include "frozen/frozen.h"
#include "common/queue.h"
#include "widget.h"
struct screen_t {
char *name;
uint16_t x, y, w, h;
// Private
SLIST_HEAD(widget_entries, widget_list_t) widget_entries;
};
struct screen_t *screen_create(char *name, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
struct screen_t *screen_create_from_file(char *fn);
void screen_destroy(struct screen_t **s);
bool screen_widget_add(struct screen_t *s, struct widget_t *w);
struct widget_t *screen_widget_add_from_file(struct screen_t *s, char *fn);
bool screen_widget_destroy(struct screen_t *s, struct widget_t **w);
uint16_t screen_get_num_widgets(struct screen_t *s);
#endif //__SCREEN_H

View File

@ -1,6 +1,8 @@
#ifndef __WIDGET_H
#define __WIDGET_H
#include "common/queue.h"
struct widget_t;
#define EV_WIDGET_NONE 0
@ -25,9 +27,20 @@ struct widget_t {
mgos_timer_id _timer_id;
};
struct widget_list_t {
struct widget_t *widget;
SLIST_ENTRY(widget_list_t) entries;
};
struct widget_t *widget_add(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t timer_msec, widget_event_fn handler, void *user_data);
struct widget_t *widget_add_from_file(const char *fn, uint32_t timer_msec, widget_event_fn handler, void *user_data);
struct widget_t *widget_find(uint16_t x, uint16_t y);
void widget_remove(struct widget_t *widget);
struct widget_t *widget_create(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t timer_msec, widget_event_fn handler, void *user_data);
struct widget_t *widget_create_from_file(const char *fn);
struct widget_t *widget_create_from_json(const char *json);
void widget_destroy(struct widget_t **widget);
#endif // __WIDGET_H