[FL-2284] IR: Show universal remote loading (#1004)
* [FL-2131] IR: Show universal remote loading * Remove unused hal rtc. Gui: cleanup loading module. Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -1,84 +0,0 @@
|
||||
#include "furi_hal_resources.h"
|
||||
#include "assets_icons.h"
|
||||
#include "gui/canvas.h"
|
||||
#include "gui/view.h"
|
||||
#include "input/input.h"
|
||||
#include <gui/elements.h>
|
||||
#include <furi.h>
|
||||
#include "irda_app_brut_view.h"
|
||||
#include "gui/modules/button_panel.h"
|
||||
#include <stdint.h>
|
||||
|
||||
struct IrdaAppPopupBrut {
|
||||
uint16_t progress;
|
||||
uint16_t progress_max;
|
||||
char percents_string_storage[8];
|
||||
};
|
||||
|
||||
bool popup_brut_increase_progress(IrdaAppPopupBrut* popup_brut) {
|
||||
furi_assert(popup_brut);
|
||||
|
||||
if(popup_brut->progress < popup_brut->progress_max)
|
||||
++popup_brut->progress;
|
||||
else
|
||||
furi_assert(0);
|
||||
|
||||
return popup_brut->progress < popup_brut->progress_max;
|
||||
}
|
||||
|
||||
void popup_brut_draw_callback(Canvas* canvas, void* context) {
|
||||
furi_assert(canvas);
|
||||
furi_assert(context);
|
||||
IrdaAppPopupBrut* popup_brut = (IrdaAppPopupBrut*)context;
|
||||
uint8_t x = 0;
|
||||
uint8_t width = 64;
|
||||
uint8_t x_max = x + width - 1;
|
||||
uint8_t y = 36;
|
||||
uint8_t height = 59;
|
||||
uint8_t y_max = y + height - 1;
|
||||
|
||||
canvas_invert_color(canvas);
|
||||
canvas_draw_rbox(canvas, x + 1, y + 1, width - 2, height - 2, 3);
|
||||
canvas_invert_color(canvas);
|
||||
canvas_draw_rframe(canvas, x, y, width, height, 3);
|
||||
canvas_draw_rframe(canvas, x + 1, y + 1, width - 2, height - 2, 3);
|
||||
canvas_draw_line(canvas, x + 2, y + 1, x + 2, y + 3);
|
||||
canvas_draw_line(canvas, x + 1, y + 2, x + 3, y + 2);
|
||||
canvas_draw_line(canvas, x_max - 2, y + 1, x_max - 2, y + 3);
|
||||
canvas_draw_line(canvas, x_max - 1, y + 2, x_max - 3, y + 2);
|
||||
canvas_draw_line(canvas, x + 2, y_max - 1, x + 2, y_max - 3);
|
||||
canvas_draw_line(canvas, x + 1, y_max - 2, x + 3, y_max - 2);
|
||||
canvas_draw_line(canvas, x_max - 2, y_max - 1, x_max - 2, y_max - 3);
|
||||
canvas_draw_line(canvas, x_max - 1, y_max - 2, x_max - 3, y_max - 2);
|
||||
|
||||
elements_progress_bar(
|
||||
canvas, x + 4, y + 19, x_max - 7, popup_brut->progress, popup_brut->progress_max);
|
||||
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str(canvas, x + 15, y + 12, "Sending ...");
|
||||
canvas_draw_icon(canvas, x + 11, y_max - 14, &I_Back_15x10);
|
||||
|
||||
uint8_t percent_value = 100 * popup_brut->progress / popup_brut->progress_max;
|
||||
snprintf(
|
||||
popup_brut->percents_string_storage,
|
||||
sizeof(popup_brut->percents_string_storage),
|
||||
"%d%%",
|
||||
percent_value);
|
||||
elements_multiline_text_aligned(
|
||||
canvas, x + 32, y + 40, AlignCenter, AlignBottom, popup_brut->percents_string_storage);
|
||||
canvas_draw_str(canvas, x + 30, y_max - 5, "= stop");
|
||||
}
|
||||
|
||||
void popup_brut_set_progress_max(IrdaAppPopupBrut* popup_brut, uint16_t progress_max) {
|
||||
furi_assert(popup_brut);
|
||||
popup_brut->progress = 0;
|
||||
popup_brut->progress_max = progress_max;
|
||||
}
|
||||
|
||||
IrdaAppPopupBrut* popup_brut_alloc(void) {
|
||||
return (IrdaAppPopupBrut*)malloc(sizeof(IrdaAppPopupBrut));
|
||||
}
|
||||
|
||||
void popup_brut_free(IrdaAppPopupBrut* popup_brut) {
|
||||
free(popup_brut);
|
||||
}
|
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
#include <gui/view.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct IrdaAppPopupBrut IrdaAppPopupBrut;
|
||||
|
||||
bool popup_brut_increase_progress(IrdaAppPopupBrut* popup_brut);
|
||||
IrdaAppPopupBrut* popup_brut_alloc();
|
||||
void popup_brut_free(IrdaAppPopupBrut* popup_brut);
|
||||
void popup_brut_draw_callback(Canvas* canvas, void* model);
|
||||
void popup_brut_set_progress_max(IrdaAppPopupBrut* popup_brut, uint16_t progress_max);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
119
applications/irda/view/irda_progress_view.c
Normal file
119
applications/irda/view/irda_progress_view.c
Normal file
@@ -0,0 +1,119 @@
|
||||
#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 "irda_progress_view.h"
|
||||
#include "gui/modules/button_panel.h"
|
||||
#include <stdint.h>
|
||||
|
||||
struct IrdaProgressView {
|
||||
View* view;
|
||||
IrdaProgressViewBackCallback back_callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
size_t progress;
|
||||
size_t progress_total;
|
||||
} IrdaProgressViewModel;
|
||||
|
||||
bool irda_progress_view_increase_progress(IrdaProgressView* progress) {
|
||||
furi_assert(progress);
|
||||
bool result = false;
|
||||
|
||||
IrdaProgressViewModel* 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 irda_progress_view_draw_callback(Canvas* canvas, void* _model) {
|
||||
IrdaProgressViewModel* model = (IrdaProgressViewModel*)_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 + 11, y + height - 15, &I_Back_15x10);
|
||||
canvas_draw_str(canvas, x + 30, y + height - 6, "= stop");
|
||||
}
|
||||
|
||||
void irda_progress_view_set_progress_total(IrdaProgressView* progress, uint16_t progress_total) {
|
||||
furi_assert(progress);
|
||||
IrdaProgressViewModel* model = view_get_model(progress->view);
|
||||
model->progress = 0;
|
||||
model->progress_total = progress_total;
|
||||
view_commit_model(progress->view, false);
|
||||
}
|
||||
|
||||
bool irda_progress_view_input_callback(InputEvent* event, void* context) {
|
||||
IrdaProgressView* instance = context;
|
||||
|
||||
if((event->type == InputTypeShort) && (event->key == InputKeyBack)) {
|
||||
if(instance->back_callback) {
|
||||
instance->back_callback(instance->context);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
IrdaProgressView* irda_progress_view_alloc(void) {
|
||||
IrdaProgressView* instance = malloc(sizeof(IrdaProgressView));
|
||||
instance->view = view_alloc();
|
||||
view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(IrdaProgressViewModel));
|
||||
IrdaProgressViewModel* 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, irda_progress_view_draw_callback);
|
||||
view_set_input_callback(instance->view, irda_progress_view_input_callback);
|
||||
view_set_context(instance->view, instance);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void irda_progress_view_free(IrdaProgressView* progress) {
|
||||
view_free(progress->view);
|
||||
free(progress);
|
||||
}
|
||||
|
||||
void irda_progress_view_set_back_callback(
|
||||
IrdaProgressView* instance,
|
||||
IrdaProgressViewBackCallback callback,
|
||||
void* context) {
|
||||
furi_assert(instance);
|
||||
instance->back_callback = callback;
|
||||
instance->context = context;
|
||||
}
|
||||
|
||||
View* irda_progress_view_get_view(IrdaProgressView* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(instance->view);
|
||||
return instance->view;
|
||||
}
|
25
applications/irda/view/irda_progress_view.h
Normal file
25
applications/irda/view/irda_progress_view.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include <gui/view.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct IrdaProgressView IrdaProgressView;
|
||||
|
||||
typedef void (*IrdaProgressViewBackCallback)(void*);
|
||||
|
||||
IrdaProgressView* irda_progress_view_alloc();
|
||||
void irda_progress_view_free(IrdaProgressView* progress);
|
||||
View* irda_progress_view_get_view(IrdaProgressView* progress);
|
||||
|
||||
bool irda_progress_view_increase_progress(IrdaProgressView* progress);
|
||||
void irda_progress_view_set_progress_total(IrdaProgressView* progress, uint16_t progress_max);
|
||||
void irda_progress_view_set_back_callback(
|
||||
IrdaProgressView* instance,
|
||||
IrdaProgressViewBackCallback callback,
|
||||
void* context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user