|
5 | 5 | import os
|
6 | 6 | import math
|
7 | 7 | import time
|
| 8 | +import argparse |
8 | 9 | import board
|
9 | 10 | import busio
|
10 | 11 | from PIL import Image
|
|
22 | 23 | # high range of the sensor (this will be white on the screen)
|
23 | 24 | MAXTEMP = 50.0
|
24 | 25 |
|
| 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 | + |
25 | 40 | # 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" |
28 | 44 | 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 | + ) |
30 | 51 | print(pygame.display.Info())
|
31 | 52 |
|
32 | 53 | # the list of colors we can choose from
|
@@ -117,10 +138,13 @@ def gradient(x, width, cmap, spread=1):
|
117 | 138 | # pixelrgb = [colors[constrain(int(pixel), 0, COLORDEPTH-1)] for pixel in pixels]
|
118 | 139 | img = Image.new("RGB", (32, 24))
|
119 | 140 | 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) |
121 | 143 | img_surface = pygame.image.fromstring(img.tobytes(), img.size, img.mode)
|
122 | 144 | pygame.transform.scale(img_surface.convert(), screen.get_size(), screen)
|
123 | 145 | pygame.display.update()
|
| 146 | + if args.windowed: |
| 147 | + pygame.event.pump() |
124 | 148 | print(
|
125 | 149 | "Completed 2 frames in %0.2f s (%d FPS)"
|
126 | 150 | % (time.monotonic() - stamp, 1.0 / (time.monotonic() - stamp))
|
|
0 commit comments