Skip to content

Commit ee52aeb

Browse files
upgrade to support CircuitPython 8.0.0
1 parent e85845c commit ee52aeb

File tree

11 files changed

+442
-353
lines changed

11 files changed

+442
-353
lines changed

PyGamer_Improved_Thermal_Camera/code.py

100644100755
Lines changed: 249 additions & 252 deletions
Large diffs are not rendered by default.

PyGamer_Improved_Thermal_Camera/index_to_rgb/.circuitpython.skip

Lines changed: 0 additions & 8 deletions
This file was deleted.

PyGamer_Improved_Thermal_Camera/index_to_rgb/grayscale_spectrum.py renamed to PyGamer_Improved_Thermal_Camera/index_to_rgb/grayscale.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,41 @@
1-
# SPDX-FileCopyrightText: 2021 Cedar Grove Studios for Adafruit Industries
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 JG for Cedar Grove Maker Studios
22
#
33
# SPDX-License-Identifier: MIT
4+
"""
5+
`cedargrove_rgb_spectrumtools.grayscale`
6+
================================================================================
7+
8+
Spectral Index to Grayscale RGB Converter Helper
9+
10+
* Author(s): JG
11+
12+
Implementation Notes
13+
--------------------
14+
15+
**Hardware:**
16+
17+
**Software and Dependencies:**
18+
19+
* Adafruit CircuitPython firmware for the supported boards:
20+
https://circuitpython.org/downloads
21+
22+
"""
23+
24+
__version__ = "0.0.0+auto.0"
25+
__repo__ = "https://github.com/CedarGroveStudios/CircuitPython_RGB_SpectrumTools.git"
426

5-
# grayscale_spectrum.py
6-
# 2021-05-19 version 1.1
7-
# Copyright 2021 Cedar Grove Studios
8-
# Spectral Index to Grayscale RGB Converter Helper
927

1028
def map_range(x, in_min, in_max, out_min, out_max):
1129
"""
1230
Maps and constrains an input value from one range of values to another.
1331
(from adafruit_simpleio)
32+
33+
:param float x: The value to be mapped. No default.
34+
:param float in_min: The beginning of the input range. No default.
35+
:param float in_max: The end of the input range. No default.
36+
:param float out_min: The beginning of the output range. No default.
37+
:param float out_max: The end of the output range. No default.
38+
1439
:return: Returns value mapped to new range
1540
:rtype: float
1641
"""
@@ -28,11 +53,16 @@ def map_range(x, in_min, in_max, out_min, out_max):
2853
return max(min(mapped, out_max), out_min)
2954
return min(max(mapped, out_max), out_min)
3055

56+
3157
def index_to_rgb(index=0, gamma=0.8):
3258
"""
3359
Converts a spectral index to a grayscale RGB value. Spectral index in
3460
range of 0.0 to 1.0. Gamma in range of 0.0 to 1.0 (1.0=linear),
3561
default 0.8 for color TFT displays.
62+
63+
:param float index: The normalized index value, range 0 to 1.0. Defaults to 0.
64+
:param float gamma: The gamma color perception value. Defaults to 0.8.
65+
3666
:return: Returns a 24-bit RGB value
3767
:rtype: integer
3868
"""
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,40 @@
1-
# SPDX-FileCopyrightText: 2021 Cedar Grove Studios for Adafruit Industries
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 JG for Cedar Grove Maker Studios
22
#
33
# SPDX-License-Identifier: MIT
4+
"""
5+
`cedargrove_rgb_spectrumtools.iron`
6+
================================================================================
7+
8+
Temperature Index to Iron Pseudocolor Spectrum RGB Converter Helper
9+
10+
* Author(s): JG
11+
12+
Implementation Notes
13+
--------------------
14+
15+
**Hardware:**
16+
17+
**Software and Dependencies:**
18+
19+
* Adafruit CircuitPython firmware for the supported boards:
20+
https://circuitpython.org/downloads
21+
"""
22+
23+
__version__ = "0.0.0+auto.0"
24+
__repo__ = "https://github.com/CedarGroveStudios/CircuitPython_RGB_SpectrumTools.git"
425

5-
# iron_spectrum.py
6-
# 2021-05-27 version 1.2
7-
# Copyright 2021 Cedar Grove Studios
8-
# Temperature Index to Iron Pseudocolor Spectrum RGB Converter Helper
926

1027
def map_range(x, in_min, in_max, out_min, out_max):
1128
"""
1229
Maps and constrains an input value from one range of values to another.
1330
(from adafruit_simpleio)
31+
32+
:param float x: The value to be mapped. No default.
33+
:param float in_min: The beginning of the input range. No default.
34+
:param float in_max: The end of the input range. No default.
35+
:param float out_min: The beginning of the output range. No default.
36+
:param float out_max: The end of the output range. No default.
37+
1438
:return: Returns value mapped to new range
1539
:rtype: float
1640
"""
@@ -28,11 +52,16 @@ def map_range(x, in_min, in_max, out_min, out_max):
2852
return max(min(mapped, out_max), out_min)
2953
return min(max(mapped, out_max), out_min)
3054

55+
3156
def index_to_rgb(index=0, gamma=0.5):
3257
"""
3358
Converts a temperature index to an iron thermographic pseudocolor spectrum
3459
RGB value. Temperature index in range of 0.0 to 1.0. Gamma in range of
3560
0.0 to 1.0 (1.0=linear), default 0.5 for color TFT displays.
61+
62+
:param float index: The normalized index value, range 0 to 1.0. Defaults to 0.
63+
:param float gamma: The gamma color perception value. Defaults to 0.5.
64+
3665
:return: Returns a 24-bit RGB value
3766
:rtype: integer
3867
"""
@@ -43,25 +72,29 @@ def index_to_rgb(index=0, gamma=0.5):
4372
red = 0.1
4473
grn = 0.1
4574
blu = (0.2 + (0.8 * map_range(band, 0, 70, 0.0, 1.0))) ** gamma
46-
if band >= 70 and band < 200: # blue to violet
75+
# if band >= 70 and band < 200: # blue to violet
76+
if 70 <= band < 200: # blue to violet
4777
red = map_range(band, 70, 200, 0.0, 0.6) ** gamma
4878
grn = 0.0
49-
blu = 1.0 ** gamma
50-
if band >= 200 and band < 300: # violet to red
79+
blu = 1.0**gamma
80+
# if band >= 200 and band < 300: # violet to red
81+
if 200 <= band < 300: # violet to red
5182
red = map_range(band, 200, 300, 0.6, 1.0) ** gamma
5283
grn = 0.0
5384
blu = map_range(band, 200, 300, 1.0, 0.0) ** gamma
54-
if band >= 300 and band < 400: # red to orange
55-
red = 1.0 ** gamma
85+
# if band >= 300 and band < 400: # red to orange
86+
if 300 <= band < 400: # red to orange
87+
red = 1.0**gamma
5688
grn = map_range(band, 300, 400, 0.0, 0.5) ** gamma
5789
blu = 0.0
58-
if band >= 400 and band < 500: # orange to yellow
59-
red = 1.0 ** gamma
90+
# if band >= 400 and band < 500: # orange to yellow
91+
if 400 <= band < 500: # orange to yellow
92+
red = 1.0**gamma
6093
grn = map_range(band, 400, 500, 0.5, 1.0) ** gamma
6194
blu = 0.0
6295
if band >= 500: # yellow to white
63-
red = 1.0 ** gamma
64-
grn = 1.0 ** gamma
96+
red = 1.0**gamma
97+
grn = 1.0**gamma
6598
blu = map_range(band, 500, 580, 0.0, 1.0) ** gamma
6699

67100
return (int(red * 255) << 16) + (int(grn * 255) << 8) + int(blu * 255)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 JG for Cedar Grove Maker Studios
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
`cedargrove_rgb_spectrumtools.visible`
6+
================================================================================
7+
8+
A Spectral Index to Visible (Rainbow) Spectrum RGB Converter Helper
9+
10+
Based on original 1996 Fortran code by Dan Bruton:
11+
physics.sfasu.edu/astro/color/spectra.html
12+
13+
* Author(s): JG
14+
15+
Implementation Notes
16+
--------------------
17+
18+
**Hardware:**
19+
20+
**Software and Dependencies:**
21+
22+
* Adafruit CircuitPython firmware for the supported boards:
23+
https://circuitpython.org/downloads
24+
"""
25+
26+
__version__ = "0.0.0+auto.0"
27+
__repo__ = "https://github.com/CedarGroveStudios/CircuitPython_RGB_SpectrumTools.git"
28+
29+
30+
def index_to_rgb(index=0, gamma=0.5):
31+
"""
32+
Converts a spectral index to rainbow (visible light wavelength)
33+
spectrum to an RGB value. Spectral index in range of 0.0 to 1.0
34+
(violet --> white). Gamma in range of 0.0 to 1.0 (1.0=linear),
35+
default 0.5 for color TFT displays.
36+
37+
:param float index: The normalized index value, range 0 to 1.0. Defaults to 0.
38+
:param float gamma: The gamma color perception value. Defaults to 0.5.
39+
40+
:return: Returns a 24-bit RGB value
41+
:rtype: integer
42+
"""
43+
44+
wavelength = (index * 320) + 380
45+
46+
if wavelength < 440:
47+
intensity = 0.1 + (0.9 * (wavelength - 380) / (440 - 380))
48+
red = ((-1.0 * (wavelength - 440) / (440 - 380)) * intensity) ** gamma
49+
grn = 0.0
50+
blu = (1.0 * intensity) ** gamma
51+
# if wavelength >= 440 and wavelength < 490:
52+
if 440 <= wavelength < 490:
53+
red = 0.0
54+
grn = (1.0 * (wavelength - 440) / (490 - 440)) ** gamma
55+
blu = 1.0**gamma
56+
# if wavelength >= 490 and wavelength < 510:
57+
if 490 <= wavelength < 510:
58+
red = 0.0
59+
grn = 1.0**gamma
60+
blu = (-1.0 * (wavelength - 510) / (510 - 490)) ** gamma
61+
# if wavelength >= 510 and wavelength < 580:
62+
if 510 <= wavelength < 580:
63+
red = (1.0 * (wavelength - 510) / (580 - 510)) ** gamma
64+
grn = 1.0**gamma
65+
blu = 0.0
66+
# if wavelength >= 580 and wavelength < 645:
67+
if 580 <= wavelength < 645:
68+
red = 1.0**gamma
69+
grn = (-1.0 * (wavelength - 645) / (645 - 580)) ** gamma
70+
blu = 0.0
71+
if wavelength >= 645:
72+
intensity = 0.3 + (0.7 * (700 - wavelength) / (700 - 645))
73+
red = (1.0) ** gamma
74+
grn = (1.0 - intensity) ** gamma
75+
blu = (1.0 - intensity) ** gamma
76+
77+
return (int(red * 255) << 16) + (int(grn * 255) << 8) + int(blu * 255)

PyGamer_Improved_Thermal_Camera/index_to_rgb/visible_spectrum.py

Lines changed: 0 additions & 51 deletions
This file was deleted.

PyGamer_Improved_Thermal_Camera/thermal_cam_config.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

PyGamer_Improved_Thermal_Camera/thermal_cam_converters.py

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-FileCopyrightText: 2022 Jan Goolsbey for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
`thermalcamera_config`
6+
================================================================================
7+
Thermal Camera configuration parameters.
8+
"""
9+
10+
# ### Alarm and range default values in Farenheit ###
11+
ALARM_F = 120
12+
MIN_RANGE_F = 60
13+
MAX_RANGE_F = 120
14+
15+
# ### Display characteristics
16+
SELFIE = False # Rear camera view; True for front view
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-FileCopyrightText: 2022 Jan Goolsbey for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
`thermalcamera_converters`
6+
================================================================================
7+
Celsius-to-Fahrenheit and Fahrenheit-to-Celsius converter helpers.
8+
"""
9+
10+
11+
def celsius_to_fahrenheit(deg_c=None):
12+
"""Convert C to F; round to 1 degree C"""
13+
return round(((9 / 5) * deg_c) + 32)
14+
15+
16+
def fahrenheit_to_celsius(deg_f=None):
17+
"""Convert F to C; round to 1 degree F"""
18+
return round((deg_f - 32) * (5 / 9))

0 commit comments

Comments
 (0)