7#include "pulse/tools/Vector.h"
33 _shortPulseUs = shortPulseUs;
34 _longPulseUs = longPulseUs;
35 _toleranceUs = toleranceUs;
40 if (_shortPulseUs == 0) _shortPulseUs = 1000000UL / (
bitFrequencyHz * 2);
41 if (_longPulseUs == 0) _longPulseUs = 1000000UL / (
bitFrequencyHz / 2);
42 if (_toleranceUs == 0) _toleranceUs = _bitPeriodUs * 0.3;
49 CodecEnum
getCodecType()
const override {
return CodecEnum::PulseWidth; }
60 for (
int i = 0;
i < 8; ++
i) {
78 assert(_preamble !=
nullptr);
80 if (_preamble->preambleLength() == 0) {
82 _decodeEdgeStream.
clear();
89 _decodeEdgeStream.
clear();
98 bool rc = decodeByte(_decodeEdgeStream,
result);
100 _decodeEdgeStream.
clear();
128 pulse.pulseUs =
bit ? _longPulseUs : _shortPulseUs;
130 space.pulseUs = _shortPulseUs;
142 for (
auto& edge : edges) {
145 if (bitMatch(edge.pulseUs,
true)) {
146 byte |= (1 << (7 - bit));
147 }
else if (bitMatch(edge.pulseUs,
false)) {
150 Logger::error(
"Invalid pulse duration for bit %d: %d us", bit,
Abstract base class for IR protocol encoding and decoding.
void setPreamble(Preamble &preamble)
Set the Preamble Detector object.
virtual bool getIdleLevel() const
Provides the initial ldle state (low or hith)
virtual void encodeByte(uint8_t byte, std::vector< bool > &bits) const
Encode a byte to protocol bitstream. Default implementation encodes to raw bits (MSB first),...
virtual bool begin(uint32_t bitFrequencyHz)
initialization method for codecs that require setup before use (e.g., loading PIO programs,...
virtual void reset()
Reset the internal state of the codec.
static void debug(const char *format,...)
Log a debug message with formatting.
static void error(const char *format,...)
Log an error message with formatting.
Abstract base class for preamble detection and generation.
virtual bool detect(const OutputEdge &edge)
Detects if the incoming edge matches the expected preamble pattern.
Pulse-width encoding/decoding utility class for IR communication.
CodecEnum getCodecType() const override
size_t encodeBit(bool bit, Vector< OutputEdge > &output)
Fill output vector with PulseWidth OutputSpec(s) for a bit.
size_t getEdgeCount() const override
Get the number of protocol symbols (bits, pulses, etc.) per encoded byte.
size_t encode(uint8_t byte, Vector< OutputEdge > &output) override
Fill output vector with protocol-specific OutputSpec(s) for a byte.
bool begin(uint32_t bitFrequencyHz) override
initialization method for codecs that require setup before use (e.g., loading PIO programs,...
int getEndOfFrameDelayUs() override
virtual void init(Preamble &detector, uint32_t shortPulseUs, uint32_t longPulseUs, uint32_t toleranceUs)
bool decodeEdge(uint32_t durationUs, bool level, uint8_t &result) override
Edge-based decoding for protocol-agnostic RX drivers.
Small, header-only vector replacement for non-STL environments.
size_t capacity() const
Current allocated capacity.
void clear()
Remove all elements.
void push_back(const T &value)
Add element to end of vector.
void reserve(size_t cap)
Reserve space for at least cap elements.
size_t size() const
Number of elements in vector.
Specifies a single IR signal segment for protocol-agnostic transmission.