Select one of the symbols to view example projects that use it.
 
Outline
#include <string.h>
#include "esp_err.h"
#include "esp_mesh.h"
#include "mesh_light.h"
#include "driver/gpio.h"
#include "driver/ledc.h"
#define LEDC_IO_0
#define LEDC_IO_1
#define LEDC_IO_2
#define LEDC_IO_3
s_light_inited
mesh_light_init()
mesh_light_set(int)
mesh_connected_indicator(int)
mesh_disconnected_indicator()
mesh_light_process(mesh_addr_t *, uint8_t *, uint16_t)
Files
loading...
SourceVuESP-IDF Framework and Examplesinternal_communication samplemain/mesh_light.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* Mesh Internal Communication Example This example code is in the Public Domain (or CC0 licensed, at your option.) Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *//* ... */ #include <string.h> #include "esp_err.h" #include "esp_mesh.h" #include "mesh_light.h" #include "driver/gpio.h" #include "driver/ledc.h"6 includes /******************************************************* * Constants *******************************************************//* ... */ /* RGB configuration on ESP-WROVER-KIT board */ #define LEDC_IO_0 (0) #define LEDC_IO_1 (2) #define LEDC_IO_2 (4) #define LEDC_IO_3 (5) /******************************************************* * Variable Definitions *******************************************************//* ... */ static bool s_light_inited = false; /******************************************************* * Function Definitions *******************************************************//* ... */ esp_err_t mesh_light_init(void) { if (s_light_inited == true) { return ESP_OK; }{...} s_light_inited = true; ledc_timer_config_t ledc_timer = { .duty_resolution = LEDC_TIMER_13_BIT, .freq_hz = 5000, .speed_mode = LEDC_LOW_SPEED_MODE, .timer_num = LEDC_TIMER_0, .clk_cfg = LEDC_AUTO_CLK, }{...}; ledc_timer_config(&ledc_timer); ledc_channel_config_t ledc_channel = { .channel = LEDC_CHANNEL_0, .duty = 100, .gpio_num = LEDC_IO_0, .intr_type = LEDC_INTR_FADE_END, .speed_mode = LEDC_LOW_SPEED_MODE, .timer_sel = LEDC_TIMER_0, .hpoint = 0, }{...}; ledc_channel_config(&ledc_channel); ledc_channel.channel = LEDC_CHANNEL_1; ledc_channel.gpio_num = LEDC_IO_1; ledc_channel_config(&ledc_channel); ledc_channel.channel = LEDC_CHANNEL_2; ledc_channel.gpio_num = LEDC_IO_2; ledc_channel_config(&ledc_channel); ledc_channel.channel = LEDC_CHANNEL_3; ledc_channel.gpio_num = LEDC_IO_3; ledc_channel_config(&ledc_channel); ledc_fade_func_install(0); mesh_light_set(MESH_LIGHT_INIT); return ESP_OK; }{ ... } esp_err_t mesh_light_set(int color) { switch (color) { case MESH_LIGHT_RED: /* Red */ ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 3000); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2, 0); break;... case MESH_LIGHT_GREEN: /* Green */ ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 3000); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2, 0); break;... case MESH_LIGHT_BLUE: /* Blue */ ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2, 3000); break;... case MESH_LIGHT_YELLOW: /* Yellow */ ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 3000); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 3000); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2, 0); break;... case MESH_LIGHT_PINK: /* Pink */ ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 3000); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2, 3000); break;... case MESH_LIGHT_INIT: /* can't say */ ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 3000); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2, 3000); break;... case MESH_LIGHT_WARNING: /* warning */ ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 3000); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 3000); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2, 3000); break;... default: /* off */ ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1, 0); ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2, 0);... }{...} ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_1); ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_2); return ESP_OK; }{ ... } void mesh_connected_indicator(int layer) { switch (layer) { case 1: mesh_light_set(MESH_LIGHT_PINK); break;... case 2: mesh_light_set(MESH_LIGHT_YELLOW); break;... case 3: mesh_light_set(MESH_LIGHT_RED); break;... case 4: mesh_light_set(MESH_LIGHT_BLUE); break;... case 5: mesh_light_set(MESH_LIGHT_GREEN); break;... case 6: mesh_light_set(MESH_LIGHT_WARNING); break;... default: mesh_light_set(0);... }{...} }{ ... } void mesh_disconnected_indicator(void) { mesh_light_set(MESH_LIGHT_WARNING); }{ ... } esp_err_t mesh_light_process(mesh_addr_t *from, uint8_t *buf, uint16_t len) { mesh_light_ctl_t *in = (mesh_light_ctl_t *) buf; if (!from || !buf || len < sizeof(mesh_light_ctl_t)) { return ESP_FAIL; }{...} if (in->token_id != MESH_TOKEN_ID || in->token_value != MESH_TOKEN_VALUE) { return ESP_FAIL; }{...} if (in->cmd == MESH_CONTROL_CMD) { if (in->on) { mesh_connected_indicator(esp_mesh_get_layer()); }{...} else { mesh_light_set(0); }{...} }{...} return ESP_OK; }{ ... }
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.