nfc_magic_scene_key_input.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "../nfc_magic_i.h"
  2. void nfc_magic_scene_key_input_byte_input_callback(void* context) {
  3. NfcMagic* nfc_magic = context;
  4. view_dispatcher_send_custom_event(
  5. nfc_magic->view_dispatcher, NfcMagicCustomEventByteInputDone);
  6. }
  7. void nfc_magic_scene_key_input_on_enter(void* context) {
  8. NfcMagic* nfc_magic = context;
  9. // Setup view
  10. ByteInput* byte_input = nfc_magic->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. nfc_magic,
  17. (uint8_t*)&nfc_magic->dev->password,
  18. 4);
  19. view_dispatcher_switch_to_view(nfc_magic->view_dispatcher, NfcMagicViewByteInput);
  20. }
  21. bool nfc_magic_scene_key_input_on_event(void* context, SceneManagerEvent event) {
  22. NfcMagic* nfc_magic = context;
  23. bool consumed = false;
  24. if(event.type == SceneManagerEventTypeCustom) {
  25. if(event.event == NfcMagicCustomEventByteInputDone) {
  26. scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneCheck);
  27. consumed = true;
  28. }
  29. }
  30. return consumed;
  31. }
  32. void nfc_magic_scene_key_input_on_exit(void* context) {
  33. NfcMagic* nfc_magic = context;
  34. // Clear view
  35. byte_input_set_result_callback(nfc_magic->byte_input, NULL, NULL, NULL, NULL, 0);
  36. byte_input_set_header_text(nfc_magic->byte_input, "");
  37. }