3#include "pulse/SignalBase.h"
4#include "pulse/codecs/Codec.h"
5#include "pulse/tools/Vector.h"
26 CodecEnum
getCodecType()
const override {
return CodecEnum::Manchester; }
28 bool begin(uint32_t bitFrequencyHz)
override {
30 if (_preamble == &_defaultPreamble) {
31 _defaultPreamble.clear();
32 uint32_t halfBit = (1000000UL / bitFrequencyHz) / 2;
33 _defaultPreamble.addEdge(
true, halfBit);
50 bool decodeEdge(uint32_t durationUs,
bool level, uint8_t& result)
override {
57 int edgePeriod = 0.45f * _bitPeriodUs;
58 int edgeCount = durationUs / edgePeriod;
59 if (edgeCount < 1) edgeCount = 1;
60 if (edgeCount > 4) edgeCount = 4;
61 int avg_period = durationUs / edgeCount;
64 for (
int i = 0; i < edgeCount; ++i) {
93 first.pulseUs = _bitPeriodUs / 2;
95 second.pulseUs = _bitPeriodUs / 2;
98 first.pulseUs = _bitPeriodUs / 2;
100 second.pulseUs = _bitPeriodUs / 2;
111 uint8_t&
byte = result;
114 for (
int i = 0; i < 8; ++i) {
115 bool b0 = edges[i * 2].level;
116 bool b1 = edges[i * 2 + 1].level;
118 if (b0 == 1 && b1 == 0) {
119 byte |= (1 << (7 - i));
120 }
else if (b0 == 0 && b1 == 1) {
124 Logger::error(
"Invalid Manchester pair at bit %d: b0=%d, b1=%d", i, b0,
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,...
static void error(const char *format,...)
Log an error message with formatting.
Manchester encoding/decoding utility class for IR communication.
bool decodeEdge(uint32_t durationUs, bool level, uint8_t &result) override
Decode incoming edges to reconstruct bytes. Handles multiple edges per bit for noise tolerance by ave...
size_t encodeBit(bool bit, Vector< OutputEdge > &output) override
Fill output vector with Manchester OutputSpec(s) for a bit.
bool decodeByte(Vector< OutputEdge > &edges, uint8_t &result) override
Decode edges into a byte.
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 edges used to encode a byte (16 for Manchester).
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.