7#include "pulse/tools/Vector.h"
31 uint32_t longPulseUs, uint32_t toleranceUs) {
33 _shortPulseUs = shortPulseUs;
34 _longPulseUs = longPulseUs;
35 _toleranceUs = toleranceUs;
38 bool begin(uint32_t bitFrequencyHz)
override {
40 if (_shortPulseUs == 0) _shortPulseUs = 1000000UL / (bitFrequencyHz * 2);
41 if (_longPulseUs == 0) _longPulseUs = 1000000UL / (bitFrequencyHz / 2);
42 if (_toleranceUs == 0) _toleranceUs = _bitPeriodUs * 0.3;
60 pulse.pulseUs = bit ? _longPulseUs : _shortPulseUs;
62 space.pulseUs = _shortPulseUs;
69 if (edges.
size() < 16) {
75 for (
auto& edge : edges) {
78 if (bitMatch(edge.pulseUs,
true)) {
79 byte |= (1 << (7 - bit));
80 }
else if (bitMatch(edge.pulseUs,
false)) {
83 Logger::error(
"Invalid pulse duration for bit %d: %d us", bit,
93 CodecEnum
getCodecType()
const override {
return CodecEnum::PulseWidth; }
100 uint32_t _shortPulseUs = 0;
101 uint32_t _longPulseUs = 0;
102 uint32_t _toleranceUs = 0;
104 bool bitMatch(uint32_t duration,
bool bit)
const {
105 uint32_t expected = bit ? _longPulseUs : _shortPulseUs;
106 return (duration >= expected - _toleranceUs &&
107 duration <= expected + _toleranceUs);
Abstract base class for IR protocol encoding and decoding.
virtual bool begin(uint32_t bitFrequencyHz)
initialization method for codecs that require setup before use (e.g., loading PIO programs,...
void setPreamble(Preamble &preamble)
Set the Preamble Detector object.
static void error(const char *format,...)
Log an error message with formatting.
Abstract base class for preamble detection and generation.
Pulse-width encoding/decoding utility class for IR communication.
bool decodeByte(Vector< OutputEdge > &edges, uint8_t &result) override
Decode edges into a byte.
CodecEnum getCodecType() const override
instance.
size_t getEdgeCount() const override
Get the number of protocol symbols (bits, pulses, etc.) per encoded byte.
bool begin(uint32_t bitFrequencyHz) override
initialization method for codecs that require setup before use (e.g., loading PIO programs,...
int getEndOfFrameDelayUs() override
Provide the end of frame delay in microseconds for this protocol, used by RX driver to.
virtual void init(Preamble &detector, uint32_t shortPulseUs, uint32_t longPulseUs, uint32_t toleranceUs)
size_t encodeBit(bool bit, Vector< OutputEdge > &output) override
Fill output vector with PulseWidth OutputSpec(s) for a bit.
Small, header-only vector replacement for non-STL environments.
void push_back(const T &value)
Add element to end of vector.
size_t size() const
Number of elements in vector.
Specifies a single IR signal segment for protocol-agnostic transmission.