serial_gamepad.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:BiblioPixel2 作者: ManiacalLabs 项目源码 文件源码
def getKeys(self):
        bits = 0
        try:
            packet = SerialGamePad._generateHeader(CMDTYPE.GET_BTNS, 0)
            self._com.write(packet)
            resp = self._com.read(1)

            if len(resp) == 0:
                SerialGamePad._comError()
            elif ord(resp) != RETURN_CODES.SUCCESS:
                SerialGamePad._printError(ord(resp))
            resp = self._com.read(2)
            if len(resp) != 2:
                SerialGamePad._comError()

            bits = ord(resp[0]) + (ord(resp[1]) << 8)
        except IOError:
            log.error("IO Error Communicatng With Game Pad!")

        index = 0
        result = {}
        for m in self._map:
            result[m] = (bits & (1 << index) > 0)
            index += 1
        return d(result)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号