picopass_scene_key_input.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "../picopass_i.h"
  2. #include <lib/toolbox/name_generator.h>
  3. #include <gui/modules/validators.h>
  4. #include <toolbox/path.h>
  5. void picopass_scene_key_input_text_input_callback(void* context) {
  6. Picopass* picopass = context;
  7. memcpy(picopass->write_key_context.key_to_write, picopass->byte_input_store, PICOPASS_KEY_LEN);
  8. picopass->write_key_context.is_elite = true;
  9. view_dispatcher_send_custom_event(picopass->view_dispatcher, PicopassCustomEventByteInputDone);
  10. }
  11. void picopass_scene_key_input_on_enter(void* context) {
  12. Picopass* picopass = context;
  13. ByteInput* byte_input = picopass->byte_input;
  14. byte_input_set_header_text(byte_input, "Enter The Key In Hex");
  15. byte_input_set_result_callback(
  16. byte_input,
  17. picopass_scene_key_input_text_input_callback,
  18. NULL,
  19. picopass,
  20. picopass->byte_input_store,
  21. PICOPASS_BLOCK_LEN);
  22. view_dispatcher_switch_to_view(picopass->view_dispatcher, PicopassViewByteInput);
  23. }
  24. bool picopass_scene_key_input_on_event(void* context, SceneManagerEvent event) {
  25. Picopass* picopass = context;
  26. bool consumed = false;
  27. if(event.type == SceneManagerEventTypeCustom) {
  28. if(event.event == PicopassCustomEventByteInputDone) {
  29. scene_manager_next_scene(picopass->scene_manager, PicopassSceneWriteKey);
  30. consumed = true;
  31. }
  32. }
  33. return consumed;
  34. }
  35. void picopass_scene_key_input_on_exit(void* context) {
  36. Picopass* picopass = context;
  37. // Clear view
  38. byte_input_set_result_callback(picopass->byte_input, NULL, NULL, NULL, NULL, 0);
  39. byte_input_set_header_text(picopass->byte_input, "");
  40. }