Revert "Add message in case of Arduino disconnect at any time"
This reverts commit ff20725b0f
.
Help i broke it
This commit is contained in:
parent
ff20725b0f
commit
d8572bb331
1 changed files with 56 additions and 69 deletions
|
@ -1,11 +1,8 @@
|
||||||
|
import os
|
||||||
|
import GPUtil
|
||||||
import time
|
import time
|
||||||
|
from pySerialTransfer import pySerialTransfer as txfer
|
||||||
from subprocess import getoutput
|
from subprocess import getoutput
|
||||||
try:
|
|
||||||
import GPUtil
|
|
||||||
from pySerialTransfer import pySerialTransfer as txfer
|
|
||||||
from serial import SerialException
|
|
||||||
except ImportError:
|
|
||||||
print('Make sure you have installed the required libraries: GPUtil, pySerialTransfer')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# ---
|
# ---
|
||||||
|
@ -15,7 +12,6 @@ try:
|
||||||
# Then, just remove "/dev/", and the number, from the port, and type it into the variable `port`
|
# Then, just remove "/dev/", and the number, from the port, and type it into the variable `port`
|
||||||
# ---
|
# ---
|
||||||
|
|
||||||
def get_port():
|
|
||||||
port = 'ttyACM'
|
port = 'ttyACM'
|
||||||
while True:
|
while True:
|
||||||
ports = getoutput(f'ls /dev | grep {port}').split('\n')
|
ports = getoutput(f'ls /dev | grep {port}').split('\n')
|
||||||
|
@ -26,20 +22,19 @@ try:
|
||||||
print('Waiting for Arduino...')
|
print('Waiting for Arduino...')
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
return port
|
link = txfer.SerialTransfer(port, 115200, timeout=.1)
|
||||||
|
|
||||||
link = txfer.SerialTransfer(get_port(), 115200, timeout=.1)
|
|
||||||
link.open()
|
link.open()
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
try:
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
gpus = GPUtil.getGPUs()
|
gpus = GPUtil.getGPUs()
|
||||||
temp = max(gpu.temperature for gpu in gpus)
|
temp = max(gpu.temperature for gpu in gpus)
|
||||||
|
|
||||||
speed = int(((temp - 40) / 40) * 100)
|
speed = int(((temp - 40) / 40) * 100)
|
||||||
min_speed = 34
|
min_speed = 0
|
||||||
max_speed = 100
|
max_speed = 100
|
||||||
if speed < 0:
|
if speed < 0:
|
||||||
speed = min_speed
|
speed = min_speed
|
||||||
|
@ -81,14 +76,6 @@ try:
|
||||||
# Evaluate for comm. errors
|
# Evaluate for comm. errors
|
||||||
if speed != rec_int:
|
if speed != rec_int:
|
||||||
print(f'Error: sent {speed}, received {rec_int}')
|
print(f'Error: sent {speed}, received {rec_int}')
|
||||||
except OSError or SerialException:
|
|
||||||
try:
|
|
||||||
link.close()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
link = txfer.SerialTransfer(get_port(), 115200, timeout=.1)
|
|
||||||
link.open()
|
|
||||||
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue