ibutton_scene_add_value.c 2.0 KB

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