本文整理汇总了Python中pyb.RTC属性的典型用法代码示例。如果您正苦于以下问题:Python pyb.RTC属性的具体用法?Python pyb.RTC怎么用?Python pyb.RTC使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pyb
的用法示例。
在下文中一共展示了pyb.RTC属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_rtc
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import RTC [as 别名]
def _do_rtc(self):
lnk = self._lnk
lnk.vbprint('Start RTC synchroniser')
self._time_valid = not self._rtc_last_syn == 0 # Valid on restart
while True:
while not self._time_valid:
lnk.channel.send(TIME)
# Give 5s time for response
await asyn.sleep(5)
if not self._time_valid:
# WiFi may be down. Delay 1 min before retry.
await asyn.sleep(60)
else: # Valid time received or restart
if self._rtc_interval < 0:
break # One resync only: done
tend = self._rtc_last_syn + self._rtc_interval
twait = max(tend - time(), 5) # Prolonged outage
await asyn.sleep(twait)
self._time_valid = False
示例2: _do_time
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import RTC [as 别名]
def _do_time(self, action): # TIME received from ESP8266
lnk = self._lnk
try:
t = int(action[0])
except ValueError: # Gibberish.
lnk.quit('Invalid data from ESP8266')
return
self._time_valid = t > 0
if self._time_valid:
rtc = pyb.RTC()
tm = localtime(t)
hours = (tm[3] + self._local_time_offset) % 24
tm = tm[0:3] + (tm[6] + 1,) + (hours,) + tm[4:6] + (0,)
rtc.datetime(tm)
self._rtc_last_syn = time()
lnk.vbprint('time', localtime())
else:
lnk.vbprint('Bad time received.')
# Is Pyboard RTC synchronised?
示例3: __init__
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import RTC [as 别名]
def __init__(self, *args, **kwargs):
super(BlueSTProtocol, self).__init__(*args, **kwargs)
self.rtc = pyb.RTC()
self.rtc.init()
self.rtc.calibration(-129)
self.rtc.datetime((2017, 10, 6, 5, 16, 41, 0, 0))
self.bdaddr = bytes(reversed([0x12, 0x34, 0x00, 0xE1, 0x80, 0x02]))
self.name = b'PyBLE'
self.connection_handle = None
self.service_handle = None
self.dev_name_char_handle = None
self.appearance_char_handle = None
self.hw_serv_handle = None
self.acc_gyro_mag_bluest_char_handle = None
self.pressure_bluest_char_handle = None
self.temperature_bluest_char_handle = None
self.pwr_bluest_char_handle = None
示例4: _run
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import RTC [as 别名]
def _run(self):
print('Low power mode is ON.')
rtc = pyb.RTC()
rtc.wakeup(self._t_ms)
t_ms = self._t_ms
while True:
if t_ms > 0:
pyb.stop()
# Pending tasks run once, may change self._t_ms
yield
if t_ms != self._t_ms: # Has changed: update wakeup
t_ms = self._t_ms
if t_ms > 0:
rtc.wakeup(t_ms)
else:
rtc.wakeup(None)
示例5: calibrate
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import RTC [as 别名]
def calibrate(self, minutes=5):
if not on_pyboard:
raise OSError('Only available on STM targets.')
print('Waiting for GPS startup.')
await self.ready()
print('Waiting up to {} minutes to acquire calibration factor...'.format(minutes))
cal = await self._getcal(minutes)
if cal <= 512 and cal >= -511:
rtc.calibration(cal)
print('Pyboard RTC is calibrated. Factor is {:d}.'.format(cal))
else:
print('Calibration factor {:d} is out of range.'.format(cal))
# User interface functions: accurate GPS time.
# Return GPS time in ms since midnight (small int on 32 bit h/w).
# No allocation.
示例6: do_set_time
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import RTC [as 别名]
def do_set_time(self, line):
args = split_line(line)
if (len(args) != 6):
self.stderr.write('Expecting 6 arguments in the order: YYYY MM DD HH MM SS\n')
return
try:
(year, month, day, hours, minutes, seconds) = [int(arg) for arg in args]
except:
self.stderr.write("Expecting numeric arguments\n")
return
# Run the date through mktime and back through localtime so that we
# get a normalized date and time, and calculate the weekday
t = time.mktime((year, month, day, hours, minutes, seconds, 0, 0, -1))
(year, month, day, hours, minutes, seconds, weekday, yearday) = time.localtime(t)
rtc = pyb.RTC()
# localtime weekday is 0-6, Monday is 0
# RTC weekday is 1-7, Monday is 1
rtc.datetime((year, month, day, weekday + 1, hours, minutes, seconds, 0))
self.stdout.write(ctime(time.time()))
示例7: default_status_handler
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import RTC [as 别名]
def default_status_handler(mqtt_link, status):
await asyncio.sleep_ms(0)
if status == SPECNET:
if mqtt_link.first_run:
mqtt_link.first_run = False
return 1 # By default try specified network on 1st run only
asyncio.sleep(30) # Pause before reboot.
return 0
# Optionally synch the Pyboard's RTC to an NTP timeserver. When instantiated
# is idle bar reporting synch status. _start runs _do_rtc coro if required.
示例8: command
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import RTC [as 别名]
def command(self, *argsend):
self.channel.send(argformat(*argsend))
# Is Pyboard RTC synchronised?
示例9: set_time
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import RTC [as 别名]
def set_time(rtc_time):
rtc = None
try:
# Pyboard (pyboard doesn't have machine.RTC()).
# The pyb.RTC.datetime function takes the arguments in the order:
# (year, month, day, weekday, hour, minute, second, subseconds)
# http://docs.micropython.org/en/latest/library/pyb.RTC.html#pyb.RTC.datetime
import pyb
rtc = pyb.RTC()
rtc.datetime(rtc_time)
except:
try:
import pycom
# PyCom's machine.RTC takes its arguments in a slightly different order
# than the official machine.RTC.
# (year, month, day, hour, minute, second[, microsecond[, tzinfo]])
# https://docs.pycom.io/firmwareapi/pycom/machine/rtc/#rtc-init-datetime-none-source-rtc-internal-rc
rtc_time2 = (rtc_time[0], rtc_time[1], rtc_time[2], rtc_time[4], rtc_time[5], rtc_time[6])
import machine
rtc = machine.RTC()
rtc.init(rtc_time2)
except:
try:
# The machine.RTC documentation was incorrect and doesn't agree with the code, so no link
# is presented here. The order of the arguments is the same as the pyboard.
import machine
rtc = machine.RTC()
try:
# ESP8266 uses rtc.datetime() rather than rtc.init()
rtc.datetime(rtc_time)
except:
# ESP32 (at least Loboris port) uses rtc.init()
rtc.init(rtc_time)
except:
pass
# 0x0D's sent from the host get transformed into 0x0A's, and 0x0A sent to the
# host get converted into 0x0D0A when using sys.stdin. sys.tsin.buffer does
# no transformations, so if that's available, we use it, otherwise we need
# to use hexlify in order to get unaltered data.
示例10: main
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import RTC [as 别名]
def main(loop):
rtc = RTC()
red = LED(1)
red.on()
grn = LED(2)
sta_if = network.WLAN()
sta_if.active(True)
sta_if.connect(SSID, PW)
while sta_if.status() in (1, 2): # https://github.com/micropython/micropython/issues/4682
await asyncio.sleep(1)
grn.toggle()
if sta_if.isconnected():
red.off()
grn.on()
await asyncio.sleep(1) # 1s of green == success.
grn.off() # Conserve power
Latency(2000)
count = 0
while True:
print('Publish')
publish(ujson.dumps([count, rtc.datetime()]))
count += 1
print('Wait 2 mins')
await asyncio.sleep(120) # 2 mins
else: # Fail to connect
red.on()
grn.off()
示例11: setup
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import RTC [as 别名]
def setup(self, pps_pin, pps_cb, pps_cb_args):
self._pps_pin = pps_pin
self._pps_cb = pps_cb
self._pps_cb_args = pps_cb_args
self.msecs = None # Integer time in ms since midnight at last PPS
self.t_ms = 0 # ms since midnight
self.acquired = None # Value of ticks_us at edge of PPS
self._rtc_set = False # Set RTC flag
self._rtcbuf = [0]*8 # Buffer for RTC setting
self._time = [0]*4 # get_t_split() time buffer.
asyncio.create_task(self._start())
示例12: close
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import RTC [as 别名]
def close(self):
self._pps_pin.irq(None)
# If update rate > 1Hz, when PPS edge occurs the last RMC message will have
# a nonzero ms value. Need to set RTC to 1 sec after the last 1 second boundary
示例13: _isr
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import RTC [as 别名]
def _isr(self, _):
acquired = utime.ticks_us() # Save time of PPS
# Time in last NMEA sentence was time of last PPS.
# Reduce to integer secs since midnight local time.
isecs = (self.epoch_time + int(3600*self.local_offset)) % 86400
# ms since midnight (28 bits). Add in any ms in RMC data
msecs = isecs * 1000 + self.msecs
# This PPS is presumed to be one update later
msecs += self._update_ms
if msecs >= 86400000: # Next PPS will deal with rollover
return
if self.t_ms == msecs: # No RMC message has arrived: nothing to do
return
self.t_ms = msecs # Current time in ms past midnight
self.acquired = acquired
# Set RTC if required and if last RMC indicated a 1 second boundary
if self._rtc_set:
# Time as int(seconds) in last NMEA sentence. Earlier test ensures
# no rollover when we add 1.
self._rtcbuf[6] = (isecs + 1) % 60
rtc.datetime(self._rtcbuf)
self._rtc_set = False
# Could be an outage here, so PPS arrives many secs after last sentence
# Is this right? Does PPS continue during outage?
self._pps_cb(self, *self._pps_cb_args)
# Called when base class updates the epoch_time.
# Need local time for setting Pyboard RTC in interrupt context
示例14: set_rtc
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import RTC [as 别名]
def set_rtc(self):
if not on_pyboard:
raise OSError('Only available on STM targets.')
self._rtc_set = True
while self._rtc_set:
await asyncio.sleep_ms(250)
# Value of RTC time at current instant. This is a notional arbitrary
# precision integer in μs since Y2K. Notional because RTC is set to
# local time.
示例15: _get_rtc_usecs
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import RTC [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.