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.

115 lines
4.1 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. /**
  2. * @file light.c
  3. * @author Finny (tianjialong0106@163.com)
  4. * @brief Project micro shape photometer light control
  5. * @version 0.1
  6. * @date 2022-09-25
  7. *
  8. * @copyright Copyright (c) 2022
  9. *
  10. */
  11. #include "light.h"
  12. #include "driver/gpio.h"
  13. #include "esp_log.h"
  14. #include "port.h"
  15. #define GPIO_DEBUG_LIGHT 12
  16. #define GPIO_POWER_LIGHT 12
  17. #define GPIO_HEATING_PLATE_STATE_LIGHT 12
  18. #define GPIO_REACTION_STATE_LIGHT 12
  19. #define GPIO_WIFI_STATE_LIGHT 12
  20. static power_state_light_structer_t *power_state_light_structer_s;
  21. static heating_plate_state_light_structer_t *heating_plate_state_light_structer_s;
  22. static reaction_state_light_structer_t *reaction_state_light_structer_s;
  23. static wifi_state_light_structer_t *wifi_state_light_structer_s;
  24. // Debug light
  25. void T_debug_light_init(void)
  26. {
  27. gpio_config_t gpio_debug_light_init_structer;
  28. gpio_debug_light_init_structer.intr_type = GPIO_INTR_DISABLE;
  29. gpio_debug_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT;
  30. gpio_debug_light_init_structer.pin_bit_mask = (1ULL << GPIO_DEBUG_LIGHT);
  31. gpio_debug_light_init_structer.pull_down_en = 0;
  32. gpio_debug_light_init_structer.pull_up_en = 0;
  33. gpio_config(&gpio_debug_light_init_structer);
  34. }
  35. void T_debug_light_toggle_level(void)
  36. {
  37. gpio_set_level(GPIO_DEBUG_LIGHT, !gpio_get_level(GPIO_DEBUG_LIGHT));
  38. }
  39. // Power light
  40. void T_power_light_init(power_state_light_structer_t *power_state_light_structer)
  41. {
  42. power_state_light_structer_s = power_state_light_structer;
  43. gpio_config_t gpio_debug_light_init_structer;
  44. gpio_debug_light_init_structer.intr_type = GPIO_INTR_DISABLE;
  45. gpio_debug_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT;
  46. gpio_debug_light_init_structer.pin_bit_mask = (1ULL << GPIO_POWER_LIGHT);
  47. gpio_debug_light_init_structer.pull_down_en = 0;
  48. gpio_debug_light_init_structer.pull_up_en = 0;
  49. gpio_config(&gpio_debug_light_init_structer);
  50. }
  51. // Heating state light
  52. void T_heating_plate_state_light_init(heating_plate_state_light_structer_t *heating_plate_state_light_structer)
  53. {
  54. heating_plate_state_light_structer_s = heating_plate_state_light_structer;
  55. gpio_config_t gpio_heating_plate_state_light_init_structer;
  56. gpio_heating_plate_state_light_init_structer.intr_type = GPIO_INTR_DISABLE;
  57. gpio_heating_plate_state_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT;
  58. gpio_heating_plate_state_light_init_structer.pin_bit_mask = (1ULL << GPIO_HEATING_PLATE_STATE_LIGHT);
  59. gpio_heating_plate_state_light_init_structer.pull_down_en = 0;
  60. gpio_heating_plate_state_light_init_structer.pull_up_en = 0;
  61. gpio_config(&gpio_heating_plate_state_light_init_structer);
  62. }
  63. // Reaction state light
  64. void T_reaction_state_light_init(reaction_state_light_structer_t *reaction_state_light_structer)
  65. {
  66. reaction_state_light_structer_s = reaction_state_light_structer;
  67. gpio_config_t gpio_reaction_state_light_init_structer;
  68. gpio_reaction_state_light_init_structer.intr_type = GPIO_INTR_DISABLE;
  69. gpio_reaction_state_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT;
  70. gpio_reaction_state_light_init_structer.pin_bit_mask = (1ULL << GPIO_REACTION_STATE_LIGHT);
  71. gpio_reaction_state_light_init_structer.pull_down_en = 0;
  72. gpio_reaction_state_light_init_structer.pull_up_en = 0;
  73. gpio_config(&gpio_reaction_state_light_init_structer);
  74. }
  75. // WIFI state light
  76. void T_wifi_state_light_init(wifi_state_light_structer_t *wifi_state_light_structer)
  77. {
  78. wifi_state_light_structer_s = wifi_state_light_structer;
  79. gpio_config_t gpio_wifi_state_light_init_structer;
  80. gpio_wifi_state_light_init_structer.intr_type = GPIO_INTR_DISABLE;
  81. gpio_wifi_state_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT;
  82. gpio_wifi_state_light_init_structer.pin_bit_mask = (1ULL << GPIO_WIFI_STATE_LIGHT);
  83. gpio_wifi_state_light_init_structer.pull_down_en = 0;
  84. gpio_wifi_state_light_init_structer.pull_up_en = 0;
  85. gpio_config(&gpio_wifi_state_light_init_structer);
  86. }
  87. void T_debug_light_schedule(void)
  88. {
  89. static uint32_t debug_light_time;
  90. if (port_haspassedms(debug_light_time) > 300)
  91. {
  92. T_debug_light_toggle_level();
  93. debug_light_time = port_get_ticket();
  94. }
  95. }