def right(): """one step to the right""" conn_lock.acquire() if conn == True: toCliQ.put(CR.CRclass(commands.step("right"))) cli_lock.acquire() cli_alarm.notify() cli_lock.release() conn_lock.release()
def back(): """one step backward""" conn_lock.acquire() if conn == True: toCliQ.put(CR.CRclass(commands.step("back"))) cli_lock.acquire() cli_alarm.notify() cli_lock.release() conn_lock.release()
def fwd(): """one step forward""" conn_lock.acquire() if conn == True: toCliQ.put(CR.CRclass(commands.step())) cli_lock.acquire() cli_alarm.notify() cli_lock.release() conn_lock.release()
def keyboardControl(): """this thread is responsible for keyboard control""" global escape_lock global escape global keyb_lock global keyb global toCliQ global toKeybQ pygame.init() escape_lock.acquire() while escape == False: escape_lock.release() pack = ["", requests.ready()] for event in pygame.event.get(): keyb_lock.acquire() if event.type == pygame.KEYDOWN and keyb == True: keyb_lock.release() if event.key == pygame.K_w: #w pack[0] = commands.step("backward") toCliQ.put(CR.CRclass(pack, toKeybQ, None, None, True)) cli_lock.acquire() cli_alarm.notify() cli_lock.release() rdy = False while rdy is False: for r in toKeybQ.get( ): #this will block until cli return response if r == [requests.ready(), reports.yes()]: rdy = True break if rdy is True: break toCliQ.put( CR.CRclass(requests.ready(), toKeybQ, None, None, True)) cli_lock.acquire() cli_alarm.notify() cli_lock.release() time.sleep(0.2) elif event.key == pygame.K_s: #s pack[0] = commands.step("backward") toCliQ.put(CR.CRclass(pack, toKeybQ, None, None, True)) cli_lock.acquire() cli_alarm.notify() cli_lock.release() rdy = False while rdy is False: for r in toKeybQ.get( ): #this will block until cli return response if r == [requests.ready(), reports.yes()]: rdy = True break if rdy is True: break toCliQ.put( CR.CRclass(requests.ready(), toKeybQ, None, None, True)) cli_lock.acquire() cli_alarm.notify() cli_lock.release() time.sleep(0.2) elif event.key == pygame.K_a: pack[0] = commands.step("left") toCliQ.put(CR.CRclass(pack, toKeybQ, None, None, True)) cli_lock.acquire() cli_alarm.notify() cli_lock.release() rdy = False while rdy is False: for r in toKeybQ.get( ): #this will block until cli return response if r == [requests.ready(), reports.yes()]: rdy = True break if rdy is True: break toCliQ.put( CR.CRclass(requests.ready(), toKeybQ, None, None, True)) cli_lock.acquire() cli_alarm.notify() cli_lock.release() time.sleep(0.2) elif event.key == pygame.K_d: pack[0] = commands.step("right") toCliQ.put(CR.CRclass(pack, toKeybQ, None, None, True)) cli_lock.acquire() cli_alarm.notify() cli_lock.release() rdy = False while rdy is False: for r in toKeybQ.get( ): #this will block until cli return response if r == [requests.ready(), reports.yes()]: rdy = True break if rdy is True: break toCliQ.put( CR.CRclass(requests.ready(), toKeybQ, None, None, True)) cli_lock.acquire() cli_alarm.notify() cli_lock.release() time.sleep(0.2) elif event.key == pygame.K_q: pack[0] = commands.rotate("ccw") toCliQ.put(CR.CRclass(pack, toKeybQ, None, None, True)) cli_lock.acquire() cli_alarm.notify() cli_lock.release() rdy = False while rdy is False: for r in toKeybQ.get( ): #this will block until cli return response if r == [requests.ready(), reports.yes()]: rdy = True break if rdy is True: break toCliQ.put( CR.CRclass(requests.ready(), toKeybQ, None, None, True)) cli_lock.acquire() cli_alarm.notify() cli_lock.release() time.sleep(0.2) elif event.key == pygame.K_e: pack[0] = commands.rotate("cw") toCliQ.put(CR.CRclass(pack, toKeybQ, None, None, True)) cli_lock.acquire() cli_alarm.notify() cli_lock.release() rdy = False while rdy is False: for r in toKeybQ.get( ): #this will block until cli return response if r == [requests.ready(), reports.yes()]: rdy = True break if rdy is True: break toCliQ.put( CR.CRclass(requests.ready(), toKeybQ, None, None, True)) cli_lock.acquire() cli_alarm.notify() cli_lock.release() time.sleep(0.2) elif event.key == pygame.K_j: toDispQ.put(4) elif event.key == pygame.K_l: toDispQ.put(-4) else: keyb_lock.release() escape_lock.acquire() time.sleep(0.1) escape_lock.release()