20 _multiProtocol.
setCallback(onProtocolDetected,
this);
25 if (_pin != -1)
end();
38 IRProtocolEnum getDetectedProtocol()
const {
return _detectedProtocol; }
40 const char* getDetectedProtocolStr()
const {
return toStr(_detectedProtocol); }
42 void reset() { _detectedProtocol = IRProtocolEnum::Unknown; }
45 static IRProtocolDetector* _instance;
47 IRMultiProtocol _multiProtocol;
48 volatile IRProtocolEnum _detectedProtocol = IRProtocolEnum::Unknown;
49 volatile uint32_t _lastEdge = 0;
51 static void interruptHandler() {
52 if (_instance) _instance->handleInterrupt();
55 static void onProtocolDetected(IRProtocolEnum proto, IRProtocol& info,
57 IRProtocolDetector* detector =
static_cast<IRProtocolDetector*
>(ref);
58 if (detector) detector->_detectedProtocol = proto;
62 void handleInterrupt() {
63 bool level = digitalRead(_pin);
64 uint32_t now = micros();
65 uint32_t duration = now - _lastEdge;
67 OutputEdge edge{level, duration};
68 _multiProtocol.detect(edge);