Commit 83cc1980 authored by Klint Youngmeyer's avatar Klint Youngmeyer
Browse files

Update blechat.py to be useful as a show demo.

Pull connect to menu into separate function
Add a couple special words
parent 2dd62b80
......@@ -37,6 +37,12 @@ class BleChat:
self.lcd.show()
self.led.off()
def _connect_message(self):
self.clear_lcd()
self.lcd.write('Connect to:\n')
self.lcd.write('{}\n'.format(self.name))
self.lcd.write('{}\n'.format(self.local_mac[0:17]))
def clear_lcd(self):
for i in range(0, 4):
i += 1
......@@ -45,12 +51,9 @@ class BleChat:
self.lcd.show()
pyb.delay(50)
def start(self):
def start(self, demo=False):
print("Waiting for connection...")
self.clear_lcd()
self.lcd.write('Connect to:\n')
self.lcd.write('{}\n'.format(self.name))
self.lcd.write('{}\n'.format(self.local_mac[0:17]))
self._connect_message()
done = False
while not done:
event = self.rs.get_event()
......@@ -70,9 +73,16 @@ class BleChat:
elif event == self.rs.DISCONNECT_EVENT:
print('Disconnected')
print('Remote Device State = {}'.format(self.rs.get_device_status()))
self.clear_lcd()
self.lcd.write('Device\nDisconnected,\nPlease Reset\nCutiPy')
done = True
if demo:
self.clear_lcd()
self.lcd.write('Device\nDisconnected\n')
self.rs.advertise(True)
pyb.delay(100)
self._connect_message()
else:
self.clear_lcd()
self.lcd.write('Device\nDisconnected,\nPlease Reset\nCutiPy')
done = True
elif event == self.rs.WRITE_EVENT:
event_rsp = self.rs.get_event_data(event)
print('Write event')
......@@ -83,7 +93,14 @@ class BleChat:
else:
self.led.on()
else:
self.lcd.write(event_rsp[0] + '\n')
if event_rsp[0] == 'clear':
self.clear_lcd()
elif event_rsp[0] == 'exit':
self.clear_lcd()
self.lcd.write('App Exited,\nPlease Reset\nCutiPy')
done = True
else:
self.lcd.write(event_rsp[0] + '\n')
# event_attr_index = rs.event_attr_hiandle()
# if event_attr_index == write_attr_ index:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment