GCC Code Coverage Report


Directory: ./
File: channeloutput/PixelString.cpp
Date: 2026-12-01 12:27:28
Exec Total Coverage
Lines: 459 572 80.2%
Functions: 28 31 90.3%
Branches: 377 822 45.9%

Line Branch Exec Source
1 /*
2 * This file is part of the Falcon Player (FPP) and is Copyright (C)
3 * 2013-2022 by the Falcon Player Developers.
4 *
5 * The Falcon Player (FPP) is free software, and is covered under
6 * multiple Open Source licenses. Please see the included 'LICENSES'
7 * file for descriptions of what files are covered by each license.
8 *
9 * This source file is covered under the LGPL v2.1 as described in the
10 * included LICENSE.LGPL file.
11 */
12
13 #include "fpp-pch.h"
14
15 #include "fpp-json.h"
16
17 // not in fpp-pch.h; libc++ pulls them in transitively but libstdc++ does not
18 #include <cmath>
19 #include <memory>
20 #include <tuple>
21
22 #include "../Sequence.h"
23 #include "../log.h"
24
25 #include "PixelString.h"
26 #include "ChannelOutputSetup.h"
27 #include "../OutputMonitor.h"
28 #include "../Warnings.h"
29 #include "overlays/PixelOverlay.h"
30
31 /////////////////////////////////////////////////////////////////////////////
32
33 #define MAX_PIXEL_STRING_LENGTH 1600
34
35 constexpr uint32_t SMART_RECEIVER_LEADIN = 6 * 3;
36 constexpr uint32_t SMART_RECEIVER_LEN = 6 * 3;
37 constexpr uint32_t SMART_RECEIVER_LEADOUT = 6 * 3;
38
39 constexpr uint32_t SMART_RECEIVER_V2_GAP = 10;
40
41 #define CHECKPS_SETTING(SETTING) \
42 if (SETTING) { \
43 LogErr(VB_CHANNELOUT, "Invalid PixelString Config %s\n", #SETTING); \
44 AddOutputConfigWarning(26, "Invalid PixelString Config: " + std::string(#SETTING)); \
45 return 0; \
46 }
47
48 // one config key per receiver; the hasChannels array in Init() is sized to
49 // match, so nothing may index either of them past this
50 constexpr int MAX_SMART_RECEIVERS = 6;
51
52 const char* SMART_RECEIVER_LABELS[MAX_SMART_RECEIVERS] = {
53 "virtualStrings",
54 "virtualStringsB",
55 "virtualStringsC",
56 "virtualStringsD",
57 "virtualStringsE",
58 "virtualStringsF",
59 };
60
61 852 VirtualString::VirtualString() :
62 852 receiverNum(-1),
63 852 startChannel(0),
64 852 pixelCount(0),
65 852 groupCount(0),
66 852 reverse(0),
67 852 colorOrder(FPPColorOrder::kColorOrderRGB),
68 852 startNulls(0),
69 852 endNulls(0),
70 852 zigZag(0),
71 852 brightness(100),
72 852 gamma(1.0),
73 852 leadInCount(0),
74 852 toggleCount(0),
75 852 leadOutCount(0) {
76 // never leave this dangling - ReadVirtualString normally replaces it, but
77 // a default constructed string is used directly for empty ports
78
1/2
✓ Branch 0 taken 852 times.
✗ Branch 1 not taken.
852 brightnessMap = BrightnessLUTCache::get(100, 1.0f, false);
79 852 }
80
81 4 VirtualString::VirtualString(int rt, int rn) :
82 4 receiverNum(rn),
83 4 startChannel(0),
84 4 pixelCount(0),
85 4 groupCount(0),
86 4 reverse(0),
87 4 colorOrder(FPPColorOrder::kColorOrderRGB),
88 4 startNulls(0),
89 4 endNulls(0),
90 4 zigZag(0),
91 4 brightness(100),
92 4 gamma(1.0),
93 4 leadInCount(0),
94 4 toggleCount(0),
95 4 leadOutCount(0) {
96
1/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
4 switch (rt) {
97 ✗ case 0:
98 ✗ leadInCount = 0;
99 ✗ toggleCount = SMART_RECEIVER_LEN;
100 ✗ leadOutCount = SMART_RECEIVER_LEADOUT;
101 ✗ break;
102 ✗ case 1:
103 ✗ leadInCount = SMART_RECEIVER_LEADIN;
104 ✗ toggleCount = SMART_RECEIVER_LEN * 2;
105 ✗ leadOutCount = SMART_RECEIVER_LEADOUT;
106 ✗ break;
107 ✗ case 2:
108 ✗ leadInCount = SMART_RECEIVER_LEADIN;
109 ✗ toggleCount = SMART_RECEIVER_LEN * 3;
110 ✗ leadOutCount = SMART_RECEIVER_LEADOUT;
111 ✗ break;
112 4 case 3:
113 4 leadInCount = SMART_RECEIVER_V2_GAP;
114 4 toggleCount = 0;
115 4 leadOutCount = 0;
116 4 break;
117 ✗ case 4: // Falcon v5
118 ✗ leadInCount = 0;
119 ✗ toggleCount = 0;
120 ✗ leadOutCount = 0;
121 ✗ break;
122 }
123 4 pixelCount = leadInCount + toggleCount + leadOutCount;
124 // identity: full brightness, no gamma
125
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 brightnessMap = BrightnessLUTCache::get(100, 1.0f, false);
126 4 }
127 namespace {
128 struct LUTKey {
129 int brightness;
130 int gammaScaled;
131 bool inverted;
132 3007 bool operator<(const LUTKey& o) const {
133
1/2
✓ Branch 0 taken 3007 times.
✗ Branch 1 not taken.
5641 return std::tie(brightness, gammaScaled, inverted) <
134 6014 std::tie(o.brightness, o.gammaScaled, o.inverted);
135 }
136 };
137 std::map<LUTKey, std::unique_ptr<std::array<uint8_t, 256>>> g_luts;
138 std::map<LUTKey, std::unique_ptr<std::array<uint16_t, 256>>> g_wideLuts;
139 std::mutex g_lutLock;
140
141 // gamma is quantised so it can key the cache; build from the quantised value
142 // so two strings sharing a key get byte-identical tables whichever is built
143 // first. 1/10000 is past any configurable gamma - 2.2f round trips exactly.
144 1671 int scaleGamma(float gamma) {
145 1671 return (int)std::lround(gamma * 10000.0f);
146 }
147 } // namespace
148
149 1671 const uint8_t* BrightnessLUTCache::get(int brightness, float gamma, bool inverted) {
150 // Quantise gamma so it can key the cache, then build from the quantised
151 // value rather than the caller's: two strings that share a key must get
152 // byte-identical tables whichever of them is built first. 1/10000 is fine
153 // past any gamma anyone configures - 2.2f round trips exactly.
154 1671 int gammaScaled = scaleGamma(gamma);
155 1671 LUTKey key{ brightness, gammaScaled, inverted };
156
157
1/2
✓ Branch 0 taken 1671 times.
✗ Branch 1 not taken.
1671 std::lock_guard<std::mutex> lock(g_lutLock);
158
1/2
✓ Branch 0 taken 1671 times.
✗ Branch 1 not taken.
1671 auto it = g_luts.find(key);
159
2/2
✓ Branch 0 taken 1497 times.
✓ Branch 1 taken 174 times.
1671 if (it != g_luts.end()) {
160 2994 return it->second->data();
161 }
162
163
1/2
✓ Branch 0 taken 174 times.
✗ Branch 1 not taken.
174 auto table = std::make_unique<std::array<uint8_t, 256>>();
164 // identical to the original per-string computation, so the tables are
165 // byte for byte what they always were (at 100/1.0 that is the identity
166 // map, which is what the smart receiver markers want)
167 174 float maxB = brightness * 2.55f;
168 174 float g = gammaScaled / 10000.0f;
169
2/2
✓ Branch 0 taken 44544 times.
✓ Branch 1 taken 174 times.
44718 for (int x = 0; x < 256; x++) {
170 44544 float f = maxB * pow((float)x / 255.0f, g);
171
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44544 times.
44544 if (f > 255.0) {
172 ✗ f = 255.0;
173 }
174
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44544 times.
44544 if (f < 0.0) {
175 ✗ f = 0.0;
176 }
177 44544 uint8_t v = (uint8_t)round(f);
178
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 44032 times.
44544 (*table)[x] = inverted ? (uint8_t)~v : v;
179 }
180 174 const uint8_t* p = table->data();
181
1/2
✓ Branch 0 taken 174 times.
✗ Branch 1 not taken.
174 g_luts[key] = std::move(table);
182 174 return p;
183 1671 }
184
185 ✗ const uint16_t* BrightnessLUTCache::getWide(int brightness, float gamma, bool inverted) {
186 ✗ int gammaScaled = scaleGamma(gamma);
187 ✗ LUTKey key{ brightness, gammaScaled, inverted };
188
189 ✗ std::lock_guard<std::mutex> lock(g_lutLock);
190 ✗ auto it = g_wideLuts.find(key);
191 ✗ if (it != g_wideLuts.end()) {
192 ✗ return it->second->data();
193 }
194
195 ✗ auto table = std::make_unique<std::array<uint16_t, 256>>();
196 // the same curve as the 8 bit table, evaluated to full 16 bit range
197 ✗ float maxB = brightness * 655.35f;
198 ✗ float g = gammaScaled / 10000.0f;
199 ✗ for (int x = 0; x < 256; x++) {
200 ✗ float f = maxB * pow((float)x / 255.0f, g);
201 ✗ if (f > 65535.0) {
202 ✗ f = 65535.0;
203 }
204 ✗ if (f < 0.0) {
205 ✗ f = 0.0;
206 }
207 ✗ uint16_t v = (uint16_t)llround(f);
208 ✗ (*table)[x] = inverted ? (uint16_t)~v : v;
209 }
210 ✗ const uint16_t* p = table->data();
211 ✗ g_wideLuts[key] = std::move(table);
212 ✗ return p;
213 ✗ }
214
215 ✗ size_t BrightnessLUTCache::tableCount() {
216 ✗ std::lock_guard<std::mutex> lock(g_lutLock);
217 ✗ return g_luts.size() + g_wideLuts.size();
218 ✗ }
219
220 4 bool VirtualString::isSmartReceiver() const {
221 4 return receiverNum >= 0;
222 }
223 155 bool VirtualString::isFalconV5SmartReceiver() const {
224
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 155 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
155 return receiverNum >= 0 && leadInCount == 0 && toggleCount == 0 && leadOutCount == 0;
225 }
226
227 304982 int VirtualString::channelsPerNode() const {
228
2/2
✓ Branch 0 taken 220 times.
✓ Branch 1 taken 304762 times.
304982 if (receiverNum >= 0) {
229 220 return 1;
230 }
231 304762 return colorOrder.channelCount();
232 }
233
234 513 int VirtualString::channelCount() const {
235 513 return (startNulls + pixelCount + endNulls) * channelsPerNode();
236 }
237
238 /*
239 *
240 */
241 807 PixelString::PixelString(bool supportSmart) :
242 807 m_portNumber(0),
243 807 m_channelOffset(0),
244 807 m_outputBytes(0),
245 807 m_isSmartReceiver(supportSmart),
246 807 m_brightnessMaps(nullptr),
247
1/2
✓ Branch 0 taken 807 times.
✗ Branch 1 not taken.
807 m_outputBuffer(nullptr) {
248 807 }
249
250 /*
251 *
252 */
253 807 PixelString::~PixelString() {
254
2/2
✓ Branch 0 taken 720 times.
✓ Branch 1 taken 87 times.
807 if (!m_pinConfig.empty()) {
255 720 OutputMonitor::INSTANCE.RemovePortConfiguration(m_portNumber, m_pinConfig);
256 }
257
2/2
✓ Branch 0 taken 805 times.
✓ Branch 1 taken 2 times.
807 if (m_brightnessMaps) {
258 805 free(m_brightnessMaps);
259 }
260
2/2
✓ Branch 0 taken 805 times.
✓ Branch 1 taken 2 times.
807 if (m_outputBuffer) {
261 805 free(m_outputBuffer);
262 }
263 807 }
264
265 /*
266 *
267 */
268 807 int PixelString::Init(Json::Value config, Json::Value* pinConfig) {
269
2/4
✓ Branch 0 taken 807 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 807 times.
✗ Branch 3 not taken.
807 m_portNumber = config["portNumber"].asInt();
270 // Drivers index per-port arrays (smart receiver packets, GPIO commands,
271 // current monitoring) by this, unchecked.
272
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 806 times.
807 if (m_portNumber < 0) {
273
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 LogErr(VB_CHANNELOUT, "Pixel string has an invalid port number %d\n", m_portNumber);
274 1 return 0;
275 }
276 806 m_outputBytes = 0;
277 // needed before the virtual strings are read so their lookup tables are
278 // built at the right width
279
3/6
✓ Branch 0 taken 806 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 806 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 806 times.
✗ Branch 5 not taken.
806 m_bytesPerChannel = protocolBytesPerChannel(config["protocol"].asString());
280
281 806 int receiverCount = 1;
282
7/8
✓ Branch 0 taken 741 times.
✓ Branch 1 taken 65 times.
✓ Branch 2 taken 741 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 645 times.
✓ Branch 5 taken 96 times.
✓ Branch 6 taken 645 times.
✓ Branch 7 taken 161 times.
806 if (m_isSmartReceiver && config.isMember("differentialType")) {
283 645 smartReceiverType = ReceiverType::Standard;
284
2/4
✓ Branch 0 taken 645 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 645 times.
✗ Branch 3 not taken.
645 int rt = config["differentialType"].asInt();
285
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 594 times.
645 if (rt) {
286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if (rt <= 3) {
287 // v1 smart receivers
288 ✗ receiverCount = rt;
289 ✗ smartReceiverType = ReceiverType::v1;
290
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 42 times.
51 } else if (rt > 15) {
291 // Falcon V4 smart receivers (send-only config packet)
292 9 receiverCount = rt - 15;
293 9 smartReceiverType = ReceiverType::FalconV4;
294
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 7 times.
42 } else if (rt > 9) {
295 // Falcon V5 smart receivers (bidirectional)
296 35 receiverCount = rt - 9;
297 35 smartReceiverType = ReceiverType::FalconV5;
298 } else {
299 // v2 smart receivers
300 7 receiverCount = rt - 3;
301 7 smartReceiverType = ReceiverType::v2;
302 }
303
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if (receiverCount > MAX_SMART_RECEIVERS) {
304 // only the Falcon v4 range is open ended (rt - 15), so a hand
305 // edited differentialType is the only way to get here
306 ✗ LogWarn(VB_CHANNELOUT, "Invalid smart receiver count %d on port %d; using %d\n",
307 receiverCount, m_portNumber + 1, MAX_SMART_RECEIVERS);
308 ✗ AddOutputConfigWarning(UNKNOWN_WARNING_ID, "PixelString: invalid smart receiver count on port " +
309 ✗ std::to_string(m_portNumber + 1) + ", using " +
310 ✗ std::to_string(MAX_SMART_RECEIVERS));
311 ✗ receiverCount = MAX_SMART_RECEIVERS;
312 }
313 }
314 645 m_isSmartReceiver = smartReceiverType != ReceiverType::Standard;
315
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 645 times.
645 if (m_bytesPerChannel != 1 &&
316 ✗ (smartReceiverType == ReceiverType::v1 || smartReceiverType == ReceiverType::v2)) {
317 // v1/v2 receivers interleave fixed width marker patterns with the
318 // pixel data, so a wide part would need two widths in one stream.
319 // Falcon v4/v5 markers are zero length, so those are fine.
320 ✗ LogWarn(VB_CHANNELOUT, "16 bit protocols are not supported with v1/v2 smart receivers on port %d; using 8 bit\n", m_portNumber + 1);
321 ✗ AddOutputConfigWarning(UNKNOWN_WARNING_ID, "PixelString: 16 bit protocol not supported with v1/v2 smart receivers on port " + std::to_string(m_portNumber + 1));
322 ✗ m_bytesPerChannel = 1;
323 }
324 } else {
325 161 smartReceiverType = ReceiverType::None;
326 161 m_isSmartReceiver = false;
327 }
328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 806 times.
806 if (smartReceiverType == ReceiverType::v1) {
329 // v1 needs a lead in
330 ✗ AddVirtualString(VirtualString(0, 0));
331 }
332 806 int startMaxChan = m_outputBytes;
333
4/6
✓ Branch 0 taken 1616 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1616 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 811 times.
✓ Branch 5 taken 805 times.
1616 for (int i = 0; i < config["virtualStrings"].size(); i++) {
334
3/6
✓ Branch 0 taken 811 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 811 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 811 times.
✗ Branch 5 not taken.
811 Json::Value vsc = config["virtualStrings"][i];
335
1/2
✓ Branch 0 taken 811 times.
✗ Branch 1 not taken.
811 VirtualString vs;
336
3/4
✓ Branch 0 taken 811 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 810 times.
811 if (!ReadVirtualString(vsc, vs)) {
337 1 return 0;
338 }
339
1/2
✓ Branch 0 taken 810 times.
✗ Branch 1 not taken.
810 AddVirtualString(vs);
340
4/4
✓ Branch 0 taken 810 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 810 times.
✓ Branch 3 taken 1 times.
812 }
341 std::array<bool, MAX_SMART_RECEIVERS> hasChannels;
342 805 hasChannels[0] = startMaxChan != m_outputBytes;
343
5/8
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 768 times.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 37 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 805 times.
805 if (!hasChannels[0] && (smartReceiverType == ReceiverType::v1 || smartReceiverType == ReceiverType::v2)) {
344 // we need to output at least 1 pixel
345 ✗ AddNullPixelString();
346 }
347
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 805 times.
809 for (int p = 1; p < receiverCount; p++) {
348 4 int sz = m_virtualStrings.size();
349 4 int mc = m_outputBytes;
350
351
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (smartReceiverType == ReceiverType::v1) {
352 // v1 smart receiver
353 ✗ AddVirtualString(VirtualString(p, p));
354
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 } else if (smartReceiverType == ReceiverType::v2) {
355 // v2 smart receiver, .15ms gap
356
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 AddVirtualString(VirtualString(3, p));
357 ✗ } else if (smartReceiverType == ReceiverType::FalconV5 || smartReceiverType == ReceiverType::FalconV4) {
358 // Falcon v4/v5, just marker to determine config packets later
359 ✗ AddVirtualString(VirtualString(4, p));
360 }
361 4 startMaxChan = m_outputBytes;
362
4/6
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 4 times.
7 for (int i = 0; i < config[SMART_RECEIVER_LABELS[p]].size(); i++) {
363
3/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 Json::Value vsc = config[SMART_RECEIVER_LABELS[p]][i];
364
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 VirtualString vs;
365
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 if (!ReadVirtualString(vsc, vs)) {
366 ✗ return 0;
367 }
368
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 AddVirtualString(vs);
369
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 }
370 4 hasChannels[p] = startMaxChan != m_outputBytes;
371 4 hasChannels[0] |= hasChannels[p];
372
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 if (!hasChannels[p]) {
373
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (p != (receiverCount - 1)) {
374 // we need to output at least 1 pixel
375
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 AddNullPixelString();
376 } else {
377 // in this case, we can revert and just send one less receivers of data
378 ✗ m_outputBytes = mc;
379 ✗ while (sz != m_virtualStrings.size()) {
380 ✗ m_virtualStrings.pop_back();
381 }
382 }
383 }
384 }
385
386
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 768 times.
805 if (!hasChannels[0]) {
387 // empty, no strings
388 37 m_outputBytes = 0;
389 37 m_virtualStrings.clear();
390
2/4
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
37 AddVirtualString(VirtualString());
391 }
392
2/2
✓ Branch 0 taken 722 times.
✓ Branch 1 taken 83 times.
805 if (pinConfig) {
393
1/2
✓ Branch 0 taken 722 times.
✗ Branch 1 not taken.
722 m_pinConfig = *pinConfig;
394
1/2
✓ Branch 0 taken 722 times.
✗ Branch 1 not taken.
722 OutputMonitor::INSTANCE.AddPortConfiguration(m_portNumber, m_pinConfig, m_outputBytes > 0);
395 }
396
397
1/2
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
805 m_outputMap.resize(m_outputBytes);
398
399 // Initialize all maps to an unused location which should be zero.
400 // We need this so that null nodes in the middle of a string are sent
401 // all zeroes to keep them dark.
402
2/2
✓ Branch 0 taken 66597 times.
✓ Branch 1 taken 805 times.
67402 for (int i = 0; i < m_outputBytes; i++) {
403 66597 m_outputMap[i] = FPPD_OFF_CHANNEL;
404 }
405
406 805 int offset = 0;
407 805 int mapIndex = 0;
408
409 805 m_brightnessMaps = (const uint8_t**)calloc(1, sizeof(const uint8_t*) * m_outputBytes);
410
411
2/2
✓ Branch 0 taken 818 times.
✓ Branch 1 taken 805 times.
1623 for (int i = 0; i < m_virtualStrings.size(); i++) {
412 818 m_virtualStrings[i].chMap = &m_outputMap[offset];
413 818 int start = offset;
414
1/2
✓ Branch 0 taken 818 times.
✗ Branch 1 not taken.
818 offset += m_virtualStrings[i].startNulls * m_virtualStrings[i].channelsPerNode();
415
1/2
✓ Branch 0 taken 818 times.
✗ Branch 1 not taken.
818 SetupMap(offset, m_virtualStrings[i]);
416
1/2
✓ Branch 0 taken 818 times.
✗ Branch 1 not taken.
818 offset += m_virtualStrings[i].pixelCount * m_virtualStrings[i].channelsPerNode();
417
1/2
✓ Branch 0 taken 818 times.
✗ Branch 1 not taken.
818 offset += m_virtualStrings[i].endNulls * m_virtualStrings[i].channelsPerNode();
418 818 m_virtualStrings[i].chMapCount = offset - start;
419
5/8
✓ Branch 0 taken 67415 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 67415 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 67415 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 66597 times.
✓ Branch 7 taken 818 times.
67415 for (int j = 0; j < ((m_virtualStrings[i].startNulls * m_virtualStrings[i].channelsPerNode()) + (m_virtualStrings[i].pixelCount * m_virtualStrings[i].channelsPerNode()) + (m_virtualStrings[i].endNulls * m_virtualStrings[i].channelsPerNode())); j++)
420 66597 m_brightnessMaps[mapIndex++] = m_virtualStrings[i].brightnessMap;
421 }
422 // A 16 bit part clocks two bytes per colour channel. The channel maps
423 // above are per channel and stay as they are - only the wire length grows.
424 // Marker strings from a smart receiver are raw wire bytes and do not
425 // widen, but the only receivers allowed here (Falcon v4/v5) have zero
426 // length markers, so this is a straight doubling.
427
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 805 times.
805 if (m_bytesPerChannel != 1) {
428 ✗ m_outputBytes *= m_bytesPerChannel;
429 }
430
431 // Protocol preamble, if any. It has to land after the channel maps are
432 // built (those are sized for the pixel bytes only) and before the gpio off
433 // command below, which needs the full wire length.
434
11/16
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 37 times.
✓ Branch 2 taken 768 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 768 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 768 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 766 times.
✓ Branch 10 taken 768 times.
✓ Branch 11 taken 37 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 803 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
805 if (m_outputBytes && protocolNeedsTM1814Preamble(config["protocol"].asString())) {
435 // per channel drive current; the part powers up at its 6.5mA floor, so
436 // without this a TM1814 string just looks dim
437
2/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2 float mA = config.isMember("tm1814MilliAmps") ? config["tm1814MilliAmps"].asFloat() : 38.0f;
438
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 m_preamble = buildTM1814Preamble(mA);
439 2 m_outputBytes += m_preamble.size();
440 }
441
442 // turn gpio off after all channels on this port are done
443
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 37 times.
805 if (m_outputBytes) {
444
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 m_gpioCommands.push_back(GPIOCommand(m_portNumber, m_outputBytes));
445 }
446
447 // certain testing capabilities (like pixel counting) may require a
448 // buffer larger than the number of pixels configured
449 805 int obs = std::max(2400, m_outputBytes);
450 805 m_outputBuffer = (uint8_t*)calloc(obs, 1);
451
452 // Cape declared inversion corrects a wiring defect; protocol inversion is
453 // the pixel type asking for it. Both flip the same line, so they compose
454 // by xor and cancel when a TM18xx string lands on a backwards-wired port.
455
3/6
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 805 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 805 times.
✗ Branch 5 not taken.
805 m_protocolInverted = isInvertedProtocol(config["protocol"].asString());
456 // isMember first: pinConfig points into the cape config and a bare
457 // operator[] would insert a null member into it
458
4/12
✓ Branch 0 taken 722 times.
✓ Branch 1 taken 83 times.
✓ Branch 2 taken 722 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 722 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
805 bool wireInverted = pinConfig && pinConfig->isMember("inverted") && (*pinConfig)["inverted"].asBool();
459
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 803 times.
805 if (m_protocolInverted != wireInverted) {
460
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 invertOutput();
461 }
462
463 // after any inversion, so the bytes copied in are the wire form
464
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 803 times.
805 if (!m_preamble.empty()) {
465 2 memcpy(m_outputBuffer, m_preamble.data(), m_preamble.size());
466 }
467
468 805 return 1;
469 }
470
471 // TM1814 frames are "C1 C2 D1..Dn Reset". C1 carries four 6 bit constant
472 // current levels in the chip's physical W,R,G,B pin order with the top two
473 // bits of each byte fixed at 0; C2 is the bitwise complement of C1 and the
474 // chip will not decode the frame without it. Every chip in the chain reads
475 // and forwards both, so this is once per frame, not once per pixel.
476 2 std::vector<uint8_t> PixelString::buildTM1814Preamble(float milliAmps) {
477 // 64 levels spanning 6.5mA (all zero) to 38mA (all ones)
478 2 constexpr float MIN_MA = 6.5f;
479 2 constexpr float MAX_MA = 38.0f;
480
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 milliAmps = std::clamp(milliAmps, MIN_MA, MAX_MA);
481 2 uint8_t level = (uint8_t)std::lround((milliAmps - MIN_MA) * 63.0f / (MAX_MA - MIN_MA)) & 0x3F;
482
483
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 std::vector<uint8_t> p(8);
484 // C1: W, R, G, B - all four channels get the same level. This is the
485 // chip's pin order and is independent of the string's color order, which
486 // only decides how channel data lands in the W/R/G/B slots of Dn.
487
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
10 for (int i = 0; i < 4; i++) {
488 8 p[i] = level;
489 8 p[i + 4] = ~level;
490 }
491 2 return p;
492 }
493
494 // Per protocol bit cell. Anything not listed is the 800kHz ws281x family,
495 // which is the overwhelming majority and what the timing has always been.
496 //
497 // The listed ones are genuinely different parts, not aliases: driving them
498 // with the ws281x cell does not merely shift an edge, it puts the pulse
499 // outside the window the part decodes. That is why they were kept out of the
500 // protocol dropdown until the firmware could take its timing at runtime.
501 398 PixelString::Timing PixelString::protocolTiming(const std::string& protocol) {
502 // the ws281x family - see the alias list in co-pixelStrings.php
503 static const Timing ws281x{ 320, 750, 1120 };
504
505 // 400kHz parts: a 2.5us cell, twice the ws281x period
506
6/8
✓ Branch 0 taken 380 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 380 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 380 times.
✓ Branch 6 taken 18 times.
✓ Branch 7 taken 380 times.
398 if (protocol == "ucs1903" || protocol == "ws2811slow" || protocol == "ws2811 slow") {
507 18 return { 500, 2000, 2500 };
508 }
509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 380 times.
380 if (protocol == "tm1803") {
510 ✗ return { 750, 1875, 2625 };
511 }
512
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 380 times.
380 if (protocol == "gw6205") {
513 ✗ return { 750, 1625, 2375 };
514 }
515 // longer cell parts, between the two
516
3/6
✓ Branch 0 taken 380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 380 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 380 times.
380 if (protocol == "tm1804" || protocol == "tm1809slow") {
517 ✗ return { 500, 1000, 1500 };
518 }
519
3/6
✓ Branch 0 taken 380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 380 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 380 times.
380 if (protocol == "sk6822" || protocol == "pl9823") {
520 ✗ return { 375, 1375, 1750 };
521 }
522
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 380 times.
380 if (protocol == "ucs1912") {
523 ✗ return { 250, 1250, 1625 };
524 }
525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 380 times.
380 if (protocol == "ge8822") {
526 ✗ return { 375, 1000, 1375 };
527 }
528 380 return ws281x;
529 }
530
531 806 int PixelString::protocolBytesPerChannel(const std::string& protocol) {
532 // single wire 16 bit parts; bit depths follow the pixel table in xLights
533 // (src-core/models/Pixels.cpp). The bare name is the 16 bit part itself,
534 // and the explicit "16 bit"/"(16)" spellings some controllers use mean the
535 // same thing here.
536
2/4
✓ Branch 0 taken 806 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 806 times.
✗ Branch 3 not taken.
1612 if (protocol == "ucs8903" || protocol == "ucs8904" || protocol == "ucs7604" ||
537
4/8
✓ Branch 0 taken 806 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 806 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 806 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 806 times.
2418 protocol == "ucs8903 16 bit" || protocol == "ucs8904 16 bit" ||
538
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 806 times.
806 protocol == "ucs7604 16 bit") {
539 ✗ return 2;
540 }
541 806 return 1;
542 }
543
544 768 bool PixelString::protocolNeedsTM1814Preamble(const std::string& protocol) {
545
3/4
✓ Branch 0 taken 766 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 766 times.
768 return protocol == "tm1814" || protocol == "tm1814a";
546 }
547
548 512 void PixelString::setPixelDataChannels(int channels) {
549 // a port clamped to nothing sends nothing, preamble included - the same
550 // rule Init uses when deciding to build one at all
551
2/2
✓ Branch 0 taken 476 times.
✓ Branch 1 taken 36 times.
512 m_outputBytes = channels ? channels * m_bytesPerChannel + (int)m_preamble.size() : 0;
552 512 }
553
554 ✗ void PixelString::dropPreamble() {
555 ✗ if (m_preamble.empty()) {
556 ✗ return;
557 }
558 ✗ int n = (int)m_preamble.size();
559 ✗ m_outputBytes -= n;
560 // the preamble shifted the whole stream, so every command past it moves back
561 ✗ for (auto& c : m_gpioCommands) {
562 ✗ if (c.channelOffset >= n) {
563 ✗ c.channelOffset -= n;
564 }
565 }
566 ✗ m_preamble.clear();
567 ✗ memset(m_outputBuffer, 0, n);
568 }
569
570 805 bool PixelString::isInvertedProtocol(const std::string& protocol) {
571 // Only the protocols FPP can actually drive today. The TM18xx bit cell
572 // is close enough to ws2811 that the shared timing covers it; what makes
573 // them different is the idle level.
574
3/4
✓ Branch 0 taken 803 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 803 times.
805 return protocol == "tm1814" || protocol == "tm1814a";
575 }
576
577 855 void PixelString::AddVirtualString(const VirtualString& vs) {
578 855 m_outputBytes += vs.startNulls * vs.channelsPerNode();
579 855 m_outputBytes += vs.pixelCount * vs.channelsPerNode();
580 855 m_outputBytes += vs.endNulls * vs.channelsPerNode();
581
582 855 m_virtualStrings.push_back(vs);
583 855 }
584
585 814 int PixelString::ReadVirtualString(Json::Value& vsc, VirtualString& vs) const {
586 814 vs.startChannel = vsc["startChannel"].asInt();
587 814 vs.pixelCount = vsc["pixelCount"].asInt();
588 814 vs.groupCount = vsc["groupCount"].asInt();
589 814 vs.reverse = vsc["reverse"].asInt();
590 814 vs.startNulls = vsc["nullNodes"].asInt();
591
1/2
✓ Branch 0 taken 814 times.
✗ Branch 1 not taken.
814 if (vsc.isMember("description")) {
592
2/4
✓ Branch 0 taken 814 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 814 times.
✗ Branch 3 not taken.
814 vs.description = vsc["description"].asString();
593 }
594
1/2
✓ Branch 0 taken 814 times.
✗ Branch 1 not taken.
814 if (vsc.isMember("endNulls")) {
595 814 vs.endNulls = vsc["endNulls"].asInt();
596 } else {
597 ✗ vs.endNulls = 0;
598 }
599 814 vs.zigZag = vsc["zigZag"].asInt();
600 814 vs.brightness = vsc["brightness"].asInt();
601
2/4
✓ Branch 0 taken 814 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 814 times.
✗ Branch 3 not taken.
814 vs.gamma = atof(vsc["gamma"].asString().c_str());
602
603
2/4
✓ Branch 0 taken 814 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 814 times.
814 if (vs.brightness > 100 || vs.brightness < 0) {
604 ✗ vs.brightness = 100;
605 }
606
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 812 times.
814 if (!std::isfinite(vs.gamma)) {
607 // "nan" or "inf" in a hand-edited config: not a gamma anyone chose,
608 // so use the default rather than clamping it to an end of the range
609 // (NaN fails both clamps below and landed on 0.01, a curve that
610 // drives every lit channel near full brightness)
611 2 vs.gamma = 1.0f;
612 }
613
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 814 times.
814 if (vs.gamma < 0.01f) {
614 ✗ vs.gamma = 0.01f;
615 }
616
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 814 times.
814 if (vs.gamma > 50.0f) {
617 ✗ vs.gamma = 50.0f;
618 }
619
620
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 814 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
814 CHECKPS_SETTING(vs.pixelCount < 0);
621
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 814 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
814 CHECKPS_SETTING(vs.pixelCount > MAX_PIXEL_STRING_LENGTH);
622
2/2
✓ Branch 0 taken 777 times.
✓ Branch 1 taken 37 times.
814 if (vs.pixelCount) {
623 // only validate settings and such if there are pixels on this string
624
1/10
✗ Branch 0 not taken.
✓ Branch 1 taken 777 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
778 CHECKPS_SETTING(vs.startChannel < 0);
625
1/10
✗ Branch 0 not taken.
✓ Branch 1 taken 777 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
777 CHECKPS_SETTING(vs.startChannel > FPPD_MAX_CHANNELS);
626
1/10
✗ Branch 0 not taken.
✓ Branch 1 taken 777 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
777 CHECKPS_SETTING(vs.startNulls < 0);
627
1/10
✗ Branch 0 not taken.
✓ Branch 1 taken 777 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
777 CHECKPS_SETTING(vs.startNulls > MAX_PIXEL_STRING_LENGTH);
628
1/10
✗ Branch 0 not taken.
✓ Branch 1 taken 777 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
777 CHECKPS_SETTING(vs.endNulls < 0);
629
1/10
✗ Branch 0 not taken.
✓ Branch 1 taken 777 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
777 CHECKPS_SETTING(vs.endNulls > MAX_PIXEL_STRING_LENGTH);
630
1/10
✗ Branch 0 not taken.
✓ Branch 1 taken 777 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
777 CHECKPS_SETTING((vs.startNulls + vs.pixelCount + vs.endNulls) > MAX_PIXEL_STRING_LENGTH);
631
1/10
✗ Branch 0 not taken.
✓ Branch 1 taken 777 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
777 CHECKPS_SETTING(vs.reverse < 0);
632
1/10
✗ Branch 0 not taken.
✓ Branch 1 taken 777 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
777 CHECKPS_SETTING(vs.reverse > 1);
633
1/10
✗ Branch 0 not taken.
✓ Branch 1 taken 777 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
777 CHECKPS_SETTING(vs.groupCount < 0);
634
1/10
✗ Branch 0 not taken.
✓ Branch 1 taken 777 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
777 CHECKPS_SETTING(vs.groupCount > vs.pixelCount);
635
1/10
✗ Branch 0 not taken.
✓ Branch 1 taken 777 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
777 CHECKPS_SETTING(vs.zigZag > vs.pixelCount);
636
1/10
✗ Branch 0 not taken.
✓ Branch 1 taken 777 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
777 CHECKPS_SETTING(vs.zigZag < 0);
637
638
2/4
✓ Branch 0 taken 777 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 777 times.
✗ Branch 3 not taken.
777 std::string colorOrder = vsc["colorOrder"].asString();
639
1/2
✓ Branch 0 taken 777 times.
✗ Branch 1 not taken.
777 vs.colorOrder = ColorOrderFromString(colorOrder);
640
641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 777 times.
777 if (vs.groupCount == 1)
642 ✗ vs.groupCount = 0;
643
644 // The start is checked above, but not where the string ends:
645 // prepareOutput() reads up to the last node's channels, and the drivers
646 // drop channels at or past FPPD_MAX_CHANNELS from the range they
647 // report, so the loader's range check never saw the overrun.
648
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 776 times.
777 int64_t vsNodes = vs.groupCount ? (vs.pixelCount + vs.groupCount - 1) / vs.groupCount : vs.pixelCount;
649
1/2
✓ Branch 0 taken 777 times.
✗ Branch 1 not taken.
777 int64_t vsEnd = (int64_t)vs.startChannel + vsNodes * vs.channelsPerNode();
650
6/10
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 776 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
779 CHECKPS_SETTING(vsEnd > FPPD_MAX_CHANNELS);
651
652
2/4
✓ Branch 0 taken 776 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 776 times.
776 if ((vs.zigZag == vs.pixelCount) || (vs.zigZag == 1))
653 ✗ vs.zigZag = 0;
654
655
1/2
✓ Branch 0 taken 776 times.
✗ Branch 1 not taken.
776 vs.brightnessMap = BrightnessLUTCache::get(vs.brightness, vs.gamma, false);
656
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 776 times.
776 if (m_bytesPerChannel == 2) {
657 ✗ vs.brightnessMap16 = BrightnessLUTCache::getWide(vs.brightness, vs.gamma, false);
658 }
659
2/2
✓ Branch 0 taken 776 times.
✓ Branch 1 taken 1 times.
777 } else {
660
2/4
✓ Branch 0 taken 37 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
37 vs.colorOrder = ColorOrderFromString("RGB");
661 37 vs.groupCount = 1;
662 37 vs.zigZag = 0;
663 37 vs.reverse = 0;
664 37 vs.startNulls = 0;
665 37 vs.endNulls = 0;
666 37 vs.startChannel = 0;
667 37 vs.brightnessMap = BrightnessLUTCache::get(100, 1.0f, false);
668 }
669
670 813 return 1;
671 }
672 1 void PixelString::AddNullPixelString() {
673
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 VirtualString vs;
674 1 vs.pixelCount = 1;
675 1 vs.startChannel = FPPD_OFF_CHANNEL;
676
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 AddVirtualString(vs);
677 1 }
678
679 818 void PixelString::SetupMap(int vsOffset, const VirtualString& vs) {
680
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 814 times.
818 if (vs.receiverNum >= 0) {
681 // smart receiever, add codes to outputs
682 // drop low to trigger receiver to start trying to figure out which data is next
683
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (vs.leadInCount > 0) {
684
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 m_gpioCommands.push_back(GPIOCommand(m_portNumber, vsOffset));
685
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 4 times.
44 for (int x = 0; x < vs.channelsPerNode() * vs.leadInCount; x++) {
686 40 m_outputMap[vsOffset++] = FPPD_OFF_CHANNEL;
687 }
688 // Turn back on
689
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 m_gpioCommands.push_back(GPIOCommand(m_portNumber, vsOffset, 1));
690 }
691
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (vs.toggleCount) {
692 // Toggle a bunch back and forth
693 ✗ for (int x = 0; x < vs.channelsPerNode() * vs.toggleCount; x++) {
694 // using white allows an even up/down on the GPIO
695 ✗ m_outputMap[vsOffset++] = FPPD_WHITE_CHANNEL;
696 }
697 }
698
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (vs.leadOutCount) {
699 // drop low again and turn off so receiver can enable/disable whichever outputs are needed
700 ✗ m_gpioCommands.push_back(GPIOCommand(m_portNumber, vsOffset));
701 ✗ for (int x = 0; x < vs.channelsPerNode() * vs.leadOutCount; x++) {
702 ✗ m_outputMap[vsOffset++] = FPPD_OFF_CHANNEL;
703 }
704 // turn gpio back on
705 ✗ m_gpioCommands.push_back(GPIOCommand(m_portNumber, vsOffset, 1));
706 }
707 4 return;
708 }
709
710 814 int offset = vsOffset;
711 814 int group = 0;
712 814 int maxGroups = 0;
713 814 int itemsInGroup = 0;
714 814 int ch = 0;
715 814 int pStart = 0;
716 814 int ch1 = 0;
717 814 int ch2 = 0;
718 814 int ch3 = 0;
719
720
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 813 times.
814 if (vs.groupCount) {
721 1 maxGroups = vs.pixelCount / vs.groupCount;
722 }
723
724 814 int redOffset = vs.colorOrder.redOffset();
725 814 int greenOffset = vs.colorOrder.greenOffset();
726 814 int blueOffset = vs.colorOrder.blueOffset();
727 814 int whiteOffset = vs.colorOrder.whiteOffset();
728
729
2/2
✓ Branch 0 taken 22176 times.
✓ Branch 1 taken 814 times.
22990 for (int p = pStart; p < vs.pixelCount; p++) {
730
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 22146 times.
22176 if (vs.groupCount) {
731
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 21 times.
30 if (itemsInGroup >= vs.groupCount) {
732 9 group++;
733 9 itemsInGroup = 0;
734 }
735
736 30 ch = vs.startChannel + (group * vs.channelsPerNode());
737
738 30 itemsInGroup++;
739 } else {
740 22146 ch = vs.startChannel + (p * vs.channelsPerNode());
741 }
742
743
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 22166 times.
22176 if (vs.colorOrder == FPPColorOrder::kColorOrderONE) {
744 10 m_outputMap[offset++] = ch;
745 } else {
746 // incoming data is always RGB or RGBW, map to whatever order is
747 // needed. The offsets are positions within the output node with
748 // W counted, so for WRGB red is at 1, not 0.
749 22166 m_outputMap[offset + redOffset] = ch; // red is always data[0]
750 22166 m_outputMap[offset + greenOffset] = ch + 1; // green is always data[1]
751 22166 m_outputMap[offset + blueOffset] = ch + 2; // blue is always data[2]
752
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 22147 times.
22166 if (whiteOffset >= 0) {
753 19 m_outputMap[offset + whiteOffset] = ch + 3; // W is always data[3]
754 19 offset += 4;
755 } else {
756 22147 offset += 3;
757 }
758 }
759 }
760
761 814 DumpMap("BEFORE ZIGZAG");
762
763
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 812 times.
814 if (vs.zigZag) {
764 2 int chanCount = vs.channelsPerNode();
765 2 int zigChannelCount = vs.zigZag * chanCount;
766 // the folds belong to this virtual string, so they are counted from
767 // its first pixel and stop at its last. Anchoring at the port instead
768 // re-flips segments owned by the other strings sharing the port, and
769 // any lead in or null nodes ahead of this one shift every boundary.
770 2 int vsEnd = vsOffset + (vs.pixelCount * chanCount);
771
772
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 for (int i = vsOffset; i < vsEnd; i += zigChannelCount) {
773 6 int segment = (i - vsOffset) / zigChannelCount;
774
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 if (segment % 2) {
775 2 int offset1 = i;
776 2 int offset2 = i + zigChannelCount - chanCount;
777
778 // the whole of the segment's last node has to be there - it is
779 // chanCount channels wide, which is 4 for RGBW, not 3
780
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if ((offset2 + chanCount) <= vsEnd)
781 2 FlipPixels(offset1, offset2, chanCount);
782 }
783 }
784
785 2 DumpMap("AFTER ZIGZAG");
786 }
787
788
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 812 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
814 if (vs.reverse && (vs.pixelCount > 1)) {
789 2 FlipPixels(vsOffset, vsOffset + (vs.pixelCount * vs.channelsPerNode()) - vs.channelsPerNode(), vs.channelsPerNode());
790
791 2 DumpMap("AFTER REVERSE");
792 }
793 }
794
795 /*
796 *
797 */
798 818 void PixelString::DumpMap(const char* msg) {
799
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 818 times.
818 if (WillLog(LOG_EXCESSIVE, VB_CHANNELOUT)) {
800 ✗ LogExcess(VB_CHANNELOUT, "OutputMap: %s\n", msg);
801 ✗ for (int i = 0; i < m_outputBytes; i++) {
802 ✗ LogExcess(VB_CHANNELOUT, "map[%d] = %d\n", i, m_outputMap[i]);
803 }
804 }
805 818 }
806
807 /*
808 *
809 */
810 4 void PixelString::FlipPixels(int offset1, int offset2, int chanCount) {
811 4 int flipPixels = (offset2 - offset1 + chanCount) / chanCount / 2;
812
813
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 4 times.
15 for (int i = 0; i < flipPixels; i++) {
814 // a node is exactly chanCount channels wide - 1 for a single colour
815 // string, 3 for RGB, 4 for RGBW - so swapping a fixed three either
816 // steps outside the node or leaves part of it behind
817
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 11 times.
34 for (int c = 0; c < chanCount; c++) {
818 23 int ch = m_outputMap[offset1 + c];
819 23 m_outputMap[offset1 + c] = m_outputMap[offset2 + c];
820 23 m_outputMap[offset2 + c] = ch;
821 }
822
823 11 offset1 += chanCount;
824 11 offset2 -= chanCount;
825 }
826 4 }
827
828 /*
829 *
830 */
831 802 void PixelString::DumpConfig(void) {
832 802 LogDebug(VB_CHANNELOUT, " port number : %d\n", m_portNumber);
833
834 802 int count = 0;
835
2/2
✓ Branch 0 taken 805 times.
✓ Branch 1 taken 802 times.
1607 for (auto& vs : m_virtualStrings) {
836
1/2
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
805 if (vs.receiverNum == -1) {
837
1/2
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
805 LogDebug(VB_CHANNELOUT, " --- Virtual String #%d ---\n", ++count);
838
1/2
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
805 LogDebug(VB_CHANNELOUT, " description : %s\n", vs.description.c_str());
839
1/2
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
805 LogDebug(VB_CHANNELOUT, " start channel : %d\n", vs.startChannel + m_channelOffset);
840
1/2
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
805 LogDebug(VB_CHANNELOUT, " pixel count : %d\n", vs.pixelCount);
841
1/2
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
805 LogDebug(VB_CHANNELOUT, " group count : %d\n", vs.groupCount);
842
1/2
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
805 LogDebug(VB_CHANNELOUT, " reverse : %d\n", vs.reverse);
843
2/4
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 805 times.
✗ Branch 3 not taken.
805 LogDebug(VB_CHANNELOUT, " color order : %s\n", ColorOrderToString(vs.colorOrder).c_str());
844
1/2
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
805 LogDebug(VB_CHANNELOUT, " start nulls : %d\n", vs.startNulls);
845
1/2
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
805 LogDebug(VB_CHANNELOUT, " end nulls : %d\n", vs.endNulls);
846
1/2
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
805 LogDebug(VB_CHANNELOUT, " zig zag : %d\n", vs.zigZag);
847
1/2
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
805 LogDebug(VB_CHANNELOUT, " brightness : %d\n", vs.brightness);
848
1/2
✓ Branch 0 taken 805 times.
✗ Branch 1 not taken.
805 LogDebug(VB_CHANNELOUT, " gamma : %.3f\n", vs.gamma);
849 }
850 }
851 802 }
852
853 // Everything downstream of here holds wire form, not logical form: on an
854 // inverted port the line idles high and the data phase drives high for a
855 // logical zero, so every byte that goes out has to be complemented. The
856 // brightness maps carry that for pixel data; the preamble needs it too.
857 2 void PixelString::invertOutput() {
858 2 m_isInverted = !m_isInverted;
859
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 for (auto& vs : m_virtualStrings) {
860 // the tables are shared, so swap to the complemented one rather than
861 // flipping this string's in place and corrupting every other user
862
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 int b = vs.isSmartReceiver() ? 100 : vs.brightness;
863
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 float g = vs.isSmartReceiver() ? 1.0f : vs.gamma;
864
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 vs.brightnessMap = BrightnessLUTCache::get(b, g, m_isInverted);
865
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (vs.brightnessMap16) {
866 ✗ vs.brightnessMap16 = BrightnessLUTCache::getWide(b, g, m_isInverted);
867 }
868 }
869
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 2 times.
18 for (auto& b : m_preamble) {
870 16 b = ~b;
871 }
872 2 }
873
874 144 void PixelString::AutoCreateOverlayModels(const std::vector<PixelString*>& strings, std::list<std::string>& autoModelNames) {
875
2/2
✓ Branch 0 taken 143 times.
✓ Branch 1 taken 1 times.
144 if (PixelOverlayManager::INSTANCE.isAutoCreatePixelOverlayModels()) {
876 143 std::map<std::string, std::vector<VirtualString*>> vstrings;
877
2/2
✓ Branch 0 taken 596 times.
✓ Branch 1 taken 143 times.
739 for (int s = 0; s < strings.size(); s++) {
878 596 char vsnum = 'A';
879 596 int vsidx = 0;
880
2/2
✓ Branch 0 taken 608 times.
✓ Branch 1 taken 596 times.
1204 for (int vs = 0; vs < strings[s]->m_virtualStrings.size(); vs++) {
881
1/2
✓ Branch 0 taken 608 times.
✗ Branch 1 not taken.
608 std::string desc = strings[s]->m_virtualStrings[vs].description;
882
3/4
✓ Branch 0 taken 608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 572 times.
608 if (desc == "") {
883
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 desc = "String-" + std::to_string(s + 1);
884
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 28 times.
36 if (strings[s]->m_virtualStrings.size() > 1) {
885
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 desc.append(1, vsnum);
886
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 desc += std::string("-");
887
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 desc += std::to_string(vsidx + 1);
888
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (strings[s]->m_virtualStrings[vs].receiverNum == -1) {
889 4 vsidx++;
890
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 } else if (vs != 0) {
891 4 vsidx = 0;
892 4 vsnum++;
893 }
894 }
895 }
896 // AddNullPixelString() placeholders (an empty receiver between
897 // populated ones) have no channels; a model for one would sit
898 // at FPPD_OFF_CHANNEL and push the output past the channel limit.
899 // Skipped after naming so the numbering of real strings is unchanged.
900
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 607 times.
608 if (strings[s]->m_virtualStrings[vs].startChannel >= FPPD_OFF_CHANNEL) {
901 1 continue;
902 }
903 // xLights will name the individual strings of a matrix/prop/model with a -str-# postfix
904 // so we will try and detect this and recreate the original model.
905 // Anything that is not a modest non-negative number (free-form
906 // user names, corrupt descriptions) is treated as a plain name
907 // below instead of throwing (stoi) or resizing gigabytes (huge
908 // index) and terminating fppd at model creation.
909 607 size_t found = desc.find("-str-");
910
2/2
✓ Branch 0 taken 603 times.
✓ Branch 1 taken 4 times.
607 if (found == std::string::npos) {
911
2/4
✓ Branch 0 taken 603 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 603 times.
✗ Branch 3 not taken.
603 vstrings[desc].push_back(&strings[s]->m_virtualStrings[vs]);
912 } else {
913 4 int idx = -1;
914 try {
915 4 size_t len = 0;
916
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 long long v = std::stoll(desc.substr(found + 5), &len);
917 // Entire tail must be the number (no "12x" partial
918 // parses) and it must fit a realistic string count.
919
4/8
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
4 if (len == desc.size() - (found + 5) && v >= 0 && v <= 100000) {
920 4 idx = (int)v;
921 }
922 ✗ } catch (...) {
923 ✗ }
924
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (idx < 0) {
925 ✗ vstrings[desc].push_back(&strings[s]->m_virtualStrings[vs]);
926 } else {
927
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (idx > 0)
928 4 --idx;
929
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 desc = desc.substr(0, found);
930
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 if (vstrings[desc].size() <= (size_t)idx) {
931
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 vstrings[desc].resize(idx + 1);
932 }
933
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 vstrings[desc][idx] = &strings[s]->m_virtualStrings[vs];
934 }
935 }
936
2/2
✓ Branch 0 taken 607 times.
✓ Branch 1 taken 1 times.
608 }
937 }
938
2/2
✓ Branch 0 taken 605 times.
✓ Branch 1 taken 143 times.
748 for (auto& m : vstrings) {
939
3/4
✓ Branch 0 taken 605 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 604 times.
605 if (PixelOverlayManager::INSTANCE.getModel(m.first) != nullptr) {
940 1 continue;
941 }
942
1/2
✓ Branch 0 taken 604 times.
✗ Branch 1 not taken.
604 std::string name = m.first;
943 604 auto& vs = m.second;
944
945 604 uint32_t startChannel = FPPD_MAX_CHANNELS;
946 604 uint32_t channelsPerNode = 0;
947
1/2
✓ Branch 0 taken 604 times.
✗ Branch 1 not taken.
1208 std::string orientation = "H";
948
1/2
✓ Branch 0 taken 604 times.
✗ Branch 1 not taken.
604 std::string startLocation = "BL";
949 604 uint32_t strings = vs.size();
950 604 uint32_t strands = 1;
951 604 uint32_t maxChan = 0;
952 604 uint32_t minChannelsPerNode = UINT32_MAX;
953 604 int8_t rn = -1;
954
2/2
✓ Branch 0 taken 607 times.
✓ Branch 1 taken 604 times.
1211 for (auto& a : vs) {
955
2/2
✓ Branch 0 taken 606 times.
✓ Branch 1 taken 1 times.
607 if (a) {
956 606 startChannel = std::min(startChannel, (uint32_t)a->startChannel);
957
3/4
✓ Branch 0 taken 606 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 605 times.
606 maxChan = std::max(maxChan, (uint32_t)a->startChannel + (a->pixelCount * a->channelsPerNode() / (a->groupCount ? a->groupCount : 1)));
958
1/2
✓ Branch 0 taken 606 times.
✗ Branch 1 not taken.
606 channelsPerNode = std::max(channelsPerNode, (uint32_t)a->channelsPerNode());
959
1/2
✓ Branch 0 taken 606 times.
✗ Branch 1 not taken.
606 minChannelsPerNode = std::min(minChannelsPerNode, (uint32_t)a->channelsPerNode());
960 606 rn = std::max(rn, a->receiverNum);
961 } else {
962 1 --strings;
963 }
964 }
965
2/4
✓ Branch 0 taken 604 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 604 times.
604 if (strings && minChannelsPerNode != channelsPerNode) {
966 // One model cannot describe two node widths. Taking the wider of
967 // them mis-addresses every pixel on the narrower strings, and the
968 // channel order reported for the model is wrong for them too, so
969 // say so rather than creating a silently broken model.
970 ✗ LogWarn(VB_CHANNELOUT, "Overlay model %s spans strings of %u and %u channels per node; using %u - pixels on the narrower strings will not line up\n",
971 name.c_str(), minChannelsPerNode, channelsPerNode, channelsPerNode);
972 }
973 // The model's channel order is derived from channelsPerNode by
974 // PixelOverlayModel - the virtual string's own colour order describes
975 // the wire, which is applied later by prepareOutput(), and must not be
976 // copied onto the model or it would be applied twice.
977 604 int32_t channelCount = maxChan - startChannel;
978
979
6/12
✓ Branch 0 taken 604 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 604 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 604 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 604 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 604 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 604 times.
604 if (name.find("Tree") != std::string::npos || name.find("TREE") != std::string::npos || name.find("tree") != std::string::npos || name.find("Vert") != std::string::npos || name.find("vert") != std::string::npos) {
980 // some common names that are usually vertical oriented
981 ✗ orientation = std::string("V");
982 }
983
984
4/4
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 572 times.
✓ Branch 3 taken 4 times.
604 if ((channelCount > 0) && (rn == -1)) {
985
1/2
✓ Branch 0 taken 572 times.
✗ Branch 1 not taken.
572 autoModelNames.push_back(name);
986
2/4
✓ Branch 0 taken 572 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 572 times.
✗ Branch 3 not taken.
1693 PixelOverlayManager::INSTANCE.addAutoOverlayModel(name, startChannel, channelCount, channelsPerNode, orientation,
987 startLocation, strings, strands);
988 }
989 604 }
990 143 }
991 144 }
992
993 1969 uint8_t* PixelString::prepareOutput(uint8_t* channelData) {
994 // any protocol preamble is already sitting at the head of the buffer
995 1969 int idx = m_preamble.size();
996
2/2
✓ Branch 0 taken 2037 times.
✓ Branch 1 taken 1969 times.
4006 for (auto& vs : m_virtualStrings) {
997 2037 int* map = vs.chMap;
998
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2037 times.
2037 if (vs.brightnessMap16) {
999 // 16 bit parts take each channel most significant byte first
1000 ✗ const uint16_t* brightness = vs.brightnessMap16;
1001 ✗ for (int ch = 0; ch < vs.chMapCount; ch++) {
1002 ✗ uint16_t v = brightness[channelData[map[ch]]];
1003 ✗ m_outputBuffer[idx++] = (uint8_t)(v >> 8);
1004 ✗ m_outputBuffer[idx++] = (uint8_t)v;
1005 }
1006 } else {
1007 2037 const uint8_t* brightness = vs.brightnessMap;
1008
2/2
✓ Branch 0 taken 132628 times.
✓ Branch 1 taken 2037 times.
134665 for (int ch = 0; ch < vs.chMapCount; ch++) {
1009 132628 m_outputBuffer[idx++] = brightness[channelData[map[ch]]];
1010 }
1011 }
1012 }
1013 1969 return m_outputBuffer;
1014 }
1015