#pragma once // BMW I/K-Bus interface — backward-compatible facade // Wraps KLineTransport + IbusHandler so existing sketches need zero changes. // For new code, use KLineTransport + IbusHandler (or KLineObd2) directly. #include #include #include "KLineTransport.h" #include "IbusHandler.h" // Re-export library defaults for existing config.h compatibility #ifndef IBUS_BAUD #define IBUS_BAUD 9600 #endif #ifndef IBUS_FRAMING #define IBUS_FRAMING SERIAL_8E1 #endif #ifndef IBUS_IDLE_TIMEOUT_US #define IBUS_IDLE_TIMEOUT_US 1500 #endif #ifndef IBUS_IDLE_CHECK_US #define IBUS_IDLE_CHECK_US 250 #endif #ifndef IBUS_PACKET_GAP_MS #define IBUS_PACKET_GAP_MS 10 #endif #ifndef IBUS_UART_NUM #define IBUS_UART_NUM 1 #endif class IbusEsp32 { public: using PacketCallback = std::function; IbusEsp32(); void begin(HardwareSerial& serial, int8_t rxPin, int8_t txPin, int8_t ledPin = -1, uint8_t uartNum = IBUS_UART_NUM); void run(); void write(const uint8_t* message, uint8_t size); void onPacket(PacketCallback callback); void setFilterEnabled(bool enabled); void setFilterAddress(uint8_t addr); void setFilterAddresses(const uint8_t* addrs, uint8_t count); static uint8_t calculateChecksum(const uint8_t* data, uint8_t length); private: KLineTransport _transport; IbusHandler _handler; };