Improved interface and ergonomy
This commit is contained in:
parent
91d6b5af4b
commit
34406690f8
37
color.py
37
color.py
@ -4,7 +4,7 @@ import serial
|
|||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
def compute_value(line, minimum, maximum):
|
def compute_value(line, minimum, maximum, inv):
|
||||||
line = line.split(" ")
|
line = line.split(" ")
|
||||||
if len(line) < 3:
|
if len(line) < 3:
|
||||||
return False
|
return False
|
||||||
@ -16,6 +16,9 @@ def compute_value(line, minimum, maximum):
|
|||||||
elif value[i] < 0:
|
elif value[i] < 0:
|
||||||
value[i] = 0
|
value[i] = 0
|
||||||
|
|
||||||
|
if inv is True:
|
||||||
|
return 255-value[0], 255-value[1], 255-value[2]
|
||||||
|
else:
|
||||||
return value[0], value[1], value[2]
|
return value[0], value[1], value[2]
|
||||||
|
|
||||||
|
|
||||||
@ -41,9 +44,23 @@ if ser.isOpen():
|
|||||||
minimum = [-1, -1, -1]
|
minimum = [-1, -1, -1]
|
||||||
|
|
||||||
print("Calibration :")
|
print("Calibration :")
|
||||||
|
print("Press any key to launch the program when calibration is" +
|
||||||
|
"finished.")
|
||||||
|
# Display info in window
|
||||||
|
label = font.render("Calibration...", 1, (255, 255, 255))
|
||||||
|
label_pos = label.get_rect()
|
||||||
|
label_pos.centerx = screen.get_rect().centerx
|
||||||
|
label_pos.centery = 20
|
||||||
|
screen.blit(label, label_pos)
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
for i in range(50):
|
running = True
|
||||||
|
while running:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.K_RETURN:
|
||||||
|
running = False
|
||||||
|
|
||||||
line = float(ser.readline())
|
line = float(ser.readline())
|
||||||
|
|
||||||
if line < minimum or minimum < 0:
|
if line < minimum or minimum < 0:
|
||||||
@ -51,21 +68,31 @@ if ser.isOpen():
|
|||||||
if line > maximum:
|
if line > maximum:
|
||||||
maximumR = line
|
maximumR = line
|
||||||
|
|
||||||
print("Go :")
|
print("Running...")
|
||||||
running = True
|
running = True
|
||||||
while running:
|
while running:
|
||||||
# Quit if window is closed
|
# Quit if window is closed
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN:
|
||||||
|
pygame.quit()
|
||||||
running = False
|
running = False
|
||||||
|
|
||||||
# Read line from serial
|
# Read line from serial
|
||||||
line = float(ser.readline())
|
line = float(ser.readline())
|
||||||
# Compute the value for red
|
# Compute the value for red
|
||||||
value = compute_value(line, minimum, maximum)
|
value = compute_value(line, minimum, maximum, False)
|
||||||
|
value_text = compute_value(line, minimum, maximum, True)
|
||||||
|
|
||||||
if value is not False:
|
if value is not False:
|
||||||
screen.fill(value)
|
screen.fill(value)
|
||||||
|
|
||||||
|
# Display info in window
|
||||||
|
label = font.render("Running...", 1, value_text)
|
||||||
|
label_pos = label.get_rect()
|
||||||
|
label_pos.centerx = screen.get_rect().centerx
|
||||||
|
label_pos.centery = 20
|
||||||
|
screen.blit(label, label_pos)
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
ser.close()
|
ser.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user