droidDepotPythonControl/keyboard_control.py
hornet 8e02ed1a8b
feature/button_input (#2)
* Added keyboard functionality for existing features

* Droid won't repeat most recent noise

* Starting button input

* bcm

* async

* no args

* no arglist

* asycnio

* lgpio

* asyncio

* wait

* async

* asycn

* remove wait

* added keyboard interrup

* params

* test

* got callbacks working

* added keyboard control update

* droid commands have movement

* i do not honestly know what is different

* added movement stub

* added movement support?

* string

* format string

* trying less space

* added global

* manual control

* select_speed

* stop

* droid running

* stupid multiple naming

* play sound fixed

* testing forward functionality

* callback

* move

* rotate head

* typo
2022-10-19 22:11:43 -04:00

88 lines
1.9 KiB
Python

import asyncio
from re import L
from time import sleep
from random import randrange
import droid_commands as d
from droid import Directions
runningDroid = True
async def select_noise(d):
bank = input("\tBank> ")
sound = input("\tSound> ")
await d.play_specific_sound(bank, sound)
async def play_sound(d):
await d.play_sound()
async def select_speed(d):
direction = input("\tDirection> ")
motor = input("\tMotor> ")
speed = input("\tSpeed> ")
await d.move_manually(direction, motor, speed)
async def forward(d):
await d.move_droid(Directions.FORWARD)
async def backward(d):
await d.move_droid(Directions.BACKWARD)
async def left(d):
await d.move_droid(Directions.LEFT)
async def right(d):
await d.move_droid(Directions.RIGHT)
async def move_stop(d):
await d.move_stop()
async def quit(d):
global runningDroid
runningDroid = False
async def main():
# first, get droid
await d.start_droid()
commands = {
"w": forward,
"a": left,
"s": backward,
"d": right,
"x": move_stop,
"z": select_speed,
#"e": rotate counter-clockwise,
#"r": rotate clockwise,
#"f": special effect
"n": play_sound,
"m": select_noise,
"q": quit
}
try:
global runningDroid
while runningDroid:
# next, await input
command = input("Please input a command > ")
# next, parse that command
c = command.lower()[0:1]
if c in commands.keys():
await commands[c](d)
else:
print("Command does not exist.")
sleep(0.2)
except Exception as e:
print(e)
finally:
await d.stop_droid()
if __name__ == "__main__":
asyncio.run(main())