nfc_magic_scene_key_input.c 2.0 KB

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