2022-05-06 16:48:39 +00:00
|
|
|
#include "../ibutton_i.h"
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
iButtonSceneWriteStateDefault,
|
|
|
|
iButtonSceneWriteStateBlinkYellow,
|
|
|
|
} iButtonSceneWriteState;
|
|
|
|
|
|
|
|
static void ibutton_scene_write_callback(void* context, iButtonWorkerWriteResult result) {
|
|
|
|
iButton* ibutton = context;
|
|
|
|
view_dispatcher_send_custom_event(ibutton->view_dispatcher, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ibutton_scene_write_on_enter(void* context) {
|
|
|
|
iButton* ibutton = context;
|
2023-03-02 13:23:33 +00:00
|
|
|
furi_assert(ibutton->write_mode != iButtonWriteModeInvalid);
|
|
|
|
|
2022-05-06 16:48:39 +00:00
|
|
|
iButtonKey* key = ibutton->key;
|
2023-03-02 13:23:33 +00:00
|
|
|
iButtonWorker* worker = ibutton->worker;
|
|
|
|
const iButtonProtocolId protocol_id = ibutton_key_get_protocol_id(key);
|
2022-05-06 16:48:39 +00:00
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
Widget* widget = ibutton->widget;
|
|
|
|
FuriString* tmp = furi_string_alloc();
|
2022-05-27 11:19:21 +00:00
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
widget_add_icon_element(widget, 3, 10, &I_iButtonKey_49x44);
|
2022-05-06 16:48:39 +00:00
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
furi_string_printf(
|
|
|
|
tmp,
|
|
|
|
"%s\n[%s]",
|
|
|
|
ibutton->key_name,
|
|
|
|
ibutton_protocols_get_name(ibutton->protocols, protocol_id));
|
2022-05-06 16:48:39 +00:00
|
|
|
|
2022-09-30 12:56:12 +00:00
|
|
|
widget_add_text_box_element(
|
2023-03-02 13:23:33 +00:00
|
|
|
widget, 52, 38, 75, 26, AlignCenter, AlignCenter, furi_string_get_cstr(tmp), true);
|
2022-05-06 16:48:39 +00:00
|
|
|
|
|
|
|
ibutton_worker_write_set_callback(worker, ibutton_scene_write_callback, ibutton);
|
2022-05-27 11:19:21 +00:00
|
|
|
|
2023-03-02 13:23:33 +00:00
|
|
|
furi_string_set(tmp, "iButton\nwriting ");
|
|
|
|
|
|
|
|
if(ibutton->write_mode == iButtonWriteModeBlank) {
|
|
|
|
furi_string_cat(tmp, "Blank");
|
|
|
|
ibutton_worker_write_blank_start(worker, key);
|
|
|
|
|
|
|
|
} else if(ibutton->write_mode == iButtonWriteModeCopy) {
|
|
|
|
furi_string_cat(tmp, "Copy");
|
|
|
|
ibutton_worker_write_copy_start(worker, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
widget_add_string_multiline_element(
|
|
|
|
widget, 88, 10, AlignCenter, AlignTop, FontPrimary, furi_string_get_cstr(tmp));
|
2022-06-13 01:08:28 +00:00
|
|
|
|
|
|
|
ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateStart);
|
2023-03-02 13:23:33 +00:00
|
|
|
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
|
|
|
|
|
|
|
|
furi_string_free(tmp);
|
2022-05-06 16:48:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ibutton_scene_write_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
iButton* ibutton = context;
|
|
|
|
SceneManager* scene_manager = ibutton->scene_manager;
|
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
consumed = true;
|
|
|
|
if((event.event == iButtonWorkerWriteOK) || (event.event == iButtonWorkerWriteSameKey)) {
|
|
|
|
scene_manager_next_scene(scene_manager, iButtonSceneWriteSuccess);
|
|
|
|
} else if(event.event == iButtonWorkerWriteNoDetect) {
|
2022-06-13 01:08:28 +00:00
|
|
|
ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateBlink);
|
2022-05-06 16:48:39 +00:00
|
|
|
} else if(event.event == iButtonWorkerWriteCannotWrite) {
|
2022-06-13 01:08:28 +00:00
|
|
|
ibutton_notification_message(ibutton, iButtonNotificationMessageYellowBlink);
|
2022-05-06 16:48:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if(event.type == SceneManagerEventTypeTick) {
|
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ibutton_scene_write_on_exit(void* context) {
|
|
|
|
iButton* ibutton = context;
|
2023-03-02 13:23:33 +00:00
|
|
|
ibutton->write_mode = iButtonWriteModeInvalid;
|
|
|
|
|
|
|
|
ibutton_worker_stop(ibutton->worker);
|
2022-09-30 12:56:12 +00:00
|
|
|
widget_reset(ibutton->widget);
|
2022-06-13 01:08:28 +00:00
|
|
|
|
|
|
|
ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop);
|
2022-05-06 16:48:39 +00:00
|
|
|
}
|