Działająca kontrola zmiany koloeów przez HomeKit - problem jedynie ze startem, uchamia sie wyłączone światło
This commit is contained in:
92
ESP32/StadlerHomeKitUpgrade/DEV_LED.h
Normal file
92
ESP32/StadlerHomeKitUpgrade/DEV_LED.h
Normal file
@@ -0,0 +1,92 @@
|
||||
extern int RedHomeKit;
|
||||
extern int GreenHomeKit;
|
||||
extern int BlueHomeKit;
|
||||
|
||||
|
||||
struct DEV_RgbLED : Service::LightBulb { // RGB LED (Command Cathode)
|
||||
|
||||
SpanCharacteristic *power; // reference to the On Characteristic
|
||||
SpanCharacteristic *H; // reference to the Hue Characteristic
|
||||
SpanCharacteristic *S; // reference to the Saturation Characteristic
|
||||
SpanCharacteristic *V; // reference to the Brightness Characteristic
|
||||
|
||||
DEV_RgbLED() : Service::LightBulb(){ // constructor() method
|
||||
|
||||
power=new Characteristic::On();
|
||||
H=new Characteristic::Hue(100); // instantiate the Hue Characteristic with an initial value of 0 out of 360
|
||||
S=new Characteristic::Saturation(100); // instantiate the Saturation Characteristic with an initial value of 0%
|
||||
V=new Characteristic::Brightness(100); // instantiate the Brightness Characteristic with an initial value of 100%
|
||||
V->setRange(5,100,1); // sets the range of the Brightness to be from a min of 5%, to a max of 100%, in steps of 1%
|
||||
|
||||
char cBuf[128];
|
||||
Serial.print(cBuf);
|
||||
|
||||
} // end constructor
|
||||
|
||||
boolean update(){ // update() method
|
||||
|
||||
boolean p;
|
||||
float v, h, s, r, g, b;
|
||||
|
||||
h=H->getVal<float>(); // get and store all current values. Note the use of the <float> template to properly read the values
|
||||
s=S->getVal<float>();
|
||||
v=V->getVal<float>(); // though H and S are defined as FLOAT in HAP, V (which is brightness) is defined as INT, but will be re-cast appropriately
|
||||
p=power->getVal();
|
||||
|
||||
char cBuf[128];
|
||||
LOG1(cBuf);
|
||||
|
||||
if(power->updated()){
|
||||
p=power->getNewVal();
|
||||
sprintf(cBuf,"Power=%s->%s, ",power->getVal()?"true":"false",p?"true":"false");
|
||||
} else {
|
||||
sprintf(cBuf,"Power=%s, ",p?"true":"false");
|
||||
}
|
||||
LOG1(cBuf);
|
||||
|
||||
if(H->updated()){
|
||||
h=H->getNewVal<float>();
|
||||
sprintf(cBuf,"H=%.0f->%.0f, ",H->getVal<float>(),h);
|
||||
} else {
|
||||
sprintf(cBuf,"H=%.0f, ",h);
|
||||
}
|
||||
LOG1(cBuf);
|
||||
|
||||
if(S->updated()){
|
||||
s=S->getNewVal<float>();
|
||||
sprintf(cBuf,"S=%.0f->%.0f, ",S->getVal<float>(),s);
|
||||
} else {
|
||||
sprintf(cBuf,"S=%.0f, ",s);
|
||||
}
|
||||
LOG1(cBuf);
|
||||
|
||||
if(V->updated()){
|
||||
v=V->getNewVal<float>();
|
||||
sprintf(cBuf,"V=%.0f->%.0f ",V->getVal<float>(),v);
|
||||
} else {
|
||||
sprintf(cBuf,"V=%.0f ",v);
|
||||
}
|
||||
LOG1(cBuf);
|
||||
|
||||
LedPin::HSVtoRGB(h,s/100.0,v/100.0,&r,&g,&b); // since HomeKit provides S and V in percent, scale down by 100
|
||||
|
||||
int R, G, B;
|
||||
|
||||
// if (trurOnFlag == 1){
|
||||
// p = 1;
|
||||
// }
|
||||
|
||||
R=p*r*100; // since LedPin uses percent, scale back up by 100, and multiple by status fo power (either 0 or 1)
|
||||
G=p*g*100;
|
||||
B=p*b*100;
|
||||
|
||||
RedHomeKit = R;
|
||||
GreenHomeKit = G;
|
||||
BlueHomeKit = B;
|
||||
|
||||
sprintf(cBuf,"RGB=(%d,%d,%d)\n",R,G,B);
|
||||
LOG1(cBuf);
|
||||
|
||||
return(true); // return true
|
||||
}
|
||||
};
|
||||
@@ -5,6 +5,9 @@
|
||||
#include "DHT.h"
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include <BH1750.h>
|
||||
#include "HomeSpan.h"
|
||||
#include "DEV_LED.h"
|
||||
|
||||
#define Version "0.3.3"
|
||||
|
||||
|
||||
@@ -67,6 +70,11 @@ BH1750 lightMeter;
|
||||
|
||||
|
||||
//MAIN VALUES VARIABLES
|
||||
// homekit
|
||||
int RedHomeKit = 0;
|
||||
int GreenHomeKit = 0;
|
||||
int BlueHomeKit = 0;
|
||||
|
||||
int8_t resetVal = 0;
|
||||
int8_t fanSpeedVal = 1;
|
||||
int8_t hygrostatVal = 55;
|
||||
@@ -171,7 +179,7 @@ uint32_t Wheel(byte pos) {
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.begin(115200);
|
||||
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
||||
Serial.println(F("SSD1306 allocation failed"));
|
||||
}
|
||||
@@ -215,9 +223,31 @@ void setup() {
|
||||
} else {
|
||||
dimmVal = 24;
|
||||
}
|
||||
}
|
||||
// ##### HOME SPAN
|
||||
homeSpan.setPairingCode("11122333");
|
||||
homeSpan.setQRID("111-22-333");
|
||||
// konfiguracja WIFI przez port szerefowy "W<returm"
|
||||
// 1.Płytka ESP32 Dev Module
|
||||
// 2 Partycja: Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS)
|
||||
// 3. konfiguracja WIFI przez port szerefowy komenda "W", U - unpair
|
||||
homeSpan.begin(Category::Bridges,"HomeSpan Bridge");
|
||||
|
||||
new SpanAccessory();
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
|
||||
new SpanAccessory();
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
new Characteristic::Name("RGB LED");
|
||||
new DEV_RgbLED();
|
||||
// ##### HOME SPAN END
|
||||
} //setup end
|
||||
|
||||
void loop() {
|
||||
neoPixelRed = int(RedHomeKit/10);
|
||||
neoPixelGreen = int(GreenHomeKit/10);
|
||||
neoPixelBlue = int(BlueHomeKit/10);
|
||||
// ###################################################
|
||||
// WYŚWIETLACZ
|
||||
display.clearDisplay();
|
||||
@@ -447,7 +477,6 @@ void loop() {
|
||||
}
|
||||
|
||||
|
||||
delay(100);
|
||||
//NEOPIXELS
|
||||
// #################################################################
|
||||
// #################################################################
|
||||
@@ -465,4 +494,16 @@ void loop() {
|
||||
// pixels.setPixelColor(ADR_NEOPXL_TANK, pixels.Color(neoPixelGreen*dimmVal*neoPixelSwitch*neoPixelTank, neoPixelRed*dimmVal*neoPixelSwitch*neoPixelTank, neoPixelBlue*dimmVal*neoPixelSwitch*neoPixelTank));
|
||||
pixels.show();
|
||||
// rainbowCycle(10); // im mniejsza liczba, tym szybsza animacja
|
||||
|
||||
homeSpan.poll();
|
||||
Serial.println("---------------------------");
|
||||
Serial.print("R: ");
|
||||
Serial.println(RedHomeKit);
|
||||
Serial.print("G: ");
|
||||
Serial.println(GreenHomeKit);
|
||||
Serial.print("B: ");
|
||||
Serial.println(BlueHomeKit);
|
||||
|
||||
delay(500);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user