12 NRZCodec(uint8_t stopBits = 1) : _stopBits(stopBits) {}
15 :
Codec(preambleDetector), _stopBits(stopBits) {}
19 bool getIdleLevel() {
return true; }
21 void setStopBits(uint8_t stopBits) { _stopBits = stopBits; }
23 uint8_t getStopBits()
const {
return _stopBits; }
25 bool begin(uint32_t bitFrequencyHz)
override {
26 if (_preamble == &_defaultPreamble) {
27 _defaultPreamble.clear();
30 uint32_t bp = 1000000UL / bitFrequencyHz;
31 _defaultPreamble.addEdge(
false, bp);
32 _defaultPreamble.addEdge(
true, bp);
44 start.pulseUs = _bitPeriodUs;
49 for (
int bit = 0; bit < 8; ++bit) {
51 data.level = (
byte & (1 << bit)) != 0;
52 data.pulseUs = _bitPeriodUs;
58 for (uint8_t s = 0; s < _stopBits; ++s) {
61 stop.pulseUs = _bitPeriodUs;
69 bool decodeEdge(uint32_t durationUs,
bool level, uint8_t& result)
override {
78 int count = (durationUs + _bitPeriodUs / 2) / _bitPeriodUs;
79 if (count < 1) count = 1;
83 for (
int i = 0; i < count; ++i) {
92 if (edges.
size() < 1 + 8 + _stopBits)
return false;
94 if (edges[0].level !=
false)
return false;
97 for (
int i = 0; i < 8; ++i) {
98 if (edges[i + 1].level)
byte |= (1 << i);
102 for (
int s = 0; s < _stopBits; ++s) {
103 if (edges[9 + s].level !=
true) valid =
false;
118 bool bitMatch(uint32_t duration,
bool bit)
const {
119 uint32_t expectedDuration = _bitPeriodUs;
120 return (duration >= expectedDuration - (_bitPeriodUs / 2)) &&
121 (duration <= expectedDuration + (_bitPeriodUs / 2));
Abstract base class for IR protocol encoding and decoding.
virtual bool decodeEdge(uint32_t durationUs, bool level, uint8_t &result)
Edge-based decoding for protocol-agnostic RX drivers.
virtual bool begin(uint32_t bitFrequencyHz)
initialization method for codecs that require setup before use (e.g., loading PIO programs,...
NRZ (Non-Return-to-Zero) codec for serial-like encoding/decoding with start/stop bit framing.
int getEndOfFrameDelayUs() override
Provide the end of frame delay in microseconds for this protocol, used by RX driver to.
CodecEnum getCodecType() const override
instance.
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 decodeByte(Vector< OutputEdge > &edges, uint8_t &result) override
Decode edges into a byte.
bool decodeEdge(uint32_t durationUs, bool level, uint8_t &result) override
Edge-based decoding for protocol-agnostic RX drivers.
bool begin(uint32_t bitFrequencyHz) override
initialization method for codecs that require setup before use (e.g., loading PIO programs,...
Abstract base class for preamble detection and generation.
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.