2021-09-30 20:03:28 +00:00
|
|
|
#include "../gpio_app_i.h"
|
2022-01-05 16:10:18 +00:00
|
|
|
#include "furi_hal_power.h"
|
2022-03-24 15:45:03 +00:00
|
|
|
#include "furi_hal_usb.h"
|
2021-09-30 20:03:28 +00:00
|
|
|
|
|
|
|
enum GpioItem {
|
2021-10-21 18:12:20 +00:00
|
|
|
GpioItemUsbUart,
|
2021-11-21 15:17:43 +00:00
|
|
|
GpioItemTest,
|
|
|
|
GpioItemOtg,
|
2021-09-30 20:03:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum GpioOtg {
|
|
|
|
GpioOtgOff,
|
|
|
|
GpioOtgOn,
|
|
|
|
GpioOtgSettingsNum,
|
|
|
|
};
|
|
|
|
|
|
|
|
const char* const gpio_otg_text[GpioOtgSettingsNum] = {
|
|
|
|
"Off",
|
|
|
|
"On",
|
|
|
|
};
|
|
|
|
|
|
|
|
static void gpio_scene_start_var_list_enter_callback(void* context, uint32_t index) {
|
|
|
|
furi_assert(context);
|
|
|
|
GpioApp* app = context;
|
|
|
|
if(index == GpioItemTest) {
|
2021-11-21 15:17:43 +00:00
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, GpioStartEventManualConrol);
|
2021-10-21 18:12:20 +00:00
|
|
|
} else if(index == GpioItemUsbUart) {
|
2021-11-21 15:17:43 +00:00
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, GpioStartEventUsbUart);
|
2021-09-30 20:03:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gpio_scene_start_var_list_change_callback(VariableItem* item) {
|
|
|
|
GpioApp* app = variable_item_get_context(item);
|
|
|
|
uint8_t index = variable_item_get_current_value_index(item);
|
|
|
|
|
|
|
|
variable_item_set_current_value_text(item, gpio_otg_text[index]);
|
|
|
|
if(index == GpioOtgOff) {
|
2021-11-21 15:17:43 +00:00
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, GpioStartEventOtgOff);
|
2021-09-30 20:03:28 +00:00
|
|
|
} else if(index == GpioOtgOn) {
|
2021-11-21 15:17:43 +00:00
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, GpioStartEventOtgOn);
|
2021-09-30 20:03:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gpio_scene_start_on_enter(void* context) {
|
|
|
|
GpioApp* app = context;
|
|
|
|
VariableItemList* var_item_list = app->var_item_list;
|
|
|
|
|
|
|
|
VariableItem* item;
|
|
|
|
variable_item_list_set_enter_callback(
|
|
|
|
var_item_list, gpio_scene_start_var_list_enter_callback, app);
|
2021-11-21 15:17:43 +00:00
|
|
|
|
|
|
|
variable_item_list_add(var_item_list, "USB-UART bridge", 0, NULL, NULL);
|
|
|
|
|
|
|
|
variable_item_list_add(var_item_list, "GPIO manual control", 0, NULL, NULL);
|
|
|
|
|
2021-09-30 20:03:28 +00:00
|
|
|
item = variable_item_list_add(
|
|
|
|
var_item_list,
|
|
|
|
"5V on GPIO",
|
|
|
|
GpioOtgSettingsNum,
|
|
|
|
gpio_scene_start_var_list_change_callback,
|
|
|
|
app);
|
|
|
|
if(furi_hal_power_is_otg_enabled()) {
|
|
|
|
variable_item_set_current_value_index(item, GpioOtgOn);
|
|
|
|
variable_item_set_current_value_text(item, gpio_otg_text[GpioOtgOn]);
|
|
|
|
} else {
|
|
|
|
variable_item_set_current_value_index(item, GpioOtgOff);
|
|
|
|
variable_item_set_current_value_text(item, gpio_otg_text[GpioOtgOff]);
|
|
|
|
}
|
|
|
|
|
2021-11-04 19:33:28 +00:00
|
|
|
variable_item_list_set_selected_item(
|
|
|
|
var_item_list, scene_manager_get_scene_state(app->scene_manager, GpioSceneStart));
|
|
|
|
|
2021-09-30 20:03:28 +00:00
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewVarItemList);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool gpio_scene_start_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
GpioApp* app = context;
|
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
2021-11-21 15:17:43 +00:00
|
|
|
if(event.event == GpioStartEventOtgOn) {
|
2021-09-30 20:03:28 +00:00
|
|
|
furi_hal_power_enable_otg();
|
2021-11-21 15:17:43 +00:00
|
|
|
} else if(event.event == GpioStartEventOtgOff) {
|
2021-09-30 20:03:28 +00:00
|
|
|
furi_hal_power_disable_otg();
|
2021-11-21 15:17:43 +00:00
|
|
|
} else if(event.event == GpioStartEventManualConrol) {
|
|
|
|
scene_manager_set_scene_state(app->scene_manager, GpioSceneStart, GpioItemTest);
|
2021-09-30 20:03:28 +00:00
|
|
|
scene_manager_next_scene(app->scene_manager, GpioSceneTest);
|
2021-11-21 15:17:43 +00:00
|
|
|
} else if(event.event == GpioStartEventUsbUart) {
|
|
|
|
scene_manager_set_scene_state(app->scene_manager, GpioSceneStart, GpioItemUsbUart);
|
2022-03-24 15:45:03 +00:00
|
|
|
if(!furi_hal_usb_is_locked()) {
|
|
|
|
scene_manager_next_scene(app->scene_manager, GpioSceneUsbUart);
|
|
|
|
} else {
|
|
|
|
scene_manager_next_scene(app->scene_manager, GpioSceneUsbUartCloseRpc);
|
|
|
|
}
|
2021-09-30 20:03:28 +00:00
|
|
|
}
|
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gpio_scene_start_on_exit(void* context) {
|
|
|
|
GpioApp* app = context;
|
2022-01-21 17:32:03 +00:00
|
|
|
variable_item_list_reset(app->var_item_list);
|
2021-09-30 20:03:28 +00:00
|
|
|
}
|