2023-02-07 15:35:49 +00:00
|
|
|
#include <furi.h>
|
|
|
|
#include <furi_hal.h>
|
|
|
|
#include <flipper.h>
|
|
|
|
#include <alt_boot.h>
|
|
|
|
#include <assets_icons.h>
|
2023-03-22 17:00:48 +00:00
|
|
|
#include <toolbox/compress.h>
|
2023-04-06 03:36:12 +00:00
|
|
|
#include <gui/canvas.h>
|
|
|
|
#include <gui/canvas_i.h>
|
2023-02-07 15:35:49 +00:00
|
|
|
|
2023-03-02 11:56:23 +00:00
|
|
|
#define COUNTER_VALUE (136U)
|
2023-02-07 15:35:49 +00:00
|
|
|
|
2023-04-06 03:36:12 +00:00
|
|
|
static void flipper_boot_recovery_draw_progress(Canvas* canvas, size_t progress) {
|
2023-02-07 15:35:49 +00:00
|
|
|
if(progress < COUNTER_VALUE) {
|
2023-03-02 11:56:23 +00:00
|
|
|
// Fill the progress bar while the progress is going down
|
2023-04-06 03:36:12 +00:00
|
|
|
canvas_draw_rframe(canvas, 59, 41, 69, 8, 2);
|
2023-03-02 11:56:23 +00:00
|
|
|
size_t width = (COUNTER_VALUE - progress) * 68 / COUNTER_VALUE;
|
2023-04-06 03:36:12 +00:00
|
|
|
canvas_draw_box(canvas, 60, 42, width, 6);
|
2023-03-02 11:56:23 +00:00
|
|
|
} else {
|
2023-04-06 03:36:12 +00:00
|
|
|
canvas_draw_rframe(canvas, 59, 41, 69, 8, 2);
|
|
|
|
canvas_set_color(canvas, ColorWhite);
|
|
|
|
canvas_draw_box(canvas, 60, 42, 67, 6);
|
|
|
|
canvas_set_color(canvas, ColorBlack);
|
2023-02-07 15:35:49 +00:00
|
|
|
}
|
|
|
|
|
2023-04-06 03:36:12 +00:00
|
|
|
canvas_commit(canvas);
|
2023-02-07 15:35:49 +00:00
|
|
|
}
|
|
|
|
|
2023-04-06 03:36:12 +00:00
|
|
|
void flipper_boot_recovery_draw_splash(Canvas* canvas) {
|
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
canvas_set_font(canvas, FontPrimary);
|
|
|
|
|
|
|
|
canvas_draw_icon(canvas, 0, 0, &I_Erase_pin_128x64);
|
2023-02-07 15:35:49 +00:00
|
|
|
|
2023-04-06 03:36:12 +00:00
|
|
|
canvas_commit(canvas);
|
|
|
|
}
|
2023-03-02 11:56:23 +00:00
|
|
|
|
2023-04-06 03:36:12 +00:00
|
|
|
void flipper_boot_recovery_exec() {
|
|
|
|
Canvas* canvas = canvas_init();
|
2023-03-02 11:56:23 +00:00
|
|
|
|
2023-04-06 03:36:12 +00:00
|
|
|
// Show recovery splashscreen
|
|
|
|
flipper_boot_recovery_draw_splash(canvas);
|
2023-03-02 11:56:23 +00:00
|
|
|
|
2023-02-07 15:35:49 +00:00
|
|
|
size_t counter = COUNTER_VALUE;
|
|
|
|
while(counter) {
|
|
|
|
if(!furi_hal_gpio_read(&gpio_button_down)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!furi_hal_gpio_read(&gpio_button_right)) {
|
|
|
|
counter--;
|
|
|
|
} else {
|
|
|
|
counter = COUNTER_VALUE;
|
|
|
|
}
|
|
|
|
|
2023-04-06 03:36:12 +00:00
|
|
|
flipper_boot_recovery_draw_progress(canvas, counter);
|
2023-02-07 15:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!counter) {
|
|
|
|
furi_hal_rtc_set_flag(FuriHalRtcFlagFactoryReset);
|
|
|
|
furi_hal_rtc_set_pin_fails(0);
|
|
|
|
furi_hal_rtc_reset_flag(FuriHalRtcFlagLock);
|
|
|
|
}
|
2023-02-07 16:33:05 +00:00
|
|
|
}
|