gpio_scene_start.c 2.9 KB

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