當前位置: 首頁>>代碼示例>>Python>>正文


Python machine.idle方法代碼示例

本文整理匯總了Python中machine.idle方法的典型用法代碼示例。如果您正苦於以下問題:Python machine.idle方法的具體用法?Python machine.idle怎麽用?Python machine.idle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在machine的用法示例。


在下文中一共展示了machine.idle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: read_frames

# 需要導入模塊: import machine [as 別名]
# 或者: from machine import idle [as 別名]
def read_frames(self, count):
        frames = []
        # flush the buffer to read fresh data
        self.uart.readall()
        while len(frames) < count:
            self.__wait_for_data(32)

            while self.uart.read(1) != b'\x42':
                machine.idle()

            if self.uart.read(1) == b'\x4D':
                self.__wait_for_data(30)

                try:
                    data = PMSData.from_bytes(b'\x42\x4D' + self.uart.read(30))
                    print('cPM25: {}, cPM10: {}, PM25: {}, PM10: {}' \
                            .format(data.cpm25, data.cpm10, data.pm25, data.pm10))
                    frames.append(data)
                except ValueError as e:
                    print('error reading frame: {}'.format(e.message))
                    pass

        return frames 
開發者ID:ayoy,項目名稱:upython-aq-monitor,代碼行數:25,代碼來源:pms5003.py

示例2: connect_blocking

# 需要導入模塊: import machine [as 別名]
# 或者: from machine import idle [as 別名]
def connect_blocking():
    global _wlan

    activate()

    # no scan of networks to allow connect to hidden essid
    # Try to connect
    tries = 15
    for i in range(tries):
        print("%d/%d. Trying to connect." % (i + 1, tries))
        machine.idle()
        time.sleep(1)
        if connected():
            break

    if connected():
        print('Wifi: connection succeeded!')
        print(_wlan.ifconfig())
    else:
        print('Wifi: connection failed, starting accesspoint!')
        accesspoint()
    nr.start(nostop=True) 
開發者ID:ulno,項目名稱:ulnoiot-upy,代碼行數:24,代碼來源:_wifi.py

示例3: measurements

# 需要導入模塊: import machine [as 別名]
# 或者: from machine import idle [as 別名]
def measurements(self):
        # flush the buffer to read fresh data
        ret_data = None
        self._wait_for_data(32)

        while self._uart.read(1) != b'\x42':
            machine.idle()

        if self._uart.read(1) == b'\x4D':
            self._wait_for_data(30)
            try:
                self._data = self._uart.read(30)
                if self._data:
                    ret_data = self._PMdata()
            except ValueError as e:
                print('error reading frame: {}'.format(e.message))
                pass
                
        return ret_data 
開發者ID:lemariva,項目名稱:uPySensors,代碼行數:21,代碼來源:pmsa003.py

示例4: wait_for_nic

# 需要導入模塊: import machine [as 別名]
# 或者: from machine import idle [as 別名]
def wait_for_nic(self, retries=5):
        """

        :param retries:  (Default value = 5)

        """
        attempts = 0
        while attempts < retries:
            try:
                socket.getaddrinfo("localhost", 333)
                break
            except OSError as ex:
                print('Network interface not available: {}'.format(ex))
            print('Waiting for network interface')
            # Save power while waiting.
            machine.idle()
            time.sleep(0.25)
            attempts += 1
        print('Network interface ready') 
開發者ID:hiveeyes,項目名稱:terkin-datalogger,代碼行數:21,代碼來源:mininet.py

示例5: runLoop

# 需要導入模塊: import machine [as 別名]
# 或者: from machine import idle [as 別名]
def runLoop():
    while True:
        blynk.run()
        machine.idle()

# Run blynk in the main thread: 
開發者ID:vshymanskyy,項目名稱:blynk-library-python,代碼行數:8,代碼來源:PyCom_WiPy.py

示例6: runLoop

# 需要導入模塊: import machine [as 別名]
# 或者: from machine import idle [as 別名]
def runLoop():
    while True:
        blynk.run()
        machine.idle() 
開發者ID:vshymanskyy,項目名稱:blynk-library-python,代碼行數:6,代碼來源:WM_W600.py

示例7: runLoop

# 需要導入模塊: import machine [as 別名]
# 或者: from machine import idle [as 別名]
def runLoop():
    while True:
        blynk.run()
        time.sleep(0.1)
        #machine.idle()

# Run blynk in the main thread: 
開發者ID:vshymanskyy,項目名稱:blynk-library-python,代碼行數:9,代碼來源:PyCom_BLE.py

示例8: idle

# 需要導入模塊: import machine [as 別名]
# 或者: from machine import idle [as 別名]
def idle(self):
        self.en(False)
        self.uart.deinit() 
開發者ID:ayoy,項目名稱:upython-aq-monitor,代碼行數:5,代碼來源:pms5003.py

示例9: _idle_task

# 需要導入模塊: import machine [as 別名]
# 或者: from machine import idle [as 別名]
def _idle_task(self):
        while True:
            await asyncio.sleep_ms(10)
            machine.idle()  # Yield to underlying RTOS 
開發者ID:peterhinch,項目名稱:micropython-async,代碼行數:6,代碼來源:sock_nonblock.py

示例10: init_wlan_sta

# 需要導入模塊: import machine [as 別名]
# 或者: from machine import idle [as 別名]
def init_wlan_sta():
    """Connect to wifi network specified in configuration."""

    print('WLAN: STA mode')
    wlan.init(mode=WLAN.STA)
    if not wlan.isconnected():
        wlan.connect(WLAN_SSID, auth=WLAN_AUTH, timeout=5000)
        while not wlan.isconnected():
            machine.idle()  # save power while waiting 
開發者ID:ttn-be,項目名稱:ttnmapper,代碼行數:11,代碼來源:boot.py

示例11: connect_wifi_sta_single

# 需要導入模塊: import machine [as 別名]
# 或者: from machine import idle [as 別名]
def connect_wifi_sta_single(self, ssid, authmode, password, timeout=10000):
        """

        :param ssid: 
        :param authmode: 
        :param password: 
        :param timeout:  (Default value = 10000)

        """

        print('INFO:  WiFi STA: Connecting to "{}"'.format(ssid))
        self.station.connect(ssid, auth=(authmode, password), timeout=timeout)

        try:
            # FIXME: This is a candidate for an infinite loop.
            while not self.station.isconnected():
                # Save power while waiting
                machine.idle()
                time.sleep_ms(250)

            print('INFO:  WiFi STA: Connected to "{}"'.format(ssid))

            return True

        except Exception as ex:
            print('ERROR: WiFi STA: Connecting to "{}" failed. Please check SSID and PASSWORD.\n{}'.format(ssid, ex)) 
開發者ID:hiveeyes,項目名稱:terkin-datalogger,代碼行數:28,代碼來源:mininet.py

示例12: monkeypatch_machine

# 需要導入模塊: import machine [as 別名]
# 或者: from machine import idle [as 別名]
def monkeypatch_machine():

    from mock import Mock

    import uuid
    import machine

    # Some primitives.
    machine.enable_irq = Mock()
    machine.disable_irq = Mock()
    machine.unique_id = lambda: str(uuid.uuid4().fields[-1])[:5].encode()
    machine.freq = Mock(return_value=42000000)
    machine.idle = Mock()

    # Reset cause and wake reason.
    machine.PWRON_RESET = 0
    machine.HARD_RESET = 1
    machine.WDT_RESET = 2
    machine.DEEPSLEEP_RESET = 3
    machine.SOFT_RESET = 4
    machine.BROWN_OUT_RESET = 5

    machine.PWRON_WAKE = 0
    machine.GPIO_WAKE = 1
    machine.RTC_WAKE = 2
    machine.ULP_WAKE = 3

    machine.reset_cause = Mock(return_value=0)
    machine.wake_reason = wake_reason 
開發者ID:hiveeyes,項目名稱:terkin-datalogger,代碼行數:31,代碼來源:compat.py

示例13: stay_connected

# 需要導入模塊: import machine [as 別名]
# 或者: from machine import idle [as 別名]
def stay_connected(self):
        """ """

        # Prepare information about known WiFi networks.
        networks_known = self.get_configured_stations()

        # Attempt to connect to known/configured networks.
        attempt = 0
        while self.is_running:

            delay = 1

            if self.is_connected():
                attempt = 0

            else:
                log.info("WiFi STA: Connecting to configured networks: %s. "
                         "Attempt: #%s", list(networks_known), attempt + 1)
                try:
                    self.connect_stations(networks_known)

                except KeyboardInterrupt:
                    raise

                except Exception as ex:
                    log.exc(ex, 'WiFi STA: Connecting to configured networks "{}" failed'.format(list(networks_known)))
                    delay = backoff_time(attempt, minimum=1, maximum=600)
                    log.info('WiFi STA: Retrying in {} seconds'.format(delay))

                attempt += 1

            machine.idle()
            time.sleep(delay) 
開發者ID:hiveeyes,項目名稱:terkin-datalogger,代碼行數:35,代碼來源:wifi.py

示例14: wait_for_connection

# 需要導入模塊: import machine [as 別名]
# 或者: from machine import idle [as 別名]
def wait_for_connection(self, timeout=15.0):
        """
        Wait for network to arrive.

        :param timeout:  (Default value = 15.0)

        """

        # Set interval how often to poll for WiFi connectivity.
        network_poll_interval = 250

        # How many checks to make.
        checks = int(timeout / (network_poll_interval / 1000.0))

        self.stopwatch.reset()

        do_report = True
        while not self.is_connected():

            delta = self.stopwatch.elapsed()
            eta = timeout - delta

            if checks <= 0 or eta <= 0:
                break

            # Report about the progress each 3 seconds.
            if int(delta) % 3 == 0:
                if do_report:
                    log.info('WiFi STA: Waiting for network to come up within {} seconds'.format(eta))
                    do_report = False
            else:
                do_report = True

            # Save power while waiting.
            machine.idle()

            # Don't busy-wait.
            time.sleep_ms(network_poll_interval)

            checks -= 1 
開發者ID:hiveeyes,項目名稱:terkin-datalogger,代碼行數:42,代碼來源:wifi.py

示例15: wait_for_nic

# 需要導入模塊: import machine [as 別名]
# 或者: from machine import idle [as 別名]
def wait_for_nic(self, timeout=5):
        """

        :param timeout:  (Default value = 5)

        """

        eggtimer = Eggtimer(duration=timeout)

        log.info('Waiting for network interface')
        while not eggtimer.expired():

            self.device.watchdog.feed()

            try:
                # TODO: Make WiFi-agnostic.
                if self.wifi_manager.is_connected():
                    log.info('Network interface ready')
                    return True

            except OSError as ex:
                log.warning('Network interface not available: %s', format_exception(ex))

            # Report about progress.
            sys.stderr.write('.')
            #sys.stderr.flush()

            # Save power while waiting.
            machine.idle()
            time.sleep(0.25)

        # TODO: Make WiFi-agnostic.
        raise NetworkUnavailable('Could not connect to WiFi network') 
開發者ID:hiveeyes,項目名稱:terkin-datalogger,代碼行數:35,代碼來源:core.py


注:本文中的machine.idle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。