meal_pager_scene_set_last_pager.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "../meal_pager_i.h"
  2. #include "../helpers/meal_pager_custom_event.h"
  3. #include "../helpers/meal_pager_led.h"
  4. #include <dolphin/dolphin.h>
  5. void meal_pager_set_last_pager_callback(void* context) {
  6. furi_assert(context);
  7. Meal_Pager* app = context;
  8. view_dispatcher_send_custom_event(app->view_dispatcher, Meal_PagerCustomerEventIntInput);
  9. }
  10. void meal_pager_scene_set_last_pager_on_enter(void* context) {
  11. furi_assert(context);
  12. Meal_Pager* app = context;
  13. IntInput* int_input = app->int_input;
  14. size_t enter_name_length = 5;
  15. meal_pager_set_max_values(app);
  16. char* str = "Set Last Pager (0 - 999)";
  17. const char* constStr = str;
  18. snprintf(str, 36, "Set Last Pager (%lu - %lu)", app->first_pager, app->max_pager);
  19. int_input_set_header_text(int_input, constStr);
  20. int_input_set_result_callback(
  21. int_input,
  22. meal_pager_set_last_pager_callback,
  23. context,
  24. app->text_store[3],
  25. enter_name_length,
  26. false);
  27. view_dispatcher_switch_to_view(app->view_dispatcher, Meal_PagerViewIdIntInput);
  28. }
  29. bool meal_pager_scene_set_last_pager_on_event(void* context, SceneManagerEvent event) {
  30. Meal_Pager* app = context;
  31. bool consumed = false;
  32. if(event.type == SceneManagerEventTypeBack) {
  33. scene_manager_previous_scene(app->scene_manager);
  34. return true;
  35. } else if(event.type == SceneManagerEventTypeCustom) {
  36. app->last_pager = atoi(app->text_store[3]);
  37. if(app->last_pager > app->max_pager) {
  38. app->last_pager = app->max_pager;
  39. snprintf(app->text_store[3], sizeof(app->text_store[3]), "%lu", app->last_pager);
  40. }
  41. if(app->last_pager < app->first_pager) {
  42. app->last_pager = app->first_pager;
  43. snprintf(app->text_store[3], sizeof(app->text_store[3]), "%lu", app->last_pager);
  44. }
  45. app->last_pager_char = app->text_store[3];
  46. scene_manager_previous_scene(app->scene_manager);
  47. return true;
  48. } else if(event.type == SceneManagerEventTypeTick) {
  49. if(app->state_notifications == SubGhzNotificationStateTx) {
  50. app->state_notifications = SubGhzNotificationStateIDLE;
  51. subghz_txrx_stop(app->subghz->txrx);
  52. meal_pager_blink_stop(app);
  53. meal_pager_transmit_model_set_sending(app->meal_pager_transmit, 0);
  54. }
  55. return true;
  56. }
  57. return consumed;
  58. }
  59. void meal_pager_scene_set_last_pager_on_exit(void* context) {
  60. Meal_Pager* app = context;
  61. UNUSED(app);
  62. }