2023-02-07 16:33:05 +00:00
|
|
|
#include "infrared_progress_view.h"
|
|
|
|
|
|
|
|
#include <assets_icons.h>
|
|
|
|
#include <gui/canvas.h>
|
|
|
|
#include <gui/view.h>
|
2022-02-24 11:59:36 +00:00
|
|
|
#include <gui/elements.h>
|
2023-02-07 16:33:05 +00:00
|
|
|
#include <gui/modules/button_panel.h>
|
|
|
|
#include <input/input.h>
|
|
|
|
|
2022-02-24 11:59:36 +00:00
|
|
|
#include <furi.h>
|
2023-02-07 16:33:05 +00:00
|
|
|
#include <furi_hal_resources.h>
|
|
|
|
#include <core/check.h>
|
2022-02-24 11:59:36 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
struct InfraredProgressView {
|
2022-02-24 11:59:36 +00:00
|
|
|
View* view;
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredProgressViewBackCallback back_callback;
|
2022-02-24 11:59:36 +00:00
|
|
|
void* context;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
size_t progress;
|
|
|
|
size_t progress_total;
|
2022-02-25 15:22:58 +00:00
|
|
|
} InfraredProgressViewModel;
|
2022-02-24 11:59:36 +00:00
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
bool infrared_progress_view_increase_progress(InfraredProgressView* progress) {
|
2022-02-24 11:59:36 +00:00
|
|
|
furi_assert(progress);
|
|
|
|
bool result = false;
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredProgressViewModel* model = view_get_model(progress->view);
|
2022-02-24 11:59:36 +00:00
|
|
|
if(model->progress < model->progress_total) {
|
|
|
|
++model->progress;
|
|
|
|
result = model->progress < model->progress_total;
|
|
|
|
}
|
|
|
|
view_commit_model(progress->view, true);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
static void infrared_progress_view_draw_callback(Canvas* canvas, void* _model) {
|
|
|
|
InfraredProgressViewModel* model = (InfraredProgressViewModel*)_model;
|
2022-02-24 11:59:36 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2022-05-19 16:07:45 +00:00
|
|
|
canvas_draw_icon(canvas, x + 14, y + height - 14, &I_Pin_back_arrow_10x8);
|
2022-02-24 11:59:36 +00:00
|
|
|
canvas_draw_str(canvas, x + 30, y + height - 6, "= stop");
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void infrared_progress_view_set_progress_total(
|
|
|
|
InfraredProgressView* progress,
|
|
|
|
uint16_t progress_total) {
|
2022-02-24 11:59:36 +00:00
|
|
|
furi_assert(progress);
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredProgressViewModel* model = view_get_model(progress->view);
|
2022-02-24 11:59:36 +00:00
|
|
|
model->progress = 0;
|
|
|
|
model->progress_total = progress_total;
|
|
|
|
view_commit_model(progress->view, false);
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
bool infrared_progress_view_input_callback(InputEvent* event, void* context) {
|
|
|
|
InfraredProgressView* instance = context;
|
2022-02-24 11:59:36 +00:00
|
|
|
|
|
|
|
if((event->type == InputTypeShort) && (event->key == InputKeyBack)) {
|
|
|
|
if(instance->back_callback) {
|
|
|
|
instance->back_callback(instance->context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
InfraredProgressView* infrared_progress_view_alloc(void) {
|
|
|
|
InfraredProgressView* instance = malloc(sizeof(InfraredProgressView));
|
2022-02-24 11:59:36 +00:00
|
|
|
instance->view = view_alloc();
|
2022-02-25 15:22:58 +00:00
|
|
|
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(InfraredProgressViewModel));
|
|
|
|
InfraredProgressViewModel* model = view_get_model(instance->view);
|
2022-02-24 11:59:36 +00:00
|
|
|
model->progress = 0;
|
|
|
|
model->progress_total = 0;
|
|
|
|
view_commit_model(instance->view, false);
|
2022-02-25 15:22:58 +00:00
|
|
|
view_set_draw_callback(instance->view, infrared_progress_view_draw_callback);
|
|
|
|
view_set_input_callback(instance->view, infrared_progress_view_input_callback);
|
2022-02-24 11:59:36 +00:00
|
|
|
view_set_context(instance->view, instance);
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void infrared_progress_view_free(InfraredProgressView* progress) {
|
2022-02-24 11:59:36 +00:00
|
|
|
view_free(progress->view);
|
|
|
|
free(progress);
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
void infrared_progress_view_set_back_callback(
|
|
|
|
InfraredProgressView* instance,
|
|
|
|
InfraredProgressViewBackCallback callback,
|
2022-02-24 11:59:36 +00:00
|
|
|
void* context) {
|
|
|
|
furi_assert(instance);
|
|
|
|
instance->back_callback = callback;
|
|
|
|
instance->context = context;
|
|
|
|
}
|
|
|
|
|
2022-02-25 15:22:58 +00:00
|
|
|
View* infrared_progress_view_get_view(InfraredProgressView* instance) {
|
2022-02-24 11:59:36 +00:00
|
|
|
furi_assert(instance);
|
|
|
|
furi_assert(instance->view);
|
|
|
|
return instance->view;
|
|
|
|
}
|