[FL-3656] Fix crash when exiting write mode (#3191)

This commit is contained in:
Georgii Surkov 2023-11-02 16:10:16 +03:00 committed by GitHub
parent 47cc05dab4
commit 0131eb3aa2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 9 deletions

View file

@ -1,6 +1,6 @@
#pragma once
enum iButtonCustomEvent {
typedef enum {
// Reserve first 100 events for button types and indexes, starting from 0
iButtonCustomEventReserved = 100,
@ -10,8 +10,12 @@ enum iButtonCustomEvent {
iButtonCustomEventByteEditResult,
iButtonCustomEventWorkerEmulated,
iButtonCustomEventWorkerRead,
iButtonCustomEventWorkerWriteOK,
iButtonCustomEventWorkerWriteSameKey,
iButtonCustomEventWorkerWriteNoDetect,
iButtonCustomEventWorkerWriteCannotWrite,
iButtonCustomEventRpcLoad,
iButtonCustomEventRpcExit,
iButtonCustomEventRpcSessionClose,
};
} iButtonCustomEvent;

View file

@ -5,9 +5,26 @@ typedef enum {
iButtonSceneWriteStateBlinkYellow,
} iButtonSceneWriteState;
static inline iButtonCustomEvent
ibutton_scene_write_to_custom_event(iButtonWorkerWriteResult result) {
switch(result) {
case iButtonWorkerWriteOK:
return iButtonCustomEventWorkerWriteOK;
case iButtonWorkerWriteSameKey:
return iButtonCustomEventWorkerWriteSameKey;
case iButtonWorkerWriteNoDetect:
return iButtonCustomEventWorkerWriteNoDetect;
case iButtonWorkerWriteCannotWrite:
return iButtonCustomEventWorkerWriteCannotWrite;
default:
furi_crash();
}
}
static void ibutton_scene_write_callback(void* context, iButtonWorkerWriteResult result) {
iButton* ibutton = context;
view_dispatcher_send_custom_event(ibutton->view_dispatcher, result);
view_dispatcher_send_custom_event(
ibutton->view_dispatcher, ibutton_scene_write_to_custom_event(result));
}
void ibutton_scene_write_on_enter(void* context) {
@ -61,16 +78,14 @@ bool ibutton_scene_write_on_event(void* context, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
if((event.event == iButtonWorkerWriteOK) || (event.event == iButtonWorkerWriteSameKey)) {
if((event.event == iButtonCustomEventWorkerWriteOK) ||
(event.event == iButtonCustomEventWorkerWriteSameKey)) {
scene_manager_next_scene(scene_manager, iButtonSceneWriteSuccess);
} else if(event.event == iButtonWorkerWriteNoDetect) {
} else if(event.event == iButtonCustomEventWorkerWriteNoDetect) {
ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateBlink);
} else if(event.event == iButtonWorkerWriteCannotWrite) {
} else if(event.event == iButtonCustomEventWorkerWriteCannotWrite) {
ibutton_notification_message(ibutton, iButtonNotificationMessageYellowBlink);
}
} else if(event.type == SceneManagerEventTypeTick) {
consumed = true;
}
return consumed;