Skip to content

Commit

Permalink
Merge pull request #111 from mariusmotea/develop
Browse files Browse the repository at this point in the history
Add all new changes to master
  • Loading branch information
mariusmotea authored Dec 1, 2017
2 parents cab2d6f + d78afcc commit 98cef99
Show file tree
Hide file tree
Showing 12 changed files with 1,501 additions and 191 deletions.
194 changes: 107 additions & 87 deletions BridgeEmulator/HueEmulator.py

Large diffs are not rendered by default.

76 changes: 64 additions & 12 deletions Lights/Arduino/Generic_CCT_Light/Generic_CCT_Light.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
This can control bulbs with 5 pwm channels (red, gree, blue, warm white and could wihite). Is tested with MiLight RGB_CCT bulb.
This can control bulbs with 2 pwm channel
*/


Expand All @@ -15,6 +15,10 @@
#define PWM_CHANNELS 2
const uint32_t period = 1024;

#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
#define button1_pin 1 // on and bri up
#define button2_pin 3 // off and bri down

//define pins
uint32 io_info[PWM_CHANNELS][3] = {
// MUX, FUNC, PIN
Expand Down Expand Up @@ -82,6 +86,20 @@ void apply_scene(uint8_t new_scene) {
}
}

void process_lightdata(float transitiontime) {
if (light_state == true) {
convert_ct();
}
transitiontime *= 16;
for (uint8_t color = 0; color < PWM_CHANNELS; color++) {
if (light_state) {
step_level[color] = (cct[color] - current_cct[color]) / transitiontime;
} else {
step_level[color] = current_cct[color] / transitiontime;
}
}
}

void lightEngine() {
for (uint8_t color = 0; color < PWM_CHANNELS; color++) {
if (light_state) {
Expand All @@ -105,6 +123,46 @@ void lightEngine() {
if (in_transition) {
delay(6);
in_transition = false;
} else if (use_hardware_switch == true) {
if (digitalRead(button1_pin) == HIGH) {
int i = 0;
while (digitalRead(button1_pin) == HIGH && i < 30) {
delay(20);
i++;
}
if (i < 30) {
// there was a short press
light_state = true;
}
else {
// there was a long press
bri += 56;
if (bri > 254) {
// don't increase the brightness more then maximum value
bri = 254;
}
}
process_lightdata(4);
} else if (digitalRead(button2_pin) == HIGH) {
int i = 0;
while (digitalRead(button2_pin) == HIGH && i < 30) {
delay(20);
i++;
}
if (i < 30) {
// there was a short press
light_state = false;
}
else {
// there was a long press
bri -= 56;
if (bri < 1) {
// don't decrease the brightness less than minimum value.
bri = 1;
}
}
process_lightdata(4);
}
}
}

Expand Down Expand Up @@ -154,6 +212,10 @@ void setup() {

pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
if (use_hardware_switch == true) {
pinMode(button1_pin, INPUT);
pinMode(button2_pin, INPUT);
}

server.on("/switch", []() {
server.send(200, "text/plain", "OK");
Expand Down Expand Up @@ -246,17 +308,7 @@ void setup() {
}
}
server.send(200, "text/plain", "OK, bri:" + (String)bri + ", ct:" + ct + ", colormode: ct, state:" + light_state);
if (light_state == true) {
convert_ct();
}
transitiontime *= 16;
for (uint8_t color = 0; color < PWM_CHANNELS; color++) {
if (light_state) {
step_level[color] = (cct[color] - current_cct[color]) / transitiontime;
} else {
step_level[color] = current_cct[color] / transitiontime;
}
}
process_lightdata(transitiontime);
});

server.on("/get", []() {
Expand Down
92 changes: 74 additions & 18 deletions Lights/Arduino/Generic_Dimmable_Light/Generic_Dimmable_Light.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@
#include <EEPROM.h>
#include "pwm.c"

#define lightsCount 3
#define lightsCount 4

#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.
#define button1_pin 4 // on and bri up
#define button2_pin 5 // off and bri down

const uint32_t period = 1024;

//define pins
uint32 io_info[lightsCount][3] = {
// MUX, FUNC, PIN
//{PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12, 12},
//{PERIPHS_IO_MUX_MTDO_U, FUNC_GPIO15, 15},
//{PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13, 13},
//{PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14, 14},
{PERIPHS_IO_MUX_GPIO4_U, FUNC_GPIO4 , 4},
{PERIPHS_IO_MUX_GPIO5_U, FUNC_GPIO5 , 5},
{PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12, 12},
{PERIPHS_IO_MUX_MTDO_U, FUNC_GPIO15, 15},
{PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13, 13},
{PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14, 14},
//{PERIPHS_IO_MUX_GPIO4_U, FUNC_GPIO4 , 4},
//{PERIPHS_IO_MUX_GPIO5_U, FUNC_GPIO5 , 5},
};

// initial duty: all off
Expand Down Expand Up @@ -65,6 +69,15 @@ void apply_scene(uint8_t new_scene, uint8_t light) {
}
}

void process_lightdata(uint8_t light, float transitiontime) {
transitiontime *= 16;
if (light_state[light]) {
step_level[light] = (bri[light] - current_bri[light]) / transitiontime;
} else {
step_level[light] = current_bri[light] / transitiontime;
}
}


void lightEngine() {
for (int i = 0; i < lightsCount; i++) {
Expand All @@ -89,6 +102,50 @@ void lightEngine() {
if (in_transition) {
delay(6);
in_transition = false;
} else if (use_hardware_switch == true) {
if (digitalRead(button1_pin) == HIGH) {
int i = 0;
while (digitalRead(button1_pin) == HIGH && i < 30) {
delay(20);
i++;
}
for (int light = 0; light < lightsCount; light++) {
if (i < 30) {
// there was a short press
light_state[light] = true;
}
else {
// there was a long press
bri[light] += 56;
if (bri[light] > 254) {
// don't increase the brightness more then maximum value
bri[light] = 254;
}
}
process_lightdata(light, 4);
}
} else if (digitalRead(button2_pin) == HIGH) {
int i = 0;
while (digitalRead(button2_pin) == HIGH && i < 30) {
delay(20);
i++;
}
for (int light = 0; light < lightsCount; light++) {
if (i < 30) {
// there was a short press
light_state[light] = false;
}
else {
// there was a long press
bri[light] -= 56;
if (bri[light] < 1) {
// don't decrease the brightness less than minimum value.
bri[light] = 1;
}
}
process_lightdata(light, 4);
}
}
}
}

Expand Down Expand Up @@ -143,6 +200,10 @@ void setup() {

pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
if (use_hardware_switch == true) {
pinMode(button1_pin, INPUT);
pinMode(button2_pin, INPUT);
}


server.on("/switch", []() {
Expand Down Expand Up @@ -180,11 +241,11 @@ void setup() {
} else if (button == 4000) {
light_state[i] = false;
}
if (light_state[i]) {
step_level[i] = ((float)bri[i] - current_bri[i]) / transitiontime;
} else {
step_level[i] = current_bri[i] / transitiontime;
}
if (light_state[i]) {
step_level[i] = ((float)bri[i] - current_bri[i]) / transitiontime;
} else {
step_level[i] = current_bri[i] / transitiontime;
}
}
});

Expand Down Expand Up @@ -231,13 +292,8 @@ void setup() {
transitiontime = server.arg(i).toInt();
}
}
process_lightdata(light, transitiontime);
server.send(200, "text/plain", "OK, bri:" + (String)bri[light] + ", state:" + light_state[light]);
transitiontime *= 16;
if (light_state[light]) {
step_level[light] = (bri[light] - current_bri[light]) / transitiontime;
} else {
step_level[light] = current_bri[light] / transitiontime;
}
});

server.on("/get", []() {
Expand Down
83 changes: 68 additions & 15 deletions Lights/Arduino/Generic_RGBW_Light/Generic_RGBW_Light.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#define PWM_CHANNELS 4
const uint32_t period = 1024;

#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
#define button1_pin 1 // on and bri up
#define button2_pin 3 // off and bri down

//define pins
uint32 io_info[PWM_CHANNELS][3] = {
// MUX, FUNC, PIN
Expand Down Expand Up @@ -201,6 +205,24 @@ void apply_scene(uint8_t new_scene) {
}
}

void process_lightdata(float transitiontime) {
if (color_mode == 1 && light_state == true) {
convert_xy();
} else if (color_mode == 2 && light_state == true) {
convert_ct();
} else if (color_mode == 3 && light_state == true) {
convert_hue();
}
transitiontime *= 16;
for (uint8_t color = 0; color < PWM_CHANNELS; color++) {
if (light_state) {
step_level[color] = (rgbw[color] - current_rgbw[color]) / transitiontime;
} else {
step_level[color] = current_rgbw[color] / transitiontime;
}
}
}

void lightEngine() {
for (uint8_t color = 0; color < PWM_CHANNELS; color++) {
if (light_state) {
Expand All @@ -224,6 +246,46 @@ void lightEngine() {
if (in_transition) {
delay(6);
in_transition = false;
} else if (use_hardware_switch == true) {
if (digitalRead(button1_pin) == HIGH) {
int i = 0;
while (digitalRead(button1_pin) == HIGH && i < 30) {
delay(20);
i++;
}
if (i < 30) {
// there was a short press
light_state = true;
}
else {
// there was a long press
bri += 56;
if (bri > 254) {
// don't increase the brightness more then maximum value
bri = 254;
}
}
process_lightdata(4);
} else if (digitalRead(button2_pin) == HIGH) {
int i = 0;
while (digitalRead(button2_pin) == HIGH && i < 30) {
delay(20);
i++;
}
if (i < 30) {
// there was a short press
light_state = false;
}
else {
// there was a long press
bri -= 56;
if (bri < 1) {
// don't decrease the brightness less than minimum value.
bri = 1;
}
}
process_lightdata(4);
}
}
}

Expand Down Expand Up @@ -273,6 +335,11 @@ void setup() {

pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
if (use_hardware_switch == true) {
pinMode(button1_pin, INPUT);
pinMode(button2_pin, INPUT);
}


server.on("/switch", []() {
server.send(200, "text/plain", "OK");
Expand Down Expand Up @@ -402,21 +469,7 @@ void setup() {
}
}
server.send(200, "text/plain", "OK, x: " + (String)x + ", y:" + (String)y + ", bri:" + (String)bri + ", ct:" + ct + ", colormode:" + color_mode + ", state:" + light_state);
if (color_mode == 1 && light_state == true) {
convert_xy();
} else if (color_mode == 2 && light_state == true) {
convert_ct();
} else if (color_mode == 3 && light_state == true) {
convert_hue();
}
transitiontime *= 16;
for (uint8_t color = 0; color < PWM_CHANNELS; color++) {
if (light_state) {
step_level[color] = (rgbw[color] - current_rgbw[color]) / transitiontime;
} else {
step_level[color] = current_rgbw[color] / transitiontime;
}
}
process_lightdata(transitiontime);
});

server.on("/get", []() {
Expand Down
Binary file removed Lights/Arduino/Generic_RGB_CCT_Light/.DS_Store
Binary file not shown.
Loading

0 comments on commit 98cef99

Please sign in to comment.