Skip to content
Snippets Groups Projects
Commit e5953db9 authored by mosesafr's avatar mosesafr
Browse files

Functional bluetooth client code, WASD bluetooth command support

parent 0b6db43b
No related branches found
No related tags found
No related merge requests found
File added
File added
from bluedot.btcomm import BluetoothServer
from bluedot.btcomm import BluetoothClient
from time import sleep
from signal import pause
from droneStatusEnum import DroneStatusEnum
......@@ -8,7 +8,7 @@ class BLEClientPi:
_instance = None
def __new__(cls):
if cls._instance is None:
cls._instance = super(BLEServicePi, cls).__new__(cls)
cls._instance = super(BLEClientPi, cls).__new__(cls)
cls._instance.coordinate_queue = None
cls._instance.command_queue = None
cls._instance.drone_status = DroneStatusEnum.Uninitialized
......@@ -16,23 +16,37 @@ class BLEClientPi:
cls._instance.bluetoothClient = None
return cls._instance
def data_received(data):
def data_received(cls,data):
print("recv - {}".format(data))
def send(cls, data):
cls.bluetoothClient.send(data)
def connect():
def send_command(cls, command):
# 100 ms delay to seperate commands
sleep(0.1)
cls.bluetoothClient.send(command)
def connect(cls):
try:
cls.bluetoothClient = BluetoothClient("pi4", data_received)
cls.bluetoothClient.send("Connectedddd")
cls.bluetoothClient = BluetoothClient("DC:A6:32:18:4C:22", cls.data_received)
cls.send_command(DroneCommandEnum.Clear_Queue.get_name())
keypress = ""
while keypress.upper() != "Q":
keypress = input("Enter Command")
keypress = keypress.upper()
cls.send_command(keypress)
#cls.send_command(DroneCommandEnum.W.get_name())
#cls.send_command(DroneCommandEnum.A.get_name())
#cls.send_command(DroneCommandEnum.S.get_name())
#cls.send_command(DroneCommandEnum.D.get_name())
finally:
cls.bluetoothClient.disconnect()
def main():
bluetoothClient = BLEClientPi()
bluetoothClient.start()
bluetoothClient.stop()
bluetoothClient.connect()
if __name__ == "__main__":
main()
......
......@@ -4,23 +4,38 @@ class DroneCommandEnum(Enum):
Get_Location = 2
Move = 3
Stop = 4
W = 5
A = 6
S = 7
D = 8
Clear_Queue = 9
def get_name(self):
command_names = {
DroneCommandEnum.Initialize: "Initialize_Command",
DroneCommandEnum.Get_Location: "Get_Location_Command",
DroneCommandEnum.Move: "Move_Command",
DroneCommandEnum.Stop: "Stop_Command",
}
return command_names[self]
command_names = {
DroneCommandEnum.Initialize: "Initialize_Command",
DroneCommandEnum.Get_Location: "Get_Location_Command",
DroneCommandEnum.Move: "Move_Command",
DroneCommandEnum.Stop: "Stop_Command",
DroneCommandEnum.W: "W",
DroneCommandEnum.A: "A",
DroneCommandEnum.S: "S",
DroneCommandEnum.D: "D",
DroneCommandEnum.Clear_Queue: "Clear_Queue"
}
return command_names[self]
def get_enum_by_name(name:str):
command_names = {
"Initialize_Command": DroneCommandEnum.Initialize,
"Get_Location_Command": DroneCommandEnum.Get_Location,
"Move_Command": DroneCommandEnum.Move,
"Stop_Command": DroneCommandEnum.Stop,
}
command_names = {
"Initialize_Command": DroneCommandEnum.Initialize,
"Get_Location_Command": DroneCommandEnum.Get_Location,
"Move_Command": DroneCommandEnum.Move,
"Stop_Command": DroneCommandEnum.Stop,
"W": DroneCommandEnum.W,
"A": DroneCommandEnum.A,
"S": DroneCommandEnum.S,
"D": DroneCommandEnum.D,
"Clear_Queue": DroneCommandEnum.Clear_Queue
}
return command_names[name]
raise ValueError(f"No enum member found with name: {name}")
\ No newline at end of file
return command_names[name]
raise ValueError(f"No enum member found with name: {name}")
\ No newline at end of file
......@@ -7,23 +7,23 @@ class DroneStatusEnum(Enum):
Stopped = 5
def get_name(self):
status_names = {
DroneStatusEnum.Uninitialized: "Uninitialized",
DroneStatusEnum.Location_Unknown_Idle: "Unknown_Idle",
DroneStatusEnum.Location_Known_Idle: "Idle",
DroneStatusEnum.Moving: "Moving",
DroneStatusEnum.Stopped: "Stopped"
}
return status_names[self]
status_names = {
DroneStatusEnum.Uninitialized: "Uninitialized",
DroneStatusEnum.Location_Unknown_Idle: "Unknown_Idle",
DroneStatusEnum.Location_Known_Idle: "Idle",
DroneStatusEnum.Moving: "Moving",
DroneStatusEnum.Stopped: "Stopped"
}
return status_names[self]
def get_enum_by_name(name:str):
status_names = {
"Uninitialized": DroneStatusEnum.Uninitialized,
"Unknown_Idle": DroneStatusEnum.Location_Unknown_Idle,
"Idle": DroneStatusEnum.Location_Known_Idle,
"Moving": DroneStatusEnum.Moving,
"Stopped": DroneStatusEnum.Stopped
}
status_names = {
"Uninitialized": DroneStatusEnum.Uninitialized,
"Unknown_Idle": DroneStatusEnum.Location_Unknown_Idle,
"Idle": DroneStatusEnum.Location_Known_Idle,
"Moving": DroneStatusEnum.Moving,
"Stopped": DroneStatusEnum.Stopped
}
return status_names[name]
raise ValueError(f"No enum member found with name: {name}")
\ No newline at end of file
return status_names[name]
raise ValueError(f"No enum member found with name: {name}")
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment