[FL-1884] GPIO application (#732)
* gpio: rename gpio application * bq25896: add reading OTG config * furi-hal-power: add is_otg_enabled API * gpio: introduce new GPIO app, add OTG enable / disable * variable-item-list: add enter callback * gpio: add output test view and scene * gpio app: fix GpioItemTester -> GpioItemTest Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
30
applications/gpio/scenes/gpio_scene.c
Normal file
30
applications/gpio/scenes/gpio_scene.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "gpio_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const gpio_scene_on_enter_handlers[])(void*) = {
|
||||
#include "gpio_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const gpio_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "gpio_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const gpio_scene_on_exit_handlers[])(void* context) = {
|
||||
#include "gpio_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers gpio_scene_handlers = {
|
||||
.on_enter_handlers = gpio_scene_on_enter_handlers,
|
||||
.on_event_handlers = gpio_scene_on_event_handlers,
|
||||
.on_exit_handlers = gpio_scene_on_exit_handlers,
|
||||
.scene_num = GpioSceneNum,
|
||||
};
|
29
applications/gpio/scenes/gpio_scene.h
Normal file
29
applications/gpio/scenes/gpio_scene.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) GpioScene##id,
|
||||
typedef enum {
|
||||
#include "gpio_scene_config.h"
|
||||
GpioSceneNum,
|
||||
} GpioScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers gpio_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "gpio_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||
#include "gpio_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||
#include "gpio_scene_config.h"
|
||||
#undef ADD_SCENE
|
2
applications/gpio/scenes/gpio_scene_config.h
Normal file
2
applications/gpio/scenes/gpio_scene_config.h
Normal file
@@ -0,0 +1,2 @@
|
||||
ADD_SCENE(gpio, start, Start)
|
||||
ADD_SCENE(gpio, test, Test)
|
92
applications/gpio/scenes/gpio_scene_start.c
Executable file
92
applications/gpio/scenes/gpio_scene_start.c
Executable file
@@ -0,0 +1,92 @@
|
||||
#include "../gpio_app_i.h"
|
||||
#include "furi-hal-power.h"
|
||||
|
||||
#define GPIO_SCENE_START_CUSTOM_EVENT_OTG_OFF (0UL)
|
||||
#define GPIO_SCENE_START_CUSTOM_EVENT_OTG_ON (1UL)
|
||||
#define GPIO_SCENE_START_CUSTOM_EVENT_TEST (2UL)
|
||||
|
||||
enum GpioItem {
|
||||
GpioItemOtg,
|
||||
GpioItemTest,
|
||||
};
|
||||
|
||||
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) {
|
||||
view_dispatcher_send_custom_event(
|
||||
app->view_dispatcher, GPIO_SCENE_START_CUSTOM_EVENT_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
view_dispatcher_send_custom_event(
|
||||
app->view_dispatcher, GPIO_SCENE_START_CUSTOM_EVENT_OTG_OFF);
|
||||
} else if(index == GpioOtgOn) {
|
||||
view_dispatcher_send_custom_event(
|
||||
app->view_dispatcher, GPIO_SCENE_START_CUSTOM_EVENT_OTG_ON);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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]);
|
||||
}
|
||||
variable_item_list_add(var_item_list, "GPIO tester", 0, NULL, NULL);
|
||||
|
||||
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) {
|
||||
if(event.event == GPIO_SCENE_START_CUSTOM_EVENT_OTG_ON) {
|
||||
furi_hal_power_enable_otg();
|
||||
} else if(event.event == GPIO_SCENE_START_CUSTOM_EVENT_OTG_OFF) {
|
||||
furi_hal_power_disable_otg();
|
||||
} else if(event.event == GPIO_SCENE_START_CUSTOM_EVENT_TEST) {
|
||||
scene_manager_next_scene(app->scene_manager, GpioSceneTest);
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void gpio_scene_start_on_exit(void* context) {
|
||||
GpioApp* app = context;
|
||||
variable_item_list_clean(app->var_item_list);
|
||||
}
|
27
applications/gpio/scenes/gpio_scene_test.c
Normal file
27
applications/gpio/scenes/gpio_scene_test.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "../gpio_app_i.h"
|
||||
|
||||
void gpio_scene_test_ok_callback(InputType type, void* context) {
|
||||
furi_assert(context);
|
||||
GpioApp* app = context;
|
||||
|
||||
if(type == InputTypePress) {
|
||||
notification_message(app->notifications, &sequence_set_green_255);
|
||||
} else if(type == InputTypeRelease) {
|
||||
notification_message(app->notifications, &sequence_reset_green);
|
||||
}
|
||||
}
|
||||
|
||||
void gpio_scene_test_on_enter(void* context) {
|
||||
GpioApp* app = context;
|
||||
gpio_item_configure_all_pins(GpioModeOutputPushPull);
|
||||
gpio_test_set_ok_callback(app->gpio_test, gpio_scene_test_ok_callback, app);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewGpioTest);
|
||||
}
|
||||
|
||||
bool gpio_scene_test_on_event(void* context, SceneManagerEvent event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void gpio_scene_test_on_exit(void* context) {
|
||||
gpio_item_configure_all_pins(GpioModeAnalog);
|
||||
}
|
Reference in New Issue
Block a user