@@ -67,23 +67,22 @@ def display_text(variable, data, unit):
6767 # Maintain length of list
6868 values [variable ] = values [variable ][1 :] + [data ]
6969 # Scale the values for the variable between 0 and 1
70- colours = [(v - min (values [variable ]) + 1 ) / (max (values [variable ])
71- - min (values [variable ]) + 1 ) for v in values [variable ]]
70+ vmin = min (values [variable ])
71+ vmax = max (values [variable ])
72+ colours = [(v - vmin + 1 ) / (vmax - vmin + 1 ) for v in values [variable ]]
7273 # Format the variable name and value
7374 message = "{}: {:.1f} {}" .format (variable [:4 ], data , unit )
7475 logging .info (message )
7576 draw .rectangle ((0 , 0 , WIDTH , HEIGHT ), (255 , 255 , 255 ))
7677 for i in range (len (colours )):
7778 # Convert the values to colours from red to blue
7879 colour = (1.0 - colours [i ]) * 0.6
79- r , g , b = [int (x * 255.0 ) for x in colorsys .hsv_to_rgb (colour ,
80- 1.0 , 1.0 )]
80+ r , g , b = [int (x * 255.0 ) for x in colorsys .hsv_to_rgb (colour , 1.0 , 1.0 )]
8181 # Draw a 1-pixel wide rectangle of colour
82- draw .rectangle ((i , top_pos , i + 1 , HEIGHT ), (r , g , b ))
82+ draw .rectangle ((i , top_pos , i + 1 , HEIGHT ), (r , g , b ))
8383 # Draw a line graph in black
84- line_y = HEIGHT - (top_pos + (colours [i ] * (HEIGHT - top_pos )))\
85- + top_pos
86- draw .rectangle ((i , line_y , i + 1 , line_y + 1 ), (0 , 0 , 0 ))
84+ line_y = HEIGHT - (top_pos + (colours [i ] * (HEIGHT - top_pos ))) + top_pos
85+ draw .rectangle ((i , line_y , i + 1 , line_y + 1 ), (0 , 0 , 0 ))
8786 # Write the text at the top in black
8887 draw .text ((0 , 0 ), message , font = font , fill = (0 , 0 , 0 ))
8988 st7735 .display (img )
0 commit comments