From 3ac03af3ba9b0cabddd230d4416e4e6266178923 Mon Sep 17 00:00:00 2001 From: zwsd Date: Sun, 25 Sep 2022 17:05:59 +0800 Subject: [PATCH] update light --- main/CMakeLists.txt | 1 + main/app_main.cpp | 30 +++++++++++++- main/light.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++ main/light.h | 84 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 main/light.c create mode 100644 main/light.h diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 9aae90a..7af198f 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,6 +1,7 @@ set(srcs "app_main.cpp" # "ble_spp_server_demo.c" "camera.cpp" + "light.c" ) idf_component_register(SRCS "${srcs}"# diff --git a/main/app_main.cpp b/main/app_main.cpp index 5d39962..cc373c9 100644 --- a/main/app_main.cpp +++ b/main/app_main.cpp @@ -3,15 +3,43 @@ extern "C" { #include "ble_spp_server_demo.h" +#include "light.h" +} +power_state_light_structer_t power_state_light_structer = { + .state = ShutDown, + .change_flag = false, +}; +heating_state_light_structer_t heating_state_light_structer = { + .state = NoHeat, + .change_flag = false, +}; +reaction_state_light_structer_t reaction_state_light_structer = { + .state = NoReaction, + .change_flag = false, +}; +wifi_state_light_structer_t wifi_state_light_structer = { + .state = NotConnected, + .change_flag = false, +}; + +static void T_all_light_init(void) +{ + T_power_light_init(&power_state_light_structer); + T_heating_state_light_init(&heating_state_light_structer); + T_reaction_state_light_init(&reaction_state_light_structer); + T_wifi_state_light_init(&wifi_state_light_structer); } extern "C" void app_main(void) { + T_debug_light_init(); + T_all_light_init(); ble_spp_server_init(); camera_motion_detection_init(); while (true) { - /* code */ + T_debug_light_schedule(); + T_light_schedule(); } } \ No newline at end of file diff --git a/main/light.c b/main/light.c new file mode 100644 index 0000000..093ab1a --- /dev/null +++ b/main/light.c @@ -0,0 +1,114 @@ +#include "light.h" + +#include "driver/gpio.h" +#include "esp_log.h" + +#define GPIO_DEBUG_LIGHT 12 +#define GPIO_POWER_LIGHT 12 +#define GPIO_HEATING_STATE_LIGHT 12 +#define GPIO_REACTION_STATE_LIGHT 12 +#define GPIO_WIFI_STATE_LIGHT 12 + +static power_state_light_structer_t *power_state_light_structer_s; +static heating_state_light_structer_t *heating_state_light_structer_s; +static reaction_state_light_structer_t *reaction_state_light_structer_s; +static wifi_state_light_structer_t *wifi_state_light_structer_s; + +// Debug light +void T_debug_light_init(void) +{ + gpio_config_t gpio_debug_light_init_structer; + + gpio_debug_light_init_structer.intr_type = GPIO_INTR_DISABLE; + gpio_debug_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT; + gpio_debug_light_init_structer.pin_bit_mask = (1ULL << GPIO_DEBUG_LIGHT); + gpio_debug_light_init_structer.pull_down_en = 0; + gpio_debug_light_init_structer.pull_up_en = 0; + + gpio_config(&gpio_debug_light_init_structer); +} + +void T_debug_light_toggle_level(void) +{ + gpio_set_level(GPIO_DEBUG_LIGHT, !gpio_get_level(GPIO_DEBUG_LIGHT)); +} + +// Power light +void T_power_light_init(power_state_light_structer_t *power_state_light_structer) +{ + power_state_light_structer_s = power_state_light_structer; + gpio_config_t gpio_debug_light_init_structer; + + gpio_debug_light_init_structer.intr_type = GPIO_INTR_DISABLE; + gpio_debug_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT; + gpio_debug_light_init_structer.pin_bit_mask = (1ULL << GPIO_POWER_LIGHT); + gpio_debug_light_init_structer.pull_down_en = 0; + gpio_debug_light_init_structer.pull_up_en = 0; + + gpio_config(&gpio_debug_light_init_structer); +} + +// Heating state light +void T_heating_state_light_init(heating_state_light_structer_t *heating_state_light_structer) +{ + heating_state_light_structer_s = heating_state_light_structer; + gpio_config_t gpio_heating_state_light_init_structer; + + gpio_heating_state_light_init_structer.intr_type = GPIO_INTR_DISABLE; + gpio_heating_state_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT; + gpio_heating_state_light_init_structer.pin_bit_mask = (1ULL << GPIO_HEATING_STATE_LIGHT); + gpio_heating_state_light_init_structer.pull_down_en = 0; + gpio_heating_state_light_init_structer.pull_up_en = 0; + + gpio_config(&gpio_heating_state_light_init_structer); +} + +// Reaction state light +void T_reaction_state_light_init(reaction_state_light_structer_t *reaction_state_light_structer) +{ + reaction_state_light_structer_s = reaction_state_light_structer; + gpio_config_t gpio_reaction_state_light_init_structer; + + gpio_reaction_state_light_init_structer.intr_type = GPIO_INTR_DISABLE; + gpio_reaction_state_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT; + gpio_reaction_state_light_init_structer.pin_bit_mask = (1ULL << GPIO_REACTION_STATE_LIGHT); + gpio_reaction_state_light_init_structer.pull_down_en = 0; + gpio_reaction_state_light_init_structer.pull_up_en = 0; + + gpio_config(&gpio_reaction_state_light_init_structer); +} + +// WIFI state light +void T_wifi_state_light_init(wifi_state_light_structer_t *wifi_state_light_structer) +{ + wifi_state_light_structer_s = wifi_state_light_structer; + gpio_config_t gpio_wifi_state_light_init_structer; + + gpio_wifi_state_light_init_structer.intr_type = GPIO_INTR_DISABLE; + gpio_wifi_state_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT; + gpio_wifi_state_light_init_structer.pin_bit_mask = (1ULL << GPIO_WIFI_STATE_LIGHT); + gpio_wifi_state_light_init_structer.pull_down_en = 0; + gpio_wifi_state_light_init_structer.pull_up_en = 0; + + gpio_config(&gpio_wifi_state_light_init_structer); +} + +void T_debug_light_schedule(void) +{ +} + +void T_light_schedule(void) +{ + if (power_state_light_structer_s->change_flag) + { + } + if (heating_state_light_structer_s->change_flag) + { + } + if (reaction_state_light_structer_s->change_flag) + { + } + if (wifi_state_light_structer_s->change_flag) + { + } +} \ No newline at end of file diff --git a/main/light.h b/main/light.h new file mode 100644 index 0000000..a8245df --- /dev/null +++ b/main/light.h @@ -0,0 +1,84 @@ +/** + * @file light.h + * @author Finny (tianjialong0106@163.com) + * @brief Project micro shape photometer light control + * @version 0.1 + * @date 2022-09-25 + * + * @copyright Copyright (c) 2022 + * + */ +#pragma once + +#include + +typedef enum +{ + ShutDown = 1, //关机 + StartingUp, //开机 +} power_state_t; + +typedef enum +{ + NoHeat = 1, //没加热 + Heating, //加热中 + HeatComplete, //加热完成 +} heating_state_t; + +typedef enum +{ + NoReaction = 1, //没反应 + Reacting, //反应中 + ReactionComplete, //反应完成 +} reaction_state_t; + +typedef enum +{ + NotConnected = 1, //未连接 + Connecting, //连接中 + ConnectionComplete, //连接完成 +} wifi_state_t; + +typedef struct +{ + power_state_t state; + bool change_flag; +} power_state_light_structer_t; + +typedef struct +{ + heating_state_t state; + bool change_flag; +} heating_state_light_structer_t; + +typedef struct +{ + reaction_state_t state; + bool change_flag; +} reaction_state_light_structer_t; + +typedef struct +{ + wifi_state_t state; + bool change_flag; +} wifi_state_light_structer_t; + +// Debug light +void T_debug_light_init(void); +void T_debug_light_toggle_level(void); + +// Power light +void T_power_light_init(power_state_light_structer_t *power_state_light_structer); + +// Heating state light +void T_heating_state_light_init(heating_state_light_structer_t *heating_state_light_structer); + +// Reaction state light +void T_reaction_state_light_init(reaction_state_light_structer_t *reaction_state_light_structer); + +// WIFI state light +void T_wifi_state_light_init(wifi_state_light_structer_t *wifi_state_light_structer); + +// Schedule +void T_debug_light_schedule(void); +void T_light_schedule(void); \ No newline at end of file