A RPi Pico powered Lightning Detector
at main 1.1 kB view raw
1use alloc::collections::TryReserveError; 2use embassy_rp::rtc::RtcError; 3use sachy_sntp::SntpError; 4 5#[derive(Debug)] 6#[cfg_attr(feature = "defmt", derive(defmt::Format))] 7pub enum PicoError { 8 InvalidSntpTime(SntpError), 9 InvalidRtcTime, 10 AllocationError, 11} 12 13impl core::fmt::Display for PicoError { 14 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 15 match self { 16 PicoError::InvalidSntpTime(reason) => write!(f, "Invalid SNTP time: {reason:?}"), 17 PicoError::InvalidRtcTime => write!(f, "Invalid RTC time: Year is out of bounds"), 18 PicoError::AllocationError => write!(f, "Failed to allocate memory"), 19 } 20 } 21} 22 23impl core::error::Error for PicoError {} 24 25impl From<SntpError> for PicoError { 26 fn from(value: SntpError) -> Self { 27 Self::InvalidSntpTime(value) 28 } 29} 30 31impl From<RtcError> for PicoError { 32 fn from(_value: RtcError) -> Self { 33 Self::InvalidRtcTime 34 } 35} 36 37impl From<TryReserveError> for PicoError { 38 fn from(_value: TryReserveError) -> Self { 39 Self::AllocationError 40 } 41}