Skip to content

Commit b4ed1b0

Browse files
authored
Merge pull request #2325 from CedarGroveStudios/main
Upgrade to support 8.0.0
2 parents 612410f + a8c9693 commit b4ed1b0

File tree

11 files changed

+432
-353
lines changed

11 files changed

+432
-353
lines changed

PyGamer_Improved_Thermal_Camera/code.py

100644100755
Lines changed: 247 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,25 @@ 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 70 <= band < 200: # blue to violet
4776
red = map_range(band, 70, 200, 0.0, 0.6) ** gamma
4877
grn = 0.0
49-
blu = 1.0 ** gamma
50-
if band >= 200 and band < 300: # violet to red
78+
blu = 1.0**gamma
79+
if 200 <= band < 300: # violet to red
5180
red = map_range(band, 200, 300, 0.6, 1.0) ** gamma
5281
grn = 0.0
5382
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
83+
if 300 <= band < 400: # red to orange
84+
red = 1.0**gamma
5685
grn = map_range(band, 300, 400, 0.0, 0.5) ** gamma
5786
blu = 0.0
58-
if band >= 400 and band < 500: # orange to yellow
59-
red = 1.0 ** gamma
87+
if 400 <= band < 500: # orange to yellow
88+
red = 1.0**gamma
6089
grn = map_range(band, 400, 500, 0.5, 1.0) ** gamma
6190
blu = 0.0
6291
if band >= 500: # yellow to white
63-
red = 1.0 ** gamma
64-
grn = 1.0 ** gamma
92+
red = 1.0**gamma
93+
grn = 1.0**gamma
6594
blu = map_range(band, 500, 580, 0.0, 1.0) ** gamma
6695

6796
return (int(red * 255) << 16) + (int(grn * 255) << 8) + int(blu * 255)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 440 <= wavelength < 490:
52+
red = 0.0
53+
grn = (1.0 * (wavelength - 440) / (490 - 440)) ** gamma
54+
blu = 1.0**gamma
55+
if 490 <= wavelength < 510:
56+
red = 0.0
57+
grn = 1.0**gamma
58+
blu = (-1.0 * (wavelength - 510) / (510 - 490)) ** gamma
59+
if 510 <= wavelength < 580:
60+
red = (1.0 * (wavelength - 510) / (580 - 510)) ** gamma
61+
grn = 1.0**gamma
62+
blu = 0.0
63+
if 580 <= wavelength < 645:
64+
red = 1.0**gamma
65+
grn = (-1.0 * (wavelength - 645) / (645 - 580)) ** gamma
66+
blu = 0.0
67+
if wavelength >= 645:
68+
intensity = 0.3 + (0.7 * (700 - wavelength) / (700 - 645))
69+
red = (1.0) ** gamma
70+
grn = (1.0 - intensity) ** gamma
71+
blu = (1.0 - intensity) ** gamma
72+
73+
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)