mirror of
				https://github.com/Djeeberjr/fw-anwesenheit.git
				synced 2025-11-04 07:34:10 +00:00 
			
		
		
		
	rtc will only setup with buildtime when it is larger then actual time in rtc
This commit is contained in:
		
							parent
							
								
									6f7561a295
								
							
						
					
					
						commit
						a04400a3a0
					
				@ -1,7 +1,6 @@
 | 
				
			|||||||
use chrono::{TimeZone, Utc};
 | 
					use chrono::{TimeZone, Utc};
 | 
				
			||||||
use ds3231::{
 | 
					use ds3231::{
 | 
				
			||||||
    Config, DS3231, InterruptControl, Oscillator, SquareWaveFrequency,
 | 
					    Config, DS3231, InterruptControl, Oscillator, SquareWaveFrequency, TimeRepresentation,
 | 
				
			||||||
    TimeRepresentation,
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use esp_hal::{
 | 
					use esp_hal::{
 | 
				
			||||||
    Async,
 | 
					    Async,
 | 
				
			||||||
@ -30,9 +29,7 @@ impl RTCClock {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    pub async fn get_time(&mut self) -> u64 {
 | 
					    pub async fn get_time(&mut self) -> u64 {
 | 
				
			||||||
        match self.dev.datetime().await {
 | 
					        match self.dev.datetime().await {
 | 
				
			||||||
            Ok(datetime) => {
 | 
					            Ok(datetime) => datetime.and_utc().timestamp() as u64,
 | 
				
			||||||
                datetime.and_utc().timestamp() as u64
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            Err(e) => {
 | 
					            Err(e) => {
 | 
				
			||||||
                FEEDBACK_STATE.signal(feedback::FeedbackState::Error);
 | 
					                FEEDBACK_STATE.signal(feedback::FeedbackState::Error);
 | 
				
			||||||
                error!("Failed to read RTC datetime: {:?}", e);
 | 
					                error!("Failed to read RTC datetime: {:?}", e);
 | 
				
			||||||
@ -67,11 +64,13 @@ pub async fn rtc_config(i2c: I2c<'static, Async>) -> DS3231<I2c<'static, Async>>
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if rtc.datetime().await.unwrap() < naive_dt {
 | 
				
			||||||
        rtc.set_datetime(&naive_dt).await.unwrap_or_else(|e| {
 | 
					        rtc.set_datetime(&naive_dt).await.unwrap_or_else(|e| {
 | 
				
			||||||
            FEEDBACK_STATE.signal(feedback::FeedbackState::Error);
 | 
					            FEEDBACK_STATE.signal(feedback::FeedbackState::Error);
 | 
				
			||||||
            error!("Failed to set RTC datetime: {:?}", e);
 | 
					            error!("Failed to set RTC datetime: {:?}", e);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        info!("RTC datetime set to: {}", naive_dt);
 | 
					        info!("RTC datetime set to: {}", naive_dt);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    match rtc.status().await {
 | 
					    match rtc.status().await {
 | 
				
			||||||
        Ok(mut status) => {
 | 
					        Ok(mut status) => {
 | 
				
			||||||
@ -84,6 +83,5 @@ pub async fn rtc_config(i2c: I2c<'static, Async>) -> DS3231<I2c<'static, Async>>
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        Err(e) => info!("Failed to read status: {:?}", e),
 | 
					        Err(e) => info!("Failed to read status: {:?}", e),
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    rtc
 | 
					    rtc
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user