kopia lustrzana https://github.com/peterhinch/micropython-samples
DS3231/ds3231_port fixed for official ESP32 firmware.
rodzic
4d2a52d109
commit
e2fc55740e
|
@ -9,17 +9,10 @@ import machine
|
|||
import sys
|
||||
DS3231_I2C_ADDR = 104
|
||||
|
||||
class DS3231Exception(OSError):
|
||||
pass
|
||||
|
||||
if sys.platform == 'pyboard':
|
||||
import pyb
|
||||
rtc = pyb.RTC()
|
||||
else:
|
||||
try:
|
||||
rtc = machine.RTC()
|
||||
except: # Official ESP32 port
|
||||
print('warning: machine module does not support the RTC.')
|
||||
except:
|
||||
print('Warning: machine module does not support the RTC.')
|
||||
rtc = None
|
||||
|
||||
def bcd2dec(bcd):
|
||||
|
@ -37,7 +30,7 @@ class DS3231:
|
|||
self.ds3231 = i2c
|
||||
self.timebuf = bytearray(7)
|
||||
if DS3231_I2C_ADDR not in self.ds3231.scan():
|
||||
raise DS3231Exception("DS3231 not found on I2C bus at %d" % DS3231_I2C_ADDR)
|
||||
raise RuntimeError("DS3231 not found on I2C bus at %d" % DS3231_I2C_ADDR)
|
||||
|
||||
def get_time(self, set_rtc=False):
|
||||
if set_rtc:
|
||||
|
@ -72,10 +65,7 @@ class DS3231:
|
|||
secs = utime.mktime(result)
|
||||
utime.localtime(secs)
|
||||
else:
|
||||
if sys.platform == 'pyboard' or sys.platform == 'esp8266':
|
||||
rtc.datetime((YY, MM, DD, wday, hh, mm, ss, 0))
|
||||
else:
|
||||
rtc.init((YY, MM, DD, hh, mm, ss))
|
||||
return result
|
||||
|
||||
def save_time(self):
|
||||
|
|
Ładowanie…
Reference in New Issue