[FL-1401] Add Universal TV remote (#539)
* Remove excess headers * Add ButtonPanel * Add Popup * Move FileReader to standalone object * Universal remote (part 1) * Universal remote (part 2) * Global rename tranciever/file_parser * Compile assets * syntax fix * English: rename tranceiver to transceiver. Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
#include "irda.h"
|
||||
#include "irda/scene/irda-app-scene.hpp"
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
static void dialog_result_callback(DialogExResult result, void* context) {
|
||||
auto app = static_cast<IrdaApp*>(context);
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include <cstdio>
|
||||
|
||||
void IrdaAppSceneEditRename::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
|
@@ -1,6 +1,4 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <gui/modules/popup.h>
|
||||
|
||||
void IrdaAppSceneLearnDoneAfter::on_enter(IrdaApp* app) {
|
||||
|
@@ -1,6 +1,4 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
void IrdaAppSceneLearnDone::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
|
@@ -1,15 +1,12 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include "gui/modules/text_input.h"
|
||||
#include <callback-connector.h>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
void IrdaAppSceneLearnEnterName::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
TextInput* text_input = view_manager->get_text_input();
|
||||
|
||||
auto receiver = app->get_receiver();
|
||||
auto message = receiver->get_last_message();
|
||||
auto transceiver = app->get_transceiver();
|
||||
auto message = transceiver->get_last_message();
|
||||
|
||||
app->set_text_store(
|
||||
0,
|
||||
@@ -34,14 +31,14 @@ bool IrdaAppSceneLearnEnterName::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::TextEditDone) {
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
auto receiver = app->get_receiver();
|
||||
auto transceiver = app->get_transceiver();
|
||||
bool result = false;
|
||||
if(app->get_learn_new_remote()) {
|
||||
result = remote_manager->add_remote_with_button(
|
||||
app->get_text_store(0), receiver->get_last_message());
|
||||
app->get_text_store(0), transceiver->get_last_message());
|
||||
} else {
|
||||
result =
|
||||
remote_manager->add_button(app->get_text_store(0), receiver->get_last_message());
|
||||
result = remote_manager->add_button(
|
||||
app->get_text_store(0), transceiver->get_last_message());
|
||||
}
|
||||
|
||||
if(!result) {
|
||||
|
@@ -1,7 +1,5 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include "irda.h"
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
static void dialog_result_callback(DialogExResult result, void* context) {
|
||||
auto app = static_cast<IrdaApp*>(context);
|
||||
@@ -19,8 +17,8 @@ void IrdaAppSceneLearnSuccess::on_enter(IrdaApp* app) {
|
||||
|
||||
app->notify_green_on();
|
||||
|
||||
auto receiver = app->get_receiver();
|
||||
auto message = receiver->get_last_message();
|
||||
auto transceiver = app->get_transceiver();
|
||||
auto message = transceiver->get_last_message();
|
||||
|
||||
app->set_text_store(0, "%s", irda_get_protocol_name(message->protocol));
|
||||
app->set_text_store(
|
||||
@@ -52,8 +50,8 @@ bool IrdaAppSceneLearnSuccess::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
break;
|
||||
case DialogExResultCenter: {
|
||||
app->notify_space_blink();
|
||||
auto receiver = app->get_receiver();
|
||||
auto message = receiver->get_last_message();
|
||||
auto transceiver = app->get_transceiver();
|
||||
auto message = transceiver->get_last_message();
|
||||
irda_send(message, 1);
|
||||
break;
|
||||
}
|
||||
|
@@ -2,10 +2,10 @@
|
||||
|
||||
void IrdaAppSceneLearn::on_enter(IrdaApp* app) {
|
||||
auto view_manager = app->get_view_manager();
|
||||
auto receiver = app->get_receiver();
|
||||
auto transceiver = app->get_transceiver();
|
||||
auto event_queue = view_manager->get_event_queue();
|
||||
|
||||
receiver->capture_once_start(event_queue);
|
||||
transceiver->capture_once_start(event_queue);
|
||||
|
||||
auto popup = view_manager->get_popup();
|
||||
|
||||
|
@@ -65,7 +65,7 @@ bool IrdaAppSceneRemote::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
app->notify_click_and_blink();
|
||||
auto remote_manager = app->get_remote_manager();
|
||||
auto message = remote_manager->get_button_data(event->payload.menu_index);
|
||||
app->get_receiver()->send_message(message);
|
||||
app->get_transceiver()->send_message(message);
|
||||
break;
|
||||
}
|
||||
} else if(event->type == IrdaAppEvent::Type::Back) {
|
||||
|
98
applications/irda/scene/irda-app-scene-universal-common.cpp
Normal file
98
applications/irda/scene/irda-app-scene-universal-common.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
#include "../irda-app.hpp"
|
||||
#include "assets_icons.h"
|
||||
#include "gui/modules/button_menu.h"
|
||||
#include "gui/modules/button_panel.h"
|
||||
#include "../view/irda-app-brut-view.h"
|
||||
#include "gui/view.h"
|
||||
#include "irda/irda-app-view-manager.hpp"
|
||||
#include "irda/scene/irda-app-scene.hpp"
|
||||
|
||||
void IrdaAppSceneUniversalCommon::irda_app_item_callback(void* context, uint32_t index) {
|
||||
IrdaApp* app = static_cast<IrdaApp*>(context);
|
||||
IrdaAppEvent event;
|
||||
|
||||
event.type = IrdaAppEvent::Type::ButtonPanelPressed;
|
||||
event.payload.menu_index = index;
|
||||
|
||||
app->get_view_manager()->send_event(&event);
|
||||
}
|
||||
|
||||
static bool irda_popup_brut_input_callback(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
furi_assert(event);
|
||||
auto app = static_cast<IrdaApp*>(context);
|
||||
bool consumed = false;
|
||||
|
||||
if((event->type == InputTypeShort) && (event->key == InputKeyBack)) {
|
||||
consumed = true;
|
||||
IrdaAppEvent irda_event;
|
||||
|
||||
irda_event.type = IrdaAppEvent::Type::ButtonPanelPopupBackPressed;
|
||||
app->get_view_manager()->send_event(&irda_event);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneUniversalCommon::remove_popup(IrdaApp* app) {
|
||||
auto button_panel = app->get_view_manager()->get_button_panel();
|
||||
button_panel_set_popup_draw_callback(button_panel, NULL, NULL);
|
||||
button_panel_set_popup_input_callback(button_panel, NULL, NULL);
|
||||
}
|
||||
|
||||
void IrdaAppSceneUniversalCommon::show_popup(IrdaApp* app, int record_amount) {
|
||||
auto button_panel = app->get_view_manager()->get_button_panel();
|
||||
auto popup_brut = app->get_view_manager()->get_popup_brut();
|
||||
popup_brut_set_progress_max(popup_brut, record_amount);
|
||||
button_panel_set_popup_draw_callback(button_panel, popup_brut_draw_callback, popup_brut);
|
||||
button_panel_set_popup_input_callback(button_panel, irda_popup_brut_input_callback, app);
|
||||
}
|
||||
|
||||
void IrdaAppSceneUniversalCommon::progress_popup(IrdaApp* app) {
|
||||
popup_brut_increase_progress(app->get_view_manager()->get_popup_brut());
|
||||
auto button_panel = app->get_view_manager()->get_button_panel();
|
||||
with_view_model_cpp(button_panel_get_view(button_panel), void*, model, { return true; });
|
||||
}
|
||||
|
||||
bool IrdaAppSceneUniversalCommon::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::Tick) {
|
||||
if(brute_force_started) {
|
||||
if(brute_force.send_next_bruteforce(*app->get_transceiver())) {
|
||||
progress_popup(app);
|
||||
} else {
|
||||
brute_force.stop_bruteforce();
|
||||
brute_force_started = false;
|
||||
remove_popup(app);
|
||||
}
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
if(event->type == IrdaAppEvent::Type::ButtonPanelPopupBackPressed) {
|
||||
consumed = true;
|
||||
brute_force_started = false;
|
||||
brute_force.stop_bruteforce();
|
||||
remove_popup(app);
|
||||
} else if(event->type == IrdaAppEvent::Type::ButtonPanelPressed) {
|
||||
int record_amount = 0;
|
||||
if(brute_force.start_bruteforce(event->payload.menu_index, record_amount)) {
|
||||
if(record_amount > 0) {
|
||||
brute_force_started = true;
|
||||
show_popup(app, record_amount);
|
||||
}
|
||||
} else {
|
||||
app->switch_to_previous_scene();
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void IrdaAppSceneUniversalCommon::on_exit(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
ButtonPanel* button_panel = view_manager->get_button_panel();
|
||||
button_panel_clean(button_panel);
|
||||
}
|
61
applications/irda/scene/irda-app-scene-universal-tv.cpp
Normal file
61
applications/irda/scene/irda-app-scene-universal-tv.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "irda/scene/irda-app-scene.hpp"
|
||||
#include "irda/irda-app.hpp"
|
||||
|
||||
void IrdaAppSceneUniversalTV::on_enter(IrdaApp* app) {
|
||||
IrdaAppViewManager* view_manager = app->get_view_manager();
|
||||
ButtonPanel* button_panel = view_manager->get_button_panel();
|
||||
button_panel_reserve(button_panel, 2, 3);
|
||||
|
||||
int i = 0;
|
||||
button_panel_add_item(
|
||||
button_panel, i, 0, 0, 3, 19, I_Power_25x27, I_Power_hvr_25x27, irda_app_item_callback, app);
|
||||
brute_force.add_record(i, "POWER");
|
||||
++i;
|
||||
button_panel_add_item(
|
||||
button_panel, i, 1, 0, 36, 19, I_Mute_25x27, I_Mute_hvr_25x27, irda_app_item_callback, app);
|
||||
brute_force.add_record(i, "MUTE");
|
||||
++i;
|
||||
button_panel_add_item(
|
||||
button_panel,
|
||||
i,
|
||||
0,
|
||||
1,
|
||||
3,
|
||||
66,
|
||||
I_Vol_up_25x27,
|
||||
I_Vol_up_hvr_25x27,
|
||||
irda_app_item_callback,
|
||||
app);
|
||||
brute_force.add_record(i, "VOL+");
|
||||
++i;
|
||||
button_panel_add_item(
|
||||
button_panel, i, 1, 1, 36, 66, I_Up_25x27, I_Up_hvr_25x27, irda_app_item_callback, app);
|
||||
brute_force.add_record(i, "CH+");
|
||||
++i;
|
||||
button_panel_add_item(
|
||||
button_panel,
|
||||
i,
|
||||
0,
|
||||
2,
|
||||
3,
|
||||
98,
|
||||
I_Vol_down_25x27,
|
||||
I_Vol_down_hvr_25x27,
|
||||
irda_app_item_callback,
|
||||
app);
|
||||
brute_force.add_record(i, "VOL-");
|
||||
++i;
|
||||
button_panel_add_item(
|
||||
button_panel, i, 1, 2, 36, 98, I_Down_25x27, I_Down_hvr_25x27, irda_app_item_callback, app);
|
||||
brute_force.add_record(i, "CH-");
|
||||
|
||||
button_panel_add_label(button_panel, 6, 11, FontPrimary, "TV remote");
|
||||
button_panel_add_label(button_panel, 9, 64, FontSecondary, "Vol");
|
||||
button_panel_add_label(button_panel, 43, 64, FontSecondary, "Ch");
|
||||
|
||||
view_manager->switch_to(IrdaAppViewManager::ViewType::ButtonPanel);
|
||||
|
||||
if(!brute_force.calculate_messages()) {
|
||||
app->switch_to_previous_scene();
|
||||
}
|
||||
}
|
@@ -37,7 +37,7 @@ bool IrdaAppSceneUniversal::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
||||
submenu_item_selected = event->payload.menu_index;
|
||||
switch(event->payload.menu_index) {
|
||||
case SubmenuIndexUniversalTV:
|
||||
// app->switch_to_next_scene(IrdaApp::Scene::UniversalTV);
|
||||
app->switch_to_next_scene(IrdaApp::Scene::UniversalTV);
|
||||
break;
|
||||
case SubmenuIndexUniversalAudio:
|
||||
// app->switch_to_next_scene(IrdaApp::Scene::UniversalAudio);
|
||||
|
@@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
#include "../irda-app.hpp"
|
||||
#include "../irda-app-event.hpp"
|
||||
#include <api-hal-irda.h>
|
||||
#include "irda.h"
|
||||
#include <gui/elements.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "../irda-app-brute-force.hpp"
|
||||
|
||||
|
||||
class IrdaApp;
|
||||
|
||||
@@ -137,3 +138,31 @@ public:
|
||||
void on_exit(IrdaApp* app) final;
|
||||
};
|
||||
|
||||
class IrdaAppSceneUniversalCommon : public IrdaAppScene {
|
||||
bool brute_force_started = false;
|
||||
protected:
|
||||
bool on_event(IrdaApp* app, IrdaAppEvent* event) final;
|
||||
void on_exit(IrdaApp* app) final;
|
||||
IrdaAppBruteForce brute_force;
|
||||
void remove_popup(IrdaApp* app);
|
||||
void show_popup(IrdaApp* app, int record_amount);
|
||||
void progress_popup(IrdaApp* app);
|
||||
static void irda_app_item_callback(void* context, uint32_t index);
|
||||
IrdaAppSceneUniversalCommon(const char* filename) : brute_force(filename) {}
|
||||
~IrdaAppSceneUniversalCommon() {}
|
||||
};
|
||||
|
||||
class IrdaAppSceneUniversalTV : public IrdaAppSceneUniversalCommon {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
IrdaAppSceneUniversalTV() : IrdaAppSceneUniversalCommon("/irda/universal/tv.ir") {}
|
||||
~IrdaAppSceneUniversalTV() {}
|
||||
};
|
||||
|
||||
class IrdaAppSceneUniversalAudio : public IrdaAppSceneUniversalCommon {
|
||||
public:
|
||||
void on_enter(IrdaApp* app) final;
|
||||
IrdaAppSceneUniversalAudio() : IrdaAppSceneUniversalCommon("/irda/universal/audio.ir") {}
|
||||
~IrdaAppSceneUniversalAudio() {}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user