gpio_scene_start.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "../gpio_app_i.h"
  2. #include "furi-hal-power.h"
  3. enum GpioItem {
  4. GpioItemOtg,
  5. GpioItemTest,
  6. GpioItemUsbUart,
  7. };
  8. enum GpioOtg {
  9. GpioOtgOff,
  10. GpioOtgOn,
  11. GpioOtgSettingsNum,
  12. };
  13. const char* const gpio_otg_text[GpioOtgSettingsNum] = {
  14. "Off",
  15. "On",
  16. };
  17. static void gpio_scene_start_var_list_enter_callback(void* context, uint32_t index) {
  18. furi_assert(context);
  19. GpioApp* app = context;
  20. if(index == GpioItemTest) {
  21. view_dispatcher_send_custom_event(
  22. app->view_dispatcher, GPIO_SCENE_START_CUSTOM_EVENT_TEST);
  23. } else if(index == GpioItemUsbUart) {
  24. view_dispatcher_send_custom_event(
  25. app->view_dispatcher, GPIO_SCENE_START_CUSTOM_EVENT_USB_UART);
  26. }
  27. }
  28. static void gpio_scene_start_var_list_change_callback(VariableItem* item) {
  29. GpioApp* app = variable_item_get_context(item);
  30. uint8_t index = variable_item_get_current_value_index(item);
  31. variable_item_set_current_value_text(item, gpio_otg_text[index]);
  32. if(index == GpioOtgOff) {
  33. view_dispatcher_send_custom_event(
  34. app->view_dispatcher, GPIO_SCENE_START_CUSTOM_EVENT_OTG_OFF);
  35. } else if(index == GpioOtgOn) {
  36. view_dispatcher_send_custom_event(
  37. app->view_dispatcher, GPIO_SCENE_START_CUSTOM_EVENT_OTG_ON);
  38. }
  39. }
  40. void gpio_scene_start_on_enter(void* context) {
  41. GpioApp* app = context;
  42. VariableItemList* var_item_list = app->var_item_list;
  43. VariableItem* item;
  44. variable_item_list_set_enter_callback(
  45. var_item_list, gpio_scene_start_var_list_enter_callback, app);
  46. item = variable_item_list_add(
  47. var_item_list,
  48. "5V on GPIO",
  49. GpioOtgSettingsNum,
  50. gpio_scene_start_var_list_change_callback,
  51. app);
  52. if(furi_hal_power_is_otg_enabled()) {
  53. variable_item_set_current_value_index(item, GpioOtgOn);
  54. variable_item_set_current_value_text(item, gpio_otg_text[GpioOtgOn]);
  55. } else {
  56. variable_item_set_current_value_index(item, GpioOtgOff);
  57. variable_item_set_current_value_text(item, gpio_otg_text[GpioOtgOff]);
  58. }
  59. variable_item_list_add(var_item_list, "GPIO tester", 0, NULL, NULL);
  60. variable_item_list_add(var_item_list, "USB-UART bridge", 0, NULL, NULL);
  61. variable_item_list_set_selected_item(
  62. var_item_list, scene_manager_get_scene_state(app->scene_manager, GpioSceneStart));
  63. view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewVarItemList);
  64. }
  65. bool gpio_scene_start_on_event(void* context, SceneManagerEvent event) {
  66. GpioApp* app = context;
  67. bool consumed = false;
  68. if(event.type == SceneManagerEventTypeCustom) {
  69. if(event.event == GPIO_SCENE_START_CUSTOM_EVENT_OTG_ON) {
  70. furi_hal_power_enable_otg();
  71. } else if(event.event == GPIO_SCENE_START_CUSTOM_EVENT_OTG_OFF) {
  72. furi_hal_power_disable_otg();
  73. } else if(event.event == GPIO_SCENE_START_CUSTOM_EVENT_TEST) {
  74. scene_manager_set_scene_state(app->scene_manager, GpioSceneStart, 1);
  75. scene_manager_next_scene(app->scene_manager, GpioSceneTest);
  76. } else if(event.event == GPIO_SCENE_START_CUSTOM_EVENT_USB_UART) {
  77. scene_manager_set_scene_state(app->scene_manager, GpioSceneStart, 2);
  78. scene_manager_next_scene(app->scene_manager, GpioSceneUsbUart);
  79. }
  80. consumed = true;
  81. }
  82. return consumed;
  83. }
  84. void gpio_scene_start_on_exit(void* context) {
  85. GpioApp* app = context;
  86. variable_item_list_clean(app->var_item_list);
  87. }