Something went wrong. Try again.
A RPi Pico powered Lightning Detector
Something went wrong. Try again.
1.8 kB · 67 lines
Rust
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768use core::num::TryFromIntError;
use alloc::collections::TryReserveError;use embassy_rp::rtc::RtcError;use sachy_sntp::SntpError;
#[derive(Debug)]#[cfg_attr(feature = "defmt", derive(defmt::Format))]pub enum PicoError { InvalidSntpTime(SntpError), InvalidRtcTime, AllocationError, NoisePayloadTooBig, TcpError(embassy_net::tcp::Error), CryptoProtoError,}
impl core::fmt::Display for PicoError { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { Self::InvalidSntpTime(reason) => write!(f, "Invalid SNTP time: {reason:?}"), Self::InvalidRtcTime => write!(f, "Invalid RTC time: Year is out of bounds"), Self::AllocationError => write!(f, "Failed to allocate memory"), Self::NoisePayloadTooBig => write!(f, "Invalid payload size"), Self::TcpError(error) => write!(f, "Network error: {error:?}"), Self::CryptoProtoError => write!(f, "Crypto protocol failure"), } }}
impl core::error::Error for PicoError {}
impl From<SntpError> for PicoError { fn from(value: SntpError) -> Self { Self::InvalidSntpTime(value) }}
impl From<RtcError> for PicoError { fn from(_value: RtcError) -> Self { Self::InvalidRtcTime }}
impl From<TryReserveError> for PicoError { fn from(_value: TryReserveError) -> Self { Self::AllocationError }}
impl From<TryFromIntError> for PicoError { fn from(_value: TryFromIntError) -> Self { Self::NoisePayloadTooBig }}
impl From<embassy_net::tcp::Error> for PicoError { fn from(value: embassy_net::tcp::Error) -> Self { Self::TcpError(value) }}
impl From<aead::Error> for PicoError { fn from(_value: aead::Error) -> Self { Self::CryptoProtoError }}