spi_mem_scene_chip_detect.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "../spi_mem_app_i.h"
  2. static void spi_mem_scene_chip_detect_callback(void* context, SPIMemCustomEventWorker event) {
  3. SPIMemApp* app = context;
  4. view_dispatcher_send_custom_event(app->view_dispatcher, event);
  5. }
  6. void spi_mem_scene_chip_detect_on_enter(void* context) {
  7. SPIMemApp* app = context;
  8. notification_message(app->notifications, &sequence_blink_start_yellow);
  9. view_dispatcher_switch_to_view(app->view_dispatcher, SPIMemViewDetect);
  10. spi_mem_worker_start_thread(app->worker);
  11. spi_mem_worker_chip_detect_start(
  12. app->chip_info, &app->found_chips, app->worker, spi_mem_scene_chip_detect_callback, app);
  13. }
  14. bool spi_mem_scene_chip_detect_on_event(void* context, SceneManagerEvent event) {
  15. SPIMemApp* app = context;
  16. bool success = false;
  17. if(event.type == SceneManagerEventTypeCustom) {
  18. success = true;
  19. if(event.event == SPIMemCustomEventWorkerChipIdentified) {
  20. scene_manager_set_scene_state(app->scene_manager, SPIMemSceneSelectVendor, 0);
  21. scene_manager_next_scene(app->scene_manager, SPIMemSceneSelectVendor);
  22. } else if(event.event == SPIMemCustomEventWorkerChipUnknown) {
  23. scene_manager_next_scene(app->scene_manager, SPIMemSceneChipDetectFail);
  24. }
  25. }
  26. return success;
  27. }
  28. void spi_mem_scene_chip_detect_on_exit(void* context) {
  29. SPIMemApp* app = context;
  30. spi_mem_worker_stop_thread(app->worker);
  31. notification_message(app->notifications, &sequence_blink_stop);
  32. popup_reset(app->popup);
  33. }