def init_screen(): ''' Clears the screen and turns it blue ''' ser = serial.Serial('/dev/ttyACM0', 115200, timeout=0.5) ser.close() ser.open() dox = ErgodoxInterface(ser) dox.lcd_hex_color(0x00000C) dox.clear() ser.close()
def process_event(event, self_id): ''' Process a hangups event as nevecessary. ''' # Open the serial connection to the ergodox ser = serial.Serial('/dev/ttyACM0', 115200, timeout=0.5) ser.close() ser.open() dox = ErgodoxInterface(ser) # Determine notification type notification_type = event.WhichOneof('state_update') print("Recieved notification of type {}".format(notification_type)) if notification_type == 'event_notification': # This is our message type if event.HasField('conversation'): # When we recieve a message if event.event_notification.event.sender_id.chat_id != self_id: sender = "Unknown" for part in event.conversation.participant_data: if part.id.chat_id != self_id: sender = part.fallback_name break print("Message with {}() with message id {}".format(sender, event.event_notification.event.sender_id.chat_id, event.conversation.conversation_id.id)) print("Content: {}".format(event.event_notification.event.chat_message.message_content.segment[0].text)) # Clear the screen and write the sender name to the top left dox.clear() dox.lcd.format_string(sender, 0, 24) # Color foosball messages a different color if 'foos' in event.event_notification.event.chat_message.message_content.segment[0].text: dox.lcd.format_string('FOOSBALL REQUEST!!!', 0, 16) dox.lcd_hex_color(0x0C0C00) else: dox.lcd_hex_color(0x0C0000) dox.send() # When we send a message else: init_screen() print("Message successfully sent.") # Message read notification elif notification_type == 'watermark_notification': # Currently only care about messages we read if event.watermark_notification.sender_id.chat_id == self_id: print("Conversation {} was read by you".format(event.watermark_notification.conversation_id.id)) init_screen() # Close our serial connection ser.close()