Lumitronix_Iflex_Pro_Workshop
Library to interact with the iFlexPro
NeoSm168xxFeatures.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2 NeoSm168xxFeatures provides feature classes to describe color order and
3 color depth for LumitronixIFlexBus template class specific to the SM168xx chips/leds
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 3 channel RGB
30 SM16803P 1.8~60mA << need spec sheet to get accurate implementation
31 SM16813PB 1.8~19mA
32 SM16823E 60~350mA
33 4 channel RGBW
34 SM16804PB 1.5~60mA << need spec sheet to get accurate implementation
35 SM16804EB 1.8~19mA
36 SM16824E 60~350mA
37 */
38 
40 {
41 public:
42  NeoSm168x3SettingsBase(uint8_t redGain,
43  uint8_t greenGain,
44  uint8_t blueGain,
45  uint16_t redCurrent,
46  uint16_t greenCurrent,
47  uint16_t blueCurrent) :
48  NeoRgbCurrentSettings(redCurrent, greenCurrent, blueCurrent),
49  RedGain(redGain & 0x0f),
50  GreenGain(greenGain & 0x0f),
51  BlueGain(blueGain & 0x0f) {}
52 
53  // ------------------------------------------------------------------------
54  // operator [] - readonly
55  // access elements in order by index rather than member name
56  // ------------------------------------------------------------------------
57  uint8_t operator[](size_t idx) const
58  {
59  switch (idx)
60  {
61  case 0:
62  return RedGain;
63  case 1:
64  return GreenGain;
65  default:
66  return BlueGain;
67  }
68  }
69 
70  const uint8_t RedGain : 4;
71  const uint8_t GreenGain : 4;
72  const uint8_t BlueGain : 4;
73 };
74 
75 template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3>
77 {
78 public:
79  NeoSm16803pbSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain) :
80  NeoSm168x3SettingsBase(redGain,
81  greenGain,
82  blueGain,
83  CurrentLookup[redGain],
84  CurrentLookup[greenGain],
85  CurrentLookup[blueGain])
86  {
87  }
88 
89  void Encode(uint8_t* encoded) const
90  {
91  // 0RGB 4 bits each
92  *encoded++ = operator[](V_IC_1);
93  *encoded = operator[](V_IC_2) << 4 | operator[](V_IC_3);
94  }
95 
96 protected:
97  static constexpr uint8_t CurrentLookup[16] = {
98  18, 30, 41, 53, 64, 76, 87, 99,
99  110, 133, 145, 156, 168, 179, 190};
100 };
101 
102 template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3>
104 {
105 public:
106  NeoSm16823eSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint16_t resisterOhms) :
107  NeoSm168x3SettingsBase(redGain,
108  greenGain,
109  blueGain,
110  calcCurrent(resisterOhms, redGain),
111  calcCurrent(resisterOhms, greenGain),
112  calcCurrent(resisterOhms, blueGain)),
113  extROhms(resisterOhms)
114  {
115  }
116 
117  void Encode(uint8_t* encoded) const
118  {
119  // RGB0 4 bits each
120  *encoded++ = operator[](V_IC_1) << 4 | operator[](V_IC_2);
121  *encoded = operator[](V_IC_3) << 4;
122  }
123 
124 protected:
125  const uint16_t extROhms;
126 
127  static uint16_t calcCurrent(const uint16_t ohms, const uint8_t gain)
128  {
129  uint16_t mA = (967 * (240 + (gain * 32)) / ohms); // from spec sheet, gain 0-15 instead
130  return mA * 10; // return tenths of mA
131  }
132 };
133 
134 // RGBW versions
135 
137 {
138 public:
139  NeoSm168x4SettingsBase(uint8_t redGain,
140  uint8_t greenGain,
141  uint8_t blueGain,
142  uint8_t whiteGain,
143  uint16_t redCurrent,
144  uint16_t greenCurrent,
145  uint16_t blueCurrent,
146  uint16_t whiteCurrent) :
147  NeoRgbwCurrentSettings(redCurrent, greenCurrent, blueCurrent, whiteCurrent),
148  RedGain(redGain & 0x0f),
149  GreenGain(greenGain & 0x0f),
150  BlueGain(blueGain & 0x0f),
151  WhiteGain(whiteGain & 0x0f) {}
152 
153  // ------------------------------------------------------------------------
154  // operator [] - readonly
155  // access elements in order by index rather than member name
156  // ------------------------------------------------------------------------
157  uint8_t operator[](size_t idx) const
158  {
159  switch (idx)
160  {
161  case 0:
162  return RedGain;
163  case 1:
164  return GreenGain;
165  case 2:
166  return BlueGain;
167  default:
168  return WhiteGain;
169  }
170  }
171 
172  const uint8_t RedGain : 4;
173  const uint8_t GreenGain : 4;
174  const uint8_t BlueGain : 4;
175  const uint8_t WhiteGain : 4;
176 };
177 
178 template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3, uint8_t V_IC_4>
180 {
181 public:
182  NeoSm16804ebSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint8_t whiteGain) :
183  NeoSm168x4SettingsBase(redGain,
184  greenGain,
185  blueGain,
186  whiteGain,
187  CurrentLookup[redGain],
188  CurrentLookup[greenGain],
189  CurrentLookup[blueGain],
190  CurrentLookup[whiteGain])
191  {
192  }
193 
194  void Encode(uint8_t* encoded) const
195  {
196  // RGBW 4 bits each
197  *encoded++ = operator[](V_IC_1) << 4 | operator[](V_IC_2);
198  *encoded = operator[](V_IC_3) << 4 | operator[](V_IC_4);
199  }
200 
201 protected:
202  static constexpr uint8_t CurrentLookup[16] = {
203  18, 30, 41, 53, 64, 76, 87, 99,
204  110, 133, 145, 156, 168, 179, 190 };
205 };
206 
207 template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3, uint8_t V_IC_4>
209 {
210 public:
211  NeoSm16824eSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint8_t whiteGain, uint16_t resisterOhms) :
212  NeoSm168x4SettingsBase(redGain,
213  greenGain,
214  blueGain,
215  whiteGain,
216  calcCurrent(resisterOhms, redGain),
217  calcCurrent(resisterOhms, greenGain),
218  calcCurrent(resisterOhms, blueGain),
219  calcCurrent(resisterOhms, whiteGain)),
220  extROhms(resisterOhms)
221  {
222  }
223 
224  void Encode(uint8_t* encoded) const
225  {
226  // RGBW 4 bits each
227  *encoded++ = operator[](V_IC_1) << 4 | operator[](V_IC_2);
228  *encoded = operator[](V_IC_3) << 4 | operator[](V_IC_4);
229  }
230 
231 protected:
232  const uint16_t extROhms;
233 
234  static uint16_t calcCurrent(const uint16_t ohms, const uint8_t gain)
235  {
236  uint16_t mA = (1100 * (240 + (gain * 32)) / ohms); // from spec sheet, gain 0-15 instead
237  return mA * 10; // return tenths of mA
238  }
239 
240 };
241 
242 // CAUTION: Make sure ColorIndex order for Neo4ByteFeature matches T_SETTINGS
243 template<typename T_SETTINGS>
245  public Neo4ByteFeature<ColorIndexR, ColorIndexG, ColorIndexB, ColorIndexW>
246 {
247 public:
248  typedef T_SETTINGS SettingsObject;
249  static const size_t SettingsSize = 2;
250 
251  static void applySettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
252  {
253  // settings are at the end of the data stream
254  uint8_t* pDest = pData + sizeData - SettingsSize;
255 
256  settings.Encode(pDest);
257  }
258 
259  static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData)
260  {
261  return pData;
262  }
263 
264  static const uint8_t* pixels([[maybe_unused]] const uint8_t* pData, [[maybe_unused]] size_t sizeData)
265  {
266  return pData;
267  }
268 };
269 
270 // CAUTION: Make sure ColorIndex order for Neo3ByteFeature matches T_SETTINGS
271 template<typename T_SETTINGS> class NeoRgbSm168x3Elements :
272  public Neo3ByteFeature<ColorIndexR, ColorIndexG, ColorIndexB>
273 {
274 public:
275  typedef T_SETTINGS SettingsObject;
276  static const size_t SettingsSize = 2;
277 
278  static void applySettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
279  {
280  // settings are at the end of the data stream
281  uint8_t* pDest = pData + sizeData - SettingsSize;
282 
283  settings.Encode(pDest);
284  }
285 
286  static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData)
287  {
288  return pData;
289  }
290 
291  static const uint8_t* pixels([[maybe_unused]] const uint8_t* pData, [[maybe_unused]] size_t sizeData)
292  {
293  return pData;
294  }
295 };
296 
301 
302 
NeoRgbSm168x3Elements< NeoSm16803pbSettings< ColorIndexR, ColorIndexG, ColorIndexB > > NeoRgbSm16803pbFeature
Definition: NeoSm168xxFeatures.h:297
NeoRgbwSm168x4Elements< NeoSm16804ebSettings< ColorIndexR, ColorIndexG, ColorIndexB, ColorIndexW > > NeoRgbwSm16804ebFeature
Definition: NeoSm168xxFeatures.h:299
NeoRgbSm168x3Elements< NeoSm16823eSettings< ColorIndexR, ColorIndexG, ColorIndexB > > NeoRgbSm16823eFeature
Definition: NeoSm168xxFeatures.h:298
NeoRgbwSm168x4Elements< NeoSm16824eSettings< ColorIndexR, ColorIndexG, ColorIndexB, ColorIndexW > > NeoRgbwSm16824eFeature
Definition: NeoSm168xxFeatures.h:300
Definition: Neo3ByteFeature.h:32
Definition: Neo4ByteFeature.h:32
Definition: NeoSettings.h:33
Definition: NeoSm168xxFeatures.h:273
static uint8_t * pixels([[maybe_unused]] uint8_t *pData, [[maybe_unused]] size_t sizeData)
Definition: NeoSm168xxFeatures.h:286
static const uint8_t * pixels([[maybe_unused]] const uint8_t *pData, [[maybe_unused]] size_t sizeData)
Definition: NeoSm168xxFeatures.h:291
static void applySettings([[maybe_unused]] uint8_t *pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject &settings)
Definition: NeoSm168xxFeatures.h:278
static const size_t SettingsSize
Definition: NeoSm168xxFeatures.h:276
T_SETTINGS SettingsObject
Definition: NeoSm168xxFeatures.h:275
Definition: NeoSettings.h:65
Definition: NeoSm168xxFeatures.h:246
static void applySettings([[maybe_unused]] uint8_t *pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject &settings)
Definition: NeoSm168xxFeatures.h:251
T_SETTINGS SettingsObject
Definition: NeoSm168xxFeatures.h:248
static const uint8_t * pixels([[maybe_unused]] const uint8_t *pData, [[maybe_unused]] size_t sizeData)
Definition: NeoSm168xxFeatures.h:264
static uint8_t * pixels([[maybe_unused]] uint8_t *pData, [[maybe_unused]] size_t sizeData)
Definition: NeoSm168xxFeatures.h:259
static const size_t SettingsSize
Definition: NeoSm168xxFeatures.h:249
Definition: NeoSm168xxFeatures.h:77
void Encode(uint8_t *encoded) const
Definition: NeoSm168xxFeatures.h:89
static constexpr uint8_t CurrentLookup[16]
Definition: NeoSm168xxFeatures.h:97
NeoSm16803pbSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain)
Definition: NeoSm168xxFeatures.h:79
Definition: NeoSm168xxFeatures.h:180
NeoSm16804ebSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint8_t whiteGain)
Definition: NeoSm168xxFeatures.h:182
static constexpr uint8_t CurrentLookup[16]
Definition: NeoSm168xxFeatures.h:202
void Encode(uint8_t *encoded) const
Definition: NeoSm168xxFeatures.h:194
Definition: NeoSm168xxFeatures.h:104
const uint16_t extROhms
Definition: NeoSm168xxFeatures.h:125
NeoSm16823eSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint16_t resisterOhms)
Definition: NeoSm168xxFeatures.h:106
static uint16_t calcCurrent(const uint16_t ohms, const uint8_t gain)
Definition: NeoSm168xxFeatures.h:127
void Encode(uint8_t *encoded) const
Definition: NeoSm168xxFeatures.h:117
Definition: NeoSm168xxFeatures.h:209
const uint16_t extROhms
Definition: NeoSm168xxFeatures.h:232
static uint16_t calcCurrent(const uint16_t ohms, const uint8_t gain)
Definition: NeoSm168xxFeatures.h:234
NeoSm16824eSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint8_t whiteGain, uint16_t resisterOhms)
Definition: NeoSm168xxFeatures.h:211
void Encode(uint8_t *encoded) const
Definition: NeoSm168xxFeatures.h:224
Definition: NeoSm168xxFeatures.h:40
NeoSm168x3SettingsBase(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint16_t redCurrent, uint16_t greenCurrent, uint16_t blueCurrent)
Definition: NeoSm168xxFeatures.h:42
const uint8_t GreenGain
Definition: NeoSm168xxFeatures.h:71
uint8_t operator[](size_t idx) const
Definition: NeoSm168xxFeatures.h:57
const uint8_t BlueGain
Definition: NeoSm168xxFeatures.h:72
const uint8_t RedGain
Definition: NeoSm168xxFeatures.h:70
Definition: NeoSm168xxFeatures.h:137
const uint8_t GreenGain
Definition: NeoSm168xxFeatures.h:173
const uint8_t RedGain
Definition: NeoSm168xxFeatures.h:172
uint8_t operator[](size_t idx) const
Definition: NeoSm168xxFeatures.h:157
const uint8_t BlueGain
Definition: NeoSm168xxFeatures.h:174
const uint8_t WhiteGain
Definition: NeoSm168xxFeatures.h:175
NeoSm168x4SettingsBase(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint8_t whiteGain, uint16_t redCurrent, uint16_t greenCurrent, uint16_t blueCurrent, uint16_t whiteCurrent)
Definition: NeoSm168xxFeatures.h:139