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


Python uctypes.addressof函数代码示例

本文整理汇总了Python中uctypes.addressof函数的典型用法代码示例。如果您正苦于以下问题:Python addressof函数的具体用法?Python addressof怎么用?Python addressof使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_fillwords

    def test_fillwords(self):
        b = bytearray(range(8*4))
        ref = b[:]
        self.assertEqual(b, ref)
        a = uctypes.addressof(b)
        self.assertEqual(a&3, 0) # word-aligned

        # A zero-length fill does nothing
        _fillwords(a+2*4, 0x12345678, 0)
        self.assertEqual(b, ref)

        # A negative-length fill does nothing
        _fillwords(a+2*4, 0x12345678, -1)
        self.assertEqual(b, ref)

        # Fills single word correctly
        ref = b[:]
        _fillwords(a+2*4, 0x79616b6f, 1)
        ref[4*2:4*(2+1)] = b'okay'
        self.assertEqual(b, ref)

        # Fills multiple words correctly
        b = bytearray(range(8*4))
        a = uctypes.addressof(b)
        ref = b[:]
        _fillwords(a+2*4, 0x79616b6f, 3)
        ref[4*2:4*(2+3)] = b'okay' * 3
        self.assertEqual(b, ref)
开发者ID:pramasoul,项目名称:micropython-ws2812,代码行数:28,代码来源:test_led_utils.py

示例2: execvp

def execvp(f, args):
    import uctypes
    args_ = array.array("P", [0] * (len(args) + 1))
    i = 0
    for a in args:
        args_[i] = uctypes.addressof(a)
        i += 1
    r = execvp_(f, uctypes.addressof(args_))
    check_error(r)
开发者ID:bynds,项目名称:micropython-lib,代码行数:9,代码来源:__init__.py

示例3: get_ch

 def get_ch(self, ch):
     from uctypes import addressof
     relch = ch - self.firstchar
     if relch > self.nchars or relch < 0:
         raise ValueError('Character value {:} is unsupported.'.format(ch))
     offset = self.get_idx(relch)
     delta = self.get_idx(relch + 1) - offset
     if self.monospaced:
         return addressof(self._font) + offse, self.bits_vert, delta, self.bits_horiz
     else:
         return addressof(self._font) + offset, self.bits_vert, delta, delta // self.bytes_vert
开发者ID:fojie,项目名称:micropython-samples,代码行数:11,代码来源:TFTfont.py

示例4: frame_data_repeat

 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))
开发者ID:biazzotto,项目名称:micropython-epaper,代码行数:12,代码来源:epdpart.py

示例5: test_movewords

    def test_movewords(self):
        b = bytearray(range(8*4))
        ref = b[:]
        self.assertEqual(b, ref)
        a = uctypes.addressof(b)
        self.assertEqual(a&3, 0) # word-aligned

        # A zero-length move does nothing
        _movewords(a, a+3*4, 0)
        self.assertEqual(b, ref)

        # A negative-length move does nothing
        _movewords(a, a+3*4, -2)
        self.assertEqual(b, ref)

        # A move with dest=src does nothing
        _movewords(a+3*4, a+3*4, 0)
        self.assertEqual(b, ref)

        # A simple move down
        b = bytearray(range(8*4))
        a = uctypes.addressof(b)
        ref = b[:]
        ref[0*4:2*4] = b[3*4:5*4]
        _movewords(a, a+3*4, 2)
        self.assertEqual(list(b), list(ref))

        # A simple move up
        b = bytearray(range(8*4))
        a = uctypes.addressof(b)
        ref = b[:]
        ref[3*4:5*4] = b[0*4:2*4]
        _movewords(a+3*4, a, 2)
        self.assertEqual(list(b), list(ref))

        # An overlapping move down
        b = bytearray(range(8*4))
        a = uctypes.addressof(b)
        ref = b[:]
        ref[0*4:6*4] = b[2*4:8*4]
        _movewords(a, a+2*4, 6)
        self.assertEqual(list(b), list(ref))

        # An overlapping move up
        b = bytearray(range(8*4))
        a = uctypes.addressof(b)
        ref = b[:]
        ref[2*4:8*4] = b[0*4:6*4]
        _movewords(a+2*4, a, 6)
        self.assertEqual(list(b), list(ref))
开发者ID:pramasoul,项目名称:micropython-ws2812,代码行数:50,代码来源:test_led_utils.py

示例6: printChar

    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
开发者ID:peterhinch,项目名称:micropython-tft-gui,代码行数:34,代码来源:tft.py

示例7: sync

 def sync(self, to=None):
     if to is None:
         self.spi.send(self.buf)
     else:
         short_buf = bytearray_at(addressof(self.buf), 3*4*to + 1) # extra byte
         t = short_buf[-1]
         short_buf[-1] = 0
         self.spi.send(short_buf)
         short_buf[-1] = t
开发者ID:pramasoul,项目名称:micropython-ws2812,代码行数:9,代码来源:ws2812.py

示例8: __init__

    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
开发者ID:peterhinch,项目名称:micropython-fourier,代码行数:42,代码来源:dftclass.py

示例9: get_ch

 def get_ch(self, ch):
     from uctypes import addressof
     relch = ch - self.firstchar
     if relch > self.nchars or relch < 0:
         relch = 0 # instead of value error, typically this is space
         # raise ValueError('Character value {:} is unsupported.'.format(ch))
     offset = relch * 2            # index is 2 bytes/char
     offset =  self._index[offset] + (self._index[offset + 1] << 8)
     delta = (relch + 1) * 2            # index is 2 bytes/char
     delta =  (self._index[delta] + (self._index[delta + 1] << 8)) - offset
     return addressof(self._font) + offset, self.bits_vert, (delta * 8) // self.bits_vert
开发者ID:robert-hh,项目名称:SSD1963-TFT-Library-for-PyBoard,代码行数:11,代码来源:TFTfont.py

示例10: one_line_data

    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
开发者ID:biazzotto,项目名称:micropython-epaper,代码行数:17,代码来源:epdpart.py

示例11: next

    def next(self):
            if self.subf:
                self.subf.skip()
            buf = self.f.read(512)
            if not buf:
                return None

            h = uctypes.struct(uctypes.addressof(buf), TAR_HEADER, uctypes.LITTLE_ENDIAN)

            # Empty block means end of archive
            if h.name[0] == 0:
                return None

            d = TarInfo()
            d.name = str(h.name, "utf-8").rstrip()
            d.size = int(bytes(h.size).rstrip(), 8)
            d.type = [REGTYPE, DIRTYPE][d.name[-1] == "/"]
            self.subf = d.subf = FileSection(self.f, d.size, roundup(d.size, 512))
            return d
开发者ID:WisdomWolf,项目名称:micropython-lib,代码行数:19,代码来源:utarfile.py

示例12: _addressable

 def _addressable(self, v):
     # This dance is so we create less garbage on the heap
     if isinstance(v, bytearray):
         pass
     elif isinstance(v, bytes):
         v = addressof(v)
     else:
         #vb = bytearray(iter(vb))
         vb = self.set_led_buf # Reuse to minimise heap impact
         #print("vb starts as", vb, end=' ')
         try:
             for i in range(3):
                 vb[i] = v[i]
             #print("vb is", vb, end=' ')
         except:
             it = iter(v)
             vb[0] = next(it)
             vb[1] = next(it)
             vb[2] = next(it)
         v = vb
     return v
开发者ID:pramasoul,项目名称:micropython-ws2812,代码行数:21,代码来源:ws2812.py

示例13: draw

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]))
开发者ID:peterhinch,项目名称:micropython-tft-gui,代码行数:2,代码来源:threestate.py

示例14: bytearray

    # aligned
    "arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1),
    "arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}),

    "arr8": (uctypes.ARRAY | 0, uctypes.INT8 | 1),
    "arr9": (uctypes.ARRAY | 0, uctypes.INT16 | 1),
    "arr10": (uctypes.ARRAY | 0, uctypes.INT32 | 1),
    "arr11": (uctypes.ARRAY | 0, uctypes.INT64 | 1),
    "arr12": (uctypes.ARRAY | 0, uctypes.UINT64| 1),
    "arr13": (uctypes.ARRAY | 1, 1, {"l": {}}),
}

data = bytearray(8)

S = uctypes.struct(uctypes.addressof(data), desc)

# assign byte
S.arr[0] = 0x11
print(hex(S.arr[0]))
assert hex(S.arr[0]) == "0x11"

# assign word
S.arr3[0] = 0x2233
print(hex(S.arr3[0]))
assert hex(S.arr3[0]) == "0x2233"

# assign word, with index
S.arr3[1] = 0x4455
print(hex(S.arr3[1]))
assert hex(S.arr3[1]) == "0x4455"
开发者ID:BWhitten,项目名称:micropython,代码行数:30,代码来源:uctypes_array_assign_native_le.py

示例15: get_icon

def get_icon(icon_index = 0, color_index = 0):
    return width, height, addressof(_icons[icon_index]), colors, addressof(colortable[color_index])
开发者ID:peterhinch,项目名称:micropython-tft-gui,代码行数:2,代码来源:threestate.py


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