ibutton_scene_add_value.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "../ibutton_i.h"
  2. void ibutton_scene_add_type_byte_input_callback(void* context) {
  3. iButton* ibutton = context;
  4. view_dispatcher_send_custom_event(ibutton->view_dispatcher, iButtonCustomEventByteEditResult);
  5. }
  6. void ibutton_scene_add_value_on_enter(void* context) {
  7. iButton* ibutton = context;
  8. iButtonKey* key = ibutton->key;
  9. uint8_t* new_key_data = malloc(IBUTTON_KEY_DATA_SIZE);
  10. scene_manager_set_scene_state(
  11. ibutton->scene_manager, iButtonSceneAddValue, (uint32_t)new_key_data);
  12. memcpy(new_key_data, ibutton_key_get_data_p(key), ibutton_key_get_data_size(key));
  13. byte_input_set_result_callback(
  14. ibutton->byte_input,
  15. ibutton_scene_add_type_byte_input_callback,
  16. NULL,
  17. ibutton,
  18. new_key_data,
  19. ibutton_key_get_data_size(key));
  20. byte_input_set_header_text(ibutton->byte_input, "Enter the key");
  21. view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewByteInput);
  22. }
  23. bool ibutton_scene_add_value_on_event(void* context, SceneManagerEvent event) {
  24. iButton* ibutton = context;
  25. uint8_t* new_key_data =
  26. (uint8_t*)scene_manager_get_scene_state(ibutton->scene_manager, iButtonSceneAddValue);
  27. bool consumed = false;
  28. if(event.type == SceneManagerEventTypeCustom) {
  29. consumed = true;
  30. if(event.event == iButtonCustomEventByteEditResult) {
  31. ibutton_key_set_data(ibutton->key, new_key_data, IBUTTON_KEY_DATA_SIZE);
  32. scene_manager_next_scene(ibutton->scene_manager, iButtonSceneSaveName);
  33. }
  34. }
  35. return consumed;
  36. }
  37. void ibutton_scene_add_value_on_exit(void* context) {
  38. iButton* ibutton = context;
  39. uint8_t* new_key_data =
  40. (uint8_t*)scene_manager_get_scene_state(ibutton->scene_manager, iButtonSceneAddValue);
  41. byte_input_set_result_callback(ibutton->byte_input, NULL, NULL, NULL, NULL, 0);
  42. byte_input_set_header_text(ibutton->byte_input, NULL);
  43. free(new_key_data);
  44. }