nfc_magic_scene_key_input.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "../nfc_magic_app_i.h"
  2. void nfc_magic_scene_key_input_byte_input_callback(void* context) {
  3. NfcMagicApp* instance = context;
  4. view_dispatcher_send_custom_event(
  5. instance->view_dispatcher, NfcMagicAppCustomEventByteInputDone);
  6. }
  7. void nfc_magic_scene_key_input_on_enter(void* context) {
  8. NfcMagicApp* instance = context;
  9. // Setup view
  10. ByteInput* byte_input = instance->byte_input;
  11. byte_input_set_header_text(byte_input, "Enter the password in hex");
  12. byte_input_set_result_callback(
  13. byte_input,
  14. nfc_magic_scene_key_input_byte_input_callback,
  15. NULL,
  16. instance,
  17. instance->byte_input_store,
  18. NFC_MAGIC_APP_BYTE_INPUT_STORE_SIZE);
  19. view_dispatcher_switch_to_view(instance->view_dispatcher, NfcMagicAppViewByteInput);
  20. }
  21. bool nfc_magic_scene_key_input_on_event(void* context, SceneManagerEvent event) {
  22. NfcMagicApp* instance = context;
  23. bool consumed = false;
  24. if(event.type == SceneManagerEventTypeCustom) {
  25. if(event.event == NfcMagicAppCustomEventByteInputDone) {
  26. // TODO: NEED TEST
  27. if(scene_manager_has_previous_scene(instance->scene_manager, NfcMagicSceneGen4Menu)) {
  28. memcpy(
  29. instance->gen4_password_new.bytes,
  30. instance->byte_input_store,
  31. GEN4_PASSWORD_LEN);
  32. scene_manager_next_scene(instance->scene_manager, NfcMagicSceneChangeKey);
  33. } else {
  34. memcpy(
  35. instance->gen4_password.bytes, instance->byte_input_store, GEN4_PASSWORD_LEN);
  36. scene_manager_next_scene(instance->scene_manager, NfcMagicSceneCheck);
  37. }
  38. consumed = true;
  39. }
  40. }
  41. return consumed;
  42. }
  43. void nfc_magic_scene_key_input_on_exit(void* context) {
  44. NfcMagicApp* instance = context;
  45. // Clear view
  46. byte_input_set_result_callback(instance->byte_input, NULL, NULL, NULL, NULL, 0);
  47. byte_input_set_header_text(instance->byte_input, "");
  48. }