From 12885e0fda48f4f0846af489e38bfc881613a7bc Mon Sep 17 00:00:00 2001 From: Francois Gervais Date: Fri, 10 Apr 2020 14:45:40 -0400 Subject: [PATCH 1/5] camtest: add a --windowed parameter This allows the example to run on a PC using Blinka --- examples/mlx90640_camtest.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/examples/mlx90640_camtest.py b/examples/mlx90640_camtest.py index 1287d48..37ae2a1 100644 --- a/examples/mlx90640_camtest.py +++ b/examples/mlx90640_camtest.py @@ -9,6 +9,7 @@ import busio from PIL import Image import pygame +import argparse import adafruit_mlx90640 @@ -22,11 +23,26 @@ # high range of the sensor (this will be white on the screen) MAXTEMP = 50.0 +# if in windowed mode, make the window bigger by this factor +WINDOW_SCALING_FACTOR = 50 + +# parse command line arguments +parser = argparse.ArgumentParser() +parser.add_argument("--windowed", action="store_true", + help="display in a window") + +args = parser.parse_args() + # set up display -os.environ["SDL_FBDEV"] = "/dev/fb0" -os.environ["SDL_VIDEODRIVER"] = "fbcon" +if not args.windowed: + os.environ["SDL_FBDEV"] = "/dev/fb0" + os.environ["SDL_VIDEODRIVER"] = "fbcon" pygame.init() -screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) +if not args.windowed: + screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) +else: + screen = pygame.display.set_mode([32*WINDOW_SCALING_FACTOR, + 24*WINDOW_SCALING_FACTOR]) print(pygame.display.Info()) # the list of colors we can choose from From adf454e5bb36e93b5fc3e779f36b135ab5bd29c7 Mon Sep 17 00:00:00 2001 From: Francois Gervais Date: Fri, 10 Apr 2020 14:50:59 -0400 Subject: [PATCH 2/5] camtest: add --disable-interpolation parameter --- examples/mlx90640_camtest.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/mlx90640_camtest.py b/examples/mlx90640_camtest.py index 37ae2a1..978bc77 100644 --- a/examples/mlx90640_camtest.py +++ b/examples/mlx90640_camtest.py @@ -30,6 +30,8 @@ parser = argparse.ArgumentParser() parser.add_argument("--windowed", action="store_true", help="display in a window") +parser.add_argument("--disable-interpolation", action="store_true", + help="disable interpolation in-between camera pixels") args = parser.parse_args() @@ -133,7 +135,8 @@ def gradient(x, width, cmap, spread=1): # pixelrgb = [colors[constrain(int(pixel), 0, COLORDEPTH-1)] for pixel in pixels] img = Image.new("RGB", (32, 24)) img.putdata(pixels) - img = img.resize((32 * INTERPOLATE, 24 * INTERPOLATE), Image.BICUBIC) + if not args.disable_interpolation: + img = img.resize((32 * INTERPOLATE, 24 * INTERPOLATE), Image.BICUBIC) img_surface = pygame.image.fromstring(img.tobytes(), img.size, img.mode) pygame.transform.scale(img_surface.convert(), screen.get_size(), screen) pygame.display.update() From ae21252e3a045e76558eac6647476b4573c9db1f Mon Sep 17 00:00:00 2001 From: Francois Gervais Date: Fri, 10 Apr 2020 15:49:01 -0400 Subject: [PATCH 3/5] Reformat with black --- examples/mlx90640_camtest.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/examples/mlx90640_camtest.py b/examples/mlx90640_camtest.py index 978bc77..388c143 100644 --- a/examples/mlx90640_camtest.py +++ b/examples/mlx90640_camtest.py @@ -28,10 +28,12 @@ # parse command line arguments parser = argparse.ArgumentParser() -parser.add_argument("--windowed", action="store_true", - help="display in a window") -parser.add_argument("--disable-interpolation", action="store_true", - help="disable interpolation in-between camera pixels") +parser.add_argument("--windowed", action="store_true", help="display in a window") +parser.add_argument( + "--disable-interpolation", + action="store_true", + help="disable interpolation in-between camera pixels", +) args = parser.parse_args() @@ -43,8 +45,9 @@ if not args.windowed: screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) else: - screen = pygame.display.set_mode([32*WINDOW_SCALING_FACTOR, - 24*WINDOW_SCALING_FACTOR]) + screen = pygame.display.set_mode( + [32 * WINDOW_SCALING_FACTOR, 24 * WINDOW_SCALING_FACTOR] + ) print(pygame.display.Info()) # the list of colors we can choose from From aa4efc5601209473963fabc77d59c5792d537709 Mon Sep 17 00:00:00 2001 From: Francois Gervais Date: Fri, 10 Apr 2020 16:01:40 -0400 Subject: [PATCH 4/5] Reorder argparse import --- examples/mlx90640_camtest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/mlx90640_camtest.py b/examples/mlx90640_camtest.py index 388c143..6f489d8 100644 --- a/examples/mlx90640_camtest.py +++ b/examples/mlx90640_camtest.py @@ -5,11 +5,11 @@ import os import math import time +import argparse import board import busio from PIL import Image import pygame -import argparse import adafruit_mlx90640 From 7e25def654a72f3de5b705b1645bf14e3f7d7652 Mon Sep 17 00:00:00 2001 From: Francois Gervais Date: Fri, 10 Apr 2020 16:26:02 -0400 Subject: [PATCH 5/5] Let the OS know the window is responsive As seen at: https://www.pygame.org/docs/ref/event.html#pygame.event.pump --- examples/mlx90640_camtest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/mlx90640_camtest.py b/examples/mlx90640_camtest.py index 6f489d8..82c1ae4 100644 --- a/examples/mlx90640_camtest.py +++ b/examples/mlx90640_camtest.py @@ -143,6 +143,8 @@ def gradient(x, width, cmap, spread=1): img_surface = pygame.image.fromstring(img.tobytes(), img.size, img.mode) pygame.transform.scale(img_surface.convert(), screen.get_size(), screen) pygame.display.update() + if args.windowed: + pygame.event.pump() print( "Completed 2 frames in %0.2f s (%d FPS)" % (time.monotonic() - stamp, 1.0 / (time.monotonic() - stamp))