Bugfix and GY-33 progress
Bugfix /set_mode?m=2&rgb=000000AA&s=200 will not set color GY-33 further progress
This commit is contained in:
@@ -46,14 +46,14 @@ float powf(const float x, const float y)
|
|||||||
@brief Writes a register and an 8 bit value over I2C
|
@brief Writes a register and an 8 bit value over I2C
|
||||||
*/
|
*/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
void GY33_MCU::write8 (uint8_t reg, uint32_t val)
|
uint8_t GY33_MCU::write8 (uint8_t reg, uint8_t val)
|
||||||
{
|
{
|
||||||
uint8_t buf[2];
|
uint8_t buf[2];
|
||||||
brzo_i2c_start_transaction(MCU_ADDRESS, SCL_SPEED);
|
brzo_i2c_start_transaction(MCU_ADDRESS, SCL_SPEED);
|
||||||
buf[0]=reg;
|
buf[0]=reg;
|
||||||
buf[1]=val;
|
buf[1]=val;
|
||||||
brzo_i2c_write(buf, 2, true);
|
brzo_i2c_write(buf, 2, true);
|
||||||
brzo_i2c_end_transaction();
|
return brzo_i2c_end_transaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@@ -125,7 +125,7 @@ boolean GY33_MCU::begin(void)
|
|||||||
/* Make sure we're actually connected */
|
/* Make sure we're actually connected */
|
||||||
uint8_t x = read8(MCU_CONFIG);
|
uint8_t x = read8(MCU_CONFIG);
|
||||||
Serial.println(x, HEX);
|
Serial.println(x, HEX);
|
||||||
if ((x != 0x00) && (x != 0xFF))
|
if (x != 0x10)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -161,6 +161,7 @@ void GY33_MCU::getData (uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *c)
|
|||||||
*b = read8(MCU_BDATA);
|
*b = read8(MCU_BDATA);
|
||||||
*c = read8(MCU_COLDATA);
|
*c = read8(MCU_COLDATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
@brief Converts the raw R/G/B values to color temperature in degrees
|
@brief Converts the raw R/G/B values to color temperature in degrees
|
||||||
@@ -212,29 +213,15 @@ uint16_t GY33_MCU::calculateLux(uint16_t r, uint16_t g, uint16_t b)
|
|||||||
return (uint16_t)illuminance;
|
return (uint16_t)illuminance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*void GY33_MCU::setInterrupt(boolean i) {
|
|
||||||
uint8_t r = read8(MCU_ENABLE);
|
|
||||||
if (i) {
|
|
||||||
r |= MCU_ENABLE_AIEN;
|
|
||||||
} else {
|
|
||||||
r &= ~MCU_ENABLE_AIEN;
|
|
||||||
}
|
|
||||||
write8(MCU_ENABLE, r);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GY33_MCU::clearInterrupt(void) {
|
|
||||||
Wire.beginTransmission(MCU_ADDRESS);
|
|
||||||
#if ARDUINO >= 100
|
|
||||||
Wire.write(MCU_COMMAND_BIT | 0x66);
|
|
||||||
#else
|
|
||||||
Wire.send(MCU_COMMAND_BIT | 0x66);
|
|
||||||
#endif
|
|
||||||
Wire.endTransmission();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void GY33_MCU::setConfig(uint8_t high, uint8_t low) {
|
void GY33_MCU::setConfig(uint8_t high, uint8_t low) {
|
||||||
// write8(MCU_CONFIG, high | low);
|
// write8(MCU_CONFIG, high | low);
|
||||||
|
Serial.println("GY-33: ");
|
||||||
|
Serial.println(high | low, HEX);
|
||||||
write8(MCU_CONFIG, 0x11);
|
write8(MCU_CONFIG, 0x11);
|
||||||
}
|
}
|
||||||
|
uint8_t GY33_MCU::getConfig(void)
|
||||||
|
{
|
||||||
|
if (!_MCUInitialised) begin();
|
||||||
|
|
||||||
|
return read8(MCU_CONFIG);
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,12 +38,6 @@
|
|||||||
#ifndef _MCU_H_
|
#ifndef _MCU_H_
|
||||||
#define _MCU_H_
|
#define _MCU_H_
|
||||||
|
|
||||||
#if ARDUINO >= 100
|
|
||||||
#include <Arduino.h>
|
|
||||||
#else
|
|
||||||
#include <WProgram.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <brzo_i2c.h>
|
#include <brzo_i2c.h>
|
||||||
|
|
||||||
#define MCU_ADDRESS (0x5A)
|
#define MCU_ADDRESS (0x5A)
|
||||||
@@ -92,13 +86,11 @@ class GY33_MCU {
|
|||||||
void getData(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *c);
|
void getData(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *c);
|
||||||
uint16_t calculateColorTemperature(uint16_t r, uint16_t g, uint16_t b);
|
uint16_t calculateColorTemperature(uint16_t r, uint16_t g, uint16_t b);
|
||||||
uint16_t calculateLux(uint16_t r, uint16_t g, uint16_t b);
|
uint16_t calculateLux(uint16_t r, uint16_t g, uint16_t b);
|
||||||
void write8 (uint8_t reg, uint32_t val);
|
uint8_t write8 (uint8_t reg, uint8_t val);
|
||||||
uint8_t read8 (uint8_t reg);
|
uint8_t read8 (uint8_t reg);
|
||||||
uint16_t read16 (uint8_t reg);
|
uint16_t read16 (uint8_t reg);
|
||||||
/* void setInterrupt(boolean flag);
|
|
||||||
void clearInterrupt(void);*/
|
|
||||||
void setConfig(uint8_t h, uint8_t l);
|
void setConfig(uint8_t h, uint8_t l);
|
||||||
|
uint8_t getConfig(void);
|
||||||
private:
|
private:
|
||||||
boolean _MCUInitialised;
|
boolean _MCUInitialised;
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#include <WebSockets.h> //https://github.com/Links2004/arduinoWebSockets
|
#include <WebSockets.h> //https://github.com/Links2004/arduinoWebSockets
|
||||||
#include <WebSocketsServer.h>
|
#include <WebSocketsServer.h>
|
||||||
|
|
||||||
#ifdef ENABLE_BUTTON2
|
#ifdef ENABLE_BUTTON_GY33
|
||||||
// needed for MCU
|
// needed for MCU
|
||||||
#include "GY33_MCU.h"
|
#include "GY33_MCU.h"
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
@@ -105,7 +105,12 @@ NeoAnimationFX<NEOMETHOD> strip(neoStrip);
|
|||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
// https://github.com/kitesurfer1404/WS2812FX
|
// https://github.com/kitesurfer1404/WS2812FX
|
||||||
#include "WS2812FX.h"
|
#include "WS2812FX.h"
|
||||||
|
|
||||||
|
#ifdef RGBW
|
||||||
WS2812FX strip = WS2812FX(NUMLEDS, PIN, NEO_GRBW + NEO_KHZ800);
|
WS2812FX strip = WS2812FX(NUMLEDS, PIN, NEO_GRBW + NEO_KHZ800);
|
||||||
|
#else
|
||||||
|
WS2812FX strip = WS2812FX(NUMLEDS, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Parameter 1 = number of pixels in strip
|
// Parameter 1 = number of pixels in strip
|
||||||
// Parameter 2 = Arduino pin number (most are valid)
|
// Parameter 2 = Arduino pin number (most are valid)
|
||||||
@@ -248,8 +253,11 @@ void setup() {
|
|||||||
pinMode(BUTTON, INPUT_PULLUP);
|
pinMode(BUTTON, INPUT_PULLUP);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_BUTTON2
|
DBG_OUTPUT_PORT.println("");
|
||||||
pinMode(BUTTON2, INPUT_PULLUP);
|
DBG_OUTPUT_PORT.println("Starting....");
|
||||||
|
|
||||||
|
#ifdef ENABLE_BUTTON_GY33
|
||||||
|
pinMode(BUTTON_GY33, INPUT_PULLUP);
|
||||||
for (int i=0; i<256; i++) {
|
for (int i=0; i<256; i++) {
|
||||||
float x = i;
|
float x = i;
|
||||||
x /= 255;
|
x /= 255;
|
||||||
@@ -258,8 +266,7 @@ void setup() {
|
|||||||
gammatable[i] = x;
|
gammatable[i] = x;
|
||||||
}
|
}
|
||||||
if (tcs.begin()) {
|
if (tcs.begin()) {
|
||||||
DBG_OUTPUT_PORT.println("Found GY33 sensor");
|
DBG_OUTPUT_PORT.println("Found GY-33 sensor");
|
||||||
tcs.setConfig(MCU_LED_OFF,MCU_LED_OFF);
|
|
||||||
} else {
|
} else {
|
||||||
DBG_OUTPUT_PORT.println("No GY33 sensor found ... check your connections");
|
DBG_OUTPUT_PORT.println("No GY33 sensor found ... check your connections");
|
||||||
}
|
}
|
||||||
@@ -853,13 +860,16 @@ void setup() {
|
|||||||
}
|
}
|
||||||
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);
|
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
|
#endif
|
||||||
|
tcs.setConfig(MCU_LED_10,MCU_WHITE_ON);
|
||||||
|
DBG_OUTPUT_PORT.println("Config is:");
|
||||||
|
DBG_OUTPUT_PORT.println( tcs.getConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
#ifdef ENABLE_BUTTON
|
#ifdef ENABLE_BUTTON
|
||||||
button();
|
button();
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_BUTTON2
|
#ifdef ENABLE_BUTTON_GY33
|
||||||
button2();
|
button2();
|
||||||
#endif
|
#endif
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
@@ -901,8 +911,10 @@ void loop() {
|
|||||||
// Simple statemachine that handles the different modes
|
// Simple statemachine that handles the different modes
|
||||||
if (mode == SET_MODE) {
|
if (mode == SET_MODE) {
|
||||||
DBG_OUTPUT_PORT.printf("SET_MODE: %d %d\n", ws2812fx_mode, mode);
|
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.setMode(ws2812fx_mode);
|
||||||
mode = SETSPEED;
|
strip.setSpeed(convertSpeed(ws2812fx_speed));
|
||||||
|
mode = HOLD;
|
||||||
}
|
}
|
||||||
if (mode == OFF) {
|
if (mode == OFF) {
|
||||||
// strip.setColor(0,0,0,0);
|
// strip.setColor(0,0,0,0);
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
#define NUMLEDS 194 // Number of leds in the strip
|
#define NUMLEDS 194 // Number of leds in the strip
|
||||||
#define BUILTIN_LED 2 // ESP-12F has the built in LED on GPIO2, see https://github.com/esp8266/Arduino/issues/2192
|
#define BUILTIN_LED 2 // ESP-12F has the built in LED on GPIO2, see https://github.com/esp8266/Arduino/issues/2192
|
||||||
#define BUTTON 14 // Input pin (14 / D5) for switching the LED strip on / off, connect this PIN to ground to trigger button.
|
#define BUTTON 14 // Input pin (14 / D5) for switching the LED strip on / off, connect this PIN to ground to trigger button.
|
||||||
#define BUTTON2 12 // Input pin (12 / D6) for read color data with RGB sensor, connect this PIN to ground to trigger button.
|
#define BUTTON_GY33 12 // Input pin (12 / D6) for read color data with RGB sensor, connect this PIN to ground to trigger button.
|
||||||
|
#define RGBW
|
||||||
|
|
||||||
const char HOSTNAME[] = "ESPLightRGBW02"; // Friedly hostname
|
const char HOSTNAME[] = "ESPLightRGBW02"; // Friedly hostname
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ const char HOSTNAME[] = "ESPLightRGBW02"; // Friedly hostname
|
|||||||
//#define ENABLE_MQTT // If defined, enable MQTT client code, see: https://github.com/toblum/McLighting/wiki/MQTT-API
|
//#define ENABLE_MQTT // If defined, enable MQTT client code, see: https://github.com/toblum/McLighting/wiki/MQTT-API
|
||||||
#define ENABLE_HOMEASSISTANT // If defined, enable Homeassistant integration, ENABLE_MQTT must be active
|
#define ENABLE_HOMEASSISTANT // If defined, enable Homeassistant integration, ENABLE_MQTT must be active
|
||||||
#define ENABLE_BUTTON // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control
|
#define ENABLE_BUTTON // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control
|
||||||
#define ENABLE_BUTTON2 //
|
#define ENABLE_BUTTON_GY33 //
|
||||||
//#define MQTT_HOME_ASSISTANT_SUPPORT // If defined, use AMQTT and select Tools -> IwIP Variant -> Higher Bandwidth
|
//#define MQTT_HOME_ASSISTANT_SUPPORT // If defined, use AMQTT and select Tools -> IwIP Variant -> Higher Bandwidth
|
||||||
|
|
||||||
|
|
||||||
@@ -127,7 +128,7 @@ LEDState main_color = { 0, 255, 0, 0}; // Store the "main color" of the strip u
|
|||||||
|
|
||||||
// Button handling
|
// Button handling
|
||||||
|
|
||||||
#ifdef ENABLE_BUTTON || ENABLE_BUTTON2
|
#ifdef ENABLE_BUTTON || ENABLE_BUTTON_GY33
|
||||||
boolean buttonState = false;
|
boolean buttonState = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -144,7 +145,7 @@ LEDState main_color = { 0, 255, 0, 0}; // Store the "main color" of the strip u
|
|||||||
byte prevKeyState = HIGH; // button is active low
|
byte prevKeyState = HIGH; // button is active low
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_BUTTON2
|
#ifdef ENABLE_BUTTON_GY33
|
||||||
#define BTN_MODE_SHORT "STA| 1| 0|245|196|255| 0| 0| 0" // Static white
|
#define BTN_MODE_SHORT "STA| 1| 0|245|196|255| 0| 0| 0" // Static white
|
||||||
#define BTN_MODE_MEDIUM "STA| 1| 48|245|196| 0|255|102| 0" // Fire flicker
|
#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
|
#define BTN_MODE_LONG "STA| 1| 46|253|196| 0|255|102| 0" // Fireworks random
|
||||||
|
|||||||
@@ -1269,7 +1269,7 @@ void checkForRequests() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_BUTTON2
|
#ifdef ENABLE_BUTTON_GY33
|
||||||
void shortKeyPress2() {
|
void shortKeyPress2() {
|
||||||
DBG_OUTPUT_PORT.printf("Short button2 press\n");
|
DBG_OUTPUT_PORT.printf("Short button2 press\n");
|
||||||
if (buttonState == false) {
|
if (buttonState == false) {
|
||||||
@@ -1365,7 +1365,7 @@ void checkForRequests() {
|
|||||||
if (millis() - keyPrevMillis2 >= keySampleIntervalMs2) {
|
if (millis() - keyPrevMillis2 >= keySampleIntervalMs2) {
|
||||||
keyPrevMillis2 = millis();
|
keyPrevMillis2 = millis();
|
||||||
|
|
||||||
byte currKeyState2 = digitalRead(BUTTON2);
|
byte currKeyState2 = digitalRead(BUTTON_GY33);
|
||||||
|
|
||||||
if ((prevKeyState2 == HIGH) && (currKeyState2 == LOW)) {
|
if ((prevKeyState2 == HIGH) && (currKeyState2 == LOW)) {
|
||||||
// key goes from not pressed to pressed
|
// key goes from not pressed to pressed
|
||||||
|
|||||||
Reference in New Issue
Block a user