當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。