New feature (#680)

This commit is contained in:
Michael Miller
2023-04-06 14:32:20 -07:00
committed by GitHub
parent d25e447da9
commit 5bb30975a8
3 changed files with 190 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ License along with NeoPixel. If not, see
#include "features/Neo3ByteElements.h"
#include "features/Neo4ByteElements.h"
#include "features/Neo6ByteElements.h"
#include "features/Neo6Byte4xxElements.h"
#include "features/Neo8ByteElements.h"
#include "features/NeoBgrFeature.h"
#include "features/NeoBrgFeature.h"
@@ -43,6 +44,7 @@ License along with NeoPixel. If not, see
#include "features/NeoRgbFeature.h"
#include "features/NeoRgbw64Feature.h"
#include "features/NeoRgbwFeature.h"
#include "features/NeoRgbwxxFeature.h"
#include "features/NeoSm168xxColorFeatures.h"
#include "features/NeoTm1814ColorFeatures.h"
#include "features/NeoTm1914ColorFeatures.h"

View File

@@ -0,0 +1,116 @@
/*-------------------------------------------------------------------------
Neo6Byte4xxElements provides feature base classes to describe color elements
for NeoPixelBus Color Feature template classes. While it takes 6 bytes, it
only uses four and ignores the last two
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
class Neo6Byte4xxElements
{
public:
static const size_t PixelSize = 6;
static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel)
{
return pPixels + indexPixel * PixelSize;
}
static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel)
{
return pPixels + indexPixel * PixelSize;
}
static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
{
uint16_t* pDest = reinterpret_cast<uint16_t*>(pPixelDest);
const uint16_t* pSrc = reinterpret_cast<const uint16_t*>(pPixelSrc);
const uint16_t* pEnd = pDest + (count * PixelSize / sizeof(*pDest));
while (pDest < pEnd)
{
*pDest++ = *pSrc;
}
}
static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
{
uint16_t* pDest = reinterpret_cast<uint16_t*>(pPixelDest);
const uint16_t* pSrc = reinterpret_cast<const uint16_t*>(pPixelSrc);
const uint16_t* pEnd = pDest + (count * PixelSize / sizeof(*pDest));
while (pDest < pEnd)
{
*pDest++ = *pSrc++;
}
}
static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count)
{
uint16_t* pDest = reinterpret_cast<uint16_t*>(pPixelDest);
const uint16_t* pSrc = reinterpret_cast<const uint16_t*>(pPixelSrc);
const uint16_t* pEnd = pDest + (count * PixelSize / sizeof(*pDest));
while (pDest < pEnd)
{
*pDest++ = pgm_read_word(pSrc++);
}
}
static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
{
uint16_t* pDest = reinterpret_cast<uint16_t*>(pPixelDest);
const uint16_t* pSrc = reinterpret_cast<const uint16_t*>(pPixelSrc);
uint16_t* pDestBack = pDest + (count * PixelSize / sizeof(*pDest));
const uint16_t* pSrcBack = pSrc + (count * PixelSize / sizeof(*pSrc));
while (pDestBack > pDest)
{
*--pDestBack = *--pSrcBack;
}
}
typedef RgbwColor ColorObject;
};
class Neo6Byte4xxElementsNoSettings : public Neo6Byte4xxElements
{
public:
typedef NeoNoSettings SettingsObject;
static const size_t SettingsSize = 0;
static void applySettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
{
}
static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData)
{
return pData;
}
static const uint8_t* pixels([[maybe_unused]] const uint8_t* pData, [[maybe_unused]] size_t sizeData)
{
return pData;
}
};

View File

@@ -0,0 +1,72 @@
/*-------------------------------------------------------------------------
NeoRgbwxxFeature provides feature classes to describe color order and
color depth for NeoPixelBus template class
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
class NeoRgbwxxFeature : public Neo6Byte4xxElementsNoSettings
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
*p++ = color.R;
*p++ = color.G;
*p++ = color.B;
*p++ = color.W;
// zero the xx, this maybe unnecessary though, but its thorough
*p++ = 0;
*p = 0;
}
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
color.R = *p++;
color.G = *p++;
color.B = *p++;
color.W = *p;
// ignore the xx
return color;
}
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
{
ColorObject color;
const uint8_t* p = getPixelAddress(reinterpret_cast<const uint8_t*>(pPixels), indexPixel);
color.R = pgm_read_byte(p++);
color.G = pgm_read_byte(p++);
color.B = pgm_read_byte(p++);
color.W = pgm_read_byte(p);
// ignore the xx
return color;
}
};