Skip to content

Commit 7aa3d82

Browse files
authored
Merge pull request #14 from fgervais/pc-mode
Add 2 arguments to camtest.py
2 parents bcc7f8b + 7e25def commit 7aa3d82

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

examples/mlx90640_camtest.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import math
77
import time
8+
import argparse
89
import board
910
import busio
1011
from PIL import Image
@@ -22,11 +23,31 @@
2223
# high range of the sensor (this will be white on the screen)
2324
MAXTEMP = 50.0
2425

26+
# if in windowed mode, make the window bigger by this factor
27+
WINDOW_SCALING_FACTOR = 50
28+
29+
# parse command line arguments
30+
parser = argparse.ArgumentParser()
31+
parser.add_argument("--windowed", action="store_true", help="display in a window")
32+
parser.add_argument(
33+
"--disable-interpolation",
34+
action="store_true",
35+
help="disable interpolation in-between camera pixels",
36+
)
37+
38+
args = parser.parse_args()
39+
2540
# set up display
26-
os.environ["SDL_FBDEV"] = "/dev/fb0"
27-
os.environ["SDL_VIDEODRIVER"] = "fbcon"
41+
if not args.windowed:
42+
os.environ["SDL_FBDEV"] = "/dev/fb0"
43+
os.environ["SDL_VIDEODRIVER"] = "fbcon"
2844
pygame.init()
29-
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
45+
if not args.windowed:
46+
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
47+
else:
48+
screen = pygame.display.set_mode(
49+
[32 * WINDOW_SCALING_FACTOR, 24 * WINDOW_SCALING_FACTOR]
50+
)
3051
print(pygame.display.Info())
3152

3253
# the list of colors we can choose from
@@ -117,10 +138,13 @@ def gradient(x, width, cmap, spread=1):
117138
# pixelrgb = [colors[constrain(int(pixel), 0, COLORDEPTH-1)] for pixel in pixels]
118139
img = Image.new("RGB", (32, 24))
119140
img.putdata(pixels)
120-
img = img.resize((32 * INTERPOLATE, 24 * INTERPOLATE), Image.BICUBIC)
141+
if not args.disable_interpolation:
142+
img = img.resize((32 * INTERPOLATE, 24 * INTERPOLATE), Image.BICUBIC)
121143
img_surface = pygame.image.fromstring(img.tobytes(), img.size, img.mode)
122144
pygame.transform.scale(img_surface.convert(), screen.get_size(), screen)
123145
pygame.display.update()
146+
if args.windowed:
147+
pygame.event.pump()
124148
print(
125149
"Completed 2 frames in %0.2f s (%d FPS)"
126150
% (time.monotonic() - stamp, 1.0 / (time.monotonic() - stamp))

0 commit comments

Comments
 (0)