74 lines
No EOL
1.9 KiB
C++
74 lines
No EOL
1.9 KiB
C++
#ifndef Lighting_h
|
|
#define Lighting_h
|
|
|
|
#include <FastLED.h>
|
|
#include "NaturalLight.h"
|
|
#include "Weather.h"
|
|
|
|
DEFINE_GRADIENT_PALETTE(_sunrise_p) {
|
|
0, 0, 0, 0,
|
|
8, 0, 0, 16,
|
|
128, 255, 128, 0,
|
|
224, 255, 255, 0,
|
|
240, 255, 255, 255, // Hack to get around LINEARBLEND problem (for now, hopefully)
|
|
255, 255, 255, 255
|
|
};
|
|
|
|
class Lighting {
|
|
int _ledCount, _whitePin, _rPin, _gPin, _bPin;
|
|
NaturalLight* _naturalLight;
|
|
Weather* _weather;
|
|
float _cloudCoverLimit;
|
|
CRGB* _leds;
|
|
CRGBPalette16 _sunrise = _sunrise_p;
|
|
long _nextLightningFlash = 0;
|
|
float _heatIndex;
|
|
float _brightness;
|
|
byte _lastHeatIndex, _lastBrightness;
|
|
bool _useStrip, _usePWM;
|
|
|
|
float _currentHeatIndex();
|
|
float getIndexMultiplier(int now, int startTime, int endTime, bool swap);
|
|
float getHeatIndex(int time);
|
|
float getPaletteHeatIndex(int time);
|
|
float getBrightness();
|
|
float getPaletteBrightness();
|
|
int byteToAnalogue(byte input);
|
|
void outputColour(CRGB colour);
|
|
void updateRGB(int now);
|
|
void updateWhite();
|
|
|
|
public:
|
|
Lighting(NaturalLight* _naturalLight, Weather* _weather, float cloudCoverLimit);
|
|
|
|
template<uint8_t dataPin, int ledCount, int whitePin> void setupStrip() {
|
|
_ledCount = ledCount;
|
|
FastLED.addLeds<WS2811, dataPin, GRB>(_leds, _ledCount).setCorrection(TypicalSMD5050).setTemperature(Tungsten40W);
|
|
_whitePin = whitePin;
|
|
pinMode(_whitePin, OUTPUT);
|
|
analogWrite(_whitePin, 0);
|
|
_useStrip = true;
|
|
}
|
|
|
|
template<int rPin, int gPin, int bPin, int whitePin> void setupPWM() {
|
|
_rPin = rPin;
|
|
_gPin = gPin;
|
|
_bPin = bPin;
|
|
_whitePin = whitePin;
|
|
pinMode(_rPin, OUTPUT);
|
|
pinMode(_gPin, OUTPUT);
|
|
pinMode(_bPin, OUTPUT);
|
|
pinMode(_whitePin, OUTPUT);
|
|
analogWrite(_rPin, 0);
|
|
analogWrite(_gPin, 0);
|
|
analogWrite(_bPin, 0);
|
|
analogWrite(_whitePin, 0);
|
|
_usePWM = true;
|
|
}
|
|
|
|
void update(int time);
|
|
float getCurrentHeatIndex() { return _heatIndex; }
|
|
float getCurrentBrightness() { return _brightness; }
|
|
};
|
|
|
|
#endif |