diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 81fd92e..04d2569 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -58,6 +58,7 @@ int txt2cmd(char *payload) { else if (strcmp(payload, "HALT") == 0) cmd = CMD_HALT; else if (*payload == '-' || (*payload >= '0' && *payload <= '9')) cmd = 0; else if (*payload == '{') cmd = -2; + else if (*payload == '#') cmd = -3; return cmd; } @@ -245,7 +246,7 @@ int Item::Ctrl(short cmd, short n, int *Par, boolean send) { st.s = Par[1]; st.v = Par[2]; setVal(st.aslong); - //SendCmd(0,3,Par); // Send back triplet ? + if (send) SendCmd(0,3,Par); // Send back triplet ? break; case CH_PWM: @@ -265,7 +266,7 @@ int Item::Ctrl(short cmd, short n, int *Par, boolean send) { break; case CMD_ON: - if (getCmd() != CMD_ON) { + if (itemType!=CH_RGBW || getCmd() != CMD_ON) { short params = 0; //retrive stored values st.aslong = getVal(); @@ -278,16 +279,17 @@ int Item::Ctrl(short cmd, short n, int *Par, boolean send) { Par[0] = st.h; Par[1] = st.s; Par[2] = st.v; + if (!Par[2]) Par[2]=80; //If RGB value==0 set to 80% params = 3; SendCmd(0, params, Par); // Send restored triplet. In any cases break; - + case CH_VCTEMP: + case CH_PWM: case CH_DIMMER: //Everywhere, in flat VAL case CH_MODBUS: case CH_VC: - case CH_VCTEMP: - case CH_PWM: + Par[0] = st.aslong; params = 1; @@ -840,18 +842,26 @@ int Item::checkFM() { Serial.print(F("-")); } - + int RPM; // aJson.addNumberToObject(out,"gsw", (int) node.getResponseBuffer(1)); aJson.addNumberToObject(out, "V", (int) node.getResponseBuffer(2) / 100.); // aJson.addNumberToObject(out,"f", (int) node.getResponseBuffer(3)/100.); - aJson.addNumberToObject(out, "RPM", (int) node.getResponseBuffer(4)); + aJson.addNumberToObject(out, "RPM", RPM=(int) node.getResponseBuffer(4)); aJson.addNumberToObject(out, "I", (int) node.getResponseBuffer(5) / 100.); aJson.addNumberToObject(out, "M", (int) node.getResponseBuffer(6) / 10.); // aJson.addNumberToObject(out,"P", (int) node.getResponseBuffer(7)/10.); // aJson.addNumberToObject(out,"U", (int) node.getResponseBuffer(8)/10.); // aJson.addNumberToObject(out,"Ui", (int) node.getResponseBuffer(9)); aJson.addNumberToObject(out, "sw", (int) node.getResponseBuffer(0)); - + + if (RPM && itemArg->type == aJson_Array) + { aJsonObject *airGateObj = aJson.getArrayItem(itemArg, 1); + if (airGateObj) { + int val = 100; + Item item(airGateObj->valuestring); + if (item.isValid()) item.Ctrl(0,1,&val); + } + } Serial.println(); } else { Serial.print(F("Modbus polling error=")); diff --git a/lighthub/item.h b/lighthub/item.h index 21b8d29..6ff8c79 100644 --- a/lighthub/item.h +++ b/lighthub/item.h @@ -62,6 +62,19 @@ typedef union }; } HSVstore; + +typedef union +{ + long int aslong; + struct + { + int8_t r; + int8_t g; + int8_t b; + int8_t v; + }; +} RGBVstore; + class Item { public: diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 5eccc05..ef1cbca 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -186,7 +186,19 @@ void mqttCallback(char *topic, byte *payload, unsigned int length) { case -1: //Not known command case -2: //JSON input (not implemented yet break; - + case -3: //RGB color in #RRGGBB notation + { + CRGB rgb; + if (sscanf(payload,"#%2X%2X%2X",&rgb.r,&rgb.g,&rgb.b)==3) + { int Par[3]; + CHSV hsv=rgb2hsv_approximate(rgb); + Par[0]=map(hsv.h,0,255,0,365); + Par[1]=map(hsv.s,0,255,0,100); + Par[2]=map(hsv.v,0,255,0,100); + item.Ctrl(0, 3, Par, !retaining); + } + break; + } case CMD_ON: if (item.getEnableCMD(500) || lanStatus == 4) @@ -885,8 +897,8 @@ void printFirmwareVersionAndBuildOptions() { #endif Serial.print(F("Config server:")); Serial.println(F(CONFIG_SERVER)); - Serial.print(F("Firmware MAC Address ")); - Serial.println(F(QUOTE(CUSTOM_FIRMWARE_MAC))); +// Serial.print(F("Firmware MAC Address ")); +// Serial.println(F(QUOTE(CUSTOM_FIRMWARE_MAC))); //Q Macros didn't working with 6 args #ifdef DISABLE_FREERAM_PRINT Serial.println(F("(-)FreeRam printing")); #else @@ -897,9 +909,9 @@ void printFirmwareVersionAndBuildOptions() { } void setupMacAddress() { - byte firmwareMacAddress[6]; - const char *macStr = QUOTE(CUSTOM_FIRMWARE_MAC); - parseBytes(macStr, ':', firmwareMacAddress, 6, 16); + byte firmwareMacAddress[6]=CUSTOM_FIRMWARE_MAC; +// const char *macStr = QUOTE(CUSTOM_FIRMWARE_MAC); +// parseBytes(macStr, ':', firmwareMacAddress, 6, 16); bool isMacValid = false; for (short i = 0; i < 6; i++) { diff --git a/lighthub/main.h b/lighthub/main.h index 0addada..972ed77 100644 --- a/lighthub/main.h +++ b/lighthub/main.h @@ -41,6 +41,8 @@ #include "item.h" #include "inputs.h" #include "Dhcp.h" +#include "FastLED.h" +//#include "hsv2rgb.h" #if defined(__SAM3X8E__) @@ -178,4 +180,4 @@ int getConfig(int arg_cnt, char **args); void printFirmwareVersionAndBuildOptions(); -#endif //LIGHTHUB_MAIN_H \ No newline at end of file +#endif //LIGHTHUB_MAIN_H diff --git a/lighthub/options.h b/lighthub/options.h index d262f65..62fdedc 100644 --- a/lighthub/options.h +++ b/lighthub/options.h @@ -1,6 +1,6 @@ // Configuration of drivers enabled #ifndef PIO_SRC_REV -#define PIO_SRC_REV v0.99.1 +#define PIO_SRC_REV v0.992 #endif #define TXEnablePin 13 @@ -26,7 +26,7 @@ #endif #ifndef CUSTOM_FIRMWARE_MAC -#define CUDTOM_FIRMWARE_MAC {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0} +#define CUSTOM_FIRMWARE_MAC {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0} #endif