FastLED 3.10.8
Loading...
Searching...
No Matches

◆ finish()

void fl::channels::rx::Ws2812StreamDecoder::finish ( const ChipsetTiming4Phase & timing)

Re-classify the recorded bits with the decode-time timing and write the partial final byte.

Idempotent; call after flush().

Definition at line 259 of file ws2812_stream_decoder.cpp.hpp.

259 {
260 flush();
261 mPartialWritten = false;
262 mStats.gapBitShift = false;
263 if (mBitCount > 0 && mStats.fullBytes < mOut.size()) {
264 mOut[mStats.fullBytes] = static_cast<u8>(mCurByte << (8 - mBitCount));
265 mPartialWritten = true;
266 }
267
268 const u32 frame_mid =
270 mStats.frameMidpointNs = frame_mid;
271 const u32 drift = (frame_mid > mMidpoint) ? frame_mid - mMidpoint : mMidpoint - frame_mid;
272 bool inexact = drift > kExceptionBandNs || mStats.exceptionsDropped > 0;
273 for (u32 k = 0; k < mExceptionCount; ++k) {
274 const Exception& e = mExceptions[k];
275 int b;
276 if (e.mode == Mode::FromHigh) {
277 b = flexPwmBitFromHigh(e.high_ns, timing);
278 if ((b >= 0) != e.stream_valid) {
279 inexact = true; // the bit would be dropped / kept instead
280 mStats.gapBitShift = true;
281 continue;
282 }
283 if (b < 0) {
284 continue;
285 }
286 } else {
287 b = flexPwmBitFromMidpoint(e.high_ns, frame_mid);
288 }
289 const u32 byte = e.bit_pos / 8u;
290 if (byte >= mOut.size()) {
291 continue;
292 }
293 const u8 mask = static_cast<u8>(0x80u >> (e.bit_pos % 8u));
294 mOut[byte] = b ? static_cast<u8>(mOut[byte] | mask)
295 : static_cast<u8>(mOut[byte] & ~mask);
296 }
297 mStats.inexact = inexact;
298}
void flush() FL_NO_EXCEPT
End of capture: decode the final pair (HIGH only; its LOW is the reset) and fix the calibration.
static constexpr u32 kExceptionBandNs
Bits within this distance of the calibrated threshold are recorded for re-classification against the ...
uint8_t byte
Definition midi_Defs.h:36
int flexPwmBitFromHigh(u32 high_ns, const ChipsetTiming4Phase &timing) FL_NO_EXCEPT
Bit from a HIGH whose LOW was a gap/reset or was not captured: range check against the T0H / T1H wind...
int flexPwmBitFromMidpoint(u32 high_ns, u32 midpoint_ns) FL_NO_EXCEPT
Bit from a HIGH followed by a normal LOW: HIGH-only midpoint split.
u32 flexPwmAdaptiveMidpointNs(const ChipsetTiming4Phase &timing, u32 high_min, u32 high_max, u32 samples) FL_NO_EXCEPT
#3416 adaptive midpoint: (min + max) / 2 of the observed HIGH widths once there are enough samples sp...
unsigned char u8
Definition stdint.h:131

References fl::channels::rx::Ws2812StreamDecoder::Exception::bit_pos, fl::FL_NO_EXCEPT, fl::channels::rx::flexPwmAdaptiveMidpointNs(), fl::channels::rx::flexPwmBitFromHigh(), fl::channels::rx::flexPwmBitFromMidpoint(), fl::flush(), FromHigh, fl::channels::rx::Ws2812StreamDecoder::Exception::high_ns, kExceptionBandNs, mBitCount, mCurByte, mExceptionCount, mExceptions, mHighMax, mHighMin, mHighSamples, mMidpoint, fl::channels::rx::Ws2812StreamDecoder::Exception::mode, mOut, mPartialWritten, mStats, and fl::channels::rx::Ws2812StreamDecoder::Exception::stream_valid.

+ Here is the call graph for this function: