fix multithread logic in template app, update gpio HAL (#250)
* fix multithread logic * more buffer for dallas id string * update apps to use new logic * delay_us small speedup * add consant qualifier to gpio records and some core api * fix some apps to use simpler method of getting gpio record * fix ibutton app, stupid stack problem
This commit is contained in:
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
// state initializer
|
||||
AppExampleState() {
|
||||
example_data = 12;
|
||||
example_data = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -51,6 +51,16 @@ public:
|
||||
|
||||
// start app
|
||||
void AppExample::run() {
|
||||
// here we dont need to acquire or release state
|
||||
// because before we call app_ready our application is "single threaded"
|
||||
state.example_data = 12;
|
||||
|
||||
// signal that we ready to render and ipc
|
||||
app_ready();
|
||||
|
||||
// from here, any data that pass in render function must be guarded
|
||||
// by calling acquire_state and release_state
|
||||
|
||||
AppExampleEvent event;
|
||||
while(1) {
|
||||
if(get_event(&event, 1000)) {
|
||||
|
@@ -6,20 +6,21 @@
|
||||
// simple app class with template variables <state, events>
|
||||
template <class TState, class TEvent> class AppTemplate {
|
||||
public:
|
||||
AppTemplate();
|
||||
~AppTemplate();
|
||||
void input_callback(InputEvent* input_event, void* ctx);
|
||||
void draw_callback(CanvasApi* canvas, void* ctx);
|
||||
virtual void render(CanvasApi* canvas) = 0;
|
||||
Widget* widget;
|
||||
osMessageQueueId_t event_queue;
|
||||
TState state;
|
||||
ValueMutex state_mutex;
|
||||
GuiApi* gui;
|
||||
|
||||
AppTemplate();
|
||||
~AppTemplate();
|
||||
void input_callback(InputEvent* input_event, void* ctx);
|
||||
void draw_callback(CanvasApi* canvas, void* ctx);
|
||||
virtual void render(CanvasApi* canvas) = 0;
|
||||
void acquire_state(void);
|
||||
void release_state(void);
|
||||
bool get_event(TEvent* event, uint32_t timeout);
|
||||
void app_ready(void);
|
||||
void exit(void);
|
||||
void update_gui(void);
|
||||
};
|
||||
@@ -35,24 +36,15 @@ template <class TState, class TEvent> AppTemplate<TState, TEvent>::AppTemplate()
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
|
||||
// allocate widget
|
||||
widget = widget_alloc();
|
||||
|
||||
// connect widget with input callback
|
||||
auto input_cb_ref = cbc::obtain_connector(this, &AppTemplate::input_callback);
|
||||
widget_input_callback_set(widget, input_cb_ref, this);
|
||||
|
||||
// connect widget with draw callback
|
||||
auto draw_cb_ref = cbc::obtain_connector(this, &AppTemplate::draw_callback);
|
||||
widget_draw_callback_set(widget, draw_cb_ref, this);
|
||||
|
||||
// open gui and add widget
|
||||
// open gui
|
||||
gui = (GuiApi*)furi_open("gui");
|
||||
if(gui == NULL) {
|
||||
printf("gui is not available\n");
|
||||
furiac_exit(NULL);
|
||||
}
|
||||
gui->add_widget(gui, widget, GuiLayerFullscreen);
|
||||
|
||||
// allocate widget
|
||||
widget = widget_alloc();
|
||||
}
|
||||
|
||||
template <class TState, class TEvent> AppTemplate<TState, TEvent>::~AppTemplate() {
|
||||
@@ -96,6 +88,24 @@ bool AppTemplate<TState, TEvent>::get_event(TEvent* event, uint32_t timeout) {
|
||||
return (event_status == osOK);
|
||||
}
|
||||
|
||||
// signal that app is ready, and we can render something
|
||||
// also unblock dependent tasks
|
||||
template <class TState, class TEvent> void AppTemplate<TState, TEvent>::app_ready(void) {
|
||||
// connect widget with input callback
|
||||
auto input_cb_ref = cbc::obtain_connector(this, &AppTemplate::input_callback);
|
||||
widget_input_callback_set(widget, input_cb_ref, this);
|
||||
|
||||
// connect widget with draw callback
|
||||
auto draw_cb_ref = cbc::obtain_connector(this, &AppTemplate::draw_callback);
|
||||
widget_draw_callback_set(widget, draw_cb_ref, this);
|
||||
|
||||
// add widget
|
||||
gui->add_widget(gui, widget, GuiLayerFullscreen);
|
||||
|
||||
// signal that our app ready to work
|
||||
furiac_ready();
|
||||
}
|
||||
|
||||
template <class TState, class TEvent> void AppTemplate<TState, TEvent>::exit(void) {
|
||||
// TODO remove all widgets create by app
|
||||
widget_enabled_set(widget, false);
|
||||
|
Reference in New Issue
Block a user