flipperzero-firmware/applications/infrared/views/infrared_progress_view.c
Georgii Surkov a8acfcabb4
[FL-2568] Infrared C port (#1326)
* Add skeleton for infrared C port, rename old app
* Add scene stubs
* Add more views
* Misc changes
* Add remote and signal class stubs
* Complete infrared signal class
* Add remote button class stub
* Check if button contains a signal during destruction
* Complete infrared signal class more
* Implement remote storing
* Implement remote loading
* Fix error handling
* Implement remote transmitting
* Rename scene
* Canonise event consumption
* Implement remote learning (stub)
* Implement learn success screen (stub)
* Implement AskBack scene
* Improve remote saving&loading
* Fix remote file name
* Add LearnDone scene
* Switch from Remote scene correctly
* Add SceneButtonSelect
* Remove unneeded assert
* Add new SceneManager method
* Use new SceneManager method in Infrared
* Implement renaming of buttons and remotes
* Implement deleting of buttons and remotes
* Add universal remotes list
* Add brute force code
* Brute force code improvements
* Partially implement Universal Remote GUI
* Fix wrong singnal handling
* Fully implement Universal Remote
* Use standard custom events everywhere
* Return infrared CLI
* Remove old Infrared app
* Change container name
* Fix scene order
* Put ButtonPanel into stack only when needed
* Show loading animation during slow operations
* Do not hardcode Loading widget coordinates
* Switch Loading widget orientation as needed
* Save Start scene state
* Save Remote scene state
* Save Edit scene state
* Save EditButtonSelect scene state
* Do not use scene state
* Use string_t instead of const char* for brevity
* Fix memory leak
* Fix saving raw remotes
* Add Infrared debug menu
* Add debug view
* Move Infrared monitor into Infrared application
* Remove old Infrared monitor app
* Use common signal received callback everywhere
2022-06-21 21:45:50 +09:00

122 lines
3.8 KiB
C

#include "furi/check.h"
#include "furi_hal_resources.h"
#include "assets_icons.h"
#include "gui/canvas.h"
#include "gui/view.h"
#include "input/input.h"
#include "m-string.h"
#include <gui/elements.h>
#include <furi.h>
#include "infrared_progress_view.h"
#include "gui/modules/button_panel.h"
#include <stdint.h>
struct InfraredProgressView {
View* view;
InfraredProgressViewBackCallback back_callback;
void* context;
};
typedef struct {
size_t progress;
size_t progress_total;
} InfraredProgressViewModel;
bool infrared_progress_view_increase_progress(InfraredProgressView* progress) {
furi_assert(progress);
bool result = false;
InfraredProgressViewModel* model = view_get_model(progress->view);
if(model->progress < model->progress_total) {
++model->progress;
result = model->progress < model->progress_total;
}
view_commit_model(progress->view, true);
return result;
}
static void infrared_progress_view_draw_callback(Canvas* canvas, void* _model) {
InfraredProgressViewModel* model = (InfraredProgressViewModel*)_model;
uint8_t x = 0;
uint8_t y = 36;
uint8_t width = 63;
uint8_t height = 59;
elements_bold_rounded_frame(canvas, x, y, width, height);
canvas_set_font(canvas, FontSecondary);
elements_multiline_text_aligned(
canvas, x + 34, y + 9, AlignCenter, AlignCenter, "Sending ...");
float progress_value = (float)model->progress / model->progress_total;
elements_progress_bar(canvas, x + 4, y + 19, width - 7, progress_value);
uint8_t percent_value = 100 * model->progress / model->progress_total;
char percents_string[10] = {0};
snprintf(percents_string, sizeof(percents_string), "%d%%", percent_value);
elements_multiline_text_aligned(
canvas, x + 33, y + 37, AlignCenter, AlignCenter, percents_string);
canvas_draw_icon(canvas, x + 14, y + height - 14, &I_Pin_back_arrow_10x8);
canvas_draw_str(canvas, x + 30, y + height - 6, "= stop");
}
void infrared_progress_view_set_progress_total(
InfraredProgressView* progress,
uint16_t progress_total) {
furi_assert(progress);
InfraredProgressViewModel* model = view_get_model(progress->view);
model->progress = 0;
model->progress_total = progress_total;
view_commit_model(progress->view, false);
}
bool infrared_progress_view_input_callback(InputEvent* event, void* context) {
InfraredProgressView* instance = context;
if((event->type == InputTypeShort) && (event->key == InputKeyBack)) {
if(instance->back_callback) {
instance->back_callback(instance->context);
}
}
return true;
}
InfraredProgressView* infrared_progress_view_alloc(void) {
InfraredProgressView* instance = malloc(sizeof(InfraredProgressView));
instance->view = view_alloc();
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(InfraredProgressViewModel));
InfraredProgressViewModel* model = view_get_model(instance->view);
model->progress = 0;
model->progress_total = 0;
view_commit_model(instance->view, false);
view_set_draw_callback(instance->view, infrared_progress_view_draw_callback);
view_set_input_callback(instance->view, infrared_progress_view_input_callback);
view_set_context(instance->view, instance);
return instance;
}
void infrared_progress_view_free(InfraredProgressView* progress) {
view_free(progress->view);
free(progress);
}
void infrared_progress_view_set_back_callback(
InfraredProgressView* instance,
InfraredProgressViewBackCallback callback,
void* context) {
furi_assert(instance);
instance->back_callback = callback;
instance->context = context;
}
View* infrared_progress_view_get_view(InfraredProgressView* instance) {
furi_assert(instance);
furi_assert(instance->view);
return instance->view;
}