2016-02-28 22:09:31 -08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
NeoPixel library
|
|
|
|
|
|
|
|
|
|
Written by Michael C. Miller.
|
|
|
|
|
|
|
|
|
|
I invest time and resources providing this open source code,
|
|
|
|
|
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
|
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------
|
|
|
|
|
This file is part of the Makuna/NeoPixelBus library.
|
|
|
|
|
|
|
|
|
|
NeoPixelBus is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
published by the Free Software Foundation, either version 3 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
NeoPixelBus is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
License along with NeoPixel. If not, see
|
|
|
|
|
<http://www.gnu.org/licenses/>.
|
|
|
|
|
-------------------------------------------------------------------------*/
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
2016-03-03 14:38:35 -08:00
|
|
|
#include "internal/RgbColor.h"
|
|
|
|
|
#include "internal/HslColor.h"
|
|
|
|
|
#include "internal/HsbColor.h"
|
2016-03-05 18:50:23 -08:00
|
|
|
#include "internal/HtmlColor.h"
|
2016-03-03 14:38:35 -08:00
|
|
|
#include "internal/RgbwColor.h"
|
2016-03-20 10:06:58 -07:00
|
|
|
|
|
|
|
|
#include "internal/Layouts.h"
|
|
|
|
|
#include "internal/NeoTopology.h"
|
|
|
|
|
#include "internal/NeoTiles.h"
|
|
|
|
|
#include "internal/NeoMosaic.h"
|
|
|
|
|
|
|
|
|
|
#include "internal/NeoEase.h"
|
|
|
|
|
#include "internal/NeoGamma.h"
|
|
|
|
|
|
2016-03-03 14:38:35 -08:00
|
|
|
#include "internal/NeoColorFeatures.h"
|
2016-02-28 22:09:31 -08:00
|
|
|
|
|
|
|
|
#if defined(ARDUINO_ARCH_ESP8266)
|
2016-03-03 14:38:35 -08:00
|
|
|
#include "internal/NeoEsp8266DmaMethod.h"
|
|
|
|
|
#include "internal/NeoEsp8266UartMethod.h"
|
|
|
|
|
#include "internal/NeoEsp8266BitBangMethod.h"
|
2016-02-28 22:09:31 -08:00
|
|
|
#elif defined(__arm__) // must be before ARDUINO_ARCH_AVR due to Teensy incorrectly having it set
|
2016-03-03 14:38:35 -08:00
|
|
|
#include "internal/NeoArmMethod.h"
|
2016-02-28 22:09:31 -08:00
|
|
|
#elif defined(ARDUINO_ARCH_AVR)
|
2016-03-03 14:38:35 -08:00
|
|
|
#include "internal/NeoAvrMethod.h"
|
2016-02-28 22:09:31 -08:00
|
|
|
#else
|
|
|
|
|
#error "Platform Currently Not Supported, please add an Issue at Github/Makuna/NeoPixelBus"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// '_state' flags for internal state
|
|
|
|
|
#define NEO_DIRTY 0x80 // a change was made to pixel data that requires a show
|
|
|
|
|
|
|
|
|
|
template<typename T_COLOR_FEATURE, typename T_METHOD> class NeoPixelBus
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
// Constructor: number of LEDs, pin number
|
|
|
|
|
// NOTE: Pin Number maybe ignored due to hardware limitations of the method.
|
|
|
|
|
|
|
|
|
|
NeoPixelBus(uint16_t countPixels, uint8_t pin) :
|
|
|
|
|
_countPixels(countPixels),
|
|
|
|
|
_method(pin, countPixels, T_COLOR_FEATURE::PixelSize)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~NeoPixelBus()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Begin()
|
|
|
|
|
{
|
|
|
|
|
_method.Initialize();
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Show()
|
|
|
|
|
{
|
|
|
|
|
if (!IsDirty())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_method.Update();
|
|
|
|
|
|
|
|
|
|
ResetDirty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool CanShow() const
|
|
|
|
|
{
|
|
|
|
|
return _method.IsReadyToUpdate();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool IsDirty() const
|
|
|
|
|
{
|
|
|
|
|
return (_state & NEO_DIRTY);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void Dirty()
|
|
|
|
|
{
|
|
|
|
|
_state |= NEO_DIRTY;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void ResetDirty()
|
|
|
|
|
{
|
|
|
|
|
_state &= ~NEO_DIRTY;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
uint8_t* Pixels() const
|
|
|
|
|
{
|
|
|
|
|
return _method.getPixels();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
size_t PixelsSize() const
|
|
|
|
|
{
|
|
|
|
|
return _method.getPixelsSize();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
size_t PixelSize() const
|
|
|
|
|
{
|
|
|
|
|
return T_COLOR_FEATURE::PixelSize;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
uint16_t PixelCount() const
|
|
|
|
|
{
|
|
|
|
|
return _countPixels;
|
|
|
|
|
};
|
|
|
|
|
|
2016-03-20 10:06:58 -07:00
|
|
|
void SetPixelColor(uint16_t indexPixel, const typename T_COLOR_FEATURE::ColorObject& color)
|
2016-02-28 22:09:31 -08:00
|
|
|
{
|
|
|
|
|
if (indexPixel < _countPixels)
|
|
|
|
|
{
|
|
|
|
|
T_COLOR_FEATURE::applyPixelColor(_method.getPixels(), indexPixel, color);
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const
|
|
|
|
|
{
|
|
|
|
|
if (indexPixel < _countPixels)
|
|
|
|
|
{
|
|
|
|
|
return T_COLOR_FEATURE::retrievePixelColor(_method.getPixels(), indexPixel);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Pixel # is out of bounds, this will get converted to a
|
|
|
|
|
// color object type initialized to 0 (black)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void ClearTo(typename T_COLOR_FEATURE::ColorObject color)
|
|
|
|
|
{
|
|
|
|
|
uint8_t* pixels = _method.getPixels();
|
|
|
|
|
for (uint16_t n = 0; n < _countPixels; n++)
|
|
|
|
|
{
|
|
|
|
|
T_COLOR_FEATURE::applyPixelColor(pixels, n, color);
|
|
|
|
|
}
|
|
|
|
|
Dirty();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const uint16_t _countPixels; // Number of RGB LEDs in strip
|
|
|
|
|
|
|
|
|
|
uint8_t _state; // internal state
|
|
|
|
|
T_METHOD _method;
|
|
|
|
|
};
|
|
|
|
|
|