You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

211 lines
6.8 KiB

/**
* @file light.c
* @author Finny (tianjialong0106@163.com)
* @brief Project micro shape photometer light control
* @version 0.1
* @date 2022-09-25
*
* @copyright Copyright (c) 2022
*
*/
#include "light.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "port.h"
#define DEBUG_LIGHT_TOGGLE_TIME 300
#define OTHER_LIGHT_TOGGLE_TIME 500
#define GPIO_DEBUG_LIGHT 12
#define GPIO_POWER_LIGHT 12
#define GPIO_HEATING_PLATE_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_plate_state_light_structer_t *heating_plate_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_light_toggle_level(uint8_t io_num)
{
gpio_set_level(io_num, !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_plate_state_light_init(heating_plate_state_light_structer_t *heating_plate_state_light_structer)
{
heating_plate_state_light_structer_s = heating_plate_state_light_structer;
gpio_config_t gpio_heating_plate_state_light_init_structer;
gpio_heating_plate_state_light_init_structer.intr_type = GPIO_INTR_DISABLE;
gpio_heating_plate_state_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT;
gpio_heating_plate_state_light_init_structer.pin_bit_mask = (1ULL << GPIO_HEATING_PLATE_STATE_LIGHT);
gpio_heating_plate_state_light_init_structer.pull_down_en = 0;
gpio_heating_plate_state_light_init_structer.pull_up_en = 0;
gpio_config(&gpio_heating_plate_state_light_init_structer);
}
void T_heating_plate_light_change_state(heating_plate_state_t change_state)
{
heating_plate_state_light_structer_s->state = change_state;
heating_plate_state_light_structer_s->change_flag = true;
}
void T_heating_plate_light_set_rgb_by_state(heating_plate_state_t state)
{
if (state == NoHeat)
{
gpio_set_level(GPIO_HEATING_PLATE_STATE_LIGHT, 0);
}
else if (state == HeatComplete)
{
gpio_set_level(GPIO_HEATING_PLATE_STATE_LIGHT, 1);
}
}
// 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);
}
void T_reaction_light_change_state(reaction_state_t change_state)
{
reaction_state_light_structer_s->state = change_state;
reaction_state_light_structer_s->change_flag = true;
}
void T_reaction_light_set_rgb_by_state(reaction_state_t state)
{
if (state == NoReaction)
{
gpio_set_level(GPIO_REACTION_STATE_LIGHT, 0);
}
else if (state == ReactionComplete)
{
gpio_set_level(GPIO_REACTION_STATE_LIGHT, 1);
}
}
// 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_wifi_light_change_state(wifi_state_t change_state)
{
wifi_state_light_structer_s->state = change_state;
wifi_state_light_structer_s->change_flag = true;
}
void T_wifi_light_set_rgb_by_state(wifi_state_t state)
{
if (state == NotConnected)
{
gpio_set_level(GPIO_WIFI_STATE_LIGHT, 0);
}
else if (state == ConnectionComplete)
{
gpio_set_level(GPIO_WIFI_STATE_LIGHT, 1);
}
}
void T_debug_light_schedule(void)
{
static uint32_t debug_light_time;
if (port_haspassedms(debug_light_time) > DEBUG_LIGHT_TOGGLE_TIME)
{
T_light_toggle_level(GPIO_DEBUG_LIGHT);
debug_light_time = port_get_ticket();
}
}
void T_light_schedule(void)
{
static uint32_t light_ticket;
if (heating_plate_state_light_structer_s->change_flag)
{
T_heating_plate_light_set_rgb_by_state(heating_plate_state_light_structer_s->state);
heating_plate_state_light_structer_s->change_flag = false;
}
if (reaction_state_light_structer_s->change_flag)
{
T_reaction_light_set_rgb_by_state(reaction_state_light_structer_s->state);
reaction_state_light_structer_s->change_flag = false;
}
if (wifi_state_light_structer_s->change_flag)
{
T_reaction_light_set_rgb_by_state(wifi_state_light_structer_s->state);
wifi_state_light_structer_s->change_flag = false;
}
if (port_haspassedms(light_ticket) > OTHER_LIGHT_TOGGLE_TIME)
{
if (heating_plate_state_light_structer_s->state == Heating)
{
T_light_toggle_level(GPIO_HEATING_PLATE_STATE_LIGHT);
}
if (reaction_state_light_structer_s->state == Reacting)
{
T_light_toggle_level(GPIO_REACTION_STATE_LIGHT);
}
if (wifi_state_light_structer_s->state == Connecting)
{
T_light_toggle_level(GPIO_WIFI_STATE_LIGHT);
}
light_ticket = port_get_ticket();
}
}