uhf_scene_verify.c 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "../uhf_app_i.h"
  2. bool verify_success = false;
  3. void uhf_scene_verify_callback_event(UHFWorkerEvent event, void* ctx) {
  4. UNUSED(ctx);
  5. UHFApp* uhf_app = ctx;
  6. if(event == UHFWorkerEventSuccess) {
  7. verify_success = true;
  8. // FURI_LOG_E("verify", "UHFWorkerEventSuccess");
  9. // FURI_LOG_E("verify", "%d", verify_success);
  10. } else {
  11. // FURI_LOG_E("verify", "UHFWorkerEventFail");
  12. }
  13. view_dispatcher_send_custom_event(uhf_app->view_dispatcher, UHFCustomEventVerifyDone);
  14. }
  15. void uhf_scene_verify_widget_callback(GuiButtonType result, InputType type, void* ctx) {
  16. furi_assert(ctx);
  17. UHFApp* uhf_app = ctx;
  18. if(type == InputTypeShort) {
  19. view_dispatcher_send_custom_event(uhf_app->view_dispatcher, result);
  20. }
  21. }
  22. void uhf_scene_verify_on_enter(void* ctx) {
  23. UHFApp* uhf_app = ctx;
  24. uhf_worker_start(
  25. uhf_app->worker, UHFWorkerStateVerify, uhf_scene_verify_callback_event, uhf_app);
  26. }
  27. bool uhf_scene_verify_on_event(void* ctx, SceneManagerEvent event) {
  28. UHFApp* uhf_app = ctx;
  29. bool consumed = false;
  30. if(event.event == SceneManagerEventTypeBack) {
  31. uhf_app->worker->state = UHFWorkerStateStop;
  32. } else if(event.type == SceneManagerEventTypeCustom) {
  33. if(event.event == GuiButtonTypeRight) {
  34. scene_manager_next_scene(uhf_app->scene_manager, UHFSceneStart);
  35. consumed = true;
  36. } else if(event.event == UHFCustomEventVerifyDone) {
  37. if(verify_success) {
  38. // FuriString* temp_str = furi_string_alloc();
  39. // UHFResponseData* response_data = uhf_app->worker->data;
  40. // UHFData* software_version = uhf_response_data_get_uhf_data(response_data, 0);
  41. widget_add_string_element(
  42. uhf_app->widget, 64, 5, AlignCenter, AlignCenter, FontPrimary, "Module Info");
  43. // furi_string_cat_str(temp_str, "Software Version: ");
  44. // for(int i = 0; i < 10; i++) {
  45. // furi_string_cat_printf(temp_str, "%c ", software_version->data[6 + i]);
  46. // }
  47. // widget_add_string_element(
  48. // uhf_app->widget,
  49. // 3,
  50. // 10,
  51. // AlignLeft,
  52. // AlignBottom,
  53. // FontSecondary,
  54. // furi_string_get_cstr(temp_str));
  55. widget_add_string_element(
  56. uhf_app->widget, 64, 5, AlignCenter, AlignCenter, FontPrimary, "Module Info");
  57. widget_add_button_element(
  58. uhf_app->widget,
  59. GuiButtonTypeRight,
  60. "Continue",
  61. uhf_scene_verify_widget_callback,
  62. uhf_app);
  63. // furi_string_free(temp_str);
  64. } else {
  65. widget_add_string_element(
  66. uhf_app->widget,
  67. 64,
  68. 5,
  69. AlignCenter,
  70. AlignCenter,
  71. FontPrimary,
  72. "No UHF Module found");
  73. }
  74. }
  75. }
  76. return consumed;
  77. }
  78. void uhf_scene_verify_on_exit(void* ctx) {
  79. UHFApp* uhf_app = ctx;
  80. // // Stop worker
  81. uhf_worker_stop(uhf_app->worker);
  82. // // Clear view
  83. // popup_reset(uhf_app->popup);
  84. // clear widget
  85. widget_reset(uhf_app->widget);
  86. }