Last active
August 25, 2021 17:40
-
-
Save cmanon/2f388002c6eeaa122a853f5a360fd3cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python3 | |
# Copyright (C) 2021 Carlos Santa Cruz | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <https://www.gnu.org/licenses/>. | |
# Copyright (C) 2021 Carlos Santa Cruz | |
# This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | |
# This is free software, and you are welcome to redistribute it | |
# under certain conditions; type `show c' for details. | |
import sys | |
import asyncio | |
import psutil | |
import serial | |
from datetime import datetime | |
from serial.tools.list_ports import comports | |
def updateCustomText(text): | |
#Write custom text cXXXXXXXXXw | |
text = 'c' + text + 'w' | |
# print(text.encode()) | |
s.write(text.encode()) | |
def updateTime(): | |
d = datetime.today() | |
#Update the date tYEAR,MM,DD,HH,MM,SS,m | |
d_str = 't' + str(d.year) + ',' + str(d.month) + ',' + str(d.day) + ',' + str(d.hour) + ',' + str(d.minute) + ',' + str(d.second) + ',m' | |
# print(d_str.encode()) | |
s.write(d_str.encode()) | |
def updatePerformance(): | |
cpu_load = int(psutil.cpu_percent(interval=None)) | |
# cpu_temp_c = int(psutil.virtual_memory().percent) #There's an error in the doc and this value is being shown as mem percentage | |
cpu_temp_c = 00 | |
cpu_temp_f = 00 | |
cpu_power = 00 | |
mem_load = int(psutil.virtual_memory().percent) | |
gpu_load = 00 | |
gpu_temp_c = 00 | |
gpu_temp_f = 00 | |
gpu_mem_load = 00 | |
temp_unit = 00 | |
cpu_vcore = 00 | |
cpu_freq = int(psutil.cpu_freq().current) | |
gpu_freq = 00 | |
# s.open() | |
#Send hardware monitor data hxx,xx,xx,xx,xx,xx,xx,xx,xx,x,xx,xx,xxe | |
perf = 'h' + str(cpu_load) + ',' + str(cpu_temp_c) + ',' + str(cpu_temp_f) + ',' + str(cpu_power) + ',' + str(mem_load) + ',' + str(gpu_load) + ',' + str(gpu_temp_c) + ',' + str(gpu_temp_f) + ',' + str(gpu_mem_load) + ',' + str(temp_unit) + ',' + str(cpu_vcore) + ',' + str(cpu_freq) + ',' + str(gpu_freq) + 'e' | |
# print(perf.encode()) | |
s.write(perf.encode()) | |
# s.close() | |
async def main(): | |
# updateTime() | |
# updateCustomText('HELLO CHARLIE') | |
while True: | |
updatePerformance() | |
await asyncio.sleep(2) | |
for n, (port, desc, hwid) in enumerate(sorted(comports()), 1): | |
# sys.stderr.write('--- {:2}: {:20} {!r}\n'.format(n, port, desc)) | |
if desc == 'Arduino Leonardo': | |
grid_port = port | |
break | |
elif port == '/dev/cu.gridSignalPort-Port': | |
grid_port = port | |
break | |
# grid_port = '/dev/cu.gridSignalPort-Port' | |
# grid_port = '/dev/cu.usbmodem14113301' | |
s = serial.Serial() | |
# print(grid_port) | |
s.port = grid_port | |
s.baudrate = 115200 | |
s.timeout = None | |
s.open() | |
asyncio.run(main()) | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment