1 // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef __LIGHT_DRIVER_H__
16 #define __LIGHT_DRIVER_H__
17 
18 #include "iot_led.h"
19 
20 #ifdef  __cplusplus
21 extern "C" {
22 #endif
23 
24 #define LIGHT_STATUS_STORE_KEY   "light_status"
25 
26 /**
27  * @brief The mode of the five-color light
28  */
29 typedef enum light_mode {
30     MODE_NONE                = 0,
31     MODE_RGB                 = 1,
32     MODE_HSV                 = 2,
33     MODE_CTB                 = 3,
34     MODE_ON                  = 4,
35     MODE_OFF                 = 5,
36     MODE_HUE_INCREASE        = 4,
37     MODE_HUE_DECREASE        = 5,
38     MODE_WARM_INCREASE       = 6,
39     MODE_WARM_DECREASE       = 7,
40     MODE_BRIGHTNESS_INCREASE = 8,
41     MODE_BRIGHTNESS_DECREASE = 9,
42     MODE_HSL                 = 10,
43 } light_mode_t;
44 
45 /**
46  * @brief Light driven configuration
47  */
48 typedef struct {
49     gpio_num_t gpio_red;      /**< Red corresponds to GPIO */
50     gpio_num_t gpio_green;    /**< Green corresponds to GPIO */
51     gpio_num_t gpio_blue;     /**< Blue corresponds to GPIO */
52     gpio_num_t gpio_cold;     /**< Cool corresponds to GPIO */
53     gpio_num_t gpio_warm;     /**< Warm corresponds to GPIO */
54     uint32_t fade_period_ms;  /**< The time from the current color to the next color */
55     uint32_t blink_period_ms; /**< Period of flashing lights */
56 } light_driver_config_t;
57 
58 /**
59  * @brief  Light initialize
60  *
61  * @param  config [description]
62  *
63  * @return
64  *      - ESP_OK
65  *      - ESP_ERR_INVALID_ARG
66  */
67 esp_err_t light_driver_init(light_driver_config_t *config);
68 
69 /**
70  * @brief  Light deinitialize
71  *
72  * @return
73  *      - ESP_OK
74  *      - ESP_ERR_INVALID_ARG
75  */
76 esp_err_t light_driver_deinit(void);
77 
78 
79 /**
80  * @brief Set the fade time of the light
81  *
82  * @param  fade_period_ms  The time from the current color to the next color
83  * @param  blink_period_ms Light flashing frequency
84  *
85  * @return
86  *      - ESP_OK
87  *      - ESP_FAIL
88  */
89 esp_err_t light_driver_config(uint32_t fade_period_ms, uint32_t blink_period_ms);
90 
91 /**@{*/
92 /**
93  * @brief  Set the status of the light
94  *
95  *
96  * @return
97  *      - ESP_OK
98  *      - ESP_ERR_INVALID_ARG
99  */
100 esp_err_t light_driver_set_hue(uint16_t hue);
101 esp_err_t light_driver_set_saturation(uint8_t saturation);
102 esp_err_t light_driver_set_value(uint8_t value);
103 esp_err_t light_driver_set_color_temperature(uint8_t color_temperature);
104 esp_err_t light_driver_set_brightness(uint8_t brightness);
105 esp_err_t light_driver_set_hsv(uint16_t hue, uint8_t saturation, uint8_t value);
106 esp_err_t light_driver_set_hsl(uint16_t hue, uint8_t saturation, uint8_t lightness);
107 esp_err_t light_driver_set_lightness(uint8_t lightness);
108 esp_err_t light_driver_set_ctb(uint8_t color_temperature, uint8_t brightness);
109 esp_err_t light_driver_set_switch(bool status);
110 esp_err_t light_driver_set_mode(light_mode_t mode);
111 
112 /**@}*/
113 
114 /**@{*/
115 /**
116  * @brief  Set the status of the light
117  */
118 uint16_t light_driver_get_hue(void);
119 uint8_t light_driver_get_saturation(void);
120 uint8_t light_driver_get_value(void);
121 esp_err_t light_driver_get_hsv(uint16_t *hue, uint8_t *saturation, uint8_t *value);
122 uint8_t light_driver_get_lightness(void);
123 esp_err_t light_driver_get_hsl(uint16_t *hue, uint8_t *saturation, uint8_t *lightness);
124 uint8_t light_driver_get_color_temperature(void);
125 uint8_t light_driver_get_brightness(void);
126 esp_err_t light_driver_get_ctb(uint8_t *color_temperature, uint8_t *brightness);
127 bool light_driver_get_switch(void);
128 uint8_t light_driver_get_mode(void);
129 /**@}*/
130 
131 /**@{*/
132 /**
133  * @brief  Used to indicate the operating mode, such as configuring the network mode, upgrading mode
134  *
135  * @note   The state of the light is not saved in nvs
136  *
137  * @return
138  *      - ESP_OK
139  *      - ESP_ERR_INVALID_ARG
140  */
141 esp_err_t light_driver_set_rgb(uint8_t red, uint8_t green, uint8_t blue);
142 esp_err_t light_driver_breath_start(uint8_t red, uint8_t green, uint8_t blue);
143 esp_err_t light_driver_breath_stop(void);
144 esp_err_t light_driver_blink_start(uint8_t red, uint8_t green, uint8_t blue);
145 esp_err_t light_driver_blink_stop(void);
146 /**@}*/
147 
148 /**@{*/
149 /**
150  * @brief  Color gradient
151  *
152  * @return
153  *      - ESP_OK
154  *      - ESP_ERR_INVALID_ARG
155  */
156 esp_err_t light_driver_fade_brightness(uint8_t brightness);
157 esp_err_t light_driver_fade_hue(uint16_t hue);
158 esp_err_t light_driver_fade_warm(uint8_t color_temperature);
159 esp_err_t light_driver_fade_stop(void);
160 /**@}*/
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif/**< __LIGHT_DRIVER_H__ */
167