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()
w = wmi.WMI(namespace='root\\wmi') elif 'Darwin' in platform.system(): IS_MAC = True if not IS_MAC: import serial # TODO: Dynamically discover the serial device # dev/serial/by-id/usb-Kiibohd_Keyboard_-_MDErgo1_PartialMap_pjrcUSB_full_Clean_master_-_2016-02-11_22:56:25_-0800-if02 ser = serial.Serial('/dev/ttyACM0', 115200, timeout=0.5) #Change to (Serial port - 1) on Windows. ser.close() ser.open() else: from libs.MacSerial import MacSerial ser = MacSerial() dox = ErgodoxInterface(ser) # Keeping track of Incoming + outgoing net traffic l_net = psutil.net_io_counters().bytes_recv + psutil.net_io_counters().bytes_sent l_time = time() #Get external IP once (Not ideal....) ip = urllib.urlopen('http://whatismyip.org').read() #External IP, This may need to be fixed as website changes p = ip.find("font-weight: 600;") ip = ip[p+19:p+34].strip('</span') hostname = socket.gethostname() try: while True: if IS_WINDOWS: temp = (w.MSAcpi_ThermalZoneTemperature()[0].CurrentTemperature/10.0)-273.15 #Temp of CPU (WINDOWS ONLY, Linux needs to use sensors)
IS_MAC = True if not IS_MAC: import serial # TODO: Dynamically discover the serial device # dev/serial/by-id/usb-Kiibohd_Keyboard_-_MDErgo1_PartialMap_pjrcUSB_full_Clean_master_-_2016-02-11_22:56:25_-0800-if02 ser = serial.Serial( '/dev/ttyACM0', 115200, timeout=0.5) #Change to (Serial port - 1) on Windows. ser.close() ser.open() else: from libs.MacSerial import MacSerial ser = MacSerial() dox = ErgodoxInterface(ser) # Keeping track of Incoming + outgoing net traffic l_net = psutil.net_io_counters().bytes_recv + psutil.net_io_counters( ).bytes_sent l_time = time() #Get external IP once (Not ideal....) ip = urllib.urlopen('http://whatismyip.org').read( ) #External IP, This may need to be fixed as website changes p = ip.find("font-weight: 600;") ip = ip[p + 19:p + 34].strip('</span') hostname = socket.gethostname() try: while True:
def main(): IS_WINDOWS = False IS_MAC = False if 'Windows' in platform.system(): import wmi IS_WINDOWS = True w = wmi.WMI(namespace='root\\wmi') elif 'Darwin' in platform.system(): IS_MAC = True if not IS_MAC: import serial # TODO: Dynamically discover the serial device # dev/serial/by-id/usb-Kiibohd_Keyboard_-_MDErgo1_PartialMap_pjrcUSB_full_Clean_master_-_2016-02-11_22:56:25_-0800-if02 # Change to (Serial port - 1) on Windows. ser = serial.Serial(serial_port, 115200, timeout=0.5) ser.close() ser.open() else: from libs.MacSerial import MacSerial ser = MacSerial() dox = ErgodoxInterface(ser) # Keeping track of Incoming + outgoing net traffic l_net = psutil.net_io_counters().bytes_recv \ + psutil.net_io_counters().bytes_sent l_time = time() # Get external IP once (Not ideal....) # External IP, This may need to be fixed as website changes ip = urlopen('http://whatismyip.org').read() p = ip.find("font-weight: 600;".encode("utf-8")) ip = ip[p + 19:p + 34].strip('</span'.encode("utf-8")) ip = ip.decode("utf-8") # hostname = socket.gethostname() try: while True: if IS_WINDOWS: # Temp of CPU (WINDOWS ONLY, Linux needs to use sensors) try: temp = (w.MSAcpi_ThermalZoneTemperature() [0].CurrentTemperature / 10.0) - 273.15 except BaseException: print('Could not read temp, skipping') temp = 22.0 else: # TODO: fix temperature for linux temp = None cpu = psutil.cpu_percent(interval=None) # CPU Usage mem = psutil.virtual_memory().percent # Memory Usage disk = psutil.disk_usage('/').percent net = ((psutil.net_io_counters().bytes_recv + psutil.net_io_counters().bytes_sent) - l_net) / ( time() - l_time) # Messy, lousy net estimate l_time = time() l_net = psutil.net_io_counters().bytes_recv \ + psutil.net_io_counters().bytes_sent dox.lcd_hex_color(0x00000C) dox.lcd.clear() # Show CPU, MEM, etc loading in bar graphs y_t = 24 dox.lcd.format_string("CPU [", 0, y_t) dox.lcd.format_string("]", 76, y_t) # Represent bar graph for CPU usage (total) dox.lcd.format_string("" * int(round(cpu / 10)), 26, y_t) if temp: dox.lcd.format_string("{0:.0f}".format(temp) + "*C", 82, y_t) y_t -= 8 dox.lcd.format_string(strftime("%m-%d"), 103, y_t) # Print date and time dox.lcd.format_string("MEM [", 0, y_t) dox.lcd.format_string("]", 76, y_t) # Represent bar graph for Mem dox.lcd.format_string("" * int(round(mem / 10)), 26, y_t) y_t -= 8 dox.lcd.format_string(strftime("%H:%M"), 103, y_t) # Print date and time dox.lcd.format_string("DSK [", 0, y_t) dox.lcd.format_string("]", 76, y_t) # Represent bar graph for Disk usage dox.lcd.format_string("" * int(round(disk / 10)), 26, y_t) y_t -= 8 dox.lcd.format_string("NET ", 0, y_t) dox.lcd.format_string("{0:.1f}".format(net / 1048576) + "M", 24, y_t) dox.lcd.format_string(ip.rjust(15), 53, y_t) dox.send() # Update LCD all at once except KeyboardInterrupt: # Press Ctrl + C to exit print('Exit') ser.close()