| 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 GPL v2 as described in the | ||
| 10 | * included LICENSE.GPL file. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "fpp-pch.h" | ||
| 14 | |||
| 15 | #include "fpp-json.h" | ||
| 16 | |||
| 17 | #include <fcntl.h> | ||
| 18 | #include <signal.h> | ||
| 19 | #include <stdint.h> | ||
| 20 | |||
| 21 | #include "../Sequence.h" | ||
| 22 | #include "../common.h" | ||
| 23 | #include "../log.h" | ||
| 24 | |||
| 25 | #include "../overlays/PixelOverlay.h" | ||
| 26 | |||
| 27 | #include "spixels.h" | ||
| 28 | |||
| 29 | #include "Plugin.h" | ||
| 30 | class SpixelsPlugin : public FPPPlugins::Plugin, public FPPPlugins::ChannelOutputPlugin { | ||
| 31 | public: | ||
| 32 | 3 | SpixelsPlugin() : | |
| 33 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
9 | FPPPlugins::Plugin("Spixels") { |
| 34 | 3 | } | |
| 35 | 3 | virtual ChannelOutput* createChannelOutput(unsigned int startChannel, unsigned int channelCount) override { | |
| 36 |
2/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
6 | return new SpixelsOutput(startChannel, channelCount); |
| 37 | } | ||
| 38 | }; | ||
| 39 | |||
| 40 | extern "C" { | ||
| 41 | 3 | FPPPlugins::Plugin* createPlugin() { | |
| 42 |
2/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
6 | return new SpixelsPlugin(); |
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | ///////////////////////////////////////////////////////////////////////////// | ||
| 47 | |||
| 48 | /* | ||
| 49 | * | ||
| 50 | */ | ||
| 51 | 3 | SpixelsOutput::SpixelsOutput(unsigned int startChannel, unsigned int channelCount) : | |
| 52 | ThreadedChannelOutput(startChannel, channelCount), | ||
| 53 | 3 | m_spi(NULL) { | |
| 54 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | LogDebug(VB_CHANNELOUT, "SpixelsOutput::SpixelsOutput(%u, %u)\n", |
| 55 | startChannel, channelCount); | ||
| 56 | 3 | } | |
| 57 | |||
| 58 | /* | ||
| 59 | * | ||
| 60 | */ | ||
| 61 | 12 | SpixelsOutput::~SpixelsOutput() { | |
| 62 | 6 | LogDebug(VB_CHANNELOUT, "SpixelsOutput::~SpixelsOutput()\n"); | |
| 63 | |||
| 64 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
12 | for (int s = 0; s < m_strips.size(); s++) |
| 65 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
6 | delete m_strips[s]; |
| 66 | |||
| 67 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
6 | delete m_spi; |
| 68 | |||
| 69 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
12 | for (int s = 0; s < m_strings.size(); s++) |
| 70 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
6 | delete m_strings[s]; |
| 71 | 12 | } | |
| 72 | |||
| 73 | /* | ||
| 74 | * | ||
| 75 | */ | ||
| 76 | 3 | int SpixelsOutput::Init(Json::Value config) { | |
| 77 | 3 | LogDebug(VB_CHANNELOUT, "SpixelsOutput::Init(JSON)\n"); | |
| 78 | |||
| 79 | // WS2801 wants CreateDMAMultiSPI() for accurate timing, but that path is disabled. | ||
| 80 | 3 | m_spi = CreateDirectMultiSPI(); | |
| 81 | |||
| 82 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | for (int i = 0; i < config["outputs"].size(); i++) { |
| 83 |
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 s = config["outputs"][i]; |
| 84 |
3/8✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
3 | PixelString* newString = new PixelString(); |
| 85 | 3 | LEDStrip* strip = NULL; | |
| 86 | |||
| 87 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
|
3 | if (!newString->Init(s)) |
| 88 | ✗ | return 0; | |
| 89 | |||
| 90 | 3 | int connector = 0; | |
| 91 | 3 | int pixels = newString->m_outputBytes / 3; // FIXME, need to confirm this | |
| 92 | |||
| 93 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (pixels == 0) { |
| 94 | ✗ | delete newString; | |
| 95 | ✗ | continue; | |
| 96 | } | ||
| 97 | |||
| 98 |
3/21✓ 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.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
3 | switch (s["portNumber"].asInt()) { |
| 99 | 3 | case 0: | |
| 100 | 3 | connector = MultiSPI::SPI_P1; | |
| 101 | 3 | break; | |
| 102 | ✗ | case 1: | |
| 103 | ✗ | connector = MultiSPI::SPI_P2; | |
| 104 | ✗ | break; | |
| 105 | ✗ | case 2: | |
| 106 | ✗ | connector = MultiSPI::SPI_P3; | |
| 107 | ✗ | break; | |
| 108 | ✗ | case 3: | |
| 109 | ✗ | connector = MultiSPI::SPI_P4; | |
| 110 | ✗ | break; | |
| 111 | ✗ | case 4: | |
| 112 | ✗ | connector = MultiSPI::SPI_P5; | |
| 113 | ✗ | break; | |
| 114 | ✗ | case 5: | |
| 115 | ✗ | connector = MultiSPI::SPI_P6; | |
| 116 | ✗ | break; | |
| 117 | ✗ | case 6: | |
| 118 | ✗ | connector = MultiSPI::SPI_P7; | |
| 119 | ✗ | break; | |
| 120 | ✗ | case 7: | |
| 121 | ✗ | connector = MultiSPI::SPI_P8; | |
| 122 | ✗ | break; | |
| 123 | ✗ | case 8: | |
| 124 | ✗ | connector = MultiSPI::SPI_P9; | |
| 125 | ✗ | break; | |
| 126 | ✗ | case 9: | |
| 127 | ✗ | connector = MultiSPI::SPI_P10; | |
| 128 | ✗ | break; | |
| 129 | ✗ | case 10: | |
| 130 | ✗ | connector = MultiSPI::SPI_P11; | |
| 131 | ✗ | break; | |
| 132 | ✗ | case 11: | |
| 133 | ✗ | connector = MultiSPI::SPI_P12; | |
| 134 | ✗ | break; | |
| 135 | ✗ | case 12: | |
| 136 | ✗ | connector = MultiSPI::SPI_P13; | |
| 137 | ✗ | break; | |
| 138 | ✗ | case 13: | |
| 139 | ✗ | connector = MultiSPI::SPI_P14; | |
| 140 | ✗ | break; | |
| 141 | ✗ | case 14: | |
| 142 | ✗ | connector = MultiSPI::SPI_P15; | |
| 143 | ✗ | break; | |
| 144 | ✗ | case 15: | |
| 145 | ✗ | connector = MultiSPI::SPI_P16; | |
| 146 | ✗ | break; | |
| 147 | } | ||
| 148 | |||
| 149 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | std::string protocol = s["protocol"].asString(); |
| 150 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | toLower(protocol); |
| 151 |
3/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
|
3 | if (protocol == "ws2801") { |
| 152 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | strip = CreateWS2801Strip(m_spi, connector, pixels); |
| 153 |
3/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | } else if (protocol == "apa102") { |
| 154 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | strip = CreateAPA102Strip(m_spi, connector, pixels); |
| 155 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | } else if (protocol == "lpd6803") { |
| 156 | ✗ | strip = CreateLPD6803Strip(m_spi, connector, pixels); | |
| 157 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | } else if (protocol == "lpd8806") { |
| 158 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | strip = CreateLPD8806Strip(m_spi, connector, pixels); |
| 159 | } else { | ||
| 160 | ✗ | LogErr(VB_CHANNELOUT, "Unknown Pixel Protocol: %s\n", s["protocol"].asString().c_str()); | |
| 161 | ✗ | return 0; | |
| 162 | } | ||
| 163 | |||
| 164 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | m_strings.push_back(newString); |
| 165 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | m_strips.push_back(strip); |
| 166 |
1/3✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
3 | } |
| 167 | |||
| 168 | 3 | LogDebug(VB_CHANNELOUT, " Found %d strings of pixels\n", m_strings.size()); | |
| 169 | 3 | PixelString::AutoCreateOverlayModels(m_strings, m_autoCreatedModelNames); | |
| 170 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | return ThreadedChannelOutput::Init(config); |
| 171 | } | ||
| 172 | |||
| 173 | /* | ||
| 174 | * | ||
| 175 | */ | ||
| 176 | 3 | int SpixelsOutput::Close(void) { | |
| 177 | 3 | LogDebug(VB_CHANNELOUT, "SpixelsOutput::Close()\n"); | |
| 178 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | for (auto& n : m_autoCreatedModelNames) { |
| 179 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | PixelOverlayManager::INSTANCE.removeAutoOverlayModel(n); |
| 180 | } | ||
| 181 | 3 | return ThreadedChannelOutput::Close(); | |
| 182 | } | ||
| 183 | |||
| 184 | 6 | void SpixelsOutput::GetRequiredChannelRanges(const std::function<void(int, int)>& addRange) { | |
| 185 | 6 | PixelString* ps = NULL; | |
| 186 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | for (int s = 0; s < m_strings.size(); s++) { |
| 187 | 6 | ps = m_strings[s]; | |
| 188 | 6 | int min = FPPD_MAX_CHANNELS; | |
| 189 | 6 | int max = 0; | |
| 190 | 6 | int inCh = 0; | |
| 191 |
2/2✓ Branch 0 taken 180 times.
✓ Branch 1 taken 6 times.
|
186 | for (int p = 0; p < ps->m_outputBytes; p++) { |
| 192 | 180 | int ch = ps->m_outputMap[inCh++]; | |
| 193 |
1/2✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
|
180 | if (ch < FPPD_MAX_CHANNELS) { |
| 194 | 180 | min = std::min(min, ch); | |
| 195 | 180 | max = std::max(max, ch); | |
| 196 | } | ||
| 197 | } | ||
| 198 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (min < max) { |
| 199 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | addRange(min, max); |
| 200 | } | ||
| 201 | } | ||
| 202 | 6 | } | |
| 203 | 15 | void SpixelsOutput::PrepData(unsigned char* channelData) { | |
| 204 | 15 | unsigned char* c = channelData; | |
| 205 | 15 | unsigned int r = 0; | |
| 206 | 15 | unsigned int g = 0; | |
| 207 | 15 | unsigned int b = 0; | |
| 208 | |||
| 209 | 15 | PixelString* ps = NULL; | |
| 210 | 15 | int inCh = 0; | |
| 211 | |||
| 212 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 15 times.
|
30 | for (int s = 0; s < m_strings.size(); s++) { |
| 213 | 15 | ps = m_strings[s]; | |
| 214 | 15 | inCh = 0; | |
| 215 | |||
| 216 |
2/2✓ Branch 0 taken 150 times.
✓ Branch 1 taken 15 times.
|
165 | for (int p = 0, pix = 0; p < ps->m_outputBytes; pix++) { |
| 217 | 150 | r = ps->m_brightnessMaps[p++][channelData[ps->m_outputMap[inCh++]]]; | |
| 218 | 150 | g = ps->m_brightnessMaps[p++][channelData[ps->m_outputMap[inCh++]]]; | |
| 219 | 150 | b = ps->m_brightnessMaps[p++][channelData[ps->m_outputMap[inCh++]]]; | |
| 220 | |||
| 221 |
1/2✓ Branch 0 taken 150 times.
✗ Branch 1 not taken.
|
150 | m_strips[s]->SetPixel(pix, RGBc(r, g, b)); |
| 222 | } | ||
| 223 | } | ||
| 224 | 15 | } | |
| 225 | |||
| 226 | /* | ||
| 227 | * | ||
| 228 | */ | ||
| 229 | 9 | int SpixelsOutput::RawSendData(unsigned char* channelData) { | |
| 230 | 9 | LogExcess(VB_CHANNELOUT, "SpixelsOutput::RawSendData(%p)\n", channelData); | |
| 231 | |||
| 232 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if (m_spi) |
| 233 | 9 | m_spi->SendBuffers(); | |
| 234 | |||
| 235 | 9 | return m_channelCount; | |
| 236 | } | ||
| 237 | |||
| 238 | /* | ||
| 239 | * | ||
| 240 | */ | ||
| 241 | 6 | void SpixelsOutput::DumpConfig(void) { | |
| 242 | 6 | LogDebug(VB_CHANNELOUT, "SpixelsOutput::DumpConfig()\n"); | |
| 243 | |||
| 244 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | for (int i = 0; i < m_strings.size(); i++) { |
| 245 | 6 | LogDebug(VB_CHANNELOUT, " String #%d\n", i); | |
| 246 | 6 | m_strings[i]->DumpConfig(); | |
| 247 | } | ||
| 248 | |||
| 249 | 6 | ThreadedChannelOutput::DumpConfig(); | |
| 250 | 6 | } | |
| 251 |