• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python uctypes.addressof函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: print

# This test checks previously known problem values for 32-bit ports.
# It's less useful for 64-bit ports.
try:
    import uctypes
except ImportError:
    import sys
    print("SKIP")
    sys.exit()

buf = b"12345678abcd"
struct = uctypes.struct(
    uctypes.addressof(buf),
    {"f32": uctypes.UINT32 | 0, "f64": uctypes.UINT64 | 4},
    uctypes.LITTLE_ENDIAN
)

struct.f32 = 0x7fffffff
print(buf)

struct.f32 = 0x80000000
print(buf)

struct.f32 = 0xff010203
print(buf)

struct.f64 = 0x80000000
print(buf)

struct.f64 = 0x80000000 * 2
print(buf)
开发者ID:BWhitten,项目名称:micropython,代码行数:30,代码来源:uctypes_32bit_intbig.py


示例17: bytearray

    "arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
    "bitf0": uctypes.BFUINT16 | 0 | 0 << uctypes.BF_POS | 8 << uctypes.BF_LEN,
    "bitf1": uctypes.BFUINT16 | 0 | 8 << uctypes.BF_POS | 8 << uctypes.BF_LEN,

    "bf0": uctypes.BFUINT16 | 0 |  0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
    "bf1": uctypes.BFUINT16 | 0 |  4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
    "bf2": uctypes.BFUINT16 | 0 |  8 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
    "bf3": uctypes.BFUINT16 | 0 | 12 << uctypes.BF_POS | 4 << uctypes.BF_LEN,

    "ptr": (uctypes.PTR | 0, uctypes.UINT8),
    "ptr2": (uctypes.PTR | 0, {"b": uctypes.UINT8 | 0}),
}

data = bytearray(b"01")

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

#print(S)
print(hex(S.s0))
assert hex(S.s0) == "0x3130"
#print(S.sub.b0)
print(S.sub.b0, S.sub.b1)
assert S.sub.b0, S.sub.b1 == (0x30, 0x31)

try:
    S[0]
    assert False, "Can't index struct"
except TypeError:
    print("TypeError")

print("arr:", S.arr[0], S.arr[1])
开发者ID:fabaff,项目名称:micropython,代码行数:31,代码来源:uctypes_le.py


示例18: print

import uctypes

if sys.byteorder != "little":
    print("SKIP")
    sys.exit()


desc = {
    "ptr": (uctypes.PTR | 0, uctypes.UINT8),
    "ptr16": (uctypes.PTR | 0, uctypes.UINT16),
    "ptr2": (uctypes.PTR | 0, {"b": uctypes.UINT8 | 0}),
}

bytes = b"01"

addr = uctypes.addressof(bytes)
buf = addr.to_bytes(uctypes.sizeof(desc))

S = uctypes.struct(uctypes.addressof(buf), desc, uctypes.NATIVE)

print(S.ptr[0])
assert S.ptr[0] == ord("0")
print(S.ptr[1])
assert S.ptr[1] == ord("1")
print(hex(S.ptr16[0]))
assert hex(S.ptr16[0]) == "0x3130"
print(S.ptr2[0].b, S.ptr2[1].b)
print (S.ptr2[0].b, S.ptr2[1].b)
print(hex(S.ptr16[0]))
assert (S.ptr2[0].b, S.ptr2[1].b) == (48, 49)
开发者ID:19emtuck,项目名称:micropython,代码行数:30,代码来源:uctypes_ptr_native_le.py


示例19: _clearLEDs

def _clearLEDs(buf, i, qty):
    # Clear qty LEDs in buffer starting at i
    a = addressof(buf)
    _fillwords(a + 4*3*i, 0x11111111, 3*qty)
开发者ID:pramasoul,项目名称:micropython-ws2812,代码行数:4,代码来源:ws2812_helper_pyb.py


示例20: __init__

    def __init__(self, dev_port, show=Bus.SHOW_NONE):

        desc = {
            "model": uctypes.UINT16 | 0,
            "version": uctypes.UINT8 | 2,
            "dev_id": uctypes.UINT8 | 3,
            "baud_rate": uctypes.UINT8 | 4,
            "rdt": uctypes.UINT8 | 5,
            "num_adcs": uctypes.UINT8 | cfg.NUM_ADCS_OFFSET,
            "num_gpios": uctypes.UINT8 | cfg.NUM_GPIOS_OFFSET,
            "adc_pin": (
                uctypes.ARRAY | cfg.ADC_PIN,
                cfg.NUM_ADCS,
                {
                    "port": uctypes.BFUINT8 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
                    "pin": uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
                },
            ),
            "gpio_pin": (
                uctypes.ARRAY | cfg.GPIO_PIN,
                cfg.NUM_GPIOS,
                {
                    "port": uctypes.BFUINT8 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
                    "pin": uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
                },
            ),
            "gpio_cfg": (
                uctypes.ARRAY | cfg.GPIO_CFG,
                cfg.NUM_GPIOS,
                {
                    "dir": uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 1 << uctypes.BF_LEN,
                    "pu": uctypes.BFUINT8 | 0 | 1 << uctypes.BF_POS | 1 << uctypes.BF_LEN,
                    "pd": uctypes.BFUINT8 | 0 | 2 << uctypes.BF_POS | 1 << uctypes.BF_LEN,
                    "od": uctypes.BFUINT8 | 0 | 3 << uctypes.BF_POS | 1 << uctypes.BF_LEN,
                },
            ),
            # End of persistent values
            "adc_value": (uctypes.ARRAY | cfg.ADC_VALUE, uctypes.UINT16 | cfg.NUM_ADCS),
            "gpio_set": uctypes.UINT32 | cfg.GPIO_SET,
            "gpio_clear": uctypes.UINT32 | cfg.GPIO_CLEAR,
            "gpio_odr": uctypes.UINT32 | cfg.GPIO_ODR,
            "gpio_idr": uctypes.UINT32 | cfg.GPIO_IDR,
        }
        initial_bytes = bytearray(cfg.NUM_CTL_BYTES)
        init = uctypes.struct(uctypes.addressof(initial_bytes), desc, uctypes.LITTLE_ENDIAN)
        init.model = 123
        init.version = 1
        init.dev_id = Device.INITIAL_DEV_ID
        init.baud_rate = Device.INITIAL_BAUD
        init.rdt = Device.INITIAL_RDT
        for idx in range(cfg.NUM_GPIOS):
            init.gpio_cfg[idx].dir = 1

        ctl_bytes = bytearray(cfg.NUM_CTL_BYTES)
        self.ctl = uctypes.struct(uctypes.addressof(ctl_bytes), desc, uctypes.LITTLE_ENDIAN)

        notifications = (
            (cfg.ADC_PIN, cfg.NUM_ADCS, self.adc_pin_updated),
            (cfg.GPIO_PIN, cfg.NUM_GPIOS, self.gpio_pin_updated),
            (cfg.GPIO_CFG, cfg.NUM_GPIOS, self.gpio_cfg_updated),
            (cfg.GPIO_SET, 4, self.gpio_set_updated),
            (cfg.GPIO_CLEAR, 4, self.gpio_clear_updated),
            (cfg.GPIO_ODR, 4, self.gpio_odr_updated),
        )

        self.adc = [None] * cfg.NUM_ADCS
        self.gpio = [None] * cfg.NUM_GPIOS

        super().__init__(dev_port, cfg.PERSISTENT_BYTES, initial_bytes, ctl_bytes, notifications, show)
开发者ID:dhylands,项目名称:bioloid3,代码行数:69,代码来源:io_adapter.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python api.abort函数代码示例发布时间:2022-05-27
下一篇:
Python ucsmo.ManagedObject类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap