- Integrated `mcutie` library as a core MQTT client for device communication. - Added support for Home Assistant entities (binary sensor, button) via MQTT. - Implemented buffer management, async operations, and packet encoding/decoding. - Introduced structured error handling and device registration features. - Updated `Cargo.toml` with new dependencies and enabled feature flags for `serde` and `log`. - Enhanced logging macros with configurable options (`defmt` or `log`). - Organized codebase into modules (buffer, components, IO, publish, etc.) for better maintainability.
81 lines
2.1 KiB
Rust
81 lines
2.1 KiB
Rust
#![macro_use]
|
|
|
|
#[cfg(all(feature = "defmt", feature = "log"))]
|
|
compile_error!("The `defmt` and `log` features cannot both be enabled at the same time.");
|
|
|
|
#[cfg(not(feature = "defmt"))]
|
|
use core::fmt;
|
|
|
|
#[cfg(feature = "defmt")]
|
|
pub(crate) use ::defmt::Debug2Format;
|
|
|
|
#[cfg(not(feature = "defmt"))]
|
|
pub(crate) struct Debug2Format<D: fmt::Debug>(pub(crate) D);
|
|
|
|
#[cfg(feature = "log")]
|
|
impl<D: fmt::Debug> fmt::Debug for Debug2Format<D> {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
self.0.fmt(f)
|
|
}
|
|
}
|
|
|
|
#[collapse_debuginfo(yes)]
|
|
macro_rules! trace {
|
|
($s:literal $(, $x:expr)* $(,)?) => {
|
|
#[cfg(feature = "defmt")]
|
|
::defmt::trace!($s $(, $x)*);
|
|
#[cfg(feature = "log")]
|
|
::log::trace!($s $(, $x)*);
|
|
#[cfg(not(any(feature="defmt", feature="log")))]
|
|
let _ = ($( & $x ),*);
|
|
};
|
|
}
|
|
|
|
#[collapse_debuginfo(yes)]
|
|
macro_rules! debug {
|
|
($s:literal $(, $x:expr)* $(,)?) => {
|
|
#[cfg(feature = "defmt")]
|
|
::defmt::debug!($s $(, $x)*);
|
|
#[cfg(feature = "log")]
|
|
::log::debug!($s $(, $x)*);
|
|
#[cfg(not(any(feature="defmt", feature="log")))]
|
|
let _ = ($( & $x ),*);
|
|
};
|
|
}
|
|
|
|
#[collapse_debuginfo(yes)]
|
|
macro_rules! info {
|
|
($s:literal $(, $x:expr)* $(,)?) => {
|
|
#[cfg(feature = "defmt")]
|
|
::defmt::info!($s $(, $x)*);
|
|
#[cfg(feature = "log")]
|
|
::log::info!($s $(, $x)*);
|
|
#[cfg(not(any(feature="defmt", feature="log")))]
|
|
let _ = ($( & $x ),*);
|
|
};
|
|
}
|
|
|
|
#[collapse_debuginfo(yes)]
|
|
macro_rules! warn {
|
|
($s:literal $(, $x:expr)* $(,)?) => {
|
|
#[cfg(feature = "defmt")]
|
|
::defmt::warn!($s $(, $x)*);
|
|
#[cfg(feature = "log")]
|
|
::log::warn!($s $(, $x)*);
|
|
#[cfg(not(any(feature="defmt", feature="log")))]
|
|
let _ = ($( & $x ),*);
|
|
};
|
|
}
|
|
|
|
#[collapse_debuginfo(yes)]
|
|
macro_rules! error {
|
|
($s:literal $(, $x:expr)* $(,)?) => {
|
|
#[cfg(feature = "defmt")]
|
|
::defmt::error!($s $(, $x)*);
|
|
#[cfg(feature = "log")]
|
|
::log::error!($s $(, $x)*);
|
|
#[cfg(not(any(feature="defmt", feature="log")))]
|
|
let _ = ($( & $x ),*);
|
|
};
|
|
}
|