Python uctypes.addressof() Examples

The following are 26 code examples of uctypes.addressof(). 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 uctypes , or try the search function .
Example #1
Source File: epdpart.py    From micropython-epaper with Apache License 2.0 6 votes vote down vote up
def one_line_data(self, line, stage):
        mv_linebuf = memoryview(self.line_buffer)
        self.asm_data[2] = addressof(mv_linebuf)
        self.asm_data[3] = stage
        spi_send_byte = self.spi.send           # send data
        self._SPI_send(b'\x70\x0a')
        self.Pin_EPD_CS.low()                   # CS low until end of line
        spi_send_byte(b'\x72\x00')              # data bytes
        odd_pixels(self.asm_data, 0, line * BYTES_PER_LINE)
        offset = BYTES_PER_LINE
        offset = scan(self.line_buffer, line, offset)
        even_pixels(self.asm_data, offset, line * BYTES_PER_LINE)
        offset += BYTES_PER_LINE

        spi_send_byte(mv_linebuf[:offset])      # send the accumulated line buffer
        self.Pin_EPD_CS.high()
        self._SPI_send(b'\x70\x02\x72\x07')     # output data to panel 
Example #2
Source File: sco.py    From uble with MIT License 6 votes vote down vote up
def from_buffer(data):
        """
        Parse HCI SCO data

        References can be found here:
        * https://www.bluetooth.org/en-us/specification/adopted-specifications
        ** Core specification 4.1
        ** [vol 2] Part E (Section 5) - HCI Data Formats
        ** [vol 2] Part E (Section 5.4) - Exchange of HCI-specific information
        """
        hci_sco = uctypes.struct(
            uctypes.addressof(data[:HCI_SCO.struct_size]),
            HCI_SCO_STRUCT,
            uctypes.LITTLE_ENDIAN
        )
        data = data[HCI_SCO.struct_size:]
        return HCI_SCO(hci_sco.handle, hci_sco.ps, hci_sco.xx, data) 
Example #3
Source File: event.py    From uble with MIT License 6 votes vote down vote up
def __init__(self, evtcode, data=b'', module="IDB05A1"):
        evtname, evtstruct = HCI_EVENTS[evtcode]
        subevtcode, subevtname = (0, "")
        if evtcode in (EVT_LE_META_EVENT, EVT_VENDOR):
            subevt = uctypes.struct(
                uctypes.addressof(data),
                evtstruct,
                uctypes.LITTLE_ENDIAN
            )
            subevtcode = subevt.subevent
            if evtcode == EVT_LE_META_EVENT:
                subevtname, evtstruct = HCI_LE_META_EVENTS[subevtcode]
            elif evtcode == EVT_VENDOR:
                subevtname, evtstruct = HCI_VENDOR_EVENTS[subevtcode]
            data = bytes(subevt.data)

        self._evtcode = evtcode
        self._evtname = evtname
        self._subevtcode = subevtcode
        self._subevtname = subevtname
        self._struct = evtstruct
        self._data = data
        self._module = module 
Example #4
Source File: event.py    From uble with MIT License 6 votes vote down vote up
def __getattr__(self, name):
        if name == "evtcode":
            return self._evtcode
        elif name == "evtname":
            return self._evtname
        elif name == "subevtcode":
            return self._subevtcode
        elif name == "subevtname":
            return self._subevtname
        elif name == "struct_size":
            return uctypes.sizeof(self.struct)
        elif name == "struct":
            if self._struct is None:
                return None
            return uctypes.struct(
                uctypes.addressof(self.data),
                self._struct.get(self._module, self._struct),
                uctypes.LITTLE_ENDIAN
            )
        elif name == "length":
            return len(self._data)
        elif name == "data":
            return self._data 
Example #5
Source File: bmp_to_icon.py    From micropython-tft-gui with MIT License 6 votes vote down vote up
def write_trailer(outfile):
    outfile.write('}\n\n')
    outfile.write("colortable = (\n    b'")
    size = len(icon_colortable)
    for i in range(size):
        outfile.write("\\x{:02x}".format(icon_colortable[i]))
        if (i % 16) == 15 and i != (size - 1):
            outfile.write("'\n    b'")
    outfile.write("')\n\n")
    outfile.write("width = {}\n".format(icon_width))
    outfile.write("height = {}\n".format(icon_height))
    outfile.write("colors = {}\n".format(icon_colors))
    outfile.write("""
def get_icon(no):
    return width, height, addressof(_icons[no]), colors, addressof(colortable)
""") 
Example #6
Source File: ssd1351.py    From micropython-nano-gui with MIT License 6 votes vote down vote up
def show(self):
        lb = self.linebuf
        buf = self.buffer
        self._write(b'\x5c', 0)  # Enable data write
        if self.height == 128:
            for l in range(128):
                l0 = (95 - l) % 128  # 95 94 .. 1 0 127 126 .. 96
                start = l0 * self.width
                _lcopy(lb, addressof(buf) + start, self.width)
                self._write(lb, 1)  # Send a line
        else:
            for l in range(128):
                if l < 64:
                    start = (63 -l) * self.width  # 63 62 .. 1 0
                    _lcopy(lb, addressof(buf) + start, self.width)
                    self._write(lb, 1)  # Send a line
                elif l < 96:  # This is daft but I can't get setrow to work
                    self._write(lb, 1)  # Let RAM counter increase
                else:
                    start = (191 - l) * self.width  # 127 126 .. 95
                    _lcopy(lb, addressof(buf) + start, self.width)
                    self._write(lb, 1)  # Send a line 
Example #7
Source File: traffic.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def draw(x, y, icon_index, draw_fct, color_index = 0):
    draw_fct(x - width//2, y - height // 2, width, height, addressof(_icons[icon_index]), colors, addressof(colortable[color_index])) 
Example #8
Source File: epdpart.py    From micropython-epaper with Apache License 2.0 5 votes vote down vote up
def frame_data_repeat(self, stage, use_old):
        self.asm_data[0] = addressof(self.image)
        self.asm_data[1] = addressof(self.image_old) if use_old else 0
        start = pyb.millis()
        count = 0
        while True:
            self.frame_data(stage)
            count +=1
            if pyb.elapsed_millis(start) > self.factored_stage_time:
                break
        if self.verbose:
            print('frame_data_repeat count = {}'.format(count)) 
Example #9
Source File: checkbox.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def draw(x, y, icon_index, draw_fct, color_index = 0):
    draw_fct(x - width//2, y - height // 2, width, height, addressof(_icons[icon_index]), colors, addressof(colortable[color_index])) 
Example #10
Source File: checkbox.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def get_icon(icon_index = 0, color_index = 0):
    return width, height, addressof(_icons[icon_index]), colors, addressof(colortable[color_index]) 
Example #11
Source File: threestate.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def draw(x, y, icon_index, draw_fct, color_index = 0):
    draw_fct(x - width//2, y - height // 2, width, height, addressof(_icons[icon_index]), colors, addressof(colortable[color_index])) 
Example #12
Source File: threestate.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def get_icon(icon_index = 0, color_index = 0):
    return width, height, addressof(_icons[icon_index]), colors, addressof(colortable[color_index]) 
Example #13
Source File: flash.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def draw(x, y, icon_index, draw_fct, color_index = 0):
    draw_fct(x - width//2, y - height // 2, width, height, addressof(_icons[icon_index]), colors, addressof(colortable[color_index])) 
Example #14
Source File: iconswitch.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def draw(x, y, icon_index, draw_fct, color_index = 0):
    draw_fct(x - width//2, y - height // 2, width, height, addressof(_icons[icon_index]), colors, addressof(colortable[color_index])) 
Example #15
Source File: iconswitch.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def get_icon(icon_index = 0, color_index = 0):
    return width, height, addressof(_icons[icon_index]), colors, addressof(colortable[color_index]) 
Example #16
Source File: gauge.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def draw(x, y, icon_index, draw_fct, color_index = 0):
    draw_fct(x - width//2, y - height // 2, width, height, addressof(_icons[icon_index]), colors, addressof(colortable[color_index])) 
Example #17
Source File: gauge.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def get_icon(icon_index = 0, color_index = 0):
    return width, height, addressof(_icons[icon_index]), colors, addressof(colortable[color_index]) 
Example #18
Source File: radiobutton.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def draw(x, y, icon_index, draw_fct, color_index = 0):
    draw_fct(x - width//2, y - height // 2, width, height, addressof(_icons[icon_index]), colors, addressof(colortable[color_index])) 
Example #19
Source File: traffic.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def get_icon(icon_index = 0, color_index = 0):
    return width, height, addressof(_icons[icon_index]), colors, addressof(colortable[color_index]) 
Example #20
Source File: tft.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def printChar(self, c, bg_buf=None):
# get the charactes pixel bitmap and dimensions
        if self.text_font:
            fmv, rows, cols = self.text_font.get_ch(c)
        else:
            raise AttributeError('No font selected')
        cbytes, cbits = divmod(cols, 8)  # Not in packed format
        dcols = (cbytes + 1) * 8 if cbits else cbytes * 8 # cols for display
        pix_count = dcols * rows   # number of bits in the char
# test char fit
        if self.text_x + cols > self.text_width:  # does the char fit on the screen?
            if self.text_scroll:
                self.printCR()      # No, then CR
                self.printNewline(True) # NL: advance to the next line
            else:
                return 0
# Retrieve Background data if transparency is required
        if self.transparency: # in case of transpareny, the frame buffer content is needed
            if bg_buf is None:    # buffer allocation needed?
                if len(self.bg_buf) < pix_count * 3:
                    del(self.bg_buf)
                    gc.collect()
                    self.bg_buf = bytearray(pix_count * 3) # Make it bigger
                bg_buf = self.bg_buf
            self.setXY(self.text_x, self.text_y, self.text_x + dcols - 1, self.text_y + rows - 1) # set area
            TFT_io.tft_read_cmd_data_AS(0x2e, bg_buf, pix_count * 3) # read background data
        else:
            bg_buf = 0 # dummy assignment, since None is not accepted
# Set XY range & print char
        self.setXY(self.text_x, self.text_y, self.text_x + dcols - 1, self.text_y + rows - 1) # set area
        TFT_io.displaySCR_charbitmap(addressof(fmv), pix_count, self.text_color, bg_buf) # display char!
#advance pointer
        self.text_x += (cols + self.text_gap)
        return cols + self.text_gap 
Example #21
Source File: bmp_to_icon.py    From micropython-tft-gui with MIT License 5 votes vote down vote up
def write_header(outfile):
    outfile.write("""
# Code generated by bmp_to_icon.py
from uctypes import addressof

"""
)
    outfile.write("_icons = { \n") 
Example #22
Source File: att.py    From uble with MIT License 5 votes vote down vote up
def from_buffer(data):
        """
        Attribute opcode is the first octet of the PDU

         0 1 2 3 4 5 6 7
        -----------------
        |   att opcode  |
        -----------------
        |     a     |b|c|
        -----------------
        a - method
        b - command flag
        c - authentication signature flag

        References can be found here:
            * https://www.bluetooth.org/en-us/specification/adopted-specifications
            ** Core specification 4.1
            ** [vol 3] Part F (Section 3.3) - Attribute PDU
        """
        opcode = ustruct.unpack(ATT.struct_format, data[:ATT.struct_size])[0]

        # att = uctypes.struct(
        #     uctypes.addressof(data[:ATT.struct_size]),
        #     ATT_STRUCT,
        #     uctypes.LITTLE_ENDIAN
        # )

        data = data[ATT.struct_size:]
        return ATT(opcode, data) 
Example #23
Source File: cmd.py    From uble with MIT License 5 votes vote down vote up
def __getattr__(self, name):
        if name == "ogf":
            return self._ogf
        elif name == "ogf_name":
            return self._ogf_name
        elif name == "ocf":
            return self._ocf
        elif name == "ocf_name":
            return self._ocf_name
        elif name == "opcode":
            return self._opcode
        elif name == "evtcode":
            return self._evtcode
        elif name == "request_struct":
            if self._request_struct is None:
                return None
            return uctypes.struct(
                uctypes.addressof(self.request_data),
                self._request_struct.get(self._module, self._request_struct),
                uctypes.LITTLE_ENDIAN
            )
        elif name == "response_struct":
            if self._response_struct is None:
                return None
            return uctypes.struct(
                uctypes.addressof(self.response_data),
                self._response_struct.get(self._module, self._response_struct),
                uctypes.LITTLE_ENDIAN
            )
        elif name == "request_length":
            return len(self._request_data)
        elif name == "request_data":
            return self._request_data
        elif name == "response_length":
            return len(self._response_data)
        elif name == "response_data":
            return self._response_data
        else:
            raise AttributeError(name) 
Example #24
Source File: mutex.py    From micropython-samples with MIT License 5 votes vote down vote up
def test(self):          # Nonblocking: try to acquire, return True if success.
        return self._attempt(uctypes.addressof(self.lock)) == 0 
Example #25
Source File: mutex.py    From micropython-samples with MIT License 5 votes vote down vote up
def __enter__(self):
        self._acquire(uctypes.addressof(self.lock))
        return self 
Example #26
Source File: dftclass.py    From micropython-fourier with MIT License 4 votes vote down vote up
def __init__(self, length, popfunc=None, winfunc=None):
        bits = round(math.log(length)/math.log(2))
        assert 2**bits == length, "Length must be an integer power of two"
        self.dboffset = 0               # Offset for dB calculation
        self._length = length
        self.popfunc = popfunc          # Function to acquire data
        self.re = array.array('f', (0 for x in range(self._length)))
        self.im = array.array('f', (0 for x in range(self._length)))
        if winfunc is not None:  # If a window function is provided, create and populate the array
            self.windata = array.array('f', (0 for x in range(self._length))) # of window coefficients
            for x in range(0, length):
                self.windata[x] = winfunc(x, length)
        else:
            self.windata = None
        COMPLEX_NOS = 7                 # Size of complex buffer area before roots of unity
        ROOTSOFFSET = COMPLEX_NOS*2     # Word offset into complex array of roots of unity
        bits = round(math.log(self._length)/math.log(2))
        self.ctrl = array.array('i', [0]*6)
        self.cmplx = array.array('f', [0.0]*((bits +1 +COMPLEX_NOS)*2))
        self.ctrl[0] = self._length
        self.ctrl[1] = bits
        self.ctrl[2] = addressof(self.re)
        self.ctrl[3] = addressof(self.im)
        self.ctrl[4] = COMPLEX_NOS*8    # Byte offset into complex array of roots of unity
        self.ctrl[5] = addressof(self.cmplx) # Base address

        self.cmplx[0] = 1.0             # Initial value of u = [1 +j0]
        self.cmplx[1] = 0.0             # Intermediate values are used by fft() and not initialised
        self.cmplx[12] = 1.0/self._length # Default scaling multiply by 1/length
        self.cmplx[13] = 0.0            # ignored
        i = ROOTSOFFSET
        creal = -1
        cimag =  0
        self.cmplx[i] = creal           # Complex roots of unity
        self.cmplx[i +1] = cimag
        i += 2
        for x in range(bits):
            cimag = math.sqrt((1.0 - creal) / 2.0)  # Imaginary part
            self.cmplx[i +1] = cimag
            creal = math.sqrt((1.0 + creal) / 2.0)  # Real part
            self.cmplx[i] = creal
            i += 2