Lumitronix_Iflex_Pro_Workshop
Library to interact with the iFlexPro
NeoTm1814Features.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2 NeoTm1814Features provides feature classes to describe color order and
3 color depth for LumitronixIFlexBus template class specific to the TM1814 chip
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 
30 {
31 public:
32  NeoTm1814Settings(uint16_t red, uint16_t green, uint16_t blue, uint16_t white) :
33  NeoRgbwCurrentSettings(red, green, blue, white)
34  {
35  }
36 
37  const static uint16_t MinCurrent = 65;
38  const static uint16_t MaxCurrent = 380;
39 
40  static uint16_t LimitCurrent(uint16_t value)
41  {
42  if (value < MinCurrent)
43  {
44  value = MinCurrent;
45  }
46  else if (value > MaxCurrent)
47  {
48  value = MaxCurrent;
49  }
50  return value;
51  }
52 };
53 
54 template <uint8_t V_IC_1, uint8_t V_IC_2, uint8_t V_IC_3, uint8_t V_IC_4>
56 {
57 private:
58  const static uint16_t EncodeDivisor = 5;
59 
60 public:
62  static const size_t SettingsSize = 8;
63 
64  static void applySettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings)
65  {
66  // settings are at the front of the data stream
67  uint8_t* pSet = pData;
68 
69  // C1
70  *pSet++ = (SettingsObject::LimitCurrent(settings[V_IC_1]) - SettingsObject::MinCurrent) / EncodeDivisor;
71  *pSet++ = (SettingsObject::LimitCurrent(settings[V_IC_2]) - SettingsObject::MinCurrent) / EncodeDivisor;
72  *pSet++ = (SettingsObject::LimitCurrent(settings[V_IC_3]) - SettingsObject::MinCurrent) / EncodeDivisor;
73  *pSet++ = (SettingsObject::LimitCurrent(settings[V_IC_4]) - SettingsObject::MinCurrent) / EncodeDivisor;
74 
75  uint8_t* pC1 = pData;
76 
77  // C2
78  for (uint8_t elem = 0; elem < 4; elem++)
79  {
80  *pSet++ = ~(*pC1++);
81  }
82  }
83 
84  static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData)
85  {
86  // settings are at the front of the data stream
87  return pData + SettingsSize;
88  }
89 
90  static const uint8_t* pixels([[maybe_unused]] const uint8_t* pData, [[maybe_unused]] size_t sizeData)
91  {
92  // settings are at the front of the data stream
93  return pData + SettingsSize;
94  }
95 };
96 
97 
99  public Neo4ByteFeature<ColorIndexW, ColorIndexR, ColorIndexG, ColorIndexB>,
100  public NeoElementsTm1814Settings<ColorIndexW, ColorIndexR, ColorIndexG, ColorIndexB>
101 {
102 };
103 
Definition: Neo4ByteFeature.h:32
Definition: NeoTm1814Features.h:56
NeoTm1814Settings SettingsObject
Definition: NeoTm1814Features.h:61
static const size_t SettingsSize
Definition: NeoTm1814Features.h:62
static uint8_t * pixels([[maybe_unused]] uint8_t *pData, [[maybe_unused]] size_t sizeData)
Definition: NeoTm1814Features.h:84
static void applySettings([[maybe_unused]] uint8_t *pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject &settings)
Definition: NeoTm1814Features.h:64
static const uint8_t * pixels([[maybe_unused]] const uint8_t *pData, [[maybe_unused]] size_t sizeData)
Definition: NeoTm1814Features.h:90
Definition: NeoSettings.h:65
Definition: NeoTm1814Features.h:30
static const uint16_t MinCurrent
Definition: NeoTm1814Features.h:37
NeoTm1814Settings(uint16_t red, uint16_t green, uint16_t blue, uint16_t white)
Definition: NeoTm1814Features.h:32
static const uint16_t MaxCurrent
Definition: NeoTm1814Features.h:38
static uint16_t LimitCurrent(uint16_t value)
Definition: NeoTm1814Features.h:40
Definition: NeoTm1814Features.h:101