Lumitronix_Iflex_Pro_Workshop
Library to interact with the iFlexPro
Neo4WordFeature.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2 Neo4WordFeature provides feature base class to describe color order for
3  4 Word features
4 
5 Written by Michael C. Miller.
6 
7 I invest time and resources providing this open source code,
8 please support me by dontating (see https://github.com/Makuna)
9 
10 -------------------------------------------------------------------------
11 This file is part of the LUMITRONIX_iFlex_Workshop library.
12 
13 LumitronixIFlexBus is free software: you can redistribute it and/or modify
14 it under the terms of the GNU Lesser General Public License as
15 published by the Free Software Foundation, either version 3 of
16 the License, or (at your option) any later version.
17 
18 LumitronixIFlexBus is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU Lesser General Public License for more details.
22 
23 You should have received a copy of the GNU Lesser General Public
24 License along with LumitronixIFlex. If not, see
25 <http://www.gnu.org/licenses/>.
26 -------------------------------------------------------------------------*/
27 #pragma once
28 
29 template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3, uint8_t V_IC_4>
31  public NeoWordElements<8, Rgbw64Color, uint32_t>
32 {
33 public:
34  static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
35  {
36  uint8_t* p = getPixelAddress(pPixels, indexPixel);
37 
38  // due to endianness the byte order must be copied to output
39  *p++ = color[V_IC_1] >> 8;
40  *p++ = color[V_IC_1] & 0xff;
41  *p++ = color[V_IC_2] >> 8;
42  *p++ = color[V_IC_2] & 0xff;
43  *p++ = color[V_IC_3] >> 8;
44  *p++ = color[V_IC_3] & 0xff;
45  *p++ = color[V_IC_4] >> 8;
46  *p = color[V_IC_4] & 0xff;
47  }
48 
49  static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
50  {
51  ColorObject color;
52  const uint8_t* p = getPixelAddress(pPixels, indexPixel);
53 
54  // due to endianness the byte order must be copied to output
55  color[V_IC_1] = (static_cast<uint16_t>(*p++) << 8);
56  color[V_IC_1] |= *p++;
57  color[V_IC_2] = (static_cast<uint16_t>(*p++) << 8);
58  color[V_IC_2] |= *p++;
59  color[V_IC_3] = (static_cast<uint16_t>(*p++) << 8);
60  color[V_IC_3] |= *p++;
61  color[V_IC_4] = (static_cast<uint16_t>(*p++) << 8);
62  color[V_IC_4] |= *p;
63 
64  return color;
65  }
66 
67  static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
68  {
69  ColorObject color;
70  const uint16_t* p = reinterpret_cast<const uint16_t*>(getPixelAddress(reinterpret_cast<const uint8_t*>(pPixels), indexPixel));
71 
72  // PROGMEM unit of storage expected to be the same size as color element
73  // so no endianness issues to worry about
74  color[V_IC_1] = pgm_read_word(p++);
75  color[V_IC_2] = pgm_read_word(p++);
76  color[V_IC_3] = pgm_read_word(p++);
77  color[V_IC_4] = pgm_read_word(p);
78 
79  return color;
80  }
81 
82  };
#define PGM_VOID_P
Definition: NeoUtil.h:42
Definition: Neo4WordFeature.h:32
static void applyPixelColor(uint8_t *pPixels, uint16_t indexPixel, ColorObject color)
Definition: Neo4WordFeature.h:34
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
Definition: Neo4WordFeature.h:67
static ColorObject retrievePixelColor(const uint8_t *pPixels, uint16_t indexPixel)
Definition: Neo4WordFeature.h:49
static uint8_t * getPixelAddress(uint8_t *pPixels, uint16_t indexPixel)
Definition: NeoByteElements.h:43
T_COLOR_OBJECT ColorObject
Definition: NeoByteElements.h:41
Definition: NeoByteElements.h:123