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


Python micropython.const方法代码示例

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


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

示例1: _calculate_crc_table

# 需要导入模块: import micropython [as 别名]
# 或者: from micropython import const [as 别名]
def _calculate_crc_table():
    """Precompute the table used in calculate_crc."""
    # Code converted from https://github.com/hazelnusse/crc7/blob/master/crc7.cc by devoh747
    # With permission from Dale Lukas Peterson <hazelnusse@gmail.com>
    # 8/6/2019

    crc_table = bytearray(256)
    crc_poly = const(0x89)  # the value of our CRC-7 polynomial

    # generate a table value for all 256 possible byte values
    for i in range(256):
        if i & 0x80:
            crc_table[i] = i ^ crc_poly
        else:
            crc_table[i] = i
        for _ in range(1, 8):
            crc_table[i] = crc_table[i] << 1
            if crc_table[i] & 0x80:
                crc_table[i] = crc_table[i] ^ crc_poly
    return crc_table 
开发者ID:adafruit,项目名称:Adafruit_CircuitPython_SD,代码行数:22,代码来源:adafruit_sdcard.py

示例2: __init__

# 需要导入模块: import micropython [as 别名]
# 或者: from micropython import const [as 别名]
def __init__(self, led_pin, config):
        self.led = pulseio.PWMOut(led_pin)
        self.brightness_step = const(config['brightness_step'])
        self.brightness_limit = const(config['brightness_limit'])
        self.animation_mode = const(config['animation_mode'])
        self.animation_speed = const(config['animation_speed'])
        self.breathe_center = const(config['breathe_center'])
        if config.get('user_animation'):
            self.user_animation = config['user_animation'] 
开发者ID:KMKfw,项目名称:kmk_firmware,代码行数:11,代码来源:led.py

示例3: __init__

# 需要导入模块: import micropython [as 别名]
# 或者: from micropython import const [as 别名]
def __init__(self, config, pixel_pin):
        try:
            import neopixel

            self.neopixel = neopixel.NeoPixel(
                pixel_pin,
                config['num_pixels'],
                pixel_order=config['rgb_order'],
                auto_write=False,
            )
            if len(config['rgb_order']) == 4:
                self.rgbw = True
            self.num_pixels = const(config['num_pixels'])
            self.hue_step = const(config['hue_step'])
            self.sat_step = const(config['sat_step'])
            self.val_step = const(config['val_step'])
            self.hue = const(config['hue_default'])
            self.sat = const(config['sat_default'])
            self.val = const(config['val_default'])
            self.breathe_center = const(config['breathe_center'])
            self.knight_effect_length = const(config['knight_effect_length'])
            self.val_limit = const(config['val_limit'])
            self.animation_mode = config['animation_mode']
            self.animation_speed = const(config['animation_speed'])
            if 'user_animation' in config:
                print(config['user_animation'])
                self.user_animation = config['user_animation']

        except ImportError as e:
            print(e) 
开发者ID:KMKfw,项目名称:kmk_firmware,代码行数:32,代码来源:rgb.py

示例4: const

# 需要导入模块: import micropython [as 别名]
# 或者: from micropython import const [as 别名]
def const(a):
        return a 
开发者ID:ulno,项目名称:ulnoiot-upy,代码行数:4,代码来源:crypt_socket.py

示例5: const

# 需要导入模块: import micropython [as 别名]
# 或者: from micropython import const [as 别名]
def const(x):
        return x 
开发者ID:adafruit,项目名称:Adafruit_CircuitPython_seesaw,代码行数:4,代码来源:seesaw.py

示例6: chip_id

# 需要导入模块: import micropython [as 别名]
# 或者: from micropython import const [as 别名]
def chip_id(self):
        '''
        Returns Chip ID
        '''
        try:
            chip_id = unp('<b',self._read(const(0xD0), 1))[0]
        except OSError:
            raise MPUException(self._I2Cerror)
        if chip_id != self._chip_id:
            raise ValueError('Bad chip ID ({0}!={1}) retrieved: MPU communication failure'.format(chip_id, self._chip_id))
        return chip_id 
开发者ID:lemariva,项目名称:uPySensors,代码行数:13,代码来源:bme680.py

示例7: _get_msg_id

# 需要导入模块: import micropython [as 别名]
# 或者: from micropython import const [as 别名]
def _get_msg_id(self, **kwargs):
        if 'msg_id' in kwargs:
            return kwargs['msg_id']
        self._msg_id += const(1)
        return self._msg_id if self._msg_id <= const(0xFFFF) else const(1) 
开发者ID:blynkkk,项目名称:lib-python,代码行数:7,代码来源:blynklib_mp.py

示例8: _set_socket_timeout

# 需要导入模块: import micropython [as 别名]
# 或者: from micropython import const [as 别名]
def _set_socket_timeout(self, timeout):
        if getattr(self._socket, 'settimeout', None):
            self._socket.settimeout(timeout)
        else:
            p = select.poll()
            p.register(self._socket)
            p.poll(int(timeout * const(1000))) 
开发者ID:blynkkk,项目名称:lib-python,代码行数:9,代码来源:blynklib_mp.py

示例9: is_server_alive

# 需要导入模块: import micropython [as 别名]
# 或者: from micropython import const [as 别名]
def is_server_alive(self):
        now = ticks_ms()
        h_beat_ms = self.heartbeat * const(1000)
        rcv_delta = now - self._last_rcv_time
        ping_delta = now - self._last_ping_time
        send_delta = now - self._last_send_time
        if rcv_delta > h_beat_ms + (h_beat_ms // const(2)):
            return False
        if (ping_delta > h_beat_ms // const(10)) and (send_delta > h_beat_ms or rcv_delta > h_beat_ms):
            self.send(self.ping_msg())
            self.log('Heartbeat time: {}'.format(now))
            self._last_ping_time = now
        return True 
开发者ID:blynkkk,项目名称:lib-python,代码行数:15,代码来源:blynklib_mp.py

示例10: process

# 需要导入模块: import micropython [as 别名]
# 或者: from micropython import const [as 别名]
def process(self, msg_type, msg_id, msg_len, msg_args):
        if msg_type == self.MSG_RSP:
            self.log('Response status: {}'.format(msg_len))
        elif msg_type == self.MSG_PING:
            self.send(self.response_msg(self.STATUS_OK, msg_id=msg_id))
        elif msg_type in (self.MSG_HW, self.MSG_BRIDGE, self.MSG_INTERNAL):
            if msg_type == self.MSG_INTERNAL:
                self.call_handler("{}{}".format(self._INTERNAL, msg_args[0]), msg_args[1:])
            elif len(msg_args) >= const(3) and msg_args[0] == 'vw':
                self.call_handler("{}{}".format(self._VPIN_WRITE, msg_args[1]), int(msg_args[1]), msg_args[2:])
            elif len(msg_args) == const(2) and msg_args[0] == 'vr':
                self.call_handler("{}{}".format(self._VPIN_READ, msg_args[1]), int(msg_args[1])) 
开发者ID:blynkkk,项目名称:lib-python,代码行数:14,代码来源:blynklib_mp.py

示例11: read_response

# 需要导入模块: import micropython [as 别名]
# 或者: from micropython import const [as 别名]
def read_response(self, timeout=0.5):
        end_time = time.ticks_ms() + int(timeout * const(1000))
        while time.ticks_diff(end_time, time.ticks_ms()) > 0:
            rsp_data = self.receive(self.rcv_buffer, self.SOCK_TIMEOUT)
            if rsp_data:
                self._last_rcv_time = ticks_ms()
                msg_type, msg_id, h_data, msg_args = self.parse_response(rsp_data, self.rcv_buffer)
                self.process(msg_type, msg_id, h_data, msg_args) 
开发者ID:blynkkk,项目名称:lib-python,代码行数:10,代码来源:blynklib_mp.py

示例12: send_data

# 需要导入模块: import micropython [as 别名]
# 或者: from micropython import const [as 别名]
def send_data(self, data, data_length, frame_counter, timeout=2):
        """Function to assemble and send data
           :param data: data to send
           :param data_length: length of data to send
           :param frame_counter: frame counter variable, declared in code.py.
           :param timeout: TxDone wait time, default is 2.
        """
        # data packet
        enc_data = bytearray(data_length)
        lora_pkt = bytearray(64)
        # copy bytearray into bytearray for encryption
        enc_data[0:data_length] = data[0:data_length]
        # encrypt data (enc_data is overwritten in this function)
        self.frame_counter = frame_counter
        aes = AES(
            self._ttn_config.device_address,
            self._ttn_config.app_key,
            self._ttn_config.network_key,
            self.frame_counter,
        )
        enc_data = aes.encrypt(enc_data)
        # append preamble to packet
        lora_pkt[0] = const(_REG_DIO_MAPPING_1)
        lora_pkt[1] = self._ttn_config.device_address[3]
        lora_pkt[2] = self._ttn_config.device_address[2]
        lora_pkt[3] = self._ttn_config.device_address[1]
        lora_pkt[4] = self._ttn_config.device_address[0]
        lora_pkt[5] = 0
        lora_pkt[6] = frame_counter & 0x00FF
        lora_pkt[7] = (frame_counter >> 8) & 0x00FF
        lora_pkt[8] = 0x01
        # set length of LoRa packet
        lora_pkt_len = 9
        # load encrypted data into lora_pkt
        lora_pkt[lora_pkt_len : lora_pkt_len + data_length] = enc_data[0:data_length]
        # recalculate packet length
        lora_pkt_len += data_length
        # Calculate MIC
        mic = bytearray(4)
        mic = aes.calculate_mic(lora_pkt, lora_pkt_len, mic)
        # load mic in package
        lora_pkt[lora_pkt_len : lora_pkt_len + 4] = mic[0:4]
        # recalculate packet length (add MIC length)
        lora_pkt_len += 4
        self.send_packet(lora_pkt, lora_pkt_len, timeout) 
开发者ID:adafruit,项目名称:Adafruit_CircuitPython_TinyLoRa,代码行数:47,代码来源:adafruit_tinylora.py

示例13: __init__

# 需要导入模块: import micropython [as 别名]
# 或者: from micropython import const [as 别名]
def __init__(
        self,
        esp,
        secrets,
        status_pixel=None,
        attempts=2,
        connection_type=NORMAL,
        debug=False,
    ):
        """
        :param ESP_SPIcontrol esp: The ESP object we are using
        :param dict secrets: The WiFi and Adafruit IO secrets dict (See examples)
        :param status_pixel: (Optional) The pixel device - A NeoPixel, DotStar,
            or RGB LED (default=None)
        :type status_pixel: NeoPixel, DotStar, or RGB LED
        :param int attempts: (Optional) Failed attempts before resetting the ESP32 (default=2)
        :param const connection_type: (Optional) Type of WiFi connection: NORMAL or ENTERPRISE
        """
        # Read the settings
        self.esp = esp
        self.debug = debug
        self.ssid = secrets["ssid"]
        self.password = secrets.get("password", None)
        self.attempts = attempts
        self._connection_type = connection_type
        requests.set_socket(socket, esp)
        self.statuspix = status_pixel
        self.pixel_status(0)

        # Check for WPA2 Enterprise keys in the secrets dictionary and load them if they exist
        if secrets.get("ent_ssid"):
            self.ent_ssid = secrets["ent_ssid"]
        else:
            self.ent_ssid = secrets["ssid"]
        if secrets.get("ent_ident"):
            self.ent_ident = secrets["ent_ident"]
        else:
            self.ent_ident = ""
        if secrets.get("ent_user"):
            self.ent_user = secrets["ent_user"]
        if secrets.get("ent_password"):
            self.ent_password = secrets["ent_password"]

    # pylint: enable=too-many-arguments 
开发者ID:adafruit,项目名称:Adafruit_CircuitPython_ESP32SPI,代码行数:46,代码来源:adafruit_esp32spi_wifimanager.py


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