After setting up the hardware devices and saying hello, a few commonly used constants and variables are defined. These include the alarm threshold, display minimum/maximum, and camera orientation settings that were previously loaded from the file. Default values in Celsius are converted to Fahrenheit where needed.

# Convert default alarm and min/max range values from config file
ALARM_C = fahrenheit_to_celsius(ALARM_F)
MIN_RANGE_C = fahrenheit_to_celsius(MIN_RANGE_F)
MAX_RANGE_C = fahrenheit_to_celsius(MAX_RANGE_F)

Display width and height are retrieved from the PyGamer's board definitions. The size of individual grid image cells is calculated from the display's height and the number of displayed cells along one grid access.

By calculating the grid and cell dimensions in this manner, the code becomes adaptable for use with displays larger than the PyGamer's integral TFT display.

# The board's integral display size
WIDTH = display.width
HEIGHT = display.height

GRID_AXIS = (2 * n) - 1  # Number of cells along the grid x or y axis
GRID_SIZE = HEIGHT  # Maximum number of pixels for a square grid
GRID_X_OFFSET = WIDTH - GRID_SIZE  # Right-align grid with display boundary
CELL_SIZE = GRID_SIZE // GRID_AXIS  # Size of a grid cell in pixels

Color values are defined next. PALETTE_SIZE is used to select the maximum number of display colors across the iron spectrum to map to temperature values. The palette size of 100 colors was selected empirically as a value that balanced the sensor resolution of 0.5°C with the ability to visually discern objects. Increasing the number of colors beyond 160 does not improve readability and can slow the display frame rate. Fewer than 80 palette colors significantly decreases visual object detection.

The remaining color definitions are used for the various text labels and measured values in the display's sidebar. The param_colors list is used by the setup helper that we'll discuss in the next section.

PALETTE_SIZE = 100  # Number of colors in spectral palette (must be > 0)

# Default colors for temperature value sidebar
BLACK = 0x000000
RED = 0xFF0000
BLUE = 0x0000FF

# Text colors for setup helper's on-screen parameters
param_colors = [("ALARM", WHITE), ("RANGE", RED), ("RANGE", CYAN)]

This guide was first published on Jun 09, 2021. It was last updated on 2021-06-09 17:11:13 -0400.

This page (Constants) was last updated on Jan 11, 2022.

Text editor powered by tinymce.