Skip to content

Commit f2d6723

Browse files
committed
pylint issues addressed
1 parent 2daf427 commit f2d6723

File tree

1 file changed

+49
-63
lines changed

1 file changed

+49
-63
lines changed
Lines changed: 49 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,98 @@
11
"""This example is for Raspberry Pi (Linux) only!
22
It will not work on microcontrollers running CircuitPython!"""
33

4-
import os
54
import sys
65
import math
76
import time
87
import atexit
98
import busio
109
import board
11-
1210
import numpy as np
1311
from scipy.interpolate import griddata
14-
1512
from colour import Color
16-
from os import system, name
1713
import adafruit_amg88xx
1814

19-
i2c_bus = busio.I2C(board.SCL, board.SDA)
15+
I2C_BUS = busio.I2C(board.SCL, board.SDA)
2016

2117
# low range of the sensor (this will be blue on the screen)
2218
MINTEMP = 26.0
23-
2419
# high range of the sensor (this will be red on the screen)
2520
MAXTEMP = 32.0
26-
27-
# how many color values we can have
2821
COLORDEPTH = 1024
29-
30-
#os.putenv("SDL_FBDEV", "/dev/fb1")
31-
#pygame.init()
32-
33-
# initialize the sensor
34-
sensor = adafruit_amg88xx.AMG88XX(i2c_bus)
22+
SENSOR = adafruit_amg88xx.AMG88XX(I2C_BUS)
3523

3624
# pylint: disable=invalid-slice-index
37-
points = [(math.floor(ix / 8), (ix % 8)) for ix in range(0, 64)]
38-
grid_x, grid_y = np.mgrid[0:7:32j, 0:7:32j]
25+
POINTS = [(math.floor(ix / 8), (ix % 8)) for ix in range(0, 64)]
26+
GRID_X, GRID_Y = np.mgrid[0:7:32j, 0:7:32j]
3927
# pylint: enable=invalid-slice-index
4028

4129
# sensor is an 8x8 grid so lets do a square
42-
height = 240
43-
width = 240
30+
HEIGHT = 240
31+
WIDTH = 240
4432

4533
# the list of colors we can choose from
46-
blue = Color("indigo")
47-
colors = list(blue.range_to(Color("red"), COLORDEPTH))
34+
BLUE = Color("indigo")
35+
COLORS = list(BLUE.range_to(Color("red"), COLORDEPTH))
4836

4937
# create the array of colors
50-
colors = [(int(c.red * 255), int(c.green * 255), int(c.blue * 255)) for c in colors]
51-
console_colors = [17,18,19,20,21,57,93,129,165,201,200,199,198,197,196,202,208,214,220]
38+
COLORS = [(int(c.red * 255), int(c.green * 255), int(c.blue * 255)) for c in COLORS]
39+
CONSOLE_COLORS = [
40+
17, 18, 19, 20, 21, 57, 93, 129, 165, 201, 200,
41+
199, 198, 197, 196, 202, 208, 214, 220]
5242

53-
displayPixelWidth = width / 30
54-
displayPixelHeight = height / 30
43+
def map_value(x_value, in_min, in_max, out_min, out_max):
44+
"""Maps value of the temperature to color"""
45+
return (x_value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
5546

56-
# some utility functions
57-
def constrain(val, min_val, max_val):
58-
return min(max_val, max(min_val, val))
47+
def print_there(console_x, console_y, text, color):
48+
""" Outputs a colored text to console at coordinates """
49+
sys.stdout.write("\x1b7\x1b[48;5;%dm" % (color))
50+
sys.stdout.write("\x1b7\x1b[%d;%df%s\x1b8" % (console_x, console_y, text))
5951

60-
61-
def map_value(x, in_min, in_max, out_min, out_max):
62-
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
63-
64-
def clear():
65-
_ = system('clear')
66-
67-
def print_there(x, y, text, color):
68-
sys.stdout.write("\x1b7\x1b[48;5;%dm" % (color))
69-
sys.stdout.write("\x1b7\x1b[%d;%df%s\x1b8" % (x, y, text))
70-
maxpixel = 0
71-
minpixel = 0
72-
color_range = 1
7352
def exit_handler():
74-
print("maxpixel:" + str(maxpixel))
75-
print("minpixel:" + str(minpixel))
53+
""" print values on exit for debugging """
54+
print("maxpixel:" + str(MAXPIXEL))
55+
print("minpixel:" + str(MINPIXEL))
7656

7757
atexit.register(exit_handler)
58+
7859
# let the sensor initialize
7960
time.sleep(0.1)
8061

62+
COLOR_RANGE = 1
8163
while True:
8264

8365
# read the pixels
84-
pixels = []
85-
for row in sensor.pixels:
86-
pixels = pixels + row
87-
pixels = [map_value(p, MINTEMP, MAXTEMP, 0, COLORDEPTH - 1) for p in pixels]
66+
PIXELS = []
67+
for row in SENSOR.pixels:
68+
PIXELS = PIXELS + row
69+
PIXELS = [map_value(p, MINTEMP, MAXTEMP, 0, COLORDEPTH - 1) for p in PIXELS]
8870

8971
# perform interpolation
90-
bicubic = griddata(points, pixels, (grid_x, grid_y), method="cubic")
72+
BICUBIC = griddata(POINTS, PIXELS, (GRID_X, GRID_Y), method="cubic")
73+
74+
MAXPIXEL = 0
75+
MINPIXEL = 0
9176

9277
# draw everything
93-
y=2
94-
for ix, row in enumerate(bicubic):
95-
x=2
78+
Y_CONSOLE = 2
79+
for ix, row in enumerate(BICUBIC):
80+
x_console = 2
9681
for jx, pixel in enumerate(row):
9782
color_index = 0
98-
if (color_range != 0):
99-
color_index = int(round((pixel-minpixel)/color_range))
83+
if COLOR_RANGE != 0:
84+
color_index = int(round((pixel-MINPIXEL)/COLOR_RANGE))
10085
if color_index < 0:
10186
color_index = 0
102-
if color_index > len(console_colors)-1:
103-
color_index = len(console_colors)-1
104-
print_there(x, y*2-2, ' ', console_colors[color_index])
105-
if pixel > maxpixel:
106-
maxpixel = pixel
107-
if pixel < minpixel:
108-
minpixel = pixel
109-
x+=1
110-
y+=1
111-
heat_range = maxpixel - minpixel
112-
color_range = heat_range / len(console_colors)
87+
if color_index > len(CONSOLE_COLORS)-1:
88+
color_index = len(CONSOLE_COLORS)-1
89+
print_there(x_console, Y_CONSOLE*2-2, ' ', CONSOLE_COLORS[color_index])
90+
if pixel > MAXPIXEL:
91+
MAXPIXEL = pixel
92+
if pixel < MINPIXEL:
93+
MINPIXEL = pixel
94+
x_console += 1
95+
Y_CONSOLE += 1
96+
sys.stdout.flush()
97+
HEAT_RANGE = MAXPIXEL - MINPIXEL
98+
COLOR_RANGE = HEAT_RANGE / len(CONSOLE_COLORS)

0 commit comments

Comments
 (0)