Adafruit NeoPixel library used instead fastLed (allow define [pin#,num,LEDorder] in configuration. Use FASTLED directive to revert FASTLed back

This commit is contained in:
2019-10-23 23:53:45 +03:00
parent 86b19d081d
commit b779fd0fac
7 changed files with 174 additions and 37 deletions

View File

@@ -26,8 +26,12 @@ e-mail anklimov@gmail.com
#ifdef _dmxout
#include "dmx.h"
#ifdef ADAFRUIT_LED
#include <Adafruit_NeoPixel.h>
#else
#include "FastLED.h"
#endif
#endif
#ifndef MODBUS_DISABLE
#include <ModbusMaster.h>
@@ -364,8 +368,10 @@ debugSerial<<F("Txt2Cmd:")<<cmd<<endl;
case CMD_JSON: //JSON input (not implemented yet
break;
#if not defined(ARDUINO_ARCH_ESP32) and not defined(ESP8266) and not defined(ARDUINO_ARCH_STM32) and not defined(DMX_DISABLE)
#ifndef ADAFRUIT_LED
case CMD_RGB: //RGB color in #RRGGBB notation
{
suffixCode=S_HSV; //override code for known payload
CRGB rgb;
if (sscanf((const char*)payload, "#%2X%2X%2X", &rgb.r, &rgb.g, &rgb.b) == 3) {
@@ -378,6 +384,7 @@ debugSerial<<F("Txt2Cmd:")<<cmd<<endl;
}
break;
}
#endif
#endif
default: //some known command
return Ctrl(cmd, 0, NULL, send, suffixCode, subItem);
@@ -800,10 +807,18 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int suffixCode
case CH_RGB: // RGB
if (iaddr>0)
{
#ifdef ADAFRUIT_LED
Adafruit_NeoPixel strip(0, 0, 0);
uint32_t rgb = strip.ColorHSV(map(Par[0], 0, 365, 0, 655535), rgbSaturation, rgbValue);
DmxWrite(iaddr, (rgb >> 16)& 0xFF);
DmxWrite(iaddr + 1, (rgb >> 8) & 0xFF);
DmxWrite(iaddr + 2, rgb & 0xFF);
#else
CRGB rgb = CHSV(map(Par[0], 0, 365, 0, 255), rgbSaturation, rgbValue);
DmxWrite(iaddr, rgb.r);
DmxWrite(iaddr + 1, rgb.g);
DmxWrite(iaddr + 2, rgb.b);
#endif
break;
}
case CH_WHITE:

17
lighthub/lighthub.ino.cpp Normal file
View File

@@ -0,0 +1,17 @@
# 1 "/var/folders/kt/8psth65x03v6tw_phdhbj12r0000gn/T/tmpwztWO8"
#include <Arduino.h>
# 1 "/Users/andrey/Documents/Arduino/lighthub/lighthub/lighthub.ino"
#include "main.h"
void setup();
void loop();
#line 2 "/Users/andrey/Documents/Arduino/lighthub/lighthub/lighthub.ino"
void setup(){
setup_main();
}
void loop(){
loop_main();
}

View File

@@ -121,9 +121,9 @@
#include <ModbusMaster.h>
#endif
#ifndef DMX_DISABLE
#include "FastLED.h"
#endif
//#ifndef DMX_DISABLE
//#include "FastLED.h"
//#endif
#ifdef _owire
#include "owTerm.h"

View File

@@ -4,23 +4,63 @@
#include "Arduino.h"
#include "options.h"
#include "Streaming.h"
#include "FastLED.h"
#include "item.h"
#define NUM_LEDS 43
#define DATA_PIN 4
#ifdef ADAFRUIT_LED
//static CRGB leds[NUM_LEDS];
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
Adafruit_NeoPixel *leds = NULL;
#else
#include "FastLED.h"
static CRGB *leds = NULL;
#endif
#define NUM_LEDS 43
static int driverStatus = CST_UNKNOWN;
void out_SPILed::getConfig()
{
pin=item->getArg(0);
if(pin<=0) pin=3;
numLeds=item->getArg(1);
if (numLeds<=0) numLeds=NUM_LEDS;
ledsType=item->getArg(2);
#ifdef ADAFRUIT_LED
if (ledsType<=0) ledsType= NEO_BRG + NEO_KHZ800;
#endif
}
int out_SPILed::Setup()
{
getConfig();
Serial.println("SPI-LED Init");
leds = new CRGB [NUM_LEDS]; //Allocate dynamic memory for LED objects
if (!leds)
{
#ifdef ADAFRUIT_LED
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
leds = new Adafruit_NeoPixel(numLeds, pin, ledsType);
leds->begin();
#else
leds = new CRGB [numLeds]; //Allocate dynamic memory for LED objects
//template< CONTROLLER = TM1809, uint8_t DATA_PIN = pin, EOrder ORDER = BRG >
//FastLED.addLeds<TM1809, pin, BRG>(leds, numLeds);
FastLED.addLeds<CONTROLLER, DATA_PIN, ORDER>(leds, numLeds);
#endif
}
FastLED.addLeds<TM1809, DATA_PIN, BRG>(leds, NUM_LEDS);
driverStatus = CST_INITIALIZED;
return 1;
}
@@ -29,9 +69,15 @@ int out_SPILed::Stop()
{
Serial.println("SPI-LED De-Init");
//FastLED.addLeds<TM1809, DATA_PIN, BRG>(leds, NUM_LEDS);
#ifdef ADAFRUIT_LED
leds->clear();
delete leds;
#else
FastLED.clear(true);
driverStatus = CST_UNKNOWN;
delete [] leds;
#endif
driverStatus = CST_UNKNOWN;
return 1;
}
@@ -55,52 +101,88 @@ return 1;
int out_SPILed::getChanType()
{
return CH_RGB;
if ((ledsType>>4) == (ledsType>>6))
return CH_RGB;
else
return CH_RGBW;
}
int out_SPILed::PixelCtrl(CHstore *st, short cmd, int from, int to, bool show, bool rgb)
{
//debugSerial<<F("cmd: ")<<cmd<<endl;
CRGB pixel;
#ifdef ADAFRUIT_LED
uint32_t pixel;
#else
CRGB pixel;
#endif
if (!rgb)
{
int Saturation = map(st->s, 0, 100, 0, 255);
int Value = map(st->v, 0, 100, 0, 255);
#ifdef ADAFRUIT_LED
uint16_t Hue = map(st->h, 0, 365, 0, 655535);
pixel = leds->ColorHSV(Hue, Saturation, Value);
#else
int Hue = map(st->h, 0, 365, 0, 255);
pixel = CHSV(Hue, Saturation, Value);
#endif
debugSerial<<F("hsv: ")<<st->h<<F(",")<<st->s<<F(",")<<st->v<<endl;
}
if (to>NUM_LEDS-1) to=NUM_LEDS-1;
if (to>numLeds-1) to=numLeds-1;
if (from<0) from=0;
for (int i=from;i<=to;i++)
{
switch (cmd) {
case CMD_ON:
#ifdef ADAFRUIT_LED
if (!leds->getPixelColor(i)) leds->setPixelColor(i, leds->Color(255, 255, 255));
#else
if (!leds[i].r && !leds[i].g &&!leds[i].b) leds[i] = CRGB::White;
// FastLED.show();
#endif
break;
case CMD_OFF:
//pixel = leds[i];
#ifdef ADAFRUIT_LED
leds->setPixelColor(i, leds->Color(0, 0, 0));
#else
leds[i] = CRGB::Black;
//FastLED.show();
//leds[i] = pixel;
#endif
break;
default:
if (rgb)
{
#ifdef ADAFRUIT_LED
leds->setPixelColor(i, leds->Color(st->r,st->g,st->b));
#else
leds[i] = CRGB(st->r,st->g,st->b);
#endif
}
else
{
#ifdef ADAFRUIT_LED
leds->setPixelColor(i, pixel);
#else
leds[i] = pixel;
#endif
}
}
} //for
if (show)
{
#ifdef ADAFRUIT_LED
leds->show();
#else
FastLED.show();
#endif
debugSerial<<F("Show")<<endl;
}
return 1;
@@ -113,7 +195,7 @@ 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
int from=0, to=numLeds-1; //All LEDs on the strip by default
// retrive LEDs range from suffix
if (subItem)
{ //Just single LED to control todo - range

View File

@@ -1,13 +1,20 @@
#pragma once
#include "options.h"
#ifndef SPILED_DISABLE
#include <abstractout.h>
#include <item.h>
#ifdef ADAFRUIT_LED
#include <Adafruit_NeoPixel.h>
#else
#include "FastLED.h"
#endif
class out_SPILed : public abstractOut {
public:
out_SPILed(Item * _item):abstractOut(_item){};
out_SPILed(Item * _item):abstractOut(_item){getConfig();};
int Setup() override;
int Poll() override;
int Stop() override;
@@ -17,8 +24,9 @@ public:
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;
int8_t pin;
int ledsType;
protected:
void getConfig();
};
#endif

View File

@@ -1,13 +1,29 @@
// Configuration of drivers enabled
#ifndef PIO_SRC_REV
#define PIO_SRC_REV v0.999
#ifndef FASTLED
#define ADAFRUIT_LED
#endif
// ADAFRUIT library allow to dynamically configure SPI LED Strip Parameters
// If not defined ADAFRUIT_LED - FastLED library will be used instead
// And strip type, pin, order must defined on compilation time
#ifndef CONTROLLER
#define CONTROLLER TM1809
#endif
#ifndef DATA_PIN
#define DATA_PIN 4
#endif
#ifndef ORDER
#define ORDER BRG
#endif
#define TXEnablePin 13
#define ESP_EEPROM_SIZE 2048
#ifndef AVR_DMXOUT_PIN
#define AVR_DMXOUT_PIN 3
#define AVR_DMXOUT_PIN 18
#endif
#define T_ATTEMPTS 200
@@ -78,19 +94,6 @@
#ifndef HOMETOPIC
#define HOMETOPIC "myhome"
#endif
/*
#ifndef OUTTOPIC
#define OUTTOPIC "/myhome/s_out/"
#endif
#ifndef CMDTOPIC
#define CMDTOPIC "/myhome/in/command/"
#endif
#ifndef INTOPIC
#define INTOPIC "/myhome/in/"
#endif
*/
//Default output topic
#ifndef OUTTOPIC

View File

@@ -101,6 +101,7 @@ lib_deps =
DHT sensor library
Streaming
https://github.com/anklimov/NRFFlashStorage
Adafruit NeoPixel
; https://github.com/livello/PrintEx#is-select-redecl
@@ -150,6 +151,7 @@ lib_deps =
;SparkFun CCS811 Arduino Library
https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library.git
M5Stack
Adafruit NeoPixel
[env:esp32-wifi]
platform = espressif32
@@ -197,6 +199,7 @@ lib_deps =
ClosedCube HDC1080
;SparkFun CCS811 Arduino Library
https://github.com/sparkfun/SparkFun_CCS811_Arduino_Library.git
Adafruit NeoPixel
[env:due-5100]
platform = atmelsam
framework = arduino
@@ -238,6 +241,7 @@ lib_deps =
Streaming
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
Adafruit NeoPixel
[env:mega2560slim-5100]
platform = atmelavr
@@ -277,6 +281,7 @@ lib_deps =
Streaming
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
Adafruit NeoPixel
[env:mega2560-5500]
platform = atmelavr
@@ -315,6 +320,7 @@ lib_deps =
Streaming
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
Adafruit NeoPixel
[env:esp8266-wifi]
@@ -361,6 +367,7 @@ lib_deps =
ESP_EEPROM
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
Adafruit NeoPixel
[env:mega2560-5100]
platform = atmelavr
@@ -401,6 +408,7 @@ lib_deps =
Streaming
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
Adafruit NeoPixel
[env:due-5500]
platform = atmelsam
@@ -446,6 +454,7 @@ lib_deps =
https://github.com/livello/PrintEx#is-select-redecl
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
Adafruit NeoPixel
[env:lighthub21]
platform = atmelsam
@@ -490,6 +499,7 @@ lib_deps =
https://github.com/livello/PrintEx#is-select-redecl
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
Adafruit NeoPixel
[env:controllino]
@@ -531,6 +541,7 @@ lib_deps =
https://github.com/livello/PrintEx#is-select-redecl
ClosedCube HDC1080
SparkFun CCS811 Arduino Library
Adafruit NeoPixel
[env:stm32-enc2860]
platform = ststm32
@@ -576,3 +587,4 @@ lib_deps =
Streaming
UIPEthernet
https://github.com/anklimov/NRFFlashStorage
Adafruit NeoPixel