本文整理汇总了Python中utime.mktime方法的典型用法代码示例。如果您正苦于以下问题:Python utime.mktime方法的具体用法?Python utime.mktime怎么用?Python utime.mktime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utime
的用法示例。
在下文中一共展示了utime.mktime方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert
# 需要导入模块: import utime [as 别名]
# 或者: from utime import mktime [as 别名]
def convert(self, set_rtc=False): # Return a tuple in localtime() format (less yday)
data = self.timebuf
ss = bcd2dec(data[0])
mm = bcd2dec(data[1])
if data[2] & 0x40:
hh = bcd2dec(data[2] & 0x1f)
if data[2] & 0x20:
hh += 12
else:
hh = bcd2dec(data[2])
wday = data[3]
DD = bcd2dec(data[4])
MM = bcd2dec(data[5] & 0x1f)
YY = bcd2dec(data[6])
if data[5] & 0x80:
YY += 2000
else:
YY += 1900
# Time from DS3231 in time.localtime() format (less yday)
result = YY, MM, DD, hh, mm, ss, wday -1, 0
if set_rtc:
if rtc is None:
# Best we can do is to set local time
secs = utime.mktime(result)
utime.localtime(secs)
else:
rtc.datetime((YY, MM, DD, wday, hh, mm, ss, 0))
return result
示例2: rtc_test
# 需要导入模块: import utime [as 别名]
# 或者: from utime import mktime [as 别名]
def rtc_test(self, runtime=600, ppm=False, verbose=True):
if rtc is None:
raise RuntimeError('machine.RTC does not exist')
verbose and print('Waiting {} minutes for result'.format(runtime//60))
factor = 1_000_000 if ppm else 114_155_200 # seconds per year
self.await_transition() # Start on transition of DS3231. Record time in .timebuf
t = utime.ticks_ms() # Get system time now
ss = rtc.datetime()[6] # Seconds from system RTC
while ss == rtc.datetime()[6]:
pass
ds = utime.ticks_diff(utime.ticks_ms(), t) # ms to transition of RTC
ds3231_start = utime.mktime(self.convert()) # Time when transition occurred
t = rtc.datetime()
rtc_start = utime.mktime((t[0], t[1], t[2], t[4], t[5], t[6], t[3] - 1, 0)) # y m d h m s wday 0
utime.sleep(runtime) # Wait a while (precision doesn't matter)
self.await_transition() # of DS3231 and record the time
t = utime.ticks_ms() # and get system time now
ss = rtc.datetime()[6] # Seconds from system RTC
while ss == rtc.datetime()[6]:
pass
de = utime.ticks_diff(utime.ticks_ms(), t) # ms to transition of RTC
ds3231_end = utime.mktime(self.convert()) # Time when transition occurred
t = rtc.datetime()
rtc_end = utime.mktime((t[0], t[1], t[2], t[4], t[5], t[6], t[3] - 1, 0)) # y m d h m s wday 0
d_rtc = 1000 * (rtc_end - rtc_start) + de - ds # ms recorded by RTC
d_ds3231 = 1000 * (ds3231_end - ds3231_start) # ms recorded by DS3231
ratio = (d_ds3231 - d_rtc) / d_ds3231
ppm = ratio * 1_000_000
verbose and print('DS3231 leads RTC by {:4.1f}ppm {:4.1f}mins/yr'.format(ppm, ppm*1.903))
return ratio * factor
示例3: getcal
# 需要导入模块: import utime [as 别名]
# 或者: from utime import mktime [as 别名]
def getcal(self, minutes=5, cal=0, verbose=True):
if d_series:
return self._getcal_d(minutes, cal, verbose)
verbose and print('Pyboard 1.x. Waiting {} minutes for calibration factor.'.format(minutes))
rtc.calibration(cal) # Clear existing cal
self.save_time() # Set DS3231 from RTC
self.await_transition() # Wait for DS3231 to change: on a 1 second boundary
tus = utime.ticks_us()
st = rtc.datetime()[7]
while rtc.datetime()[7] == st: # Wait for RTC to change
pass
t1 = utime.ticks_diff(utime.ticks_us(), tus) # t1 is duration (μs) between DS and RTC change (start)
rtcstart = get_ms(rtc.datetime()) # RTC start time in mS
dsstart = utime.mktime(self.convert()) # DS start time in secs as recorded by await_transition
utime.sleep(minutes * 60)
self.await_transition() # DS second boundary
tus = utime.ticks_us()
st = rtc.datetime()[7]
while rtc.datetime()[7] == st:
pass
t2 = utime.ticks_diff(utime.ticks_us(), tus) # t2 is duration (μs) between DS and RTC change (end)
rtcend = get_ms(rtc.datetime())
dsend = utime.mktime(self.convert())
dsdelta = (dsend - dsstart) * 1000000 # Duration (μs) between DS edges as measured by DS3231
if rtcend < rtcstart: # It's run past midnight. Assumption: run time < 1 day!
rtcend += 24 * 3_600_000
rtcdelta = (rtcend - rtcstart) * 1000 + t1 - t2 # Duration (μs) between DS edges as measured by RTC and corrected
ppm = (1000000* (rtcdelta - dsdelta))/dsdelta
if cal:
verbose and print('Error {:4.1f}ppm {:4.1f}mins/year.'.format(ppm, ppm * 1.903))
return 0
cal = int(-ppm / 0.954)
verbose and print('Error {:4.1f}ppm {:4.1f}mins/year. Cal factor {}'.format(ppm, ppm * 1.903, cal))
return cal
# Version for Pyboard D. This has μs resolution.
示例4: _getcal_d
# 需要导入模块: import utime [as 别名]
# 或者: from utime import mktime [as 别名]
def _getcal_d(self, minutes, cal, verbose):
verbose and print('Pyboard D. Waiting {} minutes for calibration factor.'.format(minutes))
rtc.calibration(cal) # Clear existing cal
self.save_time() # Set DS3231 from RTC
self.await_transition() # Wait for DS3231 to change: on a 1 second boundary
t = rtc.datetime() # Get RTC time
# Time of DS3231 transition measured by RTC in μs since start of day
rtc_start_us = get_us(t)
dsstart = utime.mktime(self.convert()) # DS start time in secs
utime.sleep(minutes * 60)
self.await_transition() # Wait for DS second boundary
t = rtc.datetime()
# Time of DS3231 transition measured by RTC in μs since start of day
rtc_end_us = get_us(t)
dsend = utime.mktime(self.convert()) # DS end time in secs
if rtc_end_us < rtc_start_us: # It's run past midnight. Assumption: run time < 1 day!
rtc_end_us += 24 * 3_600_000_000
dsdelta = (dsend - dsstart) * 1_000_000 # Duration (μs) between DS3231 edges as measured by DS3231
rtcdelta = rtc_end_us - rtc_start_us # Duration (μs) between DS edges as measured by RTC
ppm = (1_000_000 * (rtcdelta - dsdelta)) / dsdelta
if cal: # We've already calibrated. Just report results.
verbose and print('Error {:4.1f}ppm {:4.1f}mins/year.'.format(ppm, ppm * 1.903))
return 0
cal = int(-ppm / 0.954)
verbose and print('Error {:4.1f}ppm {:4.1f}mins/year. Cal factor {}'.format(ppm, ppm * 1.903, cal))
return cal
示例5: delta
# 需要导入模块: import utime [as 别名]
# 或者: from utime import mktime [as 别名]
def delta(self): # Return no. of mS RTC leads DS3231
self.await_transition()
rtc_ms = now()
t_ds3231 = utime.mktime(self.get_time()) # To second precision, still in same sec as transition
return rtc_ms - 1000 * t_ds3231
示例6: get_localtime
# 需要导入模块: import utime [as 别名]
# 或者: from utime import mktime [as 别名]
def get_localtime(raw=False):
import utime
localtime = utime.localtime()
if raw:
return utime.mktime(localtime)
else:
return DateTimeCmd.datetime_str(localtime)
示例7: secs_since_midnight
# 需要导入模块: import utime [as 别名]
# 或者: from utime import mktime [as 别名]
def secs_since_midnight(localtime) :
secs = utime.mktime(localtime)
return secs - Scheduler.midnight_epoch_secs(localtime)
示例8: midnight_epoch_secs
# 需要导入模块: import utime [as 别名]
# 或者: from utime import mktime [as 别名]
def midnight_epoch_secs(localtime) :
(year, month, mday, hour, minute, second, wday, yday) = localtime
return utime.mktime((year, month, mday, 0, 0, 0, wday, yday))
示例9: date
# 需要导入模块: import utime [as 别名]
# 或者: from utime import mktime [as 别名]
def date(secs=False):
localtime = utime.localtime()
if secs:
print(utime.mktime(localtime))
else:
print(core.util.localtime_to_string(localtime))
示例10: _get_rtc_usecs
# 需要导入模块: import utime [as 别名]
# 或者: from utime import mktime [as 别名]
def _get_rtc_usecs(self):
y, m, d, weekday, hrs, mins, secs, subsecs = rtc.datetime()
tim = 1000000 * utime.mktime((y, m, d, hrs, mins, secs, weekday - 1, 0))
return tim + ((1000000 * (255 - subsecs)) >> 8)
# Return no. of μs RTC leads GPS. Done by comparing times at the instant of
# PPS leading edge.
示例11: shutoff
# 需要导入模块: import utime [as 别名]
# 或者: from utime import mktime [as 别名]
def shutoff(self):
""" shut off the MCU """
import DS3231tokei
import utime
from machine import Pin, RTC
bus = self.sensor_manager.get_bus_by_sensortype('DS3231')
ds = DS3231tokei.DS3231(bus.adapter)
interval = self.settings.get('main.interval.shutoff', 10) * 60 # convert from minutes to seconds
(year,month,day,dotw,hour,minute,second) = ds.getDateTime() # get the current time
rtc = RTC() # create RTC
if year < 2001:
year = 2001 # sanity check, as of mpy 1.12 year must be >= 2001
rtc.init((year,month,day,dotw,hour,minute,second,0)) # set time
# check if its night or winter and adjust interval
night_start = self.settings.get('main.interval.night_start', 0)
night_end = self.settings.get('main.interval.night_end', 0)
winter_start = self.settings.get('main.interval.winter_start', 0)
winter_end = self.settings.get('main.interval.winter_end', 0)
if night_start > 0 and (hour >= night_start or hour <= night_end): # double interval for the night
interval *= 2
if winter_start > 0 and (month >= winter_start or month <= winter_end): # double interval for winter
interval *= 2
# Compute sleeping duration from measurement interval and elapsed time.
elapsed = int(self.duty_chrono.read())
now_secs = utime.mktime(utime.localtime())
wake_at = now_secs - elapsed + interval
if (wake_at - now_secs) < 180: # don't shutoff for less than 3 minutes
wake_at += interval
(year,month,day,hour,minute,second, dotw, doty) = utime.localtime(wake_at) # convert the wake up time
# set alarm
ds.setAlarm2(day,hour,minute, DS3231tokei.A2_ON_HOUR_MINUTE)
# turn off MCU via MOSFET
utime.sleep(1)
ds.enableAlarm2()
ds.resetAlarm2()
# The End