Skip to content
This repository was archived by the owner on Feb 22, 2025. It is now read-only.

Commit 2ad92dc

Browse files
committed
V2
1 parent 6c6b593 commit 2ad92dc

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vscode/

arduino-intro-solution/arduino-intro-solution.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ void setup(){
2727
lcd.backlight();
2828

2929
/// Εμφανίζουμε ένα μήνυμα καλοσωρίσματος και περιμένουμε 500 miliseconds
30-
lcd.setCursor(0,0);
31-
lcd.print("Welcome to");
30+
lcd.setCursor(1,0);
31+
lcd.print("Welcome to the");
3232
lcd.setCursor(0,1);
3333
lcd.print("Arduino Workshop");
3434
delay(500);

cpu-ram-info-to-serial.py

+40-14
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import platform
2020
import sys
2121
import importlib
22+
import signal
2223

2324
#----------------------------------------------
2425
# Check dependencies
@@ -42,18 +43,16 @@
4243
#Check Platform
4344
myPlatform=''
4445
if platform.system() == 'Windows':
45-
myPlatform="Windows"
46-
for pac in packagesInstall:
47-
os.system('start cmd /k pip install ' + str(pac))
48-
print("Installing " + str(pac))
49-
importlib.import_module(pac)
46+
myPlatform="Windows"
5047
elif platform.system() == 'Linux':
5148
myPlatform="Linux"
52-
for pac in packagesInstall:
53-
print("Installing " + str(pac))
54-
os.system('pip install ' + str(pac))
55-
importlib.import_module(pac)
5649
print("My platform: " + myPlatform)
50+
51+
for pac in packagesInstall:
52+
os.system('pip install ' + str(pac))
53+
print("Installing " + str(pac))
54+
importlib.import_module(pac)
55+
5756
#----------------------------------------------
5857

5958
"""
@@ -87,15 +86,36 @@ def __init__(self, port, baud, timeout):
8786
self.port=port
8887
self.baud=baud
8988
self.timeout=timeout
89+
while 1:
90+
try:
91+
self.ser = serial.Serial(str(self.port), self.baud, timeout=self.timeout)
92+
self.ser.close()
93+
self.ser.open()
94+
break
95+
except:
96+
print("USB is not connected")
97+
98+
if handler.SIGINT:
99+
print("Exit")
100+
sys.exit()
101+
time.sleep(1)
90102

91103
def send(self, cpu, ram):
92-
ser = serial.Serial(self.port, self.baud, timeout=self.timeout)
93-
ser.close()
94-
ser.open()
95104
print ("Cpu: " + str(cpu) + " ram: " + str(ram))
96-
ser.write(str(cpu)+"|"+str(ram))
105+
self.ser.write(str(cpu)+"|"+str(ram))
97106
time.sleep(0.1)
98-
ser.close()
107+
108+
def exit(self):
109+
self.ser.close()
110+
111+
class SIGINT_handler():
112+
def __init__(self):
113+
self.SIGINT = False
114+
115+
def signal_handler(self, signal, frame):
116+
self.SIGINT = True
117+
handler = SIGINT_handler()
118+
signal.signal(signal.SIGINT, handler.signal_handler)
99119

100120
#Create PC info interface
101121
load=PCLoad()
@@ -104,6 +124,7 @@ def send(self, cpu, ram):
104124
print("Connecting to: " + str(port))
105125
toUSB = mySerial(str(port),9600,0.5)
106126

127+
107128
#Send packages FOREVER!
108129
while(1):
109130
#Read cpu and ram load
@@ -114,4 +135,9 @@ def send(self, cpu, ram):
114135
toUSB.send(cpu, ram)
115136
except:
116137
print("USB is not connected")
138+
139+
if handler.SIGINT:
140+
toUSB.exit()
141+
print("Exit")
142+
break
117143
time.sleep(0.4)

0 commit comments

Comments
 (0)