python类c_ubyte()的实例源码

vrep.py 文件源码 项目:vrep-maze-solver 作者: youralien 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def simxReadProximitySensor(clientID, sensorHandle, operationMode):
    '''
    Please have a look at the function description/documentation in the V-REP user manual
    '''

    detectionState = ct.c_ubyte()
    detectedObjectHandle = ct.c_int()
    detectedPoint  = (ct.c_float*3)()
    detectedSurfaceNormalVector = (ct.c_float*3)()
    ret = c_ReadProximitySensor(clientID, sensorHandle, ct.byref(detectionState), detectedPoint, ct.byref(detectedObjectHandle), detectedSurfaceNormalVector, operationMode)
    arr1 = []
    for i in range(3):
        arr1.append(detectedPoint[i])
    arr2 = []
    for i in range(3):
        arr2.append(detectedSurfaceNormalVector[i])
    return ret, bool(detectionState.value!=0), arr1, detectedObjectHandle.value, arr2
vrep.py 文件源码 项目:vrep-maze-solver 作者: youralien 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def simxGetAndClearStringSignal(clientID, signalName, operationMode):
    '''
    Please have a look at the function description/documentation in the V-REP user manual
    '''

    signalLength = ct.c_int();
    signalValue = ct.POINTER(ct.c_ubyte)()
    if (sys.version_info[0] == 3) and (type(signalName) is str):
        signalName=signalName.encode('utf-8')
    ret = c_GetAndClearStringSignal(clientID, signalName, ct.byref(signalValue), ct.byref(signalLength), operationMode)

    a = bytearray()
    if ret == 0:
        for i in range(signalLength.value):
            a.append(signalValue[i])
    if sys.version_info[0] != 3:
        a=str(a)

    return ret, a
vrep.py 文件源码 项目:vrep-maze-solver 作者: youralien 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def simxReadStringStream(clientID, signalName, operationMode):
    '''
    Please have a look at the function description/documentation in the V-REP user manual
    '''

    signalLength = ct.c_int();
    signalValue = ct.POINTER(ct.c_ubyte)()
    if (sys.version_info[0] == 3) and (type(signalName) is str):
        signalName=signalName.encode('utf-8')
    ret = c_ReadStringStream(clientID, signalName, ct.byref(signalValue), ct.byref(signalLength), operationMode)

    a = bytearray()
    if ret == 0:
        for i in range(signalLength.value):
            a.append(signalValue[i])
    if sys.version_info[0] != 3:
        a=str(a)

    return ret, a
vrep.py 文件源码 项目:vrep-maze-solver 作者: youralien 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def simxSetStringSignal(clientID, signalName, signalValue, operationMode):
    '''
    Please have a look at the function description/documentation in the V-REP user manual
    '''

    sigV=signalValue
    if sys.version_info[0] == 3:
        if type(signalName) is str:
            signalName=signalName.encode('utf-8')
        if type(signalValue) is bytearray:
            sigV  = (ct.c_ubyte*len(signalValue))(*signalValue)
        if type(signalValue) is str:
            signalValue=signalValue.encode('utf-8')
            sigV  = (ct.c_ubyte*len(signalValue))(*signalValue)
    else:
        if type(signalValue) is bytearray:
            sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
        if type(signalValue) is str:
            signalValue=bytearray(signalValue)
            sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
    sigV=ct.cast(sigV,ct.POINTER(ct.c_ubyte)) # IronPython needs this
    return c_SetStringSignal(clientID, signalName, sigV, len(signalValue), operationMode)
vrep.py 文件源码 项目:vrep-maze-solver 作者: youralien 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def simxAppendStringSignal(clientID, signalName, signalValue, operationMode):
    '''
    Please have a look at the function description/documentation in the V-REP user manual
    '''

    sigV=signalValue
    if sys.version_info[0] == 3:
        if type(signalName) is str:
            signalName=signalName.encode('utf-8')
        if type(signalValue) is bytearray:
            sigV  = (ct.c_ubyte*len(signalValue))(*signalValue)
        if type(signalValue) is str:
            signalValue=signalValue.encode('utf-8')
            sigV  = (ct.c_ubyte*len(signalValue))(*signalValue)
    else:
        if type(signalValue) is bytearray:
            sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
        if type(signalValue) is str:
            signalValue=bytearray(signalValue)
            sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
    sigV=ct.cast(sigV,ct.POINTER(ct.c_ubyte)) # IronPython needs this
    return c_AppendStringSignal(clientID, signalName, sigV, len(signalValue), operationMode)
vrep.py 文件源码 项目:vrep-maze-solver 作者: youralien 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def simxWriteStringStream(clientID, signalName, signalValue, operationMode):
    '''
    Please have a look at the function description/documentation in the V-REP user manual
    '''

    sigV=signalValue
    if sys.version_info[0] == 3:
        if type(signalName) is str:
            signalName=signalName.encode('utf-8')
        if type(signalValue) is bytearray:
            sigV  = (ct.c_ubyte*len(signalValue))(*signalValue)
        if type(signalValue) is str:
            signalValue=signalValue.encode('utf-8')
            sigV  = (ct.c_ubyte*len(signalValue))(*signalValue)
    else:
        if type(signalValue) is bytearray:
            sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
        if type(signalValue) is str:
            signalValue=bytearray(signalValue)
            sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
    sigV=ct.cast(sigV,ct.POINTER(ct.c_ubyte)) # IronPython needs this
    return c_WriteStringStream(clientID, signalName, sigV, len(signalValue), operationMode)
pijuice.py 文件源码 项目:PiJuice 作者: PiSupply 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def SetCustomBatteryProfile(self, profile):
        d = [0x00] * 14
        try:
            c = profile['capacity']
            d[0] = c&0xFF
            d[1] = (c >> 8)&0xFF
            d[2] = int(round((profile['chargeCurrent'] - 550) / 75))
            d[3] = int(round((profile['terminationCurrent'] - 50) / 50))
            d[4] = int(round((profile['regulationVoltage'] - 3500) / 20))
            d[5] = int(round(profile['cutoffVoltage'] / 20))
            d[6] = ctypes.c_ubyte(profile['tempCold']).value
            d[7] = ctypes.c_ubyte(profile['tempCool']).value
            d[8] = ctypes.c_ubyte(profile['tempWarm']).value
            d[9] = ctypes.c_ubyte(profile['tempHot']).value
            B = profile['ntcB']
            d[10] = B&0xFF
            d[11] = (B >> 8)&0xFF
            R = profile['ntcResistance'] / 10
            d[12] = R&0xFF
            d[13] = (R >> 8)&0xFF
        except:
            return {'error':'BAD_ARGUMENT'}
        print d
        return self.interface.WriteDataVerify(self.BATTERY_PROFILE_CMD, d, 0.2)
pijuice.py 文件源码 项目:PiJuice 作者: PiSupply 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def SetCustomBatteryProfile(self, profile):
        d = [0x00] * 14
        try:
            c = profile['capacity']
            d[0] = c&0xFF
            d[1] = (c >> 8)&0xFF
            d[2] = int(round((profile['chargeCurrent'] - 550) / 75))
            d[3] = int(round((profile['terminationCurrent'] - 50) / 50))
            d[4] = int(round((profile['regulationVoltage'] - 3500) / 20))
            d[5] = int(round(profile['cutoffVoltage'] / 20))
            d[6] = ctypes.c_ubyte(profile['tempCold']).value
            d[7] = ctypes.c_ubyte(profile['tempCool']).value
            d[8] = ctypes.c_ubyte(profile['tempWarm']).value
            d[9] = ctypes.c_ubyte(profile['tempHot']).value
            B = profile['ntcB']
            d[10] = B&0xFF
            d[11] = (B >> 8)&0xFF
            R = profile['ntcResistance'] / 10
            d[12] = R&0xFF
            d[13] = (R >> 8)&0xFF
        except:
            return {'error':'BAD_ARGUMENT'}
        print d
        return self.interface.WriteDataVerify(self.BATTERY_PROFILE_CMD, d, 0.2)
pijuice.py 文件源码 项目:PiJuice 作者: PiSupply 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def SetCustomBatteryProfile(self, profile):
        d = [0x00] * 14
        try:
            c = profile['capacity']
            d[0] = c&0xFF
            d[1] = (c >> 8)&0xFF
            d[2] = int(round((profile['chargeCurrent'] - 550) / 75))
            d[3] = int(round((profile['terminationCurrent'] - 50) / 50))
            d[4] = int(round((profile['regulationVoltage'] - 3500) / 20))
            d[5] = int(round(profile['cutoffVoltage'] / 20))
            d[6] = ctypes.c_ubyte(profile['tempCold']).value
            d[7] = ctypes.c_ubyte(profile['tempCool']).value
            d[8] = ctypes.c_ubyte(profile['tempWarm']).value
            d[9] = ctypes.c_ubyte(profile['tempHot']).value
            B = profile['ntcB']
            d[10] = B&0xFF
            d[11] = (B >> 8)&0xFF
            R = profile['ntcResistance'] / 10
            d[12] = R&0xFF
            d[13] = (R >> 8)&0xFF
        except:
            return {'error':'BAD_ARGUMENT'}
        print d
        return self.interface.WriteDataVerify(self.BATTERY_PROFILE_CMD, d, 0.2)
pijuice.py 文件源码 项目:PiJuice 作者: PiSupply 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def SetCustomBatteryProfile(self, profile):
        d = [0x00] * 14
        try:
            c = profile['capacity']
            d[0] = c&0xFF
            d[1] = (c >> 8)&0xFF
            d[2] = int(round((profile['chargeCurrent'] - 550) / 75))
            d[3] = int(round((profile['terminationCurrent'] - 50) / 50))
            d[4] = int(round((profile['regulationVoltage'] - 3500) / 20))
            d[5] = int(round(profile['cutoffVoltage'] / 20))
            d[6] = ctypes.c_ubyte(profile['tempCold']).value
            d[7] = ctypes.c_ubyte(profile['tempCool']).value
            d[8] = ctypes.c_ubyte(profile['tempWarm']).value
            d[9] = ctypes.c_ubyte(profile['tempHot']).value
            B = profile['ntcB']
            d[10] = B&0xFF
            d[11] = (B >> 8)&0xFF
            R = profile['ntcResistance'] / 10
            d[12] = R&0xFF
            d[13] = (R >> 8)&0xFF
        except:
            return {'error':'BAD_ARGUMENT'}
        print d
        return self.interface.WriteDataVerify(self.BATTERY_PROFILE_CMD, d, 0.2)
pijuice.py 文件源码 项目:PiJuice 作者: PiSupply 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def SetCustomBatteryProfile(self, profile):
        d = [0x00] * 14
        try:
            c = profile['capacity']
            d[0] = c&0xFF
            d[1] = (c >> 8)&0xFF
            d[2] = int(round((profile['chargeCurrent'] - 550) / 75))
            d[3] = int(round((profile['terminationCurrent'] - 50) / 50))
            d[4] = int(round((profile['regulationVoltage'] - 3500) / 20))
            d[5] = int(round(profile['cutoffVoltage'] / 20))
            d[6] = ctypes.c_ubyte(profile['tempCold']).value
            d[7] = ctypes.c_ubyte(profile['tempCool']).value
            d[8] = ctypes.c_ubyte(profile['tempWarm']).value
            d[9] = ctypes.c_ubyte(profile['tempHot']).value
            B = profile['ntcB']
            d[10] = B&0xFF
            d[11] = (B >> 8)&0xFF
            R = profile['ntcResistance'] / 10
            d[12] = R&0xFF
            d[13] = (R >> 8)&0xFF
        except:
            return {'error':'BAD_ARGUMENT'}
        print d
        return self.interface.WriteDataVerify(self.BATTERY_PROFILE_CMD, d, 0.2)
procedural.py 文件源码 项目:FightstickDisplay 作者: calexil 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _generate_data(self, num_bytes, offset):
        if self._bytes_per_sample == 1:
            start = offset
            samples = num_bytes
            bias = 127
            amplitude = 127
            data = (ctypes.c_ubyte * samples)()
        else:
            start = offset >> 1
            samples = num_bytes >> 1
            bias = 0
            amplitude = 32767
            data = (ctypes.c_short * samples)()
        step = self.frequency * (math.pi * 2) / self.audio_format.sample_rate
        envelope = self._envelope_array
        env_offset = offset // self._bytes_per_sample
        for i in range(samples):
            data[i] = int(math.sin(step * (i + start)) *
                          amplitude * envelope[i+env_offset] + bias)
        return data
procedural.py 文件源码 项目:FightstickDisplay 作者: calexil 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _generate_data(self, num_bytes, offset):
        # XXX TODO consider offset
        if self._bytes_per_sample == 1:
            samples = num_bytes
            value = 127
            maximum = 255
            minimum = 0
            data = (ctypes.c_ubyte * samples)()
        else:
            samples = num_bytes >> 1
            value = 0
            maximum = 32767
            minimum = -32768
            data = (ctypes.c_short * samples)()
        step = (maximum - minimum) * self.frequency / self._sample_rate
        envelope = self._envelope_array
        env_offset = offset // self._bytes_per_sample
        for i in range(samples):
            value += step
            if value > maximum:
                value = minimum + (value % maximum)
            data[i] = int(value * envelope[i+env_offset])
        return data
procedural.py 文件源码 项目:FightstickDisplay 作者: calexil 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _generate_data(self, num_bytes, offset):
        if self._bytes_per_sample == 1:
            start = offset
            samples = num_bytes
            bias = 127
            amplitude = 127
            data = (ctypes.c_ubyte * samples)()
        else:
            start = offset >> 1
            samples = num_bytes >> 1
            bias = 0
            amplitude = 32767
            data = (ctypes.c_short * samples)()
        self._advance(start)
        ring_buffer = self.ring_buffer
        decay = self.decay
        for i in range(samples):
            data[i] = int(ring_buffer[0] * amplitude + bias)
            ring_buffer.append(decay * (ring_buffer[0] + ring_buffer[1]) / 2)
        return data
bmp.py 文件源码 项目:FightstickDisplay 作者: calexil 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def decode_bitfields(bits, r_mask, g_mask, b_mask, 
                     width, height, pitch, pitch_sign):
    r_shift1, r_shift2 = get_shift(r_mask)
    g_shift1, g_shift2 = get_shift(g_mask)
    b_shift1, b_shift2 = get_shift(b_mask)

    rgb_pitch = 3 * len(bits[0])
    buffer = (ctypes.c_ubyte * (height * rgb_pitch))()

    i = 0
    for row in bits:
        for packed in row:
            buffer[i] = (packed & r_mask) >> r_shift1 << r_shift2
            buffer[i+1] = (packed & g_mask) >> g_shift1 << g_shift2
            buffer[i+2] = (packed & b_mask) >> b_shift1 << b_shift2
            i += 3

    return ImageData(width, height, 'RGB', buffer, pitch_sign * rgb_pitch)
procedural.py 文件源码 项目:cryptogram 作者: xinmingzhang 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _generate_data(self, bytes, offset):
        if self._bytes_per_sample == 1:
            start = offset
            samples = bytes
            bias = 127
            amplitude = 127
            data = (ctypes.c_ubyte * samples)()
        else:
            start = offset >> 1
            samples = bytes >> 1
            bias = 0
            amplitude = 32767
            data = (ctypes.c_short * samples)()
        step = self.frequency * (math.pi * 2) / self.audio_format.sample_rate
        for i in range(samples):
            data[i] = future_round(math.sin(step * (i + start)) * amplitude + bias)
        return data
procedural.py 文件源码 项目:cryptogram 作者: xinmingzhang 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _generate_data(self, bytes, offset):
        # XXX TODO consider offset
        if self._bytes_per_sample == 1:
            samples = bytes
            value = 127
            max = 255
            min = 0
            data = (ctypes.c_ubyte * samples)()
        else:
            samples = bytes >> 1
            value = 0
            max = 32767
            min = -32768
            data = (ctypes.c_short * samples)()
        step = (max - min) * 2 * self.frequency / self.audio_format.sample_rate
        for i in range(samples):
            value += step
            if value > max:
                value = max - (value - max)
                step = -step
            if value < min:
                value = min - (value - min)
                step = -step
            data[i] = future_round(value)
        return data
procedural.py 文件源码 项目:cryptogram 作者: xinmingzhang 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _generate_data(self, bytes, offset):
        # XXX TODO consider offset
        if self._bytes_per_sample == 1:
            samples = bytes
            value = 0
            amplitude = 255
            data = (ctypes.c_ubyte * samples)()
        else:
            samples = bytes >> 1
            value = -32768
            amplitude = 65535
            data = (ctypes.c_short * samples)()
        period = self.audio_format.sample_rate / self.frequency / 2
        count = 0
        for i in range(samples):
            count += 1
            if count == period:
                value = amplitude - value
                count = 0
            data[i] = future_round(value)
        return data
bmp.py 文件源码 项目:cryptogram 作者: xinmingzhang 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def decode_bitfields(bits, r_mask, g_mask, b_mask, 
                     width, height, pitch, pitch_sign):
    r_shift1, r_shift2 = get_shift(r_mask)
    g_shift1, g_shift2 = get_shift(g_mask)
    b_shift1, b_shift2 = get_shift(b_mask)

    rgb_pitch = 3 * len(bits[0])
    buffer = (ctypes.c_ubyte * (height * rgb_pitch))()

    i = 0
    for row in bits:
        for packed in row:
            buffer[i] = (packed & r_mask) >> r_shift1 << r_shift2
            buffer[i+1] = (packed & g_mask) >> g_shift1 << g_shift2
            buffer[i+2] = (packed & b_mask) >> b_shift1 << b_shift2
            i += 3

    return ImageData(width, height, 'RGB', buffer, pitch_sign * rgb_pitch)
dbussy.py 文件源码 项目:dbussy 作者: ldo 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def marshal(self) :
        "serializes this Message into the wire protocol format and returns a bytes object."
        buf = ct.POINTER(ct.c_ubyte)()
        nr_bytes = ct.c_int()
        if not dbus.dbus_message_marshal(self._dbobj, ct.byref(buf), ct.byref(nr_bytes)) :
            raise CallFailed("dbus_message_marshal")
        #end if
        result = bytearray(nr_bytes.value)
        ct.memmove \
          (
            ct.addressof((ct.c_ubyte * nr_bytes.value).from_buffer(result)),
            buf,
            nr_bytes.value
          )
        dbus.dbus_free(buf)
        return \
            result
    #end marshal


问题


面经


文章

微信
公众号

扫码关注公众号