当前位置: 首页>>代码示例>>Python>>正文


Python time.ticks_ms方法代码示例

本文整理汇总了Python中time.ticks_ms方法的典型用法代码示例。如果您正苦于以下问题:Python time.ticks_ms方法的具体用法?Python time.ticks_ms怎么用?Python time.ticks_ms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在time的用法示例。


在下文中一共展示了time.ticks_ms方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fixed

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_ms [as 别名]
def fixed(self):
        """fixed yet? returns true or false"""
        nmea_message = self.lastmessage
        pm = fs = False
        if nmea_message != {}:
            if nmea_message['NMEA'][2:] in ('RMC', 'GLL'):  # 'VTG',
                pm = nmea_message['PositioningMode'] != 'N'
            if nmea_message['NMEA'][2:] in ('GGA',):  # 'GSA'
                fs = int(nmea_message['FixStatus']) >= 1
        if pm or fs:
            self.fix = True
            self.timeLastFix = int(time.ticks_ms() / 1000)
            self.Latitude = nmea_message['Latitude']
            self.Longitude = nmea_message['Longitude']
        else:
            self.fix = False
            self.timeLastFix = 0xffffffff
            self.Latitude = None
            self.Longitude = None
            self.ttf = -1
        return self.fix 
开发者ID:andrethemac,项目名称:L76GLNSV4,代码行数:23,代码来源:L76GNSV4.py

示例2: publish

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_ms [as 别名]
def publish(self, topic, msg, retain=False, qos=0, timeout=None):
        task = None
        start = time.ticks_ms()
        while timeout is None or time.ticks_diff(time.ticks_ms(), start) < timeout:
            # Can't use wait_for because cancelling a wait_for would cancel _publishTimeout
            # Also a timeout in wait_for would cancel _publishTimeout without waiting for
            # the socket lock to be available, breaking mqtt protocol.
            if self._pub_task is None and task is None:
                task = asyncio.create_task(self._publishTimeout(topic, msg, retain, qos))
                self._pub_task = task
            elif task is not None:
                if self._pub_task != task:
                    return  # published
            await asyncio.sleep_ms(20)
        if task is not None:
            async with self.lock:
                task.cancel()
                return 
开发者ID:peterhinch,项目名称:micropython-mqtt,代码行数:20,代码来源:mqtt_as_timeout.py

示例3: _update

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_ms [as 别名]
def _update(self):
        if time.ticks_ms() - self.time > 100:
            self.time = time.ticks_ms()
            try:
                data = self.i2c.readfrom(self._addr, 2)
                if data[0] == 0:
                    pass
                elif data[0] > 127:
                    self.encode_value += data[0] - 256
                    self.dir = 1
                else:
                    self.encode_value += data[0]
                    self.dir = 0
                self.press = data[1]
            except:
                pass 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:18,代码来源:_encode.py

示例4: __init__

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_ms [as 别名]
def __init__(self, client_id, server, port, user=None, password=None, keepalive=300):
        if m5base.get_start() != 1:
            autoConnect(lcdShow=True)
            lcd.clear()
        else:
            raise ImportError('mqtt need download...')

        if user == '':
            user = None
        
        if password == '':
            password = None

        self.mqtt = MQTTClient(client_id, server, port, user, password, keepalive)
        self.mqtt.set_callback(self._on_data)
        try:
            self.mqtt.connect()
        except:
            lcd.clear()
            lcd.font(lcd.FONT_DejaVu24)
            lcd.setTextColor(lcd.RED)
            lcd.print('connect fail', lcd.CENTER, 100)
        self.topic_callback = {}
        self.mqttState = True
        self.ping_out_time = time.ticks_ms() + 60000 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:27,代码来源:m5mqtt.py

示例5: check

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_ms [as 别名]
def check(self):
        current_time = time.ticks_ms()
        deadline = time.ticks_add(self.last_measurement, self.interval)
        if ((time.ticks_diff(deadline, current_time) <= 0) or (self.iterations == 0)):
            self.measure()
            self.iterations += 1
            self.last_measurement = current_time

# the following function, when added to the google sheet (Tools > Script editor) allows the
# formula uploaded in the "now" variable (see "measure(self)") to calculate a local timestamp
# from the epoch value loaded in column A of the inserted row
#
#function TIMESTAMP_TO_DATE(value) {
#  return new Date(value * 1000);
#}
# see the sheets.py file to set the ValueInputOption to USER_INPUT to avoid now string value being prefixed with a ' 
开发者ID:artem-smotrakov,项目名称:esp32-weather-google-sheets,代码行数:18,代码来源:weather.py

示例6: push_sorted

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_ms [as 别名]
def push_sorted(self, v, data):
        v.data = data

        if ticks_diff(data, ticks()) <= 0:
            cur = self.last
            if cur and ticks_diff(data, cur.data) >= 0:
                # Optimisation: can start looking from self.last to insert this item
                while cur.next and ticks_diff(data, cur.next.data) >= 0:
                    cur = cur.next
                v.next = cur.next
                cur.next = v
                self.last = cur
                return

        cur = self
        while cur.next and (not isinstance(cur.next.data, int) or ticks_diff(data, cur.next.data) >= 0):
            cur = cur.next
        v.next = cur.next
        cur.next = v
        if cur is not self:
            self.last = cur 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:23,代码来源:__init__.py

示例7: button_press_callback

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_ms [as 别名]
def button_press_callback(pin):
    global last_button_press_time
    # block button press as software debounce
    if last_button_press_time < time.ticks_ms():
        
        # add 150ms delay between button presses... might be too much, we'll see!
        last_button_press_time = time.ticks_ms() + 150

        # If the pin is in the callback handler dictionary, call the appropriate function 
        if str(pin) in button_handlers:
            button_handlers[str(pin)]()
    # else:
    #     # print a debug message if button presses were too quick or a dounce happened
    #     print("Button Bounce - {}ms".format( ( last_button_press_time - time.ticks_ms() ) ) )

# Create all of the triggers for each button pointing to the single callback handler 
开发者ID:tinypico,项目名称:tinypico-micropython,代码行数:18,代码来源:main.py

示例8: convert_accell_rotation

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_ms [as 别名]
def convert_accell_rotation( vec ):
    x_Buff = vec[0] # x
    y_Buff = vec[1] # y
    z_Buff = vec[2] # z

    global last_convert_time, convert_interval, roll, pitch

    # We only want to re-process the values every 100 ms
    if last_convert_time < time.ticks_ms():
        last_convert_time = time.ticks_ms() + convert_interval

        roll = math.atan2(y_Buff , z_Buff) * 57.3
        pitch = math.atan2((- x_Buff) , math.sqrt(y_Buff * y_Buff + z_Buff * z_Buff)) * 57.3

    # Return the current values in roll and pitch
    return ( roll, pitch )

# If we have found the LIS3DH 
开发者ID:tinypico,项目名称:tinypico-micropython,代码行数:20,代码来源:example.py

示例9: _wait_off

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_ms [as 别名]
def _wait_off(self):
        print("wait_off started")
        st = time.ticks_ms()
        try:
            while time.ticks_ms() - st < self._on_time * 1000:
                await asyncio.sleep(1)
        except asyncio.CancelledError:
            self._log.debug("_wait_off canceled", local_only=True)
            print("wait_off canceled")
            return
        except Exception as e:
            await self._log.asyncLog("error", "wait_off error: {!s}".format(e))
            return False
        finally:
            print("wait_off exited")
        await super().on_message(self._topic, "OFF", False) 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:18,代码来源:rfpump.py

示例10: _repeating

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_ms [as 别名]
def _repeating(self):
        print("repeating started")
        self._repeating_mode = True
        try:
            while True:
                st = time.ticks_ms()
                await super().on_message(self._topic, "ON", False)
                while time.ticks_ms() - st < self._on_time * 1000:
                    await asyncio.sleep(1)
                await super().on_message(self._topic, "OFF", False)
                st = time.ticks_ms()
                while time.ticks_ms() - st < self._off_time * 1000:
                    await asyncio.sleep(1)
        except asyncio.CancelledError:
            print("repeating canceled")
            self._log.debug("_repeating canceled", local_only=True)
        except Exception as e:
            await self._log.asyncLog("error", "_repeating error: {!s}".format(e))
        finally:
            await super().on_message(self._topic, "OFF", False)
            self._repeating_mode = False
            print("repeating exited") 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:24,代码来源:rfpump.py

示例11: _loop

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_ms [as 别名]
def _loop(self):
        mqtt = config.getMQTT()
        mqtt.registerWifiCallback(self._wifiChanged)
        mqtt.registerConnectedCallback(self._reconnected)
        await self._flash(500, 1)
        sta = network.WLAN(network.STA_IF)
        st = time.ticks_ms()
        while True:
            while self._next:
                await self._flash(*self._next.pop(0))
                await asyncio.sleep(1)
            if time.ticks_diff(time.ticks_ms(), st) > 60000:  # heartbeat
                st = time.ticks_ms()
                if sta.isconnected():
                    await self._flash(20, 1)
                    await asyncio.sleep_ms(250)
                    await self._flash(20, 1)
                else:
                    await self._flash(500, 3)
            await asyncio.sleep_ms(500) 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:22,代码来源:wifi_led.py

示例12: __bell

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_ms [as 别名]
def __bell(self):
        while True:
            await self._event_bell
            diff = time.ticks_diff(time.ticks_ms(), self._last_activation)
            if diff > 10000:
                _log.error("Bell rang {!s}s ago, not activated ringing".format(diff / 1000))
                self._event_bell.clear()
                return
            else:
                on = await _mqtt.publish(self.topic(), "ON", qos=1, timeout=2,
                                         await_connection=False)
                await asyncio.sleep_ms(self._on_time)
                await _mqtt.publish(self.topic(), "OFF", qos=1, retain=True, await_connection=on)
                if config.RTC_SYNC_ACTIVE:
                    t = time.localtime()
                    await _mqtt.publish(_mqtt.getDeviceTopic("last_bell"),
                                        "{}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}".format(t[0], t[1],
                                                                                       t[2], t[3],
                                                                                       t[4], t[5]),
                                        qos=1, retain=True, timeout=2, await_connection=False)
                self._event_bell.clear()
                if diff > 500:
                    _log.warn("Bell rang {!s}ms ago, activated ringing".format(diff)) 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:25,代码来源:bell.py

示例13: _remoteTemp

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_ms [as 别名]
def _remoteTemp(self, topic, msg, retain):
        if retain:
            # a retained temperature value is of no use
            return
        if type(msg) == dict:
            if "temperature" in msg:
                msg = msg["temperature"]
            else:
                log.error("Dictionary has unsupported values")
                return
        try:
            msg = float(msg)
        except Exception as e:
            log.error("Can't convert remote temperature to float: {!s}".format(e))
            return
        self.__time = time.ticks_ms()
        self.__temp = msg
        log.debug("Got remote temp {!s}°C".format(msg), local_only=True) 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:20,代码来源:remoteTemperature.py

示例14: overwatch

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_ms [as 别名]
def overwatch(coro_name, threshold, asyncr=False):
    def func_wrapper(coro):
        if asyncr is True:
            raise TypeError("overwatch does not support coroutines")
            # as it makes not sense. a freeze would trigger every coroutine
        else:
            def wrapper(*args, **kwargs):
                startt = time.ticks_ms()
                res = coro(*args, **kwargs)
                if str(type(res)) == "<class 'generator'>":
                    _log.error("Coroutine in sync overwatch")
                endt = time.ticks_ms()
                diff = time.ticks_diff(endt, startt)
                if diff > threshold:
                    _log.error("Coro {!s} took {!s}ms, threshold {!s}ms".format(coro_name, diff, threshold))
                return res

            return wrapper

    return func_wrapper 
开发者ID:kevinkk525,项目名称:pysmartnode,代码行数:22,代码来源:debug.py

示例15: timeit

# 需要导入模块: import time [as 别名]
# 或者: from time import ticks_ms [as 别名]
def timeit():
        spi = SpiMaster(1, baudrate=int(pyb.freq()[3] / 16))
        start = ticks_ms()

        for i in range(2 ** 10):
            spi.write_data(b'abcdefgh' * 4)
            spi.read_data()

        print("Millisecond ticks elapsed: %i" % ticks_diff(ticks_ms(), start)) 
开发者ID:SpotlightKid,项目名称:micropython-stm-lib,代码行数:11,代码来源:spimaster.py


注:本文中的time.ticks_ms方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。