Skip to content

Commit 98cef99

Browse files
authored
Merge pull request diyhue#111 from mariusmotea/develop
Add all new changes to master
2 parents cab2d6f + d78afcc commit 98cef99

File tree

12 files changed

+1501
-191
lines changed

12 files changed

+1501
-191
lines changed

BridgeEmulator/HueEmulator.py

+107-87
Large diffs are not rendered by default.

Lights/Arduino/Generic_CCT_Light/Generic_CCT_Light.ino

+64-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
This can control bulbs with 5 pwm channels (red, gree, blue, warm white and could wihite). Is tested with MiLight RGB_CCT bulb.
2+
This can control bulbs with 2 pwm channel
33
*/
44

55

@@ -15,6 +15,10 @@
1515
#define PWM_CHANNELS 2
1616
const uint32_t period = 1024;
1717

18+
#define use_hardware_switch false // on/off state and brightness can be controlled with above gpio pins. Is mandatory to connect them to ground with 10K resistors
19+
#define button1_pin 1 // on and bri up
20+
#define button2_pin 3 // off and bri down
21+
1822
//define pins
1923
uint32 io_info[PWM_CHANNELS][3] = {
2024
// MUX, FUNC, PIN
@@ -82,6 +86,20 @@ void apply_scene(uint8_t new_scene) {
8286
}
8387
}
8488

89+
void process_lightdata(float transitiontime) {
90+
if (light_state == true) {
91+
convert_ct();
92+
}
93+
transitiontime *= 16;
94+
for (uint8_t color = 0; color < PWM_CHANNELS; color++) {
95+
if (light_state) {
96+
step_level[color] = (cct[color] - current_cct[color]) / transitiontime;
97+
} else {
98+
step_level[color] = current_cct[color] / transitiontime;
99+
}
100+
}
101+
}
102+
85103
void lightEngine() {
86104
for (uint8_t color = 0; color < PWM_CHANNELS; color++) {
87105
if (light_state) {
@@ -105,6 +123,46 @@ void lightEngine() {
105123
if (in_transition) {
106124
delay(6);
107125
in_transition = false;
126+
} else if (use_hardware_switch == true) {
127+
if (digitalRead(button1_pin) == HIGH) {
128+
int i = 0;
129+
while (digitalRead(button1_pin) == HIGH && i < 30) {
130+
delay(20);
131+
i++;
132+
}
133+
if (i < 30) {
134+
// there was a short press
135+
light_state = true;
136+
}
137+
else {
138+
// there was a long press
139+
bri += 56;
140+
if (bri > 254) {
141+
// don't increase the brightness more then maximum value
142+
bri = 254;
143+
}
144+
}
145+
process_lightdata(4);
146+
} else if (digitalRead(button2_pin) == HIGH) {
147+
int i = 0;
148+
while (digitalRead(button2_pin) == HIGH && i < 30) {
149+
delay(20);
150+
i++;
151+
}
152+
if (i < 30) {
153+
// there was a short press
154+
light_state = false;
155+
}
156+
else {
157+
// there was a long press
158+
bri -= 56;
159+
if (bri < 1) {
160+
// don't decrease the brightness less than minimum value.
161+
bri = 1;
162+
}
163+
}
164+
process_lightdata(4);
165+
}
108166
}
109167
}
110168

@@ -154,6 +212,10 @@ void setup() {
154212

155213
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
156214
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
215+
if (use_hardware_switch == true) {
216+
pinMode(button1_pin, INPUT);
217+
pinMode(button2_pin, INPUT);
218+
}
157219

158220
server.on("/switch", []() {
159221
server.send(200, "text/plain", "OK");
@@ -246,17 +308,7 @@ void setup() {
246308
}
247309
}
248310
server.send(200, "text/plain", "OK, bri:" + (String)bri + ", ct:" + ct + ", colormode: ct, state:" + light_state);
249-
if (light_state == true) {
250-
convert_ct();
251-
}
252-
transitiontime *= 16;
253-
for (uint8_t color = 0; color < PWM_CHANNELS; color++) {
254-
if (light_state) {
255-
step_level[color] = (cct[color] - current_cct[color]) / transitiontime;
256-
} else {
257-
step_level[color] = current_cct[color] / transitiontime;
258-
}
259-
}
311+
process_lightdata(transitiontime);
260312
});
261313

262314
server.on("/get", []() {

Lights/Arduino/Generic_Dimmable_Light/Generic_Dimmable_Light.ino

+74-18
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@
77
#include <EEPROM.h>
88
#include "pwm.c"
99

10-
#define lightsCount 3
10+
#define lightsCount 4
11+
12+
#define use_hardware_switch false // on/off state and brightness can be controlled with above gpio pins. Is mandatory to connect them to ground with 10K resistors.
13+
#define button1_pin 4 // on and bri up
14+
#define button2_pin 5 // off and bri down
1115

1216
const uint32_t period = 1024;
1317

1418
//define pins
1519
uint32 io_info[lightsCount][3] = {
1620
// MUX, FUNC, PIN
17-
//{PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12, 12},
18-
//{PERIPHS_IO_MUX_MTDO_U, FUNC_GPIO15, 15},
19-
//{PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13, 13},
20-
//{PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14, 14},
21-
{PERIPHS_IO_MUX_GPIO4_U, FUNC_GPIO4 , 4},
22-
{PERIPHS_IO_MUX_GPIO5_U, FUNC_GPIO5 , 5},
21+
{PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12, 12},
22+
{PERIPHS_IO_MUX_MTDO_U, FUNC_GPIO15, 15},
23+
{PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13, 13},
24+
{PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14, 14},
25+
//{PERIPHS_IO_MUX_GPIO4_U, FUNC_GPIO4 , 4},
26+
//{PERIPHS_IO_MUX_GPIO5_U, FUNC_GPIO5 , 5},
2327
};
2428

2529
// initial duty: all off
@@ -65,6 +69,15 @@ void apply_scene(uint8_t new_scene, uint8_t light) {
6569
}
6670
}
6771

72+
void process_lightdata(uint8_t light, float transitiontime) {
73+
transitiontime *= 16;
74+
if (light_state[light]) {
75+
step_level[light] = (bri[light] - current_bri[light]) / transitiontime;
76+
} else {
77+
step_level[light] = current_bri[light] / transitiontime;
78+
}
79+
}
80+
6881

6982
void lightEngine() {
7083
for (int i = 0; i < lightsCount; i++) {
@@ -89,6 +102,50 @@ void lightEngine() {
89102
if (in_transition) {
90103
delay(6);
91104
in_transition = false;
105+
} else if (use_hardware_switch == true) {
106+
if (digitalRead(button1_pin) == HIGH) {
107+
int i = 0;
108+
while (digitalRead(button1_pin) == HIGH && i < 30) {
109+
delay(20);
110+
i++;
111+
}
112+
for (int light = 0; light < lightsCount; light++) {
113+
if (i < 30) {
114+
// there was a short press
115+
light_state[light] = true;
116+
}
117+
else {
118+
// there was a long press
119+
bri[light] += 56;
120+
if (bri[light] > 254) {
121+
// don't increase the brightness more then maximum value
122+
bri[light] = 254;
123+
}
124+
}
125+
process_lightdata(light, 4);
126+
}
127+
} else if (digitalRead(button2_pin) == HIGH) {
128+
int i = 0;
129+
while (digitalRead(button2_pin) == HIGH && i < 30) {
130+
delay(20);
131+
i++;
132+
}
133+
for (int light = 0; light < lightsCount; light++) {
134+
if (i < 30) {
135+
// there was a short press
136+
light_state[light] = false;
137+
}
138+
else {
139+
// there was a long press
140+
bri[light] -= 56;
141+
if (bri[light] < 1) {
142+
// don't decrease the brightness less than minimum value.
143+
bri[light] = 1;
144+
}
145+
}
146+
process_lightdata(light, 4);
147+
}
148+
}
92149
}
93150
}
94151

@@ -143,6 +200,10 @@ void setup() {
143200

144201
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
145202
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
203+
if (use_hardware_switch == true) {
204+
pinMode(button1_pin, INPUT);
205+
pinMode(button2_pin, INPUT);
206+
}
146207

147208

148209
server.on("/switch", []() {
@@ -180,11 +241,11 @@ void setup() {
180241
} else if (button == 4000) {
181242
light_state[i] = false;
182243
}
183-
if (light_state[i]) {
184-
step_level[i] = ((float)bri[i] - current_bri[i]) / transitiontime;
185-
} else {
186-
step_level[i] = current_bri[i] / transitiontime;
187-
}
244+
if (light_state[i]) {
245+
step_level[i] = ((float)bri[i] - current_bri[i]) / transitiontime;
246+
} else {
247+
step_level[i] = current_bri[i] / transitiontime;
248+
}
188249
}
189250
});
190251

@@ -231,13 +292,8 @@ void setup() {
231292
transitiontime = server.arg(i).toInt();
232293
}
233294
}
295+
process_lightdata(light, transitiontime);
234296
server.send(200, "text/plain", "OK, bri:" + (String)bri[light] + ", state:" + light_state[light]);
235-
transitiontime *= 16;
236-
if (light_state[light]) {
237-
step_level[light] = (bri[light] - current_bri[light]) / transitiontime;
238-
} else {
239-
step_level[light] = current_bri[light] / transitiontime;
240-
}
241297
});
242298

243299
server.on("/get", []() {

Lights/Arduino/Generic_RGBW_Light/Generic_RGBW_Light.ino

+68-15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#define PWM_CHANNELS 4
1111
const uint32_t period = 1024;
1212

13+
#define use_hardware_switch false // on/off state and brightness can be controlled with above gpio pins. Is mandatory to connect them to ground with 10K resistors
14+
#define button1_pin 1 // on and bri up
15+
#define button2_pin 3 // off and bri down
16+
1317
//define pins
1418
uint32 io_info[PWM_CHANNELS][3] = {
1519
// MUX, FUNC, PIN
@@ -201,6 +205,24 @@ void apply_scene(uint8_t new_scene) {
201205
}
202206
}
203207

208+
void process_lightdata(float transitiontime) {
209+
if (color_mode == 1 && light_state == true) {
210+
convert_xy();
211+
} else if (color_mode == 2 && light_state == true) {
212+
convert_ct();
213+
} else if (color_mode == 3 && light_state == true) {
214+
convert_hue();
215+
}
216+
transitiontime *= 16;
217+
for (uint8_t color = 0; color < PWM_CHANNELS; color++) {
218+
if (light_state) {
219+
step_level[color] = (rgbw[color] - current_rgbw[color]) / transitiontime;
220+
} else {
221+
step_level[color] = current_rgbw[color] / transitiontime;
222+
}
223+
}
224+
}
225+
204226
void lightEngine() {
205227
for (uint8_t color = 0; color < PWM_CHANNELS; color++) {
206228
if (light_state) {
@@ -224,6 +246,46 @@ void lightEngine() {
224246
if (in_transition) {
225247
delay(6);
226248
in_transition = false;
249+
} else if (use_hardware_switch == true) {
250+
if (digitalRead(button1_pin) == HIGH) {
251+
int i = 0;
252+
while (digitalRead(button1_pin) == HIGH && i < 30) {
253+
delay(20);
254+
i++;
255+
}
256+
if (i < 30) {
257+
// there was a short press
258+
light_state = true;
259+
}
260+
else {
261+
// there was a long press
262+
bri += 56;
263+
if (bri > 254) {
264+
// don't increase the brightness more then maximum value
265+
bri = 254;
266+
}
267+
}
268+
process_lightdata(4);
269+
} else if (digitalRead(button2_pin) == HIGH) {
270+
int i = 0;
271+
while (digitalRead(button2_pin) == HIGH && i < 30) {
272+
delay(20);
273+
i++;
274+
}
275+
if (i < 30) {
276+
// there was a short press
277+
light_state = false;
278+
}
279+
else {
280+
// there was a long press
281+
bri -= 56;
282+
if (bri < 1) {
283+
// don't decrease the brightness less than minimum value.
284+
bri = 1;
285+
}
286+
}
287+
process_lightdata(4);
288+
}
227289
}
228290
}
229291

@@ -273,6 +335,11 @@ void setup() {
273335

274336
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
275337
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
338+
if (use_hardware_switch == true) {
339+
pinMode(button1_pin, INPUT);
340+
pinMode(button2_pin, INPUT);
341+
}
342+
276343

277344
server.on("/switch", []() {
278345
server.send(200, "text/plain", "OK");
@@ -402,21 +469,7 @@ void setup() {
402469
}
403470
}
404471
server.send(200, "text/plain", "OK, x: " + (String)x + ", y:" + (String)y + ", bri:" + (String)bri + ", ct:" + ct + ", colormode:" + color_mode + ", state:" + light_state);
405-
if (color_mode == 1 && light_state == true) {
406-
convert_xy();
407-
} else if (color_mode == 2 && light_state == true) {
408-
convert_ct();
409-
} else if (color_mode == 3 && light_state == true) {
410-
convert_hue();
411-
}
412-
transitiontime *= 16;
413-
for (uint8_t color = 0; color < PWM_CHANNELS; color++) {
414-
if (light_state) {
415-
step_level[color] = (rgbw[color] - current_rgbw[color]) / transitiontime;
416-
} else {
417-
step_level[color] = current_rgbw[color] / transitiontime;
418-
}
419-
}
472+
process_lightdata(transitiontime);
420473
});
421474

422475
server.on("/get", []() {
Binary file not shown.

0 commit comments

Comments
 (0)