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.

141 lines
4.8 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
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 DEBUG_LIGHT_TOGGLE_TIME 300
  16. #define OTHER_LIGHT_TOGGLE_TIME 500
  17. #define GPIO_DEBUG_LIGHT 12
  18. #define GPIO_POWER_LIGHT 12
  19. #define GPIO_HEATING_PLATE_STATE_LIGHT 12
  20. #define GPIO_REACTION_STATE_LIGHT 12
  21. #define GPIO_WIFI_STATE_LIGHT 12
  22. static power_state_light_structer_t *power_state_light_structer_s;
  23. static heating_plate_state_light_structer_t *heating_plate_state_light_structer_s;
  24. static reaction_state_light_structer_t *reaction_state_light_structer_s;
  25. static wifi_state_light_structer_t *wifi_state_light_structer_s;
  26. // Debug light
  27. void T_debug_light_init(void)
  28. {
  29. gpio_config_t gpio_debug_light_init_structer;
  30. gpio_debug_light_init_structer.intr_type = GPIO_INTR_DISABLE;
  31. gpio_debug_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT;
  32. gpio_debug_light_init_structer.pin_bit_mask = (1ULL << GPIO_DEBUG_LIGHT);
  33. gpio_debug_light_init_structer.pull_down_en = 0;
  34. gpio_debug_light_init_structer.pull_up_en = 0;
  35. gpio_config(&gpio_debug_light_init_structer);
  36. }
  37. void T_light_toggle_level(uint8_t io_num)
  38. {
  39. gpio_set_level(io_num, !gpio_get_level(GPIO_DEBUG_LIGHT));
  40. }
  41. // Power light
  42. void T_power_light_init(power_state_light_structer_t *power_state_light_structer)
  43. {
  44. power_state_light_structer_s = power_state_light_structer;
  45. gpio_config_t gpio_debug_light_init_structer;
  46. gpio_debug_light_init_structer.intr_type = GPIO_INTR_DISABLE;
  47. gpio_debug_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT;
  48. gpio_debug_light_init_structer.pin_bit_mask = (1ULL << GPIO_POWER_LIGHT);
  49. gpio_debug_light_init_structer.pull_down_en = 0;
  50. gpio_debug_light_init_structer.pull_up_en = 0;
  51. gpio_config(&gpio_debug_light_init_structer);
  52. }
  53. // Heating state light
  54. void T_heating_plate_state_light_init(heating_plate_state_light_structer_t *heating_plate_state_light_structer)
  55. {
  56. heating_plate_state_light_structer_s = heating_plate_state_light_structer;
  57. gpio_config_t gpio_heating_plate_state_light_init_structer;
  58. gpio_heating_plate_state_light_init_structer.intr_type = GPIO_INTR_DISABLE;
  59. gpio_heating_plate_state_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT;
  60. gpio_heating_plate_state_light_init_structer.pin_bit_mask = (1ULL << GPIO_HEATING_PLATE_STATE_LIGHT);
  61. gpio_heating_plate_state_light_init_structer.pull_down_en = 0;
  62. gpio_heating_plate_state_light_init_structer.pull_up_en = 0;
  63. gpio_config(&gpio_heating_plate_state_light_init_structer);
  64. }
  65. // Reaction state light
  66. void T_reaction_state_light_init(reaction_state_light_structer_t *reaction_state_light_structer)
  67. {
  68. reaction_state_light_structer_s = reaction_state_light_structer;
  69. gpio_config_t gpio_reaction_state_light_init_structer;
  70. gpio_reaction_state_light_init_structer.intr_type = GPIO_INTR_DISABLE;
  71. gpio_reaction_state_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT;
  72. gpio_reaction_state_light_init_structer.pin_bit_mask = (1ULL << GPIO_REACTION_STATE_LIGHT);
  73. gpio_reaction_state_light_init_structer.pull_down_en = 0;
  74. gpio_reaction_state_light_init_structer.pull_up_en = 0;
  75. gpio_config(&gpio_reaction_state_light_init_structer);
  76. }
  77. // WIFI state light
  78. void T_wifi_state_light_init(wifi_state_light_structer_t *wifi_state_light_structer)
  79. {
  80. wifi_state_light_structer_s = wifi_state_light_structer;
  81. gpio_config_t gpio_wifi_state_light_init_structer;
  82. gpio_wifi_state_light_init_structer.intr_type = GPIO_INTR_DISABLE;
  83. gpio_wifi_state_light_init_structer.mode = GPIO_MODE_INPUT_OUTPUT;
  84. gpio_wifi_state_light_init_structer.pin_bit_mask = (1ULL << GPIO_WIFI_STATE_LIGHT);
  85. gpio_wifi_state_light_init_structer.pull_down_en = 0;
  86. gpio_wifi_state_light_init_structer.pull_up_en = 0;
  87. gpio_config(&gpio_wifi_state_light_init_structer);
  88. }
  89. void T_debug_light_schedule(void)
  90. {
  91. static uint32_t debug_light_time;
  92. if (port_haspassedms(debug_light_time) > DEBUG_LIGHT_TOGGLE_TIME)
  93. {
  94. T_light_toggle_level(GPIO_DEBUG_LIGHT);
  95. debug_light_time = port_get_ticket();
  96. }
  97. }
  98. void T_light_flash_schedule(void)
  99. {
  100. static uint32_t debug_light_time;
  101. if (port_haspassedms(debug_light_time) > OTHER_LIGHT_TOGGLE_TIME)
  102. {
  103. if (heating_plate_state_light_structer_s->state == Heating)
  104. {
  105. T_light_toggle_level(GPIO_HEATING_PLATE_STATE_LIGHT);
  106. }
  107. if (reaction_state_light_structer_s->state == Reacting)
  108. {
  109. T_light_toggle_level(GPIO_REACTION_STATE_LIGHT);
  110. }
  111. if (wifi_state_light_structer_s->state == Connecting)
  112. {
  113. T_light_toggle_level(GPIO_WIFI_STATE_LIGHT);
  114. }
  115. debug_light_time = port_get_ticket();
  116. }
  117. }