Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…irmware into mntm-dev
  • Loading branch information
Willy-JL committed Apr 18, 2024
2 parents a660fa4 + 12112e7 commit cd5c76c
Show file tree
Hide file tree
Showing 31 changed files with 288 additions and 88 deletions.
1 change: 1 addition & 0 deletions applications/main/ibutton/scenes/ibutton_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ ADD_SCENE(ibutton, delete_confirm, DeleteConfirm)
ADD_SCENE(ibutton, delete_success, DeleteSuccess)
ADD_SCENE(ibutton, retry_confirm, RetryConfirm)
ADD_SCENE(ibutton, exit_confirm, ExitConfirm)
ADD_SCENE(ibutton, read_exit_confirm, ReadExitConfirm)
ADD_SCENE(ibutton, view_data, ViewData)
ADD_SCENE(ibutton, rpc, Rpc)
22 changes: 16 additions & 6 deletions applications/main/ibutton/scenes/ibutton_scene_delete_confirm.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,33 @@ void ibutton_scene_delete_confirm_on_enter(void* context) {
Widget* widget = ibutton->widget;

FuriString* tmp = furi_string_alloc();
FuriString* uid = furi_string_alloc();

widget_add_button_element(widget, GuiButtonTypeLeft, "Back", ibutton_widget_callback, context);
widget_add_button_element(
widget, GuiButtonTypeRight, "Delete", ibutton_widget_callback, context);

furi_string_printf(tmp, "\e#Delete %s?\e#", ibutton->key_name);
furi_string_printf(tmp, "\e#Delete %s?\e#\n", ibutton->key_name);

ibutton_protocols_render_uid(ibutton->protocols, key, uid);

furi_string_cat_printf(
uid,
"\n%s %s",
ibutton_protocols_get_manufacturer(ibutton->protocols, ibutton_key_get_protocol_id(key)),
ibutton_protocols_get_name(ibutton->protocols, ibutton_key_get_protocol_id(key)));

furi_string_cat(tmp, uid);

widget_add_text_box_element(
widget, 0, 0, 128, 23, AlignCenter, AlignCenter, furi_string_get_cstr(tmp), false);
widget, 0, 0, 128, 64, AlignCenter, AlignTop, furi_string_get_cstr(tmp), false);

furi_string_reset(tmp);
ibutton_protocols_render_brief_data(ibutton->protocols, key, tmp);

widget_add_string_multiline_element(
widget, 128 / 2, 24, AlignCenter, AlignTop, FontSecondary, furi_string_get_cstr(tmp));
furi_string_reset(uid);

view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
furi_string_free(tmp);
furi_string_free(uid);
}

bool ibutton_scene_delete_confirm_on_event(void* context, SceneManagerEvent event) {
Expand Down
17 changes: 10 additions & 7 deletions applications/main/ibutton/scenes/ibutton_scene_emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@ void ibutton_scene_emulate_on_enter(void* context) {

widget_add_icon_element(widget, 3, 10, &I_iButtonKey_49x44);

furi_string_printf(
tmp,
"[%s]\n%s",
ibutton_protocols_get_name(ibutton->protocols, ibutton_key_get_protocol_id(key)),
furi_string_empty(ibutton->file_path) ? "Unsaved Key" : ibutton->key_name);
if(furi_string_empty(ibutton->file_path)) {
furi_string_printf(
tmp,
"Unsaved\n%s",
ibutton_protocols_get_name(ibutton->protocols, ibutton_key_get_protocol_id(key)));
} else {
furi_string_printf(tmp, "%s", ibutton->key_name);
}

widget_add_text_box_element(
widget, 52, 30, 75, 40, AlignCenter, AlignCenter, furi_string_get_cstr(tmp), true);
widget, 52, 23, 75, 26, AlignCenter, AlignTop, furi_string_get_cstr(tmp), false);

widget_add_string_multiline_element(
widget, 88, 5, AlignCenter, AlignTop, FontPrimary, "iButton\nemulating");
widget, 88, 10, AlignCenter, AlignTop, FontPrimary, "Emulating");

ibutton_worker_emulate_set_callback(ibutton->worker, ibutton_scene_emulate_callback, ibutton);
ibutton_worker_emulate_start(ibutton->worker, key);
Expand Down
21 changes: 13 additions & 8 deletions applications/main/ibutton/scenes/ibutton_scene_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@ void ibutton_scene_info_on_enter(void* context) {
const iButtonProtocolId protocol_id = ibutton_key_get_protocol_id(key);

FuriString* tmp = furi_string_alloc();
FuriString* keynumber = furi_string_alloc();

ibutton_protocols_render_brief_data(ibutton->protocols, key, keynumber);
FuriString* brief_data = furi_string_alloc();

furi_string_printf(
tmp,
"\e#%s\n[%s]\e#\n%s",
"Name:%s\n\e#%s %s\e#\n",
ibutton->key_name,
ibutton_protocols_get_name(ibutton->protocols, protocol_id),
furi_string_get_cstr(keynumber));
ibutton_protocols_get_manufacturer(ibutton->protocols, protocol_id),
ibutton_protocols_get_name(ibutton->protocols, protocol_id));

ibutton_protocols_render_brief_data(ibutton->protocols, key, brief_data);

furi_string_cat(tmp, brief_data);

widget_add_text_box_element(
widget, 0, 2, 128, 64, AlignLeft, AlignTop, furi_string_get_cstr(tmp), true);
widget, 0, 0, 128, 64, AlignLeft, AlignTop, furi_string_get_cstr(tmp), false);

furi_string_reset(tmp);
furi_string_reset(brief_data);

if(ibutton_protocols_get_features(ibutton->protocols, protocol_id) &
iButtonProtocolFeatureExtData) {
Expand All @@ -30,7 +35,7 @@ void ibutton_scene_info_on_enter(void* context) {

view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
furi_string_free(tmp);
furi_string_free(keynumber);
furi_string_free(brief_data);
}

bool ibutton_scene_info_on_event(void* context, SceneManagerEvent event) {
Expand Down
6 changes: 3 additions & 3 deletions applications/main/ibutton/scenes/ibutton_scene_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ void ibutton_scene_read_on_enter(void* context) {
iButtonKey* key = ibutton->key;
iButtonWorker* worker = ibutton->worker;

popup_set_header(popup, "iButton", 95, 26, AlignCenter, AlignBottom);
popup_set_text(popup, "Apply key to\nFlipper's back", 95, 30, AlignCenter, AlignTop);
popup_set_icon(popup, 0, 5, &I_DolphinWait_61x59);
popup_set_header(popup, "Reading", 95, 26, AlignCenter, AlignBottom);
popup_set_text(popup, "Connect key\nwith pogo pins", 95, 30, AlignCenter, AlignTop);
popup_set_icon(popup, 0, 10, &I_DolphinWait_59x54);

view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup);

Expand Down
7 changes: 2 additions & 5 deletions applications/main/ibutton/scenes/ibutton_scene_read_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ void ibutton_scene_read_error_on_enter(void* context) {
widget_add_button_element(
widget, GuiButtonTypeRight, "More", ibutton_widget_callback, context);

widget_add_string_element(
widget, 128 / 2, 2, AlignCenter, AlignTop, FontPrimary, "Read Error");

ibutton_protocols_render_error(ibutton->protocols, key, tmp);

widget_add_string_multiline_element(
widget, 128 / 2, 16, AlignCenter, AlignTop, FontSecondary, furi_string_get_cstr(tmp));
widget_add_text_box_element(
widget, 0, 0, 128, 48, AlignCenter, AlignTop, furi_string_get_cstr(tmp), false);

ibutton_notification_message(ibutton, iButtonNotificationMessageError);
ibutton_notification_message(ibutton, iButtonNotificationMessageRedOn);
Expand Down
59 changes: 59 additions & 0 deletions applications/main/ibutton/scenes/ibutton_scene_read_exit_confirm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "../ibutton_i.h"

static void ibutton_scene_read_exit_confirm_widget_callback(
GuiButtonType result,
InputType type,
void* context) {
iButton* ibutton = context;
if(type == InputTypeShort) {
view_dispatcher_send_custom_event(ibutton->view_dispatcher, result);
}
}

void ibutton_scene_read_exit_confirm_on_enter(void* context) {
iButton* ibutton = context;
Widget* widget = ibutton->widget;

widget_add_button_element(
widget,
GuiButtonTypeLeft,
"Exit",
ibutton_scene_read_exit_confirm_widget_callback,
ibutton);
widget_add_button_element(
widget,
GuiButtonTypeRight,
"Stay",
ibutton_scene_read_exit_confirm_widget_callback,
ibutton);
widget_add_string_element(
widget, 64, 19, AlignCenter, AlignBottom, FontPrimary, "Retry Reading?");
widget_add_string_element(
widget, 64, 31, AlignCenter, AlignBottom, FontSecondary, "All unsaved data will be lost!");

view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
}

bool ibutton_scene_read_exit_confirm_on_event(void* context, SceneManagerEvent event) {
iButton* ibutton = context;
SceneManager* scene_manager = ibutton->scene_manager;
bool consumed = false;

if(event.type == SceneManagerEventTypeBack) {
consumed = true; // Ignore Back button presses
} else if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
if(event.event == GuiButtonTypeLeft) {
scene_manager_search_and_switch_to_previous_scene(scene_manager, iButtonSceneRead);
} else if(event.event == GuiButtonTypeRight) {
scene_manager_previous_scene(scene_manager);
}
}

return consumed;
}

void ibutton_scene_read_exit_confirm_on_exit(void* context) {
iButton* ibutton = context;
widget_reset(ibutton->widget);
}
18 changes: 9 additions & 9 deletions applications/main/ibutton/scenes/ibutton_scene_read_key_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,29 @@ void ibutton_scene_read_key_menu_on_enter(void* context) {
ibutton_scene_read_key_menu_submenu_callback,
ibutton);

if(features & iButtonProtocolFeatureExtData) {
if(features & iButtonProtocolFeatureWriteBlank) {
submenu_add_item(
submenu,
"View Data",
SubmenuIndexViewData,
"Write ID",
SubmenuIndexWriteBlank,
ibutton_scene_read_key_menu_submenu_callback,
ibutton);
}

if(features & iButtonProtocolFeatureWriteBlank) {
if(features & iButtonProtocolFeatureWriteCopy) {
submenu_add_item(
submenu,
"Write Blank",
SubmenuIndexWriteBlank,
"Full Write on Same Type",
SubmenuIndexWriteCopy,
ibutton_scene_read_key_menu_submenu_callback,
ibutton);
}

if(features & iButtonProtocolFeatureWriteCopy) {
if(features & iButtonProtocolFeatureExtData) {
submenu_add_item(
submenu,
"Write Copy",
SubmenuIndexWriteCopy,
"Data Info",
SubmenuIndexViewData,
ibutton_scene_read_key_menu_submenu_callback,
ibutton);
}
Expand Down
8 changes: 4 additions & 4 deletions applications/main/ibutton/scenes/ibutton_scene_read_success.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ void ibutton_scene_read_success_on_enter(void* context) {

furi_string_printf(
tmp,
"%s[%s]",
ibutton_protocols_get_name(ibutton->protocols, protocol_id),
ibutton_protocols_get_manufacturer(ibutton->protocols, protocol_id));
"%s %s",
ibutton_protocols_get_manufacturer(ibutton->protocols, protocol_id),
ibutton_protocols_get_name(ibutton->protocols, protocol_id));

widget_add_string_element(
widget, 0, 2, AlignLeft, AlignTop, FontPrimary, furi_string_get_cstr(tmp));
Expand All @@ -44,7 +44,7 @@ bool ibutton_scene_read_success_on_event(void* context, SceneManagerEvent event)

if(event.type == SceneManagerEventTypeBack) {
consumed = true;
scene_manager_next_scene(scene_manager, iButtonSceneExitConfirm);
scene_manager_next_scene(scene_manager, iButtonSceneReadExitConfirm);
} else if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
if(event.event == GuiButtonTypeRight) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ void ibutton_scene_saved_key_menu_on_enter(void* context) {

if(features & iButtonProtocolFeatureWriteBlank) {
submenu_add_item(
submenu, "Write Blank", SubmenuIndexWriteBlank, ibutton_submenu_callback, ibutton);
submenu, "Write ID", SubmenuIndexWriteBlank, ibutton_submenu_callback, ibutton);
}

if(features & iButtonProtocolFeatureWriteCopy) {
submenu_add_item(
submenu, "Write Copy", SubmenuIndexWriteCopy, ibutton_submenu_callback, ibutton);
submenu,
"Full Write on Same Type",
SubmenuIndexWriteCopy,
ibutton_submenu_callback,
ibutton);
}

submenu_add_item(submenu, "Edit", SubmenuIndexEdit, ibutton_submenu_callback, ibutton);
Expand Down
21 changes: 10 additions & 11 deletions applications/main/ibutton/scenes/ibutton_scene_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,29 @@ void ibutton_scene_write_on_enter(void* context) {

widget_add_icon_element(widget, 3, 10, &I_iButtonKey_49x44);

furi_string_printf(
tmp,
"[%s]\n%s ",
ibutton_protocols_get_name(ibutton->protocols, protocol_id),
ibutton->key_name);
if(furi_string_empty(ibutton->file_path)) {
furi_string_printf(
tmp, "Unsaved\n%s", ibutton_protocols_get_name(ibutton->protocols, protocol_id));
} else {
furi_string_printf(tmp, "%s", ibutton->key_name);
}

widget_add_text_box_element(
widget, 52, 30, 75, 40, AlignCenter, AlignCenter, furi_string_get_cstr(tmp), true);
widget, 52, 23, 75, 26, AlignCenter, AlignTop, furi_string_get_cstr(tmp), false);

ibutton_worker_write_set_callback(worker, ibutton_scene_write_callback, ibutton);

furi_string_set(tmp, "iButton\nwriting ");

if(ibutton->write_mode == iButtonWriteModeBlank) {
furi_string_cat(tmp, "Blank");
furi_string_set(tmp, "Writing ID");
ibutton_worker_write_blank_start(worker, key);

} else if(ibutton->write_mode == iButtonWriteModeCopy) {
furi_string_cat(tmp, "Copy");
furi_string_set(tmp, "Full Writing");
ibutton_worker_write_copy_start(worker, key);
}

widget_add_string_multiline_element(
widget, 88, 5, AlignCenter, AlignTop, FontPrimary, furi_string_get_cstr(tmp));
widget, 88, 10, AlignCenter, AlignTop, FontPrimary, furi_string_get_cstr(tmp));

ibutton_notification_message(ibutton, iButtonNotificationMessageEmulateStart);
view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget);
Expand Down
Binary file added assets/icons/Dolphin/DolphinWait_59x54.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions lib/ibutton/ibutton_protocols.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,17 @@ bool ibutton_protocols_load(iButtonProtocols* protocols, iButtonKey* key, const
return success;
}

void ibutton_protocols_render_uid(
iButtonProtocols* protocols,
const iButtonKey* key,
FuriString* result) {
const iButtonProtocolId id = ibutton_key_get_protocol_id(key);
const iButtonProtocolData* data = ibutton_key_get_protocol_data(key);

GET_PROTOCOL_GROUP(id);
GROUP_BASE->render_uid(GROUP_DATA, data, PROTOCOL_ID, result);
}

void ibutton_protocols_render_data(
iButtonProtocols* protocols,
const iButtonKey* key,
Expand Down
11 changes: 11 additions & 0 deletions lib/ibutton/ibutton_protocols.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ bool ibutton_protocols_save(
*/
bool ibutton_protocols_load(iButtonProtocols* protocols, iButtonKey* key, const char* file_name);

/**
* Format a string containing defice UID
* @param [in] protocols pointer to an iButtonProtocols object
* @param [in] key pointer to the key to be rendered
* @param [out] result pointer to the FuriString instance (must be initialized)
*/
void ibutton_protocols_render_uid(
iButtonProtocols* protocols,
const iButtonKey* key,
FuriString* result);

/**
* Format a string containing device full data
* @param [in] protocols pointer to an iButtonProtocols object
Expand Down
Loading

0 comments on commit cd5c76c

Please sign in to comment.