2022-02-18 20:16:22 +00:00
|
|
|
#include <gui/modules/dialog_ex.h>
|
2022-01-10 17:13:41 +00:00
|
|
|
#include <file_worker_cpp.h>
|
2021-07-22 00:07:00 +00:00
|
|
|
#include <memory>
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 09:20:41 +00:00
|
|
|
#include <dolphin/dolphin.h>
|
2021-06-02 15:16:05 +00:00
|
|
|
|
2022-02-18 20:16:22 +00:00
|
|
|
#include "../irda_app.h"
|
|
|
|
#include "irda.h"
|
|
|
|
|
2021-06-02 15:16:05 +00:00
|
|
|
static void dialog_result_callback(DialogExResult result, void* context) {
|
|
|
|
auto app = static_cast<IrdaApp*>(context);
|
|
|
|
IrdaAppEvent event;
|
|
|
|
|
|
|
|
event.type = IrdaAppEvent::Type::DialogExSelected;
|
|
|
|
event.payload.dialog_ex_result = result;
|
|
|
|
|
|
|
|
app->get_view_manager()->send_event(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppSceneLearnSuccess::on_enter(IrdaApp* app) {
|
|
|
|
IrdaAppViewManager* view_manager = app->get_view_manager();
|
|
|
|
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
|
|
|
|
[FL-2183] [FL-2209] Dolphin Deeds, Level up, assets generation, refactoring (#965)
* Desktop: cleanup headers
* Get loader pubsub via record
* [FL-2183] Dolphin refactoring 2022.01
* Restruct animations assets structure
* Rename assets
* Cleanup headers
* Update Recording animation
* Add BadBattery animation
* Provide loader's pubsub via record
* Fix load/unload animations
* Scripts: add flipper format support, initial dolphin packager rework. Assets: internal and external dolphin.
* Sync internal meta.txt and manifest.txt
* Reorder, rename dolphin assets
* Split essential generated assets
* Add ReadMe for dolphin assets
* Separate essential blocking animations
* Scripts: full dolphin validation before packaging
* Assets, Scripts: dolphin external resources packer
* Github: update codeowners
* Scripts: proper slots handling in dolphin animation meta
* Scripts: correct frames enumeration and fix compiled assets.
* [FL-2209] Add Dolphin Deeds points and many more
* Remove excess frame_rate
* Change dolphin assets directory
* Scripts: add internal resource support to dolphin compiler
* Scripts: add internal assets generation, renaming
* Scripts: correct assert, renaming
* Code cleanup, documentation, fixes
* Update Levelup animations
* Rename essential -> blocking
* Fix Unlocked hint
* Scripts: rewrite Templite compiller, replace regexps with token parser, split block types into code and variable blocks. Update dolphin templates.
* Documentation: add key combos description and use information
* Scripts: cleanup templit, more debug info and add dev comment
Co-authored-by: あく <alleteam@gmail.com>
2022-01-29 09:20:41 +00:00
|
|
|
DOLPHIN_DEED(DolphinDeedIrLearnSuccess);
|
2021-06-09 13:04:49 +00:00
|
|
|
app->notify_green_on();
|
|
|
|
|
2022-02-18 20:16:22 +00:00
|
|
|
irda_worker_tx_set_get_signal_callback(
|
|
|
|
app->get_irda_worker(), irda_worker_tx_get_signal_steady_callback, app);
|
|
|
|
irda_worker_tx_set_signal_sent_callback(
|
|
|
|
app->get_irda_worker(), IrdaApp::signal_sent_callback, app);
|
|
|
|
|
2021-07-16 16:43:54 +00:00
|
|
|
auto signal = app->get_received_signal();
|
|
|
|
|
|
|
|
if(!signal.is_raw()) {
|
|
|
|
auto message = &signal.get_message();
|
2021-11-01 16:34:50 +00:00
|
|
|
uint8_t adr_digits = ROUND_UP_TO(irda_get_protocol_address_length(message->protocol), 4);
|
|
|
|
uint8_t cmd_digits = ROUND_UP_TO(irda_get_protocol_command_length(message->protocol), 4);
|
|
|
|
uint8_t max_digits = MAX(adr_digits, cmd_digits);
|
|
|
|
max_digits = MIN(max_digits, 7);
|
|
|
|
size_t label_x_offset = 63 + (7 - max_digits) * 3;
|
|
|
|
|
2021-07-16 16:43:54 +00:00
|
|
|
app->set_text_store(0, "%s", irda_get_protocol_name(message->protocol));
|
|
|
|
app->set_text_store(
|
|
|
|
1,
|
|
|
|
"A: 0x%0*lX\nC: 0x%0*lX\n",
|
2021-11-01 16:34:50 +00:00
|
|
|
adr_digits,
|
2021-07-16 16:43:54 +00:00
|
|
|
message->address,
|
2021-11-01 16:34:50 +00:00
|
|
|
cmd_digits,
|
2021-07-16 16:43:54 +00:00
|
|
|
message->command);
|
2021-11-01 16:34:50 +00:00
|
|
|
|
|
|
|
dialog_ex_set_header(dialog_ex, app->get_text_store(0), 95, 7, AlignCenter, AlignCenter);
|
|
|
|
dialog_ex_set_text(
|
|
|
|
dialog_ex, app->get_text_store(1), label_x_offset, 34, AlignLeft, AlignCenter);
|
2021-07-16 16:43:54 +00:00
|
|
|
} else {
|
|
|
|
dialog_ex_set_header(dialog_ex, "Unknown", 95, 10, AlignCenter, AlignCenter);
|
|
|
|
app->set_text_store(0, "%d samples", signal.get_raw_signal().timings_cnt);
|
|
|
|
dialog_ex_set_text(dialog_ex, app->get_text_store(0), 75, 23, AlignLeft, AlignTop);
|
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
|
|
|
|
dialog_ex_set_left_button_text(dialog_ex, "Retry");
|
|
|
|
dialog_ex_set_right_button_text(dialog_ex, "Save");
|
2021-06-09 13:04:49 +00:00
|
|
|
dialog_ex_set_center_button_text(dialog_ex, "Send");
|
2021-11-01 16:34:50 +00:00
|
|
|
dialog_ex_set_icon(dialog_ex, 0, 1, &I_DolphinReadingSuccess_59x63);
|
2021-06-02 15:16:05 +00:00
|
|
|
dialog_ex_set_result_callback(dialog_ex, dialog_result_callback);
|
|
|
|
dialog_ex_set_context(dialog_ex, app);
|
2022-02-18 20:16:22 +00:00
|
|
|
dialog_ex_enable_extended_events(dialog_ex);
|
2021-06-02 15:16:05 +00:00
|
|
|
|
|
|
|
view_manager->switch_to(IrdaAppViewManager::ViewType::DialogEx);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IrdaAppSceneLearnSuccess::on_event(IrdaApp* app, IrdaAppEvent* event) {
|
|
|
|
bool consumed = false;
|
2021-08-11 17:51:06 +00:00
|
|
|
if(event->type == IrdaAppEvent::Type::Tick) {
|
|
|
|
/* Send event every tick to suppress any switching off green light */
|
2022-02-18 20:16:22 +00:00
|
|
|
if(!button_pressed) {
|
|
|
|
app->notify_green_on();
|
|
|
|
}
|
2021-08-11 17:51:06 +00:00
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
|
|
|
|
if(event->type == IrdaAppEvent::Type::DialogExSelected) {
|
|
|
|
switch(event->payload.dialog_ex_result) {
|
|
|
|
case DialogExResultLeft:
|
2022-02-18 20:16:22 +00:00
|
|
|
consumed = true;
|
|
|
|
if(!button_pressed) {
|
|
|
|
app->switch_to_next_scene_without_saving(IrdaApp::Scene::Learn);
|
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
break;
|
2021-07-22 00:07:00 +00:00
|
|
|
case DialogExResultRight: {
|
2022-02-18 20:16:22 +00:00
|
|
|
consumed = true;
|
2022-01-10 17:13:41 +00:00
|
|
|
FileWorkerCpp file_worker;
|
2022-02-18 20:16:22 +00:00
|
|
|
if(!button_pressed) {
|
|
|
|
if(file_worker.check_errors()) {
|
|
|
|
app->switch_to_next_scene(IrdaApp::Scene::LearnEnterName);
|
|
|
|
} else {
|
|
|
|
app->switch_to_previous_scene();
|
|
|
|
}
|
2021-06-09 13:04:49 +00:00
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-02-18 20:16:22 +00:00
|
|
|
case DialogExPressCenter:
|
|
|
|
if(!button_pressed) {
|
|
|
|
button_pressed = true;
|
|
|
|
app->notify_click_and_green_blink();
|
|
|
|
|
|
|
|
auto signal = app->get_received_signal();
|
|
|
|
if(signal.is_raw()) {
|
|
|
|
irda_worker_set_raw_signal(
|
|
|
|
app->get_irda_worker(),
|
|
|
|
signal.get_raw_signal().timings,
|
|
|
|
signal.get_raw_signal().timings_cnt);
|
|
|
|
} else {
|
|
|
|
irda_worker_set_decoded_signal(app->get_irda_worker(), &signal.get_message());
|
|
|
|
}
|
|
|
|
|
|
|
|
irda_worker_tx_start(app->get_irda_worker());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DialogExReleaseCenter:
|
|
|
|
if(button_pressed) {
|
|
|
|
button_pressed = false;
|
|
|
|
irda_worker_tx_stop(app->get_irda_worker());
|
|
|
|
app->notify_green_off();
|
|
|
|
}
|
|
|
|
break;
|
2021-07-22 00:07:00 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-16 11:09:47 +00:00
|
|
|
if(event->type == IrdaAppEvent::Type::Back) {
|
2022-02-18 20:16:22 +00:00
|
|
|
if(!button_pressed) {
|
|
|
|
app->switch_to_next_scene(IrdaApp::Scene::AskBack);
|
|
|
|
}
|
2022-02-16 11:09:47 +00:00
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
|
2021-06-02 15:16:05 +00:00
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrdaAppSceneLearnSuccess::on_exit(IrdaApp* app) {
|
2021-06-09 13:04:49 +00:00
|
|
|
IrdaAppViewManager* view_manager = app->get_view_manager();
|
|
|
|
DialogEx* dialog_ex = view_manager->get_dialog_ex();
|
2022-02-16 11:09:47 +00:00
|
|
|
dialog_ex_reset(dialog_ex);
|
2021-06-09 13:04:49 +00:00
|
|
|
app->notify_green_off();
|
2022-02-18 20:16:22 +00:00
|
|
|
irda_worker_tx_set_get_signal_callback(app->get_irda_worker(), nullptr, nullptr);
|
|
|
|
irda_worker_tx_set_signal_sent_callback(app->get_irda_worker(), nullptr, nullptr);
|
2021-06-02 15:16:05 +00:00
|
|
|
}
|