def updateJoypadWithZ(self, x,y,z,b): #print x, y, z, b x = arduino_map(x, -255, 255, 0,255) y = arduino_map(-y, -255, 255, 0,255) z = arduino_map(z, -255, 255, 0,255) msg = format(x,'02X') + format(y,'02X') + format(b, '02X') + format(z, '02X') self.bot.sendHexString(msg)
def __removed_updateJoypadWithZ(self, x,y,z,b): print x, y, z, b x = arduino_map(x, -255, 255, 0,255) y = arduino_map(-y, -255, 255, 0,255) z = arduino_map(z, -255, 255, 0,255) msg = format(x,'02X') + format(y,'02X') + format(b, '02X') + format(z, '02X') self.bot.sendHexString(msg)
def updateJoypad(self, x, y, b): #print x,y,b x = arduino_map(x, -255, 255, 0, 255) y = arduino_map(-y, -255, 255, 0, 255) msg = format(x, '02X') + format(y, '02X') + format(b, '02X') + format( 127, '02X') self.bot.sendHexString(msg)
def createJoypadMessage(x, y, z, b): #print x,y,z,b x = arduino_map(x, -255, 255, 0, 255) y = arduino_map(-y, -255, 255, 0, 255) z = arduino_map(z, -255, 255, 0, 255) return format(x, '02X') + format(y, '02X') + format(b, '02X') + format( z, '02X')
class Joypad: """ Joypad """ def __init__(self): """ init """ self.x = 120 self.y = 120 self.z = 240 - 64 self.b = 0 self.lastUpdateTime = time.time() self.running = True self.display = Display() self.screen = self.display.screen self.loadImages() self.connectBot() self.clock = pygame.time.Clock() def loadImages(self): self.logo = pygame.image.load( basedir + "/images/cannybots_logo_small.png").convert_alpha() self.joystick = pygame.image.load( basedir + "/images/joystick.png").convert_alpha() self.knob = pygame.image.load(basedir + "/images/knob.png").convert_alpha() self.button = pygame.image.load(basedir + "/images/button.png").convert_alpha() def connectBot(self): self.ble = BLE() if botName != "": self.myBot = self.ble.findNearest() else: self.myBot = self.ble.findByName(botName) self.joypadClient = SimpleJoypadClient(self.myBot) def updateJoypad(self, (newX, newY), force): if (newX > 320 - 64) and newY < 240 - 32 and newY > 32: self.z = newY - 32 if newX < 240: self.x = newX self.y = newY if force: self.z = 240 - 64 if force or (time.time() - self.lastUpdateTime) > 0.05: x = arduino_map(self.x - 120, -120, 120, -255, 255) y = arduino_map(self.y - 120, -120, 120, -255, 255) z = arduino_map(240 - 64 - self.z, 0, 240 - 32, 0, -255) self.joypadClient.updateJoypadWithZ(x, y, z * zMultiplier, self.b) self.lastUpdateTime = time.time()
def createJoypadMessage(x,y,z,b): #print x,y,z,b x = arduino_map(x, -255, 255, 0,255) y = arduino_map(-y, -255, 255, 0,255) z = arduino_map(z, -255, 255, 0,255) return format(x,'02X') + format(y,'02X') + format(b, '02X') + format(z, '02X')
def __removed__updateJoypad(self, x, y, b): #print x,y,b x = arduino_map(x, -255, 255, 0, 255) y = arduino_map(-y, -255, 255, 0, 255) msg = format(x,'02X') + format(y,'02X') + format(b, '02X') + format(127, '02X') self.bot.sendHexString(msg)