Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
bug fixes
GY-33 changes
  • Loading branch information
BPoH_Voodoo committed Apr 13, 2018
1 parent 4d78ddb commit c55a74e
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 127 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
clients/web/node_modules/

clients/web/\.vscode/
*.DS_Store
29 changes: 13 additions & 16 deletions Arduino/McLighting/GY33_MCU.cpp
Expand Up @@ -17,11 +17,7 @@
v1.0 - First release
*/
/**************************************************************************/
#ifdef __AVR
#include <avr/pgmspace.h>
#elif defined(ESP8266)
#include <pgmspace.h>
#endif

#include <stdlib.h>
#include <math.h>

Expand Down Expand Up @@ -52,7 +48,7 @@ uint8_t GY33_MCU::write8 (uint8_t reg, uint8_t val)
brzo_i2c_start_transaction(MCU_ADDRESS, SCL_SPEED);
buf[0]=reg;
buf[1]=val;
brzo_i2c_write(buf, 2, true);
brzo_i2c_write(buf, 2, false);
return brzo_i2c_end_transaction();
}

Expand Down Expand Up @@ -140,26 +136,28 @@ boolean GY33_MCU::begin(void)
@brief Reads the raw red, green, blue and clear channel values
*/
/**************************************************************************/
void GY33_MCU::getRawData (uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c, uint16_t *ct)
void GY33_MCU::getRawData (uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c, uint16_t *lux, uint16_t *ct)
{
if (!_MCUInitialised) begin();

*r = read16(MCU_RDATAH);
*g = read16(MCU_GDATAH);
*b = read16(MCU_BDATAH);
*c = read16(MCU_CDATAH);
*ct = read16(MCU_CTDATAH);
*r = read16(MCU_RDATAH);
*g = read16(MCU_GDATAH);
*b = read16(MCU_BDATAH);
*c = read16(MCU_CDATAH);
*lux = read16(MCU_LDATAH);
*ct = read16(MCU_CTDATAH);
}


void GY33_MCU::getData (uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *c)
void GY33_MCU::getData (uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *c, uint8_t *conf)
{
if (!_MCUInitialised) begin();

*r = read8(MCU_RDATA);
*g = read8(MCU_GDATA);
*b = read8(MCU_BDATA);
*c = read8(MCU_COLDATA);
*c = read8(MCU_COLDATA);
*conf = read8(MCU_CONFIG);
}

/**************************************************************************/
Expand Down Expand Up @@ -214,10 +212,9 @@ uint16_t GY33_MCU::calculateLux(uint16_t r, uint16_t g, uint16_t b)
}

void GY33_MCU::setConfig(uint8_t high, uint8_t low) {
// write8(MCU_CONFIG, high | low);
Serial.println("GY-33: ");
Serial.println(high | low, HEX);
write8(MCU_CONFIG, 0x11);
write8(MCU_CONFIG, high | low);
}
uint8_t GY33_MCU::getConfig(void)
{
Expand Down
30 changes: 15 additions & 15 deletions Arduino/McLighting/GY33_MCU.h
Expand Up @@ -38,24 +38,24 @@
#ifndef _MCU_H_
#define _MCU_H_

#include <brzo_i2c.h>
#include <brzo_i2c.h> // https://github.com/pasko-zh/brzo_i2c

#define MCU_ADDRESS (0x5A)

#define SCL_SPEED 100
#define SCL_STRETCH_TIMEOUT 50000

#define MCU_LED_OFF (0x00)
#define MCU_LED_1 (0x10)
#define MCU_LED_2 (0x20)
#define MCU_LED_3 (0x30)
#define MCU_LED_4 (0x40)
#define MCU_LED_5 (0x50)
#define MCU_LED_6 (0x60)
#define MCU_LED_7 (0x70)
#define MCU_LED_8 (0x80)
#define MCU_LED_9 (0x90)
#define MCU_LED_10 (0xA0)
#define MCU_LED_OFF (0xA0)
#define MCU_LED_01 (0x90)
#define MCU_LED_02 (0x80)
#define MCU_LED_03 (0x70)
#define MCU_LED_04 (0x60)
#define MCU_LED_05 (0x50)
#define MCU_LED_06 (0x40)
#define MCU_LED_07 (0x30)
#define MCU_LED_08 (0x20)
#define MCU_LED_09 (0x10)
#define MCU_LED_10 (0x00)
#define MCU_WHITE_OFF (0x00) /* No Whitebalance */
#define MCU_WHITE_ON (0x01) /* Whitebalance */

Expand All @@ -75,15 +75,15 @@
#define MCU_GDATA (0x0D) /* Green channel data */
#define MCU_BDATA (0x0E) /* Blue channel data */
#define MCU_COLDATA (0x0F) /* Blue channel data */
#define MCU_CONFIG (0x10)
#define MCU_CONFIG (0x10) /* Config channel data */

class GY33_MCU {
public:
GY33_MCU();

boolean begin(void);
void getRawData(uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c, uint16_t *ct);
void getData(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *c);
void getRawData(uint16_t *r, uint16_t *g, uint16_t *b, uint16_t *c, uint16_t *lux, uint16_t *ct);
void getData(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *c, uint8_t *conf);
uint16_t calculateColorTemperature(uint16_t r, uint16_t g, uint16_t b);
uint16_t calculateLux(uint16_t r, uint16_t g, uint16_t b);
uint8_t write8 (uint8_t reg, uint8_t val);
Expand Down
48 changes: 27 additions & 21 deletions Arduino/McLighting/McLighting.ino
Expand Up @@ -25,7 +25,24 @@
// Initialize Color Sensor
// ***************************************************************************
byte gammatable[256];
GY33_MCU tcs;
GY33_MCU tcs;
byte gamma8[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };
#endif

// OTA
Expand Down Expand Up @@ -565,18 +582,8 @@ DBG_OUTPUT_PORT.println("Starting....");
// Setup: SPIFFS Webserver handler
// ***************************************************************************
server.on("/set_brightness", []() {
if (server.arg("c").toInt() > 0) {
brightness = (int) server.arg("c").toInt() * 2.55;
} else {
brightness = server.arg("p").toInt();
}
if (brightness > 255) {
brightness = 255;
}
if (brightness < 0) {
brightness = 0;
}
strip.setBrightness(brightness);
getArgs();
mode = BRIGHTNESS;
#ifdef ENABLE_MQTT
mqtt_client.publish(mqtt_outtopic, String(String("OK %") + String(brightness)).c_str());
#endif
Expand Down Expand Up @@ -632,7 +639,9 @@ DBG_OUTPUT_PORT.println("Starting....");
});

server.on("/get_color", []() {
String rgbcolor = String(main_color.white, HEX) + String(main_color.red, HEX) + String(main_color.green, HEX) + String(main_color.blue, HEX);
//String rgbcolor = String(main_color.white, HEX) + String(main_color.red, HEX) + String(main_color.green, HEX) + String(main_color.blue, HEX);
char rgbcolor[9];
snprintf(rgbcolor, sizeof(rgbcolor), "%02X%02X%02X%02X", main_color.white, main_color.red, main_color.green, main_color.blue);
server.send(200, "text/plain", rgbcolor );
DBG_OUTPUT_PORT.print("/get_color: ");
DBG_OUTPUT_PORT.println(rgbcolor);
Expand Down Expand Up @@ -860,17 +869,15 @@ DBG_OUTPUT_PORT.println("Starting....");
}
sprintf(last_state, "STA|%2d|%3d|%3d|%3d|%3d|%3d|%3d|%3d", mode, ws2812fx_mode, ws2812fx_speed, brightness, main_color.white, main_color.red, main_color.green, main_color.blue);
#endif
tcs.setConfig(MCU_LED_10,MCU_WHITE_ON);
DBG_OUTPUT_PORT.println("Config is:");
DBG_OUTPUT_PORT.println( tcs.getConfig());
tcs.setConfig(MCU_LED_05, MCU_WHITE_ON);
}

void loop() {
#ifdef ENABLE_BUTTON
button();
#endif
#ifdef ENABLE_BUTTON_GY33
button2();
button_gy33();
#endif
server.handleClient();
webSocket.loop();
Expand Down Expand Up @@ -913,8 +920,7 @@ void loop() {
DBG_OUTPUT_PORT.printf("SET_MODE: %d %d\n", ws2812fx_mode, mode);
strip.setColor(main_color.white, main_color.red, main_color.green, main_color.blue);
strip.setMode(ws2812fx_mode);
strip.setSpeed(convertSpeed(ws2812fx_speed));
mode = HOLD;
mode = SETSPEED;
}
if (mode == OFF) {
// strip.setColor(0,0,0,0);
Expand All @@ -933,7 +939,7 @@ void loop() {
}
if (mode == SETSPEED) {
strip.setSpeed(convertSpeed(ws2812fx_speed));
mode = HOLD;
mode = BRIGHTNESS;
}
if (mode == BRIGHTNESS) {
strip.setBrightness(brightness);
Expand Down
12 changes: 6 additions & 6 deletions Arduino/McLighting/definitions.h
Expand Up @@ -150,11 +150,11 @@ LEDState main_color = { 0, 255, 0, 0}; // Store the "main color" of the strip u
#define BTN_MODE_MEDIUM "STA| 1| 48|245|196| 0|255|102| 0" // Fire flicker
#define BTN_MODE_LONG "STA| 1| 46|253|196| 0|255|102| 0" // Fireworks random

unsigned long keyPrevMillis2 = 0;
const unsigned long keySampleIntervalMs2 = 25;
byte longKeyPressCountMax2 = 80; // 80 * 25 = 2000 ms
byte mediumKeyPressCountMin2 = 20; // 20 * 25 = 500 ms
byte KeyPressCount2 = 0;
byte prevKeyState2 = HIGH; // button is active low
unsigned long keyPrevMillis_gy33 = 0;
const unsigned long keySampleIntervalMs_gy33 = 25;
byte longKeyPressCountMax_gy33 = 80; // 80 * 25 = 2000 ms
byte mediumKeyPressCountMin_gy33 = 20; // 20 * 25 = 500 ms
byte KeyPressCount_gy33 = 0;
byte prevKeyState_gy33 = HIGH; // button is active low
#endif

0 comments on commit c55a74e

Please sign in to comment.