pub fn read_rtc(&mut self, century_handler: CMOSCenturyHandler) -> RTCDateTime {
		// Note: This uses the "read registers until you get the same values twice in a row" technique to avoid getting
		// dodgy/inconsistent values due to RTC updates

		let mut century = 0;
		if let CMOSCenturyHandler::CenturyRegister(century_reg) = century_handler {
			century = self.read(century_reg);
		}

		let mut rtc_time = loop {
                        let prev = RTCDateTime::from_cmos(self);
                        let current = RTCDateTime::from_cmos(self);

                        if prev == current{break prev}
		};

		let register_b = self.read(0x0B);

		// Convert BCD to binary values if necessary
		if (register_b & 0x04) == 0 {
			rtc_time.second = Self::bcd_to_binary(rtc_time.second);
			rtc_time.minute = Self::bcd_to_binary(rtc_time.minute);
			rtc_time.hour = Self::bcd_to_binary(rtc_time.hour);
			rtc_time.day = Self::bcd_to_binary(rtc_time.day);
			rtc_time.month = Self::bcd_to_binary(rtc_time.month);
			rtc_time.year = Self::bcd_to_binary(rtc_time.year as u8) as usize;

			if let CMOSCenturyHandler::CenturyRegister(_) = century_handler {
				century = (century & 0x0F) + ((century / 16) * 10);
			}
		}

		// Convert 12 hour clock to 24 hour clock if necessary
		if ((register_b & 0x02) == 0) && ((rtc_time.hour & 0x80) != 0) {
			rtc_time.hour = ((rtc_time.hour & 0x7F) + 12) % 24;
		}

		// Calculate the full (4-digit) year
		match century_handler {
			CMOSCenturyHandler::CenturyRegister(_) => rtc_time.year += (century * 100) as usize,
			CMOSCenturyHandler::CurrentYear(current_year) => {
				rtc_time.year += (current_year / 100) * 100;
				if rtc_time.year < current_year {
					rtc_time.year += 100;
				}
			}
		}

		rtc_time
	}
/// Reads from the RTC part of CMOS
/// Returns an [`RTCDateTime`] struct, which includes all date time fields.
/// This method automatically converts BCD to binary values and 12 hours to 24 hour if necessary.
///
/// # Examples
/// ```rust,no_run
/// # use cmos::{CMOS, CMOSCenturyHandler};
/// let mut cmos = unsafe { CMOS::new() };
/// // Get current RTC by current year of 2019
/// let rtc = cmos.read_rtc(CMOSCenturyHandler::CurrentYear(2019));
/// ```
/// [`RTCDateTime`]: struct.RTCDateTime.html
Reads from the RTC part of CMOS
Returns an [`RTCDateTime`] struct, which includes all date time fields.
This method automatically converts BCD to binary values and 12 hours to 24 hour if necessary.
Reads from the RTC part of CMOS Returns an [ ` RTCDateTime ` ] struct which includes all date time fields . This method automatically converts BCD to binary values and 12 hours to 24 hour if necessary .
pub fn read_rtc(&mut self, century_handler: CMOSCenturyHandler) -> RTCDateTime {
		// Note: This uses the "read registers until you get the same values twice in a row" technique to avoid getting
		// dodgy/inconsistent values due to RTC updates
		let mut century = 0;
		if let CMOSCenturyHandler::CenturyRegister(century_reg) = century_handler {
			century = self.read(century_reg);
		}
		let mut rtc_time = loop {
                        let prev = RTCDateTime::from_cmos(self);
                        let current = RTCDateTime::from_cmos(self);
                        if prev == current{break prev}
		};
		let register_b = self.read(0x0B);
		// Convert BCD to binary values if necessary
		if (register_b & 0x04) == 0 {
			rtc_time.second = Self::bcd_to_binary(rtc_time.second);
			rtc_time.minute = Self::bcd_to_binary(rtc_time.minute);
			rtc_time.hour = Self::bcd_to_binary(rtc_time.hour);
			rtc_time.day = Self::bcd_to_binary(rtc_time.day);
			rtc_time.month = Self::bcd_to_binary(rtc_time.month);
			rtc_time.year = Self::bcd_to_binary(rtc_time.year as u8) as usize;
			if let CMOSCenturyHandler::CenturyRegister(_) = century_handler {
				century = (century & 0x0F) + ((century / 16) * 10);
			}
		}
		// Convert 12 hour clock to 24 hour clock if necessary
		if ((register_b & 0x02) == 0) && ((rtc_time.hour & 0x80) != 0) {
			rtc_time.hour = ((rtc_time.hour & 0x7F) + 12) % 24;
		}
		// Calculate the full (4-digit) year
		match century_handler {
			CMOSCenturyHandler::CenturyRegister(_) => rtc_time.year += (century * 100) as usize,
			CMOSCenturyHandler::CurrentYear(current_year) => {
				rtc_time.year += (current_year / 100) * 100;
				if rtc_time.year < current_year {
					rtc_time.year += 100;
				}
			}
		}
		rtc_time
	}
pub fn read_rtc ( & mut self , century_handler : CMOSCenturyHandler ) -> RTCDateTime { // Note: This uses the "read registers until you get the same values twice in a row" technique to avoid getting // dodgy/inconsistent values due to RTC updates let mut century = 0 ; if let CMOSCenturyHandler :: CenturyRegister ( century_reg ) = century_handler { century = self . read ( century_reg ) ; } let mut rtc_time = loop { let prev = RTCDateTime :: from_cmos ( self ) ; let current = RTCDateTime :: from_cmos ( self ) ; if prev == current { break prev } } ; let register_b = self . read ( 0x0B ) ; // Convert BCD to binary values if necessary if ( register_b & 0x04 ) == 0 { rtc_time . second = Self :: bcd_to_binary ( rtc_time . second ) ; rtc_time . minute = Self :: bcd_to_binary ( rtc_time . minute ) ; rtc_time . hour = Self :: bcd_to_binary ( rtc_time . hour ) ; rtc_time . day = Self :: bcd_to_binary ( rtc_time . day ) ; rtc_time . month = Self :: bcd_to_binary ( rtc_time . month ) ; rtc_time . year = Self :: bcd_to_binary ( rtc_time . year as u8 ) as usize ; if let CMOSCenturyHandler :: CenturyRegister ( _ ) = century_handler { century = ( century & 0x0F ) + ( ( century / 16 ) * 10 ) ; } } // Convert 12 hour clock to 24 hour clock if necessary if ( ( register_b & 0x02 ) == 0 ) && ( ( rtc_time . hour & 0x80 ) != 0 ) { rtc_time . hour = ( ( rtc_time . hour & 0x7F ) + 12 ) % 24 ; } // Calculate the full (4-digit) year match century_handler { CMOSCenturyHandler :: CenturyRegister ( _ ) => rtc_time . year += ( century * 100 ) as usize , CMOSCenturyHandler :: CurrentYear ( current_year ) => { rtc_time . year += ( current_year / 100 ) * 100 ; if rtc_time . year < current_year { rtc_time . year += 100 ; } } } rtc_time }
Reads from the RTC part of CMOS
Returns an [`RTCDateTime`] struct, which includes all date time fields.
Reads from the RTC part of CMOS Returns an [ ` RTCDateTime ` ] struct which includes all date time fields .
&mut self
century_handler
CMOSCenturyHandler
&mut self
century_handler
CMOSCenturyHandler
examples
None
use cmos::{cmos, cmoscenturyhandler};
let mut cmos = unsafe { CMOS::new() };
Get current RTC by current year of 2019
let rtc = cmos.read_rtc(CMOSCenturyHandler::CurrentYear(2019));
```
[`RTCDateTime`]: struct.RTCDateTime.html
let mut cmos = unsafe { CMOS :: new () } ; Get current RTC by current year of 2019 let rtc = cmos . read_rtc ( CMOSCenturyHandler :: CurrentYear ( 2019 )) ; ` ` ` [ ` RTCDateTime ` ] : struct . RTCDateTime . html