public async Task SetAsync(DateTimeOffset value) { byte[] writeBuffer = new byte[] { RTC_ADDRESS, Bcd.FromInt(value.Second), Bcd.FromInt(value.Minute), Bcd.FromInt(value.Hour), Bcd.FromInt((int)value.DayOfWeek), Bcd.FromInt(value.Day), Bcd.FromInt(value.Month), Bcd.FromInt(value.Year >= 2000 ? value.Year - 2000: 0), }; await this.WriteAsync(writeBuffer); }
private async Task TestClock() { // *** // *** Clock // *** Ds1307 dtc = new Ds1307(); await dtc.InitializeAsync(); // *** // *** Get the date and time from the clock // *** DateTimeOffset dt = await dtc.GetAsync(); // *** // *** Create an NTP client and get the date and time // *** NtpClient ntp = new NtpClient(); DateTimeOffset? ndt = await ntp.GetAsync("0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org", "3.pool.ntp.org"); // *** // *** Update the clock if we have a result from the servers // *** if (ndt.HasValue) { await dtc.SetAsync(ndt.Value); } }