Skip to content

Commit

Permalink
Update multithread comm demo script for algo and arduino
Browse files Browse the repository at this point in the history
  • Loading branch information
MDP G14 RPI committed Oct 3, 2019
1 parent 9b78e6e commit 441470a
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions playgrounds/multithread_comm_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ def __init__(self):
self.pc_queue = queue.Queue(maxsize=0)

def start(self):
# _thread.start_new_thread(self.read_android, (self.android_queue,))
_thread.start_new_thread(self.read_arduino, (self.pc_queue,))
_thread.start_new_thread(self.read_pc,(self.arduino_queue,))

# _thread.start_new_thread(self.write_android, (self.android_queue,))
_thread.start_new_thread(self.write_arduino, (self.arduino_queue,))
_thread.start_new_thread(self.write_pc, (self.pc_queue,))

Expand All @@ -38,20 +36,6 @@ def start(self):
def end(self):
log.info('Multithread Communication Session Ended')

# def read_android(self, android_queue):
# while True:
# msg = self.android.read()
# if msg is not None:
# log.info('Read Android:' + str(msg))
# android_queue.put_nowait('Hello from PC: ' + str(msg))

# def write_android(self, android_queue):
# while True:
# if not android_queue.empty():
# msg = android_queue.get_nowait()
# self.android.write(msg)
# log.info('Write Android: ' + str(msg))

def read_arduino(self, pc_queue):
while True:
msg = self.arduino.read()
Expand All @@ -70,8 +54,11 @@ def read_pc(self, arduino_queue):
while True:
msg = self.pc.read()
if msg is not None:
log.info('Read PC: ' + str(msg))
arduino_queue.put_nowait(msg)
log.info('Read PC: ' + str(msg['target']) + '; ' + str(msg['payload']))
if msg['target'] == 'arduino':
arduino_queue.put_nowait(msg['payload'])
elif msg['target'] == 'both':
arduino_queue.put_nowait(msg['payload']['arduino'])

def write_pc(self, pc_queue):
while True:
Expand Down

0 comments on commit 441470a

Please sign in to comment.