2022-02-24 11:59:36 +00:00
|
|
|
#include <gui/modules/button_menu.h>
|
|
|
|
#include <gui/view_stack.h>
|
|
|
|
#include <gui/modules/loading.h>
|
2022-02-18 20:16:22 +00:00
|
|
|
#include <gui/modules/button_panel.h>
|
|
|
|
#include <gui/modules/dialog_ex.h>
|
2022-02-24 11:59:36 +00:00
|
|
|
#include <furi.h>
|
2022-02-18 20:16:22 +00:00
|
|
|
#include <callback-connector.h>
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
#include "infrared/infrared_app_view_manager.h"
|
|
|
|
#include "infrared/view/infrared_progress_view.h"
|
|
|
|
#include "infrared_app.h"
|
|
|
|
#include "infrared/infrared_app_event.h"
|
2021-06-02 15:16:05 +00:00
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredAppViewManager::InfraredAppViewManager() {
|
|
|
|
event_queue = osMessageQueueNew(10, sizeof(InfraredAppEvent), NULL);
|
2021-06-02 15:16:05 +00:00
|
|
|
|
|
|
|
view_dispatcher = view_dispatcher_alloc();
|
2022-02-25 15:22:58 +00:00
|
|
|
auto callback = cbc::obtain_connector(this, &InfraredAppViewManager::previous_view_callback);
|
2021-06-02 15:16:05 +00:00
|
|
|
|
|
|
|
gui = static_cast<Gui*>(furi_record_open("gui"));
|
|
|
|
view_dispatcher_attach_to_gui(view_dispatcher, gui, ViewDispatcherTypeFullscreen);
|
|
|
|
|
|
|
|
button_menu = button_menu_alloc();
|
|
|
|
submenu = submenu_alloc();
|
|
|
|
popup = popup_alloc();
|
|
|
|
dialog_ex = dialog_ex_alloc();
|
|
|
|
text_input = text_input_alloc();
|
2021-06-25 13:52:27 +00:00
|
|
|
button_panel = button_panel_alloc();
|
2022-02-25 15:22:58 +00:00
|
|
|
progress_view = infrared_progress_view_alloc();
|
2022-02-24 11:59:36 +00:00
|
|
|
loading_view = loading_alloc();
|
|
|
|
universal_view_stack = view_stack_alloc();
|
|
|
|
view_stack_add_view(universal_view_stack, button_panel_get_view(button_panel));
|
|
|
|
view_set_orientation(view_stack_get_view(universal_view_stack), ViewOrientationVertical);
|
2021-06-02 15:16:05 +00:00
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
add_view(ViewId::UniversalRemote, view_stack_get_view(universal_view_stack));
|
|
|
|
add_view(ViewId::ButtonMenu, button_menu_get_view(button_menu));
|
|
|
|
add_view(ViewId::Submenu, submenu_get_view(submenu));
|
|
|
|
add_view(ViewId::Popup, popup_get_view(popup));
|
|
|
|
add_view(ViewId::DialogEx, dialog_ex_get_view(dialog_ex));
|
|
|
|
add_view(ViewId::TextInput, text_input_get_view(text_input));
|
2021-06-02 15:16:05 +00:00
|
|
|
|
2022-02-24 11:59:36 +00:00
|
|
|
view_set_previous_callback(view_stack_get_view(universal_view_stack), callback);
|
2021-06-02 15:16:05 +00:00
|
|
|
view_set_previous_callback(button_menu_get_view(button_menu), callback);
|
|
|
|
view_set_previous_callback(submenu_get_view(submenu), callback);
|
|
|
|
view_set_previous_callback(popup_get_view(popup), callback);
|
|
|
|
view_set_previous_callback(dialog_ex_get_view(dialog_ex), callback);
|
|
|
|
view_set_previous_callback(text_input_get_view(text_input), callback);
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredAppViewManager::~InfraredAppViewManager() {
|
2021-06-25 13:52:27 +00:00
|
|
|
view_dispatcher_remove_view(
|
2022-02-25 15:22:58 +00:00
|
|
|
view_dispatcher, static_cast<uint32_t>(InfraredAppViewManager::ViewId::UniversalRemote));
|
2021-06-02 15:16:05 +00:00
|
|
|
view_dispatcher_remove_view(
|
2022-02-25 15:22:58 +00:00
|
|
|
view_dispatcher, static_cast<uint32_t>(InfraredAppViewManager::ViewId::ButtonMenu));
|
2021-06-02 15:16:05 +00:00
|
|
|
view_dispatcher_remove_view(
|
2022-02-25 15:22:58 +00:00
|
|
|
view_dispatcher, static_cast<uint32_t>(InfraredAppViewManager::ViewId::TextInput));
|
2021-06-02 15:16:05 +00:00
|
|
|
view_dispatcher_remove_view(
|
2022-02-25 15:22:58 +00:00
|
|
|
view_dispatcher, static_cast<uint32_t>(InfraredAppViewManager::ViewId::DialogEx));
|
2021-06-02 15:16:05 +00:00
|
|
|
view_dispatcher_remove_view(
|
2022-02-25 15:22:58 +00:00
|
|
|
view_dispatcher, static_cast<uint32_t>(InfraredAppViewManager::ViewId::Submenu));
|
2021-06-02 15:16:05 +00:00
|
|
|
view_dispatcher_remove_view(
|
2022-02-25 15:22:58 +00:00
|
|
|
view_dispatcher, static_cast<uint32_t>(InfraredAppViewManager::ViewId::Popup));
|
2021-06-02 15:16:05 +00:00
|
|
|
|
2022-02-24 11:59:36 +00:00
|
|
|
view_stack_remove_view(universal_view_stack, button_panel_get_view(button_panel));
|
|
|
|
view_stack_free(universal_view_stack);
|
|
|
|
button_panel_free(button_panel);
|
2021-06-02 15:16:05 +00:00
|
|
|
submenu_free(submenu);
|
|
|
|
popup_free(popup);
|
|
|
|
button_menu_free(button_menu);
|
|
|
|
dialog_ex_free(dialog_ex);
|
|
|
|
text_input_free(text_input);
|
2022-02-25 15:22:58 +00:00
|
|
|
infrared_progress_view_free(progress_view);
|
2022-02-24 11:59:36 +00:00
|
|
|
loading_free(loading_view);
|
2021-06-02 15:16:05 +00:00
|
|
|
|
|
|
|
view_dispatcher_free(view_dispatcher);
|
|
|
|
furi_record_close("gui");
|
|
|
|
osMessageQueueDelete(event_queue);
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredAppViewManager::switch_to(ViewId type) {
|
2021-06-02 15:16:05 +00:00
|
|
|
view_dispatcher_switch_to_view(view_dispatcher, static_cast<uint32_t>(type));
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
TextInput* InfraredAppViewManager::get_text_input() {
|
2021-06-02 15:16:05 +00:00
|
|
|
return text_input;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
DialogEx* InfraredAppViewManager::get_dialog_ex() {
|
2021-06-02 15:16:05 +00:00
|
|
|
return dialog_ex;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
Submenu* InfraredAppViewManager::get_submenu() {
|
2021-06-02 15:16:05 +00:00
|
|
|
return submenu;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
Popup* InfraredAppViewManager::get_popup() {
|
2021-06-02 15:16:05 +00:00
|
|
|
return popup;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
ButtonMenu* InfraredAppViewManager::get_button_menu() {
|
2021-06-02 15:16:05 +00:00
|
|
|
return button_menu;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
ButtonPanel* InfraredAppViewManager::get_button_panel() {
|
2021-06-25 13:52:27 +00:00
|
|
|
return button_panel;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredProgressView* InfraredAppViewManager::get_progress() {
|
2022-02-24 11:59:36 +00:00
|
|
|
return progress_view;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
Loading* InfraredAppViewManager::get_loading() {
|
2022-02-24 11:59:36 +00:00
|
|
|
return loading_view;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
ViewStack* InfraredAppViewManager::get_universal_view_stack() {
|
2022-02-24 11:59:36 +00:00
|
|
|
return universal_view_stack;
|
2021-06-25 13:52:27 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
osMessageQueueId_t InfraredAppViewManager::get_event_queue() {
|
2021-06-02 15:16:05 +00:00
|
|
|
return event_queue;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredAppViewManager::clear_events() {
|
|
|
|
InfraredAppEvent event;
|
2021-07-22 00:07:00 +00:00
|
|
|
while(osMessageQueueGet(event_queue, &event, NULL, 0) == osOK)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredAppViewManager::receive_event(InfraredAppEvent* event) {
|
2021-06-02 15:16:05 +00:00
|
|
|
if(osMessageQueueGet(event_queue, event, NULL, 100) != osOK) {
|
2022-02-25 15:22:58 +00:00
|
|
|
event->type = InfraredAppEvent::Type::Tick;
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredAppViewManager::send_event(InfraredAppEvent* event) {
|
2021-08-11 17:51:06 +00:00
|
|
|
uint32_t timeout = 0;
|
2022-02-18 20:16:22 +00:00
|
|
|
/* Rapid button hammering on signal send scenes causes queue overflow - ignore it,
|
2022-02-25 15:22:58 +00:00
|
|
|
* but try to keep button release event - it switches off INFRARED DMA sending. */
|
|
|
|
if(event->type == InfraredAppEvent::Type::MenuSelectedRelease) {
|
2021-08-11 17:51:06 +00:00
|
|
|
timeout = 200;
|
|
|
|
}
|
2022-02-25 15:22:58 +00:00
|
|
|
if((event->type == InfraredAppEvent::Type::DialogExSelected) &&
|
2022-02-18 20:16:22 +00:00
|
|
|
(event->payload.dialog_ex_result == DialogExReleaseCenter)) {
|
|
|
|
timeout = 200;
|
|
|
|
}
|
|
|
|
|
2021-08-11 17:51:06 +00:00
|
|
|
osMessageQueuePut(event_queue, event, 0, timeout);
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
|
2022-05-06 13:37:10 +00:00
|
|
|
uint32_t InfraredAppViewManager::previous_view_callback(void*) {
|
2021-06-02 15:16:05 +00:00
|
|
|
if(event_queue != NULL) {
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredAppEvent event;
|
|
|
|
event.type = InfraredAppEvent::Type::Back;
|
2021-06-02 15:16:05 +00:00
|
|
|
send_event(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
return VIEW_IGNORE;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void InfraredAppViewManager::add_view(ViewId view_type, View* view) {
|
2021-06-02 15:16:05 +00:00
|
|
|
view_dispatcher_add_view(view_dispatcher, static_cast<uint32_t>(view_type), view);
|
|
|
|
}
|