Lumitronix_Iflex_Pro_Workshop
Library to interact with the iFlexPro
Neo2Byte555Feature.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2 Neo2Byte555Feature provides feature base classes to describe color elements
3 with 555 encoding for LumitronixIFlexBus Color Feature template classes
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>
31  public NeoByteElements<2, RgbColor, uint16_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  uint16_t color555;
38 
39  encodePixel(&color555, color);
40  *p++ = color555 >> 8;
41  *p = color555 & 0xff;
42  }
43 
44  static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
45  {
46  ColorObject color;
47  const uint8_t* p = getPixelAddress(pPixels, indexPixel);
48 
49  uint16_t color555;
50 
51  color555 = ((*p++) << 8);
52  color555 |= (*p);
53 
54  decodePixel(&color, color555);
55 
56  return color;
57  }
58 
59  static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
60  {
61  ColorObject color;
62  const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
63 
64  uint16_t color555;
65 
66  color555 = (pgm_read_byte(p++) << 8);
67  color555 |= pgm_read_byte(p);
68 
69  decodePixel(&color, color555);
70 
71  return color;
72  }
73 
74 protected:
75  static void encodePixel(uint16_t* color555, const ColorObject& color)
76  {
77  *color555 = (0x8000 |
78  ((color[V_IC_1] & 0xf8) << 7) |
79  ((color[V_IC_2] & 0xf8) << 2) |
80  ((color[V_IC_3] & 0xf8) >> 3));
81  }
82 
83  static void decodePixel(ColorObject* color, uint16_t color555)
84  {
85  (*color)[V_IC_2] = (color555 >> 2) & 0xf8;
86  (*color)[V_IC_3] = (color555 << 3) & 0xf8;
87  (*color)[V_IC_1] = (color555 >> 7) & 0xf8;
88  }
89 };
#define PGM_VOID_P
Definition: NeoUtil.h:42
Definition: Neo2Byte555Feature.h:32
static void encodePixel(uint16_t *color555, const ColorObject &color)
Definition: Neo2Byte555Feature.h:75
static ColorObject retrievePixelColor(const uint8_t *pPixels, uint16_t indexPixel)
Definition: Neo2Byte555Feature.h:44
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
Definition: Neo2Byte555Feature.h:59
static void applyPixelColor(uint8_t *pPixels, uint16_t indexPixel, ColorObject color)
Definition: Neo2Byte555Feature.h:34
static void decodePixel(ColorObject *color, uint16_t color555)
Definition: Neo2Byte555Feature.h:83
Definition: NeoByteElements.h:101
static uint8_t * getPixelAddress(uint8_t *pPixels, uint16_t indexPixel)
Definition: NeoByteElements.h:43
T_COLOR_OBJECT ColorObject
Definition: NeoByteElements.h:41