gpio_scene_start.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewVarItemList);
  62. }
  63. bool gpio_scene_start_on_event(void* context, SceneManagerEvent event) {
  64. GpioApp* app = context;
  65. bool consumed = false;
  66. if(event.type == SceneManagerEventTypeCustom) {
  67. if(event.event == GPIO_SCENE_START_CUSTOM_EVENT_OTG_ON) {
  68. furi_hal_power_enable_otg();
  69. } else if(event.event == GPIO_SCENE_START_CUSTOM_EVENT_OTG_OFF) {
  70. furi_hal_power_disable_otg();
  71. } else if(event.event == GPIO_SCENE_START_CUSTOM_EVENT_TEST) {
  72. scene_manager_next_scene(app->scene_manager, GpioSceneTest);
  73. } else if(event.event == GPIO_SCENE_START_CUSTOM_EVENT_USB_UART) {
  74. scene_manager_next_scene(app->scene_manager, GpioSceneUsbUart);
  75. }
  76. consumed = true;
  77. }
  78. return consumed;
  79. }
  80. void gpio_scene_start_on_exit(void* context) {
  81. GpioApp* app = context;
  82. variable_item_list_clean(app->var_item_list);
  83. }