From 78e1562b482ba58e864e04855efa8eec0fb8c19b Mon Sep 17 00:00:00 2001 From: Andrey Klimov Date: Mon, 21 Oct 2019 02:40:27 +0300 Subject: [PATCH] Interim SPI-LED update: general LED logic appplied, LED-ranges, dynamic LED array alloc --- lighthub/item.h | 6 +- lighthub/main.cpp | 1 + lighthub/modules/out_spiled.cpp | 234 ++++++++++++++++++++++++++------ lighthub/modules/out_spiled.h | 6 +- 4 files changed, 201 insertions(+), 46 deletions(-) diff --git a/lighthub/item.h b/lighthub/item.h index 7374ac9..9769af1 100644 --- a/lighthub/item.h +++ b/lighthub/item.h @@ -17,6 +17,7 @@ GIT: https://github.com/anklimov/lighthub e-mail anklimov@gmail.com */ +#pragma once #include "options.h" #include "abstractout.h" @@ -73,7 +74,7 @@ e-mail anklimov@gmail.com #define CMD_FAN 0xd #define CMD_DRY 0xe #define CMD_SET 0xf -#define CMD_HIGH 0x10 +#define CMD_HIGH 0x10 //AC fan leve #define CMD_MED 0x11 #define CMD_LOW 0x12 //#define CMD_CURTEMP 0xf @@ -176,7 +177,7 @@ class Item inline int Toggle(){return Ctrl(CMD_TOGGLE);}; int Poll(); int SendStatus(int sendFlags); - + int isActive(); protected: short cmd2changeActivity(int lastActivity, short defaultCmd = CMD_SET); int VacomSetFan (int8_t val, int8_t cmd=0); @@ -184,7 +185,6 @@ class Item int modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint16_t value); int modbusDimmerSet(uint16_t value); void mb_fail(); - int isActive(); void Parse(); int checkModbusDimmer(); int checkModbusDimmer(int data); diff --git a/lighthub/main.cpp b/lighthub/main.cpp index ee78339..5826716 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -1566,6 +1566,7 @@ for (short i = 0; i < 6; i++) { mac[i] = EEPROM.read(i); if (mac[i] != 0 && mac[i] != 0xff) isMacValid = true; } + if (!isMacValid) { debugSerial<(leds, NUM_LEDS); driverStatus = CST_INITIALIZED; return 1; @@ -27,6 +31,7 @@ Serial.println("SPI-LED De-Init"); //FastLED.addLeds(leds, NUM_LEDS); FastLED.clear(true); driverStatus = CST_UNKNOWN; +delete [] leds; return 1; } @@ -37,61 +42,206 @@ return driverStatus; int out_SPILed::isActive() { - +CHstore st; +st.aslong = item->getVal(); //Restore old params +debugSerial<< F(" val:")<s, 0, 100, 0, 255); + int Value = map(st->v, 0, 100, 0, 255); + int Hue = map(st->h, 0, 365, 0, 255); + pixel = CHSV(Hue, Saturation, Value); + debugSerial<h<s<v<NUM_LEDS-1) to=NUM_LEDS-1; + if (from<0) from=0; -if (subItem) -{ //Just single LED to control - from=atoi(subItem); - to=from; -} -debugSerial<r,st->g,st->b); + } + else { + leds[i] = pixel; + } - // case S_POWER: - // case S_VOL: - //leds[n].setBrightness(Parameters[0]); - // break; - case S_SET: - case S_HSV: - debugSerial<isActive(); +bool toExecute = (chActive>0); +CHstore st; +if (cmd>0 && !suffixCode) suffixCode=S_CMD; //if some known command find, but w/o correct suffix - got it + +int from=0, to=NUM_LEDS-1; //All LEDs on the strip by default +// retrive LEDs range from suffix +if (subItem) +{ //Just single LED to control todo - range +// debugSerial<setVal(st.aslong); + if (send) item->SendStatus(SEND_COMMAND | SEND_PARAMETERS ); + } + + PixelCtrl(&st,0,from,to); + } + + return 1; + + case CMD_OFF: + if (subItem) // LED range, not whole strip + PixelCtrl(&st,CMD_OFF,from,to); + else + { + st.v=0; + PixelCtrl(&st,0,from,to); + if (send) item->SendStatus(SEND_COMMAND); + // if (send) item->publishTopic(item->itemArr->name,"OFF","/cmd"); + } + return 1; + +} //switch cmd + +break; +} //switch suffix +debugSerial< +#include class out_SPILed : public abstractOut { public: @@ -13,7 +14,10 @@ public: int Status() override; int isActive() override; int Ctrl(short cmd, short n=0, int * Parameters=NULL, boolean send=true, int suffixCode=0, char* subItem=NULL) override; - + int PixelCtrl(CHstore *st, short cmd, int from =0 , int to = 1024, bool show = 1, bool rgb = 0); + int numLeds; + int pin; protected: + }; #endif