Python ustruct.calcsize() Examples
The following are 6
code examples of ustruct.calcsize().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ustruct
, or try the search function
.
Example #1
Source File: rgb.py From micropython-adafruit-rgb-display with MIT License | 5 votes |
def _block(self, x0, y0, x1, y1, data=None): """Read or write a block of data.""" self._write(self._COLUMN_SET, self._encode_pos(x0, x1)) self._write(self._PAGE_SET, self._encode_pos(y0, y1)) if data is None: size = ustruct.calcsize(self._DECODE_PIXEL) return self._read(self._RAM_READ, (x1 - x0 + 1) * (y1 - y0 + 1) * size) self._write(self._RAM_WRITE, data)
Example #2
Source File: rgb.py From Adafruit_CircuitPython_RGB_Display with MIT License | 5 votes |
def _block(self, x0, y0, x1, y1, data=None): """Read or write a block of data.""" self.write( self._COLUMN_SET, self._encode_pos(x0 + self._X_START, x1 + self._X_START) ) self.write( self._PAGE_SET, self._encode_pos(y0 + self._Y_START, y1 + self._Y_START) ) if data is None: size = struct.calcsize(self._DECODE_PIXEL) return self.read(self._RAM_READ, (x1 - x0 + 1) * (y1 - y0 + 1) * size) self.write(self._RAM_WRITE, data) return None # pylint: enable-msg=invalid-name,too-many-arguments
Example #3
Source File: i2c_struct.py From Adafruit_CircuitPython_Register with MIT License | 5 votes |
def __init__(self, register_address, struct_format): self.format = struct_format self.buffer = bytearray(1 + struct.calcsize(self.format)) self.buffer[0] = register_address
Example #4
Source File: i2c_struct.py From Adafruit_CircuitPython_Register with MIT License | 5 votes |
def __get__(self, obj, objtype=None): buf = bytearray(1 + struct.calcsize(self.format)) buf[0] = self.address with obj.i2c_device as i2c: i2c.write_then_readinto(buf, buf, out_end=1, in_start=1) return struct.unpack_from(self.format, buf, 1)[0]
Example #5
Source File: i2c_struct.py From Adafruit_CircuitPython_Register with MIT License | 5 votes |
def __set__(self, obj, value): buf = bytearray(1 + struct.calcsize(self.format)) buf[0] = self.address struct.pack_into(self.format, buf, 1, value) with obj.i2c_device as i2c: i2c.write(buf)
Example #6
Source File: vl53l0x.py From uPySensors with Apache License 2.0 | 5 votes |
def _registers(self, register, values=None, struct='B'): if values is None: size = ustruct.calcsize(struct) data = self.i2c.readfrom_mem(self.address, register, size) values = ustruct.unpack(struct, data) return values data = ustruct.pack(struct, *values) self.i2c.writeto_mem(self.address, register, data)