2021-01-08 04:42:48 +00:00
|
|
|
#include "view_dispatcher_i.h"
|
|
|
|
|
2021-11-12 13:04:35 +00:00
|
|
|
#define TAG "ViewDispatcher"
|
|
|
|
|
2021-01-08 04:42:48 +00:00
|
|
|
ViewDispatcher* view_dispatcher_alloc() {
|
|
|
|
ViewDispatcher* view_dispatcher = furi_alloc(sizeof(ViewDispatcher));
|
|
|
|
|
2021-01-29 13:52:16 +00:00
|
|
|
view_dispatcher->view_port = view_port_alloc();
|
|
|
|
view_port_draw_callback_set(
|
|
|
|
view_dispatcher->view_port, view_dispatcher_draw_callback, view_dispatcher);
|
|
|
|
view_port_input_callback_set(
|
|
|
|
view_dispatcher->view_port, view_dispatcher_input_callback, view_dispatcher);
|
|
|
|
view_port_enabled_set(view_dispatcher->view_port, false);
|
2021-01-08 04:42:48 +00:00
|
|
|
|
|
|
|
ViewDict_init(view_dispatcher->views);
|
|
|
|
|
|
|
|
return view_dispatcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
void view_dispatcher_free(ViewDispatcher* view_dispatcher) {
|
|
|
|
// Detach from gui
|
|
|
|
if(view_dispatcher->gui) {
|
2021-01-29 13:52:16 +00:00
|
|
|
gui_remove_view_port(view_dispatcher->gui, view_dispatcher->view_port);
|
2021-01-08 04:42:48 +00:00
|
|
|
}
|
2021-07-12 18:56:14 +00:00
|
|
|
// Crash if not all views were freed
|
|
|
|
furi_assert(ViewDict_size(view_dispatcher->views) == 0);
|
|
|
|
|
2021-01-08 04:42:48 +00:00
|
|
|
ViewDict_clear(view_dispatcher->views);
|
2021-03-24 09:01:00 +00:00
|
|
|
// Free ViewPort
|
|
|
|
view_port_free(view_dispatcher->view_port);
|
2021-06-24 08:46:37 +00:00
|
|
|
// Free internal queue
|
|
|
|
if(view_dispatcher->queue) {
|
|
|
|
osMessageQueueDelete(view_dispatcher->queue);
|
|
|
|
}
|
2021-01-08 04:42:48 +00:00
|
|
|
// Free dispatcher
|
|
|
|
free(view_dispatcher);
|
|
|
|
}
|
|
|
|
|
2021-05-25 10:19:07 +00:00
|
|
|
void view_dispatcher_enable_queue(ViewDispatcher* view_dispatcher) {
|
|
|
|
furi_assert(view_dispatcher);
|
|
|
|
furi_assert(view_dispatcher->queue == NULL);
|
2021-09-01 21:05:00 +00:00
|
|
|
view_dispatcher->queue = osMessageQueueNew(16, sizeof(ViewDispatcherMessage), NULL);
|
2021-05-25 10:19:07 +00:00
|
|
|
}
|
|
|
|
|
2021-07-12 18:56:14 +00:00
|
|
|
void view_dispatcher_set_event_callback_context(ViewDispatcher* view_dispatcher, void* context) {
|
|
|
|
furi_assert(view_dispatcher);
|
|
|
|
view_dispatcher->event_context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
void view_dispatcher_set_navigation_event_callback(
|
|
|
|
ViewDispatcher* view_dispatcher,
|
|
|
|
ViewDispatcherNavigationEventCallback callback) {
|
|
|
|
furi_assert(view_dispatcher);
|
|
|
|
furi_assert(callback);
|
|
|
|
view_dispatcher->navigation_event_callback = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
void view_dispatcher_set_custom_event_callback(
|
|
|
|
ViewDispatcher* view_dispatcher,
|
|
|
|
ViewDispatcherCustomEventCallback callback) {
|
2021-06-30 17:43:29 +00:00
|
|
|
furi_assert(view_dispatcher);
|
2021-07-12 18:56:14 +00:00
|
|
|
furi_assert(callback);
|
|
|
|
view_dispatcher->custom_event_callback = callback;
|
2021-06-30 17:43:29 +00:00
|
|
|
}
|
|
|
|
|
2021-07-12 18:56:14 +00:00
|
|
|
void view_dispatcher_set_tick_event_callback(
|
|
|
|
ViewDispatcher* view_dispatcher,
|
|
|
|
ViewDispatcherTickEventCallback callback,
|
|
|
|
uint32_t tick_period) {
|
2021-06-30 17:43:29 +00:00
|
|
|
furi_assert(view_dispatcher);
|
2021-07-12 18:56:14 +00:00
|
|
|
furi_assert(callback);
|
|
|
|
view_dispatcher->tick_event_callback = callback;
|
|
|
|
view_dispatcher->tick_period = tick_period;
|
2021-06-30 17:43:29 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 10:19:07 +00:00
|
|
|
void view_dispatcher_run(ViewDispatcher* view_dispatcher) {
|
|
|
|
furi_assert(view_dispatcher);
|
|
|
|
furi_assert(view_dispatcher->queue);
|
|
|
|
|
2021-07-12 18:56:14 +00:00
|
|
|
uint32_t tick_period = view_dispatcher->tick_period == 0 ? osWaitForever :
|
|
|
|
view_dispatcher->tick_period;
|
2021-05-25 10:19:07 +00:00
|
|
|
ViewDispatcherMessage message;
|
2021-07-12 18:56:14 +00:00
|
|
|
while(1) {
|
|
|
|
if(osMessageQueueGet(view_dispatcher->queue, &message, NULL, tick_period) != osOK) {
|
|
|
|
view_dispatcher_handle_tick_event(view_dispatcher);
|
|
|
|
continue;
|
|
|
|
}
|
2021-05-25 10:19:07 +00:00
|
|
|
if(message.type == ViewDispatcherMessageTypeStop) {
|
|
|
|
break;
|
|
|
|
} else if(message.type == ViewDispatcherMessageTypeInput) {
|
|
|
|
view_dispatcher_handle_input(view_dispatcher, &message.input);
|
2021-06-20 08:15:48 +00:00
|
|
|
} else if(message.type == ViewDispatcherMessageTypeCustomEvent) {
|
|
|
|
view_dispatcher_handle_custom_event(view_dispatcher, message.custom_event);
|
2021-05-25 10:19:07 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-30 20:05:09 +00:00
|
|
|
|
|
|
|
// Wait till all input events delivered
|
2021-08-31 08:22:52 +00:00
|
|
|
while(view_dispatcher->ongoing_input) {
|
2021-08-30 20:05:09 +00:00
|
|
|
osMessageQueueGet(view_dispatcher->queue, &message, NULL, osWaitForever);
|
|
|
|
if(message.type == ViewDispatcherMessageTypeInput) {
|
2021-08-31 08:22:52 +00:00
|
|
|
uint8_t key_bit = (1 << message.input.key);
|
2021-08-30 20:05:09 +00:00
|
|
|
if(message.input.type == InputTypePress) {
|
2021-08-31 08:22:52 +00:00
|
|
|
view_dispatcher->ongoing_input |= key_bit;
|
2021-08-30 20:05:09 +00:00
|
|
|
} else if(message.input.type == InputTypeRelease) {
|
2021-08-31 08:22:52 +00:00
|
|
|
view_dispatcher->ongoing_input &= ~key_bit;
|
2021-08-30 20:05:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-25 10:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void view_dispatcher_stop(ViewDispatcher* view_dispatcher) {
|
|
|
|
furi_assert(view_dispatcher);
|
|
|
|
furi_assert(view_dispatcher->queue);
|
|
|
|
ViewDispatcherMessage message;
|
|
|
|
message.type = ViewDispatcherMessageTypeStop;
|
|
|
|
furi_check(osMessageQueuePut(view_dispatcher->queue, &message, 0, osWaitForever) == osOK);
|
|
|
|
}
|
|
|
|
|
2021-01-08 04:42:48 +00:00
|
|
|
void view_dispatcher_add_view(ViewDispatcher* view_dispatcher, uint32_t view_id, View* view) {
|
|
|
|
furi_assert(view_dispatcher);
|
|
|
|
furi_assert(view);
|
new iButton app (#328)
* rename old ibutton app to ibutton-test
* more renames
* updated onewire library compilation condition
* add submenu_clean subroutine
* add index for submenu callback
* c++ guard for gui modules
* add released ibutton app
* fix the position of the submenu window if there are too few items
* iButton app basis
* negative icon position info
* fix submenu_clean subroutine
* add ibutton app to applications makefile
* add onewire key read routine to read mode
* rename mode to scene
* rename files and folder (mode to scene)
* rename ibutton view to view manager
* rename get_view to get_view_manager
* cpp guards
* key read, store and notify features
* syntax fix
* make iButtonScene functions pure virtual
* fix syntax
* add text store, add new scene (crc error)
* not a key scene
* syntax fix
* read success scene
* app, switching to the previous scene with the number of scenes to be skipped
* scene whith menu when key is readed
* fix font height calculation, fix offsets
* add key write scene
* view_dispatcher_remove_view subroutine
* generic pause/resume os methods
* fix furi_assert usage
* key store, worker
* fix pointer comparsion
* saved keys, saved key action scenes
* key delete/confirm delete scenes and routines
* use last input subsystem changes
* fix syntax
* fix new model usage in submenu
* fix includes
* use vibro pin
* use stored key name if valid
* emulate scene
* random name generator
* name and save readed key scenes, new icon
* fix icon position
* fix text scene exit
* fix naming, fix text placement, new info scene
* state-driven cyfral decoder
* better cyfral decoder
* better cyfral decoder
* one wire: search command set
* metakom decoder
* more key types
* add next scene to error scenes
* universal key reader
* use new key reader
* syntax fix
* warning fix
* byte input module template
* new thread and insomnia api usage
* New element: slightly rounded frame
* Use elements_slightly_rounded_frame in text input
* Gui test app: byte input usage
* Byte input module: data drawing and selection
* Byte input: comment currently unused fns
* remove volatile qualifier
* base byte input realisation
* App gui test: remove internal fns visibility
* Byne input, final version
* test install gcc-arm-none-eabi-10-2020-q4-major
* test install gcc-arm-none-eabi-10-2020-q4-major
* App iButton: byte input view managment
* App iButton: add key manually scenes
* App iButton: rename scenes, add popup timeout
* App iButton: use new scenes, new fn for rollback to specific prevous scene.
* App iButton: remove byte input view on app exit
* App iButton: edit key scene
* Module byte input: reduce swintch value to uint8_t
* Module byte input: switch from switch-case to if, unfortunately we need compile-time constants to use with switch
* Icons: new small arrows
* Module byte input: new arrangement of elements
* OneWire slave lib: fix deattach sequence
* App iButton: pulse sequencer
* App iButton: add more keys to store
* App iButton: split key worker to separate read/write/emulate entitys
* App iButton: use new read/emulate entities
* fix callback pointer saving
* App iButton: use KeyReader error enum instead of KeyWorker error list handling
* App iButton: do not use insomnia fns in pulse sequencer
* App iButton: use KeyReader error enum in read scene
* OneWire slave lib: more READ ROM command variants, call callback only if positive result
* GPIO resources: add external gpio
* App SD/NFC: removed application
* App iButton-test: update to new light api
* App iButton: update to new light-api
* Outdated apps: add api-light-usage
* Gpio: update SD card CS pin settings
* API-power: added fns to disable/enable external 3v3 dc-dc
* API-gpio: separated SD card detect routines
* Resources: removed sd cs pin
* SD card: low level init now resets card power supply
* App SD-filesystem: use new card detect fns
* SD card: fix low level init headers
* SD card: more realilable low level init, power reset, exit from command read cycle conditionally
* App SD-filesystem: led notifiers, init cycling
* SD card: backport to F4
* Api PWM: add c++ guards
* App iButton: yellow blink in emulate scene, vibro on
* App iButton: one wire keys command set
* App iButton: successful write scene
* App iButton: key writer
* App iButton: syntax fix
* App iButton: notify write success
* App iButton: fix double scene change
* SD card: handle eject in init sequence
* SD card: api to set level on detect gpio
* SPI: api to set state on bus pins
* SD card: set low state on bus pins while power reset
* File select: init
* File select: fix input consuming
* SD Card: fixed dir open api error
* SD-card: replace strncpy by strlcpy. Fix buffer overflow error.
* API HAL OS: replace CMP based ticks with ARR based one, hard reset lptimer on reconfiguration.
* GUI: More stack size for (temporary, wee need to implement sd card api in separate thread)
* GUI: File select module.
* App iButton-test: remove obsolete app
Co-authored-by: rusdacent <rusdacentx0x08@gmail.com>
Co-authored-by: coreglitch <mail@s3f.ru>
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-03-12 12:45:18 +00:00
|
|
|
// Check if view id is not used and register view
|
2021-01-08 04:42:48 +00:00
|
|
|
furi_check(ViewDict_get(view_dispatcher->views, view_id) == NULL);
|
2021-03-05 13:13:00 +00:00
|
|
|
|
|
|
|
// Lock gui
|
|
|
|
if(view_dispatcher->gui) {
|
|
|
|
gui_lock(view_dispatcher->gui);
|
|
|
|
}
|
|
|
|
|
2021-01-08 04:42:48 +00:00
|
|
|
ViewDict_set_at(view_dispatcher->views, view_id, view);
|
2021-04-01 12:03:02 +00:00
|
|
|
view_set_update_callback(view, view_dispatcher_update);
|
|
|
|
view_set_update_callback_context(view, view_dispatcher);
|
2021-03-05 13:13:00 +00:00
|
|
|
|
|
|
|
// Unlock gui
|
|
|
|
if(view_dispatcher->gui) {
|
|
|
|
gui_unlock(view_dispatcher->gui);
|
|
|
|
}
|
2021-01-08 04:42:48 +00:00
|
|
|
}
|
|
|
|
|
2021-03-05 09:47:27 +00:00
|
|
|
void view_dispatcher_remove_view(ViewDispatcher* view_dispatcher, uint32_t view_id) {
|
|
|
|
furi_assert(view_dispatcher);
|
|
|
|
|
2021-03-05 13:13:00 +00:00
|
|
|
// Lock gui
|
|
|
|
if(view_dispatcher->gui) {
|
|
|
|
gui_lock(view_dispatcher->gui);
|
|
|
|
}
|
2021-04-01 12:03:02 +00:00
|
|
|
// Get View by ID
|
|
|
|
View* view = *ViewDict_get(view_dispatcher->views, view_id);
|
2021-03-05 13:13:00 +00:00
|
|
|
|
2021-03-05 09:47:27 +00:00
|
|
|
// Disable the view if it is active
|
2021-04-01 12:03:02 +00:00
|
|
|
if(view_dispatcher->current_view == view) {
|
2021-03-05 09:47:27 +00:00
|
|
|
view_dispatcher_set_current_view(view_dispatcher, NULL);
|
|
|
|
}
|
2021-09-01 21:05:00 +00:00
|
|
|
// Check if view is recieving input
|
|
|
|
if(view_dispatcher->ongoing_input_view == view) {
|
|
|
|
view_dispatcher->ongoing_input_view = NULL;
|
|
|
|
}
|
2021-03-05 09:47:27 +00:00
|
|
|
// Remove view
|
|
|
|
ViewDict_erase(view_dispatcher->views, view_id);
|
2021-03-05 13:13:00 +00:00
|
|
|
|
2021-04-01 12:03:02 +00:00
|
|
|
view_set_update_callback(view, NULL);
|
|
|
|
view_set_update_callback_context(view, NULL);
|
|
|
|
|
2021-03-05 13:13:00 +00:00
|
|
|
// Unlock gui
|
|
|
|
if(view_dispatcher->gui) {
|
|
|
|
gui_unlock(view_dispatcher->gui);
|
|
|
|
}
|
2021-03-05 09:47:27 +00:00
|
|
|
}
|
|
|
|
|
2021-01-08 04:42:48 +00:00
|
|
|
void view_dispatcher_switch_to_view(ViewDispatcher* view_dispatcher, uint32_t view_id) {
|
|
|
|
furi_assert(view_dispatcher);
|
|
|
|
if(view_id == VIEW_NONE) {
|
2021-02-04 12:05:46 +00:00
|
|
|
view_dispatcher_set_current_view(view_dispatcher, NULL);
|
2021-01-08 04:42:48 +00:00
|
|
|
} else if(view_id == VIEW_IGNORE) {
|
|
|
|
} else {
|
|
|
|
View** view_pp = ViewDict_get(view_dispatcher->views, view_id);
|
|
|
|
furi_check(view_pp != NULL);
|
2021-09-01 21:05:00 +00:00
|
|
|
view_dispatcher_set_current_view(view_dispatcher, *view_pp);
|
2021-01-08 04:42:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 15:41:22 +00:00
|
|
|
void view_dispatcher_send_to_front(ViewDispatcher* view_dispatcher) {
|
|
|
|
furi_assert(view_dispatcher);
|
|
|
|
furi_assert(view_dispatcher->gui);
|
|
|
|
gui_view_port_send_to_front(view_dispatcher->gui, view_dispatcher->view_port);
|
|
|
|
}
|
|
|
|
|
|
|
|
void view_dispatcher_send_to_back(ViewDispatcher* view_dispatcher) {
|
|
|
|
furi_assert(view_dispatcher);
|
|
|
|
furi_assert(view_dispatcher->gui);
|
|
|
|
gui_view_port_send_to_front(view_dispatcher->gui, view_dispatcher->view_port);
|
|
|
|
}
|
|
|
|
|
2021-01-08 04:42:48 +00:00
|
|
|
void view_dispatcher_attach_to_gui(
|
|
|
|
ViewDispatcher* view_dispatcher,
|
|
|
|
Gui* gui,
|
|
|
|
ViewDispatcherType type) {
|
|
|
|
furi_assert(view_dispatcher);
|
|
|
|
furi_assert(view_dispatcher->gui == NULL);
|
|
|
|
furi_assert(gui);
|
|
|
|
|
2021-11-24 16:21:12 +00:00
|
|
|
if(type == ViewDispatcherTypeDesktop) {
|
|
|
|
gui_add_view_port(gui, view_dispatcher->view_port, GuiLayerDesktop);
|
|
|
|
} else if(type == ViewDispatcherTypeWindow) {
|
|
|
|
gui_add_view_port(gui, view_dispatcher->view_port, GuiLayerWindow);
|
2021-01-08 04:42:48 +00:00
|
|
|
} else if(type == ViewDispatcherTypeFullscreen) {
|
2021-01-29 13:52:16 +00:00
|
|
|
gui_add_view_port(gui, view_dispatcher->view_port, GuiLayerFullscreen);
|
2021-01-08 04:42:48 +00:00
|
|
|
} else {
|
|
|
|
furi_check(NULL);
|
|
|
|
}
|
|
|
|
view_dispatcher->gui = gui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void view_dispatcher_draw_callback(Canvas* canvas, void* context) {
|
|
|
|
ViewDispatcher* view_dispatcher = context;
|
|
|
|
if(view_dispatcher->current_view) {
|
|
|
|
view_draw(view_dispatcher->current_view, canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void view_dispatcher_input_callback(InputEvent* event, void* context) {
|
|
|
|
ViewDispatcher* view_dispatcher = context;
|
2021-05-25 10:19:07 +00:00
|
|
|
if(view_dispatcher->queue) {
|
|
|
|
ViewDispatcherMessage message;
|
|
|
|
message.type = ViewDispatcherMessageTypeInput;
|
|
|
|
message.input = *event;
|
|
|
|
furi_check(osMessageQueuePut(view_dispatcher->queue, &message, 0, osWaitForever) == osOK);
|
|
|
|
} else {
|
|
|
|
view_dispatcher_handle_input(view_dispatcher, event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void view_dispatcher_handle_input(ViewDispatcher* view_dispatcher, InputEvent* event) {
|
2021-08-31 08:22:52 +00:00
|
|
|
// Check input complementarity
|
|
|
|
uint8_t key_bit = (1 << event->key);
|
|
|
|
if(event->type == InputTypePress) {
|
|
|
|
view_dispatcher->ongoing_input |= key_bit;
|
|
|
|
} else if(event->type == InputTypeRelease) {
|
|
|
|
view_dispatcher->ongoing_input &= ~key_bit;
|
|
|
|
} else if(!(view_dispatcher->ongoing_input & key_bit)) {
|
2021-11-04 17:26:41 +00:00
|
|
|
FURI_LOG_D(
|
2021-11-12 13:04:35 +00:00
|
|
|
TAG,
|
2021-09-01 21:05:00 +00:00
|
|
|
"non-complementary input, discarding key: %s, type: %s, sequence: %p",
|
2021-08-31 08:22:52 +00:00
|
|
|
input_get_key_name(event->key),
|
2021-09-01 21:05:00 +00:00
|
|
|
input_get_type_name(event->type),
|
|
|
|
event->sequence);
|
2021-08-30 20:05:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-01 21:05:00 +00:00
|
|
|
// Set ongoing input view if this is event is first press event
|
|
|
|
if(!(view_dispatcher->ongoing_input & ~key_bit) && event->type == InputTypePress) {
|
|
|
|
view_dispatcher->ongoing_input_view = view_dispatcher->current_view;
|
2021-01-08 04:42:48 +00:00
|
|
|
}
|
2021-09-01 21:05:00 +00:00
|
|
|
|
|
|
|
// Deliver event
|
|
|
|
if(view_dispatcher->ongoing_input_view == view_dispatcher->current_view) {
|
|
|
|
bool is_consumed = false;
|
|
|
|
if(view_dispatcher->current_view) {
|
|
|
|
is_consumed = view_input(view_dispatcher->current_view, event);
|
|
|
|
}
|
2021-12-15 17:39:06 +00:00
|
|
|
if(!is_consumed && (event->type == InputTypeShort || event->type == InputTypeLong)) {
|
2021-09-01 21:05:00 +00:00
|
|
|
// TODO remove view navigation handlers
|
|
|
|
uint32_t view_id = VIEW_IGNORE;
|
|
|
|
if(event->key == InputKeyBack) {
|
|
|
|
view_id = view_previous(view_dispatcher->current_view);
|
|
|
|
if((view_id == VIEW_IGNORE) && (view_dispatcher->navigation_event_callback)) {
|
|
|
|
is_consumed =
|
|
|
|
view_dispatcher->navigation_event_callback(view_dispatcher->event_context);
|
|
|
|
if(!is_consumed) {
|
|
|
|
view_dispatcher_stop(view_dispatcher);
|
|
|
|
return;
|
|
|
|
}
|
2021-06-30 17:43:29 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-01 21:05:00 +00:00
|
|
|
if(!is_consumed) {
|
|
|
|
view_dispatcher_switch_to_view(view_dispatcher, view_id);
|
|
|
|
}
|
2021-01-08 04:42:48 +00:00
|
|
|
}
|
2021-09-01 21:05:00 +00:00
|
|
|
} else if(view_dispatcher->ongoing_input_view && event->type == InputTypeRelease) {
|
2021-11-04 17:26:41 +00:00
|
|
|
FURI_LOG_D(
|
2021-11-12 13:04:35 +00:00
|
|
|
TAG,
|
2021-09-01 21:05:00 +00:00
|
|
|
"View changed while key press %p -> %p. Sending key: %s, type: %s, sequence: %p to previous view port",
|
|
|
|
view_dispatcher->ongoing_input_view,
|
|
|
|
view_dispatcher->current_view,
|
|
|
|
input_get_key_name(event->key),
|
|
|
|
input_get_type_name(event->type),
|
|
|
|
event->sequence);
|
|
|
|
view_input(view_dispatcher->ongoing_input_view, event);
|
2021-08-30 20:05:09 +00:00
|
|
|
}
|
2021-01-08 04:42:48 +00:00
|
|
|
}
|
|
|
|
|
2021-07-12 18:56:14 +00:00
|
|
|
void view_dispatcher_handle_tick_event(ViewDispatcher* view_dispatcher) {
|
|
|
|
if(view_dispatcher->tick_event_callback) {
|
|
|
|
view_dispatcher->tick_event_callback(view_dispatcher->event_context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-20 08:15:48 +00:00
|
|
|
void view_dispatcher_handle_custom_event(ViewDispatcher* view_dispatcher, uint32_t event) {
|
2021-06-30 17:43:29 +00:00
|
|
|
bool is_consumed = false;
|
|
|
|
if(view_dispatcher->current_view) {
|
|
|
|
is_consumed = view_custom(view_dispatcher->current_view, event);
|
|
|
|
}
|
2021-07-12 18:56:14 +00:00
|
|
|
// If custom event is not consumed in View, call callback
|
|
|
|
if(!is_consumed && view_dispatcher->custom_event_callback) {
|
|
|
|
is_consumed =
|
|
|
|
view_dispatcher->custom_event_callback(view_dispatcher->event_context, event);
|
2021-06-20 08:15:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void view_dispatcher_send_custom_event(ViewDispatcher* view_dispatcher, uint32_t event) {
|
|
|
|
furi_assert(view_dispatcher);
|
|
|
|
furi_assert(view_dispatcher->queue);
|
|
|
|
|
|
|
|
ViewDispatcherMessage message;
|
|
|
|
message.type = ViewDispatcherMessageTypeCustomEvent;
|
|
|
|
message.custom_event = event;
|
|
|
|
|
|
|
|
furi_check(osMessageQueuePut(view_dispatcher->queue, &message, 0, osWaitForever) == osOK);
|
|
|
|
}
|
|
|
|
|
2021-02-04 12:05:46 +00:00
|
|
|
void view_dispatcher_set_current_view(ViewDispatcher* view_dispatcher, View* view) {
|
|
|
|
furi_assert(view_dispatcher);
|
|
|
|
// Dispatch view exit event
|
|
|
|
if(view_dispatcher->current_view) {
|
|
|
|
view_exit(view_dispatcher->current_view);
|
|
|
|
}
|
|
|
|
// Set current view
|
|
|
|
view_dispatcher->current_view = view;
|
|
|
|
// Dispatch view enter event
|
|
|
|
if(view_dispatcher->current_view) {
|
2021-05-19 09:43:15 +00:00
|
|
|
if(view->orientation == ViewOrientationVertical)
|
|
|
|
view_port_set_orientation(view_dispatcher->view_port, ViewPortOrientationVertical);
|
|
|
|
else if(view->orientation == ViewOrientationHorizontal)
|
|
|
|
view_port_set_orientation(view_dispatcher->view_port, ViewPortOrientationHorizontal);
|
2021-02-04 12:05:46 +00:00
|
|
|
view_enter(view_dispatcher->current_view);
|
|
|
|
view_port_enabled_set(view_dispatcher->view_port, true);
|
|
|
|
view_port_update(view_dispatcher->view_port);
|
|
|
|
} else {
|
|
|
|
view_port_enabled_set(view_dispatcher->view_port, false);
|
2021-05-25 10:19:07 +00:00
|
|
|
if(view_dispatcher->queue) {
|
|
|
|
view_dispatcher_stop(view_dispatcher);
|
|
|
|
}
|
2021-02-04 12:05:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-01 12:03:02 +00:00
|
|
|
void view_dispatcher_update(View* view, void* context) {
|
2021-01-08 04:42:48 +00:00
|
|
|
furi_assert(view);
|
2021-04-01 12:03:02 +00:00
|
|
|
furi_assert(context);
|
|
|
|
|
|
|
|
ViewDispatcher* view_dispatcher = context;
|
2021-01-08 04:42:48 +00:00
|
|
|
|
|
|
|
if(view_dispatcher->current_view == view) {
|
2021-01-29 13:52:16 +00:00
|
|
|
view_port_update(view_dispatcher->view_port);
|
2021-01-08 04:42:48 +00:00
|
|
|
}
|
|
|
|
}
|