mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 20:38:36 -07:00
Merge branch 'dev' of https://github.com/flipperdevices/flipperzero-firmware into mntm-dev
This commit is contained in:
@@ -72,16 +72,19 @@ bool bt_keys_storage_load(BtKeysStorage* instance) {
|
||||
bool loaded = false;
|
||||
do {
|
||||
// Get payload size
|
||||
uint8_t magic = 0, version = 0;
|
||||
size_t payload_size = 0;
|
||||
if(!saved_struct_get_payload_size(
|
||||
furi_string_get_cstr(instance->file_path),
|
||||
BT_KEYS_STORAGE_MAGIC,
|
||||
BT_KEYS_STORAGE_VERSION,
|
||||
&payload_size)) {
|
||||
if(!saved_struct_get_metadata(
|
||||
furi_string_get_cstr(instance->file_path), &magic, &version, &payload_size)) {
|
||||
FURI_LOG_E(TAG, "Failed to read payload size");
|
||||
break;
|
||||
}
|
||||
|
||||
if(magic != BT_KEYS_STORAGE_MAGIC || version != BT_KEYS_STORAGE_VERSION) {
|
||||
FURI_LOG_E(TAG, "Saved data version is mismatched");
|
||||
break;
|
||||
}
|
||||
|
||||
if(payload_size > instance->nvm_sram_buff_size) {
|
||||
FURI_LOG_E(TAG, "Saved data doesn't fit ram buffer");
|
||||
break;
|
||||
|
||||
@@ -14,7 +14,7 @@ bool bt_settings_load(BtSettings* bt_settings) {
|
||||
BT_SETTINGS_PATH, bt_settings, sizeof(BtSettings), BT_SETTINGS_MAGIC, BT_SETTINGS_VERSION);
|
||||
}
|
||||
|
||||
bool bt_settings_save(BtSettings* bt_settings) {
|
||||
bool bt_settings_save(const BtSettings* bt_settings) {
|
||||
furi_assert(bt_settings);
|
||||
|
||||
return saved_struct_save(
|
||||
|
||||
@@ -15,7 +15,7 @@ typedef struct {
|
||||
|
||||
bool bt_settings_load(BtSettings* bt_settings);
|
||||
|
||||
bool bt_settings_save(BtSettings* bt_settings);
|
||||
bool bt_settings_save(const BtSettings* bt_settings);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
typedef struct {
|
||||
FuriTimer* timer;
|
||||
FuriString* enter_pin_string;
|
||||
} DesktopScenePinInputState;
|
||||
|
||||
static void desktop_scene_locked_light_red(bool value) {
|
||||
@@ -77,6 +78,18 @@ static void desktop_scene_pin_input_timer_callback(void* context) {
|
||||
desktop->view_dispatcher, DesktopPinInputEventResetWrongPinLabel);
|
||||
}
|
||||
|
||||
static void
|
||||
desktop_scene_pin_input_update_wrong_count(DesktopScenePinInputState* state, Desktop* desktop) {
|
||||
uint32_t attempts = furi_hal_rtc_get_pin_fails();
|
||||
if(attempts > 0) {
|
||||
furi_string_printf(state->enter_pin_string, "Wrong Attempts: %lu", attempts);
|
||||
desktop_view_pin_input_set_label_tertiary(
|
||||
desktop->pin_input_view, 64, 60, furi_string_get_cstr(state->enter_pin_string));
|
||||
} else {
|
||||
desktop_view_pin_input_set_label_tertiary(desktop->pin_input_view, 64, 60, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void desktop_scene_pin_input_on_enter(void* context) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
|
||||
@@ -89,6 +102,7 @@ void desktop_scene_pin_input_on_enter(void* context) {
|
||||
desktop->pin_input_view, desktop_scene_pin_input_done_callback);
|
||||
|
||||
DesktopScenePinInputState* state = malloc(sizeof(DesktopScenePinInputState));
|
||||
state->enter_pin_string = furi_string_alloc();
|
||||
state->timer =
|
||||
furi_timer_alloc(desktop_scene_pin_input_timer_callback, FuriTimerTypeOnce, desktop);
|
||||
scene_manager_set_scene_state(desktop->scene_manager, DesktopScenePinInput, (uint32_t)state);
|
||||
@@ -96,6 +110,7 @@ void desktop_scene_pin_input_on_enter(void* context) {
|
||||
desktop_view_pin_input_hide_pin(desktop->pin_input_view, true);
|
||||
desktop_view_pin_input_set_label_button(desktop->pin_input_view, "OK");
|
||||
desktop_view_pin_input_set_label_secondary(desktop->pin_input_view, 44, 25, "Enter PIN:");
|
||||
desktop_scene_pin_input_update_wrong_count(state, desktop);
|
||||
desktop_view_pin_input_set_pin_position(desktop->pin_input_view, 64, 37);
|
||||
desktop_view_pin_input_reset_pin(desktop->pin_input_view);
|
||||
|
||||
@@ -106,7 +121,8 @@ bool desktop_scene_pin_input_on_event(void* context, SceneManagerEvent event) {
|
||||
Desktop* desktop = (Desktop*)context;
|
||||
bool consumed = false;
|
||||
uint32_t pin_timeout = 0;
|
||||
|
||||
DesktopScenePinInputState* state = (DesktopScenePinInputState*)scene_manager_get_scene_state(
|
||||
desktop->scene_manager, DesktopScenePinInput);
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
switch(event.event) {
|
||||
case DesktopPinInputEventUnlockFailed:
|
||||
@@ -122,6 +138,7 @@ bool desktop_scene_pin_input_on_event(void* context, SceneManagerEvent event) {
|
||||
desktop_view_pin_input_set_label_secondary(
|
||||
desktop->pin_input_view, 25, 25, "Wrong PIN try again:");
|
||||
desktop_scene_pin_input_set_timer(desktop, true, WRONG_PIN_HEADER_TIMEOUT);
|
||||
desktop_scene_pin_input_update_wrong_count(state, desktop);
|
||||
desktop_view_pin_input_reset_pin(desktop->pin_input_view);
|
||||
}
|
||||
consumed = true;
|
||||
@@ -131,6 +148,7 @@ bool desktop_scene_pin_input_on_event(void* context, SceneManagerEvent event) {
|
||||
desktop_view_pin_input_set_label_primary(desktop->pin_input_view, 0, 0, NULL);
|
||||
desktop_view_pin_input_set_label_secondary(
|
||||
desktop->pin_input_view, 44, 25, "Enter PIN:");
|
||||
desktop_scene_pin_input_update_wrong_count(state, desktop);
|
||||
consumed = true;
|
||||
break;
|
||||
case DesktopPinInputEventUnlocked:
|
||||
@@ -158,5 +176,6 @@ void desktop_scene_pin_input_on_exit(void* context) {
|
||||
desktop->scene_manager, DesktopScenePinInput);
|
||||
|
||||
furi_timer_free(state->timer);
|
||||
furi_string_free(state->enter_pin_string);
|
||||
free(state);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,9 @@ typedef struct {
|
||||
const char* secondary_str;
|
||||
uint8_t secondary_str_x;
|
||||
uint8_t secondary_str_y;
|
||||
const char* tertiary_str;
|
||||
uint8_t tertiary_str_x;
|
||||
uint8_t tertiary_str_y;
|
||||
const char* button_label;
|
||||
} DesktopViewPinInputModel;
|
||||
|
||||
@@ -167,6 +170,17 @@ static void desktop_view_pin_input_draw(Canvas* canvas, void* context) {
|
||||
canvas_draw_str(
|
||||
canvas, model->secondary_str_x, model->secondary_str_y, model->secondary_str);
|
||||
}
|
||||
|
||||
if(model->tertiary_str && model->pin.length == 0) {
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str_aligned(
|
||||
canvas,
|
||||
model->tertiary_str_x,
|
||||
model->tertiary_str_y,
|
||||
AlignCenter,
|
||||
AlignBottom,
|
||||
model->tertiary_str);
|
||||
}
|
||||
}
|
||||
|
||||
void desktop_view_pin_input_timer_callback(void* context) {
|
||||
@@ -294,6 +308,20 @@ void desktop_view_pin_input_set_label_secondary(
|
||||
view_commit_model(pin_input->view, true);
|
||||
}
|
||||
|
||||
void desktop_view_pin_input_set_label_tertiary(
|
||||
DesktopViewPinInput* pin_input,
|
||||
uint8_t x,
|
||||
uint8_t y,
|
||||
const char* label) {
|
||||
furi_assert(pin_input);
|
||||
|
||||
DesktopViewPinInputModel* model = view_get_model(pin_input->view);
|
||||
model->tertiary_str = label;
|
||||
model->tertiary_str_x = x;
|
||||
model->tertiary_str_y = y;
|
||||
view_commit_model(pin_input->view, true);
|
||||
}
|
||||
|
||||
void desktop_view_pin_input_set_pin_position(DesktopViewPinInput* pin_input, uint8_t x, uint8_t y) {
|
||||
furi_assert(pin_input);
|
||||
|
||||
|
||||
@@ -24,6 +24,11 @@ void desktop_view_pin_input_set_label_secondary(
|
||||
uint8_t x,
|
||||
uint8_t y,
|
||||
const char* label);
|
||||
void desktop_view_pin_input_set_label_tertiary(
|
||||
DesktopViewPinInput* pin_input,
|
||||
uint8_t x,
|
||||
uint8_t y,
|
||||
const char* label);
|
||||
void desktop_view_pin_input_set_pin_position(DesktopViewPinInput* pin_input, uint8_t x, uint8_t y);
|
||||
View* desktop_view_pin_input_get_view(DesktopViewPinInput*);
|
||||
void desktop_view_pin_input_set_done_callback(
|
||||
|
||||
@@ -18,7 +18,7 @@ bool expansion_settings_load(ExpansionSettings* settings) {
|
||||
EXPANSION_SETTINGS_VERSION);
|
||||
}
|
||||
|
||||
bool expansion_settings_save(ExpansionSettings* settings) {
|
||||
bool expansion_settings_save(const ExpansionSettings* settings) {
|
||||
furi_assert(settings);
|
||||
return saved_struct_save(
|
||||
EXPANSION_SETTINGS_PATH,
|
||||
|
||||
@@ -36,7 +36,7 @@ bool expansion_settings_load(ExpansionSettings* settings);
|
||||
* @param[in] settings pointer to an ExpansionSettings instance to save settings from.
|
||||
* @returns true if the settings were successfully saved, false otherwise.
|
||||
*/
|
||||
bool expansion_settings_save(ExpansionSettings* settings);
|
||||
bool expansion_settings_save(const ExpansionSettings* settings);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ static void text_box_insert_endline(Canvas* canvas, TextBoxModel* model) {
|
||||
line_num++;
|
||||
model->text = furi_string_get_cstr(model->text_formatted);
|
||||
model->text_pos = (char*)model->text;
|
||||
uint8_t lines_on_screen = 56 / canvas_current_font_height(canvas);
|
||||
size_t lines_on_screen = 56 / canvas_current_font_height(canvas);
|
||||
if(model->focus == TextBoxFocusEnd && line_num > lines_on_screen) {
|
||||
// Set text position to 5th line from the end
|
||||
const char* end = model->text + furi_string_size(model->text_formatted);
|
||||
|
||||
@@ -151,7 +151,7 @@ void power_draw_battery_callback(Canvas* canvas, void* context) {
|
||||
}
|
||||
|
||||
if(power->state == PowerStateCharging) {
|
||||
canvas_set_bitmap_mode(canvas, 1);
|
||||
canvas_set_bitmap_mode(canvas, true);
|
||||
// TODO: replace -1 magic for uint8_t with re-framing
|
||||
if(battery_icon == BatteryIconPercent) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
@@ -234,7 +234,7 @@ void power_draw_battery_callback(Canvas* canvas, void* context) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_icon(canvas, 8, -1, &I_Charging_lightning_9x10);
|
||||
}
|
||||
canvas_set_bitmap_mode(canvas, 0);
|
||||
canvas_set_bitmap_mode(canvas, false);
|
||||
}
|
||||
} else {
|
||||
canvas_draw_box(canvas, 8, 3, 8, 2);
|
||||
|
||||
Reference in New Issue
Block a user