22 CodecEnum
getCodecType()
const override {
return CodecEnum::Miller; }
35 _rxExpectingMidTransition =
false;
58 Logger::debug(
"Miller encode: byte=0x%02X, startLevel=%d",
byte, _encLevel);
61 for (
int i = 7;
i >= 0; --
i) {
62 bool bit = (
byte >>
i) & 0x01;
69 edge.level = _encLevel;
73 _encLevel = !_encLevel;
85 edge.level = _encLevel;
89 _encLevel = !_encLevel;
101 edge.level = _encLevel;
105 _encLevel = !_encLevel;
124 edge.level = _encLevel;
125 edge.pulseUs = 2 * _bitPeriodUs;
128 _encLevel = !_encLevel;
130 Logger::debug(
"Miller flushEncoder: added termination edge (2T)");
175 if (_rxExpectingMidTransition && _rxBitPos > 0) {
178 if (_rxBitPos >= 8) {
196 assert(_preamble !=
nullptr);
198 if (_preamble->preambleLength() == 0) {
207 Logger::debug(
"Miller: Preamble detected, starting new frame");
234 _rxBitPos, _rxExpectingMidTransition);
236 if (_rxExpectingMidTransition) {
251 _rxExpectingMidTransition =
false;
252 }
else if (
hp == 2) {
257 }
else if (
hp == 3) {
262 _rxExpectingMidTransition =
false;
263 }
else if (
hp == 4) {
279 _rxExpectingMidTransition =
true;
280 }
else if (
hp == 2) {
284 }
else if (
hp == 3) {
288 _rxExpectingMidTransition =
true;
289 }
else if (
hp == 4) {
302 if (_rxBitPos >= 8) {
319 if (_rxBitPos >= 8) {
323 _rxByte = (_rxByte << 1) | (
bit ? 1 : 0);
330 bool _encLevel =
true;
335 bool _rxExpectingMidTransition =
false;
Abstract base class for IR protocol encoding and decoding.
virtual void reset()
Reset the internal state of the codec.
static void debug(const char *format,...)
Log a debug message with formatting.
Miller (Delay Modulation) encoding/decoding utility class.
size_t encode(uint8_t byte, Vector< OutputEdge > &output) override
Encode a byte using Miller encoding (byte-aligned).
size_t flushEncoder(Vector< OutputEdge > &output) override
Add termination edge at end of frame.
CodecEnum getCodecType() const override
void decodeAtBoundary(int hp)
Decode when at bit boundary (not expecting mid-transition).
int getEndOfFrameDelayUs() override
void pushBit(bool bit)
Push a decoded bit into the receive buffer.
bool handlePreamble(uint32_t durationUs, bool level)
Handle preamble detection.
bool handleIdleGap(uint32_t durationUs, bool level, uint8_t &result)
Handle idle gap detection and end-of-frame processing.
bool decodeEdge(uint32_t durationUs, bool level, uint8_t &result) override
Decode Miller encoding edge by edge.
void decodeWhileExpectingMid(int hp)
Decode when expecting mid-transition of a '1' bit.
void reset() override
Reset the internal state of the codec.
void decodeMiller(int hp, bool level)
Decode Miller half-periods into bits.
int durationToHalfPeriods(uint32_t durationUs)
Convert duration to half-periods (rounded to nearest).
size_t getEdgeCount() const override
Get the number of protocol symbols (bits, pulses, etc.) per encoded byte.
bool getIdleLevel() const override
Provides the initial ldle state (low or hith)
bool checkByteComplete(uint8_t &result)
Check if a complete byte has been assembled.
Abstract base class for preamble detection and generation.
virtual bool detect(const OutputEdge &edge)
Detects if the incoming edge matches the expected preamble pattern.
Small, header-only vector replacement for non-STL environments.
void push_back(const T &value)
Add element to end of vector.
Specifies a single IR signal segment for protocol-agnostic transmission.