From 3bcc927a781425744252984018d1d544645a9c4d Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 21 Nov 2023 17:16:12 -0600 Subject: [PATCH 01/11] stating new ipcam example --- examples/ipcam2/code.py | 212 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 examples/ipcam2/code.py diff --git a/examples/ipcam2/code.py b/examples/ipcam2/code.py new file mode 100644 index 0000000..ed00975 --- /dev/null +++ b/examples/ipcam2/code.py @@ -0,0 +1,212 @@ +import espcamera +import os +import sys +import time +import struct +import board +import adafruit_pycamera +import displayio +import gifio +import ulab.numpy as np +import bitmaptools +import socketpool +import wifi +from adafruit_httpserver import Server, Request, Response, GET, POST + +pycam = adafruit_pycamera.PyCamera() +pycam.autofocus_init() + +if wifi.radio.ipv4_address: + # use alt port if web workflow enabled + port = 8080 +else: + # connect to wifi and use standard http port otherwise + wifi.radio.connect(os.getenv("WIFI_SSID"), os.getenv("WIFI_PASSWORD")) + port = 80 + +print(wifi.radio.ipv4_address) + +pool = socketpool.SocketPool(wifi.radio) +server = Server(pool, debug=True) + +@server.route("/lcd", [GET, POST]) +def property(request: Request) -> Response: + pycam.blit(pycam.continuous_capture()) + return Response(request, "") + +@server.route("/jpeg", [GET, POST]) +def property(request: Request) -> Response: + pycam.camera.reconfigure( + pixel_format=espcamera.PixelFormat.JPEG, + frame_size=pycam.resolution_to_frame_size[pycam._resolution] + ) + try: + jpeg = pycam.camera.take(1) + if jpeg is not None: + return Response(request, bytes(jpeg), content_type="image/jpeg") + else: + return Response(request, "", content_type="text/plain", status=INTERNAL_SERVER_ERROR_500) + finally: + pycam.live_preview_mode() + +@server.route("/property", [GET, POST]) +def property(request: Request) -> Response: + enctype = request.query_params.get("enctype", "text/plain") + + key = request.form_data.get("k") + value = request.form_data.get("v", None) + + try: + current_value = getattr(pycam, key, None) + except Exception as e: + return Response(request, str(e), status=NOT_FOUND_404) + + if value is None: + return Response(request, str(current_value)) + else: + try: + current_value_type = type(current_value) + if current_value_type is bool: + setattr(pycam, key, value not in ('False', '0', 'no', 'n', 'off', '')) + else: + setattr(pycam, key, current_value_type(value)) + return Response(request, "") + except Exception as e: + return Response(request, str(e), status=BAD_REQUEST_400) + +server.serve_forever(str(wifi.radio.ipv4_address), port) + + +server = Server(pool, debug=True) + +last_frame = displayio.Bitmap(pycam.camera.width, pycam.camera.height, 65535) +onionskin = displayio.Bitmap(pycam.camera.width, pycam.camera.height, 65535) +while True: + if (pycam.mode_text == "STOP" and pycam.stop_motion_frame != 0): + # alpha blend + new_frame = pycam.continuous_capture() + bitmaptools.alphablend(onionskin, last_frame, new_frame, + displayio.Colorspace.RGB565_SWAPPED) + pycam.blit(onionskin) + else: + pycam.blit(pycam.continuous_capture()) + #print("\t\t", capture_time, blit_time) + + pycam.keys_debounce() + print(f"{pycam.shutter.released=} {pycam.shutter.long_press=} {pycam.shutter.short_count=}") + # test shutter button + if pycam.shutter.long_press: + print("FOCUS") + print(pycam.autofocus_status) + pycam.autofocus() + print(pycam.autofocus_status) + if pycam.shutter.short_count: + print("Shutter released") + if pycam.mode_text == "STOP": + pycam.capture_into_bitmap(last_frame) + pycam.stop_motion_frame += 1 + try: + pycam.display_message("Snap!", color=0x0000FF) + pycam.capture_jpeg() + except TypeError as e: + pycam.display_message("Failed", color=0xFF0000) + time.sleep(0.5) + except RuntimeError as e: + pycam.display_message("Error\nNo SD Card", color=0xFF0000) + time.sleep(0.5) + pycam.live_preview_mode() + + if pycam.mode_text == "GIF": + try: + f = pycam.open_next_image("gif") + except RuntimeError as e: + pycam.display_message("Error\nNo SD Card", color=0xFF0000) + time.sleep(0.5) + continue + i = 0 + ft = [] + pycam._mode_label.text = "RECORDING" + + pycam.display.refresh() + with gifio.GifWriter(f, pycam.camera.width, pycam.camera.height, + displayio.Colorspace.RGB565_SWAPPED, dither=True) as g: + t00 = t0 = time.monotonic() + while (i < 15) or (pycam.shutter_button.value == False): + i += 1 + _gifframe = pycam.continuous_capture() + g.add_frame(_gifframe, .12) + pycam.blit(_gifframe) + t1 = time.monotonic() + ft.append(1/(t1-t0)) + print(end=".") + t0 = t1 + pycam._mode_label.text = "GIF" + print(f"\nfinal size {f.tell()} for {i} frames") + print(f"average framerate {i/(t1-t00)}fps") + print(f"best {max(ft)} worst {min(ft)} std. deviation {np.std(ft)}") + f.close() + pycam.display.refresh() + + if pycam.mode_text == "JPEG": + pycam.tone(200, 0.1) + try: + pycam.display_message("Snap!", color=0x0000FF) + pycam.capture_jpeg() + pycam.live_preview_mode() + except TypeError as e: + pycam.display_message("Failed", color=0xFF0000) + time.sleep(0.5) + pycam.live_preview_mode() + except RuntimeError as e: + pycam.display_message("Error\nNo SD Card", color=0xFF0000) + time.sleep(0.5) + if pycam.card_detect.fell: + print("SD card removed") + pycam.unmount_sd_card() + pycam.display.refresh() + if pycam.card_detect.rose: + print("SD card inserted") + pycam.display_message("Mounting\nSD Card", color=0xFFFFFF) + for _ in range(3): + try: + print("Mounting card") + pycam.mount_sd_card() + print("Success!") + break + except OSError as e: + print("Retrying!", e) + time.sleep(0.5) + else: + pycam.display_message("SD Card\nFailed!", color=0xFF0000) + time.sleep(0.5) + pycam.display.refresh() + + if pycam.up.fell: + print("UP") + key = settings[curr_setting] + if key: + setattr(pycam, key, getattr(pycam, key) + 1) + if pycam.down.fell: + print("DN") + key = settings[curr_setting] + if key: + setattr(pycam, key, getattr(pycam, key) - 1) + if pycam.left.fell: + print("LF") + curr_setting = (curr_setting + 1) % len(settings) + print(settings[curr_setting]) + #new_res = min(len(pycam.resolutions)-1, pycam.get_resolution()+1) + #pycam.set_resolution(pycam.resolutions[new_res]) + pycam.select_setting(settings[curr_setting]) + if pycam.right.fell: + print("RT") + curr_setting = (curr_setting - 1 + len(settings)) % len(settings) + print(settings[curr_setting]) + pycam.select_setting(settings[curr_setting]) + #new_res = max(1, pycam.get_resolution()-1) + #pycam.set_resolution(pycam.resolutions[new_res]) + if pycam.select.fell: + print("SEL") + if pycam.ok.fell: + print("OK") + From 8a6645841b5fd38e2177a703f6b8e8826d4291b8 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 22 Nov 2023 09:30:05 -0600 Subject: [PATCH 02/11] Steps towards a full UI * Add /index.html, /index.js, /metadata.json endpoints * metadata.json gives each property and its range of values * add property2 to set properties on pycam.camera (yes it stinks) now I can start creating the amateur-hour web UI on top of this --- examples/ipcam2/code.py | 125 +++++++++++++++++---------- examples/ipcam2/htdocs/metadata.json | 1 + examples/ipcam2/make_web_metadata.py | 65 ++++++++++++++ 3 files changed, 146 insertions(+), 45 deletions(-) create mode 100644 examples/ipcam2/htdocs/metadata.json create mode 100644 examples/ipcam2/make_web_metadata.py diff --git a/examples/ipcam2/code.py b/examples/ipcam2/code.py index ed00975..80049fd 100644 --- a/examples/ipcam2/code.py +++ b/examples/ipcam2/code.py @@ -1,17 +1,20 @@ -import espcamera +import json import os +import struct import sys import time -import struct -import board + import adafruit_pycamera +import bitmaptools +import board import displayio +import espcamera import gifio -import ulab.numpy as np -import bitmaptools import socketpool +import ulab.numpy as np import wifi -from adafruit_httpserver import Server, Request, Response, GET, POST +from adafruit_httpserver import (BAD_REQUEST_400, GET, NOT_FOUND_404, POST, FileResponse, + JSONResponse, Request, Response, Server) pycam = adafruit_pycamera.PyCamera() pycam.autofocus_init() @@ -27,52 +30,77 @@ print(wifi.radio.ipv4_address) pool = socketpool.SocketPool(wifi.radio) -server = Server(pool, debug=True) +server = Server(pool, debug=True, root_path='/htdocs') + +@server.route("/metadata.json", [GET]) +def property(request: Request) -> Response: + return FileResponse(request, "/metadata.json") + +@server.route("/", [GET]) +def property(request: Request) -> Response: + return FileResponse(request, "/index.html") + +@server.route("/index.js", [GET]) +def property(request: Request) -> Response: + return FileResponse(request, "/index.js") + @server.route("/lcd", [GET, POST]) def property(request: Request) -> Response: pycam.blit(pycam.continuous_capture()) return Response(request, "") + @server.route("/jpeg", [GET, POST]) def property(request: Request) -> Response: pycam.camera.reconfigure( pixel_format=espcamera.PixelFormat.JPEG, - frame_size=pycam.resolution_to_frame_size[pycam._resolution] + frame_size=pycam.resolution_to_frame_size[pycam._resolution], ) try: jpeg = pycam.camera.take(1) if jpeg is not None: return Response(request, bytes(jpeg), content_type="image/jpeg") else: - return Response(request, "", content_type="text/plain", status=INTERNAL_SERVER_ERROR_500) + return Response( + request, "", content_type="text/plain", status=INTERNAL_SERVER_ERROR_500 + ) finally: pycam.live_preview_mode() +@server.route("/focus", [GET]) +def focus(request: Request) -> Response: + return JSONResponse(request, pycam.autofocus()) + @server.route("/property", [GET, POST]) def property(request: Request) -> Response: - enctype = request.query_params.get("enctype", "text/plain") + return property_common(pycam, request) + + +@server.route("/property2", [GET, POST]) +def property2(request: Request) -> Response: + return property_common(pycam.camera, request) + - key = request.form_data.get("k") - value = request.form_data.get("v", None) - +def property_common(obj, request): try: - current_value = getattr(pycam, key, None) + params = request.query_params or request.form_data + key = params["k"] + value = params.get("v", None) + + if value is None: + try: + current_value = getattr(obj, key, None) + return JSONResponse(request, current_value) + except Exception as e: + return Response(request, {'error': str(e)}, status=BAD_REQUEST_400) + else: + new_value = json.loads(value) + setattr(obj, key, new_value) + return JSONResponse(request, {'status': 'OK'}) except Exception as e: - return Response(request, str(e), status=NOT_FOUND_404) + return JSONResponse(request, {'error': str(e)}, status=BAD_REQUEST_400) - if value is None: - return Response(request, str(current_value)) - else: - try: - current_value_type = type(current_value) - if current_value_type is bool: - setattr(pycam, key, value not in ('False', '0', 'no', 'n', 'off', '')) - else: - setattr(pycam, key, current_value_type(value)) - return Response(request, "") - except Exception as e: - return Response(request, str(e), status=BAD_REQUEST_400) server.serve_forever(str(wifi.radio.ipv4_address), port) @@ -82,18 +110,21 @@ def property(request: Request) -> Response: last_frame = displayio.Bitmap(pycam.camera.width, pycam.camera.height, 65535) onionskin = displayio.Bitmap(pycam.camera.width, pycam.camera.height, 65535) while True: - if (pycam.mode_text == "STOP" and pycam.stop_motion_frame != 0): + if pycam.mode_text == "STOP" and pycam.stop_motion_frame != 0: # alpha blend new_frame = pycam.continuous_capture() - bitmaptools.alphablend(onionskin, last_frame, new_frame, - displayio.Colorspace.RGB565_SWAPPED) + bitmaptools.alphablend( + onionskin, last_frame, new_frame, displayio.Colorspace.RGB565_SWAPPED + ) pycam.blit(onionskin) else: pycam.blit(pycam.continuous_capture()) - #print("\t\t", capture_time, blit_time) + # print("\t\t", capture_time, blit_time) pycam.keys_debounce() - print(f"{pycam.shutter.released=} {pycam.shutter.long_press=} {pycam.shutter.short_count=}") + print( + f"{pycam.shutter.released=} {pycam.shutter.long_press=} {pycam.shutter.short_count=}" + ) # test shutter button if pycam.shutter.long_press: print("FOCUS") @@ -118,26 +149,31 @@ def property(request: Request) -> Response: if pycam.mode_text == "GIF": try: - f = pycam.open_next_image("gif") + f = pycam.open_next_image("gif") except RuntimeError as e: - pycam.display_message("Error\nNo SD Card", color=0xFF0000) - time.sleep(0.5) - continue + pycam.display_message("Error\nNo SD Card", color=0xFF0000) + time.sleep(0.5) + continue i = 0 ft = [] pycam._mode_label.text = "RECORDING" pycam.display.refresh() - with gifio.GifWriter(f, pycam.camera.width, pycam.camera.height, - displayio.Colorspace.RGB565_SWAPPED, dither=True) as g: + with gifio.GifWriter( + f, + pycam.camera.width, + pycam.camera.height, + displayio.Colorspace.RGB565_SWAPPED, + dither=True, + ) as g: t00 = t0 = time.monotonic() while (i < 15) or (pycam.shutter_button.value == False): i += 1 _gifframe = pycam.continuous_capture() - g.add_frame(_gifframe, .12) + g.add_frame(_gifframe, 0.12) pycam.blit(_gifframe) t1 = time.monotonic() - ft.append(1/(t1-t0)) + ft.append(1 / (t1 - t0)) print(end=".") t0 = t1 pycam._mode_label.text = "GIF" @@ -195,18 +231,17 @@ def property(request: Request) -> Response: print("LF") curr_setting = (curr_setting + 1) % len(settings) print(settings[curr_setting]) - #new_res = min(len(pycam.resolutions)-1, pycam.get_resolution()+1) - #pycam.set_resolution(pycam.resolutions[new_res]) + # new_res = min(len(pycam.resolutions)-1, pycam.get_resolution()+1) + # pycam.set_resolution(pycam.resolutions[new_res]) pycam.select_setting(settings[curr_setting]) if pycam.right.fell: print("RT") curr_setting = (curr_setting - 1 + len(settings)) % len(settings) print(settings[curr_setting]) pycam.select_setting(settings[curr_setting]) - #new_res = max(1, pycam.get_resolution()-1) - #pycam.set_resolution(pycam.resolutions[new_res]) + # new_res = max(1, pycam.get_resolution()-1) + # pycam.set_resolution(pycam.resolutions[new_res]) if pycam.select.fell: print("SEL") if pycam.ok.fell: print("OK") - diff --git a/examples/ipcam2/htdocs/metadata.json b/examples/ipcam2/htdocs/metadata.json new file mode 100644 index 0000000..cc48434 --- /dev/null +++ b/examples/ipcam2/htdocs/metadata.json @@ -0,0 +1 @@ +{"property": {"effect": ["Normal", "Invert", "B&W", "Reddish", "Greenish", "Bluish", "Sepia", "Solarize"], "resolution": ["240x240", "320x240", "640x480", "800x600", "1024x768", "1280x720", "1280x1024", "1600x1200", "1920x1080", "2048x1536", "2560x1440", "2560x1600", "2560x1920"], "led_level": [0, 1, 2, 3, 4], "led_color": [0, 1, 2, 3, 4, 5, 6, 7]}, "property2": {"sensor_name": null, "contrast": [-2, -1, 0, 1, 2], "brightness": [-2, -1, 0, 1, 2], "saturation": [-2, -1, 0, 1, 2], "sharpness": [-2, -1, 0, 1, 2], "ae_level": [-2, -1, 0, 1, 2], "denoise": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], "gain_ceiling": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], "quality": [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35], "colorbar": [false, true], "whitebal": [false, true], "gain_ctrl": [false, true], "exposure_ctrl": [false, true], "hmirror": [false, true], "vflip": [false, true], "aec2": [false, true], "awb_gain": [false, true], "dcw": [false, true], "bpc": [false, true], "wpc": [false, true], "raw_gma": [false, true], "lenc": [false, true], "aec_gain": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29], "aec_value": [0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150], "wb_mode": [0, 1, 2, 3, 4]}} \ No newline at end of file diff --git a/examples/ipcam2/make_web_metadata.py b/examples/ipcam2/make_web_metadata.py new file mode 100644 index 0000000..4b18922 --- /dev/null +++ b/examples/ipcam2/make_web_metadata.py @@ -0,0 +1,65 @@ +import json + +def list_range(*args): return list(range(*args)) + +metadata = { + "property": { + "effect": ( + "Normal", + "Invert", + "B&W", + "Reddish", + "Greenish", + "Bluish", + "Sepia", + "Solarize", + ), + "resolution": ( + "240x240", + "320x240", + "640x480", + "800x600", + "1024x768", + "1280x720", + "1280x1024", + "1600x1200", + "1920x1080", + "2048x1536", + "2560x1440", + "2560x1600", + "2560x1920", + ), + "led_level": list_range(5), + "led_color": list_range(8), + }, + "property2": { + "sensor_name": None, + "contrast": list_range(-2, 3), + "brightness": list_range(-2, 3), + "saturation": list_range(-2, 3), + "sharpness": list_range(-2, 3), + "ae_level": list_range(-2, 3), + "denoise": list_range(10), + "gain_ceiling": list_range(10), + "quality": list_range(8, 36), + "colorbar": [False, True], + "whitebal": [False, True], + "gain_ctrl": [False, True], + "exposure_ctrl": [False, True], + "hmirror": [False, True], + "vflip": [False, True], + "aec2": [False, True], + "awb_gain": [False, True], + "dcw": [False, True], + "bpc": [False, True], + "wpc": [False, True], + "raw_gma": [False, True], + "lenc": [False, True], + "aec_gain": list_range(30), + "aec_value": list_range(0, 1200, 50), + "wb_mode": list_range(0, 5), + }, +} + +with open("metadata.json", "w", encoding="utf-8") as f: + json.dump(metadata, f) From e6540c176728dc5e02afb0d95da7e9ed8c7a2f19 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 29 Nov 2023 10:50:35 -0600 Subject: [PATCH 03/11] Update ipcam2 example --- examples/ipcam2/code.py | 7 +- examples/ipcam2/htdocs/index.html | 18 ++ examples/ipcam2/htdocs/index.js | 46 +++++ examples/ipcam2/htdocs/metadata.js | 254 +++++++++++++++++++++++++++ examples/ipcam2/htdocs/metadata.json | 1 - examples/ipcam2/make_web_metadata.py | 8 +- 6 files changed, 329 insertions(+), 5 deletions(-) create mode 100644 examples/ipcam2/htdocs/index.html create mode 100644 examples/ipcam2/htdocs/index.js create mode 100644 examples/ipcam2/htdocs/metadata.js delete mode 100644 examples/ipcam2/htdocs/metadata.json diff --git a/examples/ipcam2/code.py b/examples/ipcam2/code.py index 80049fd..eff169c 100644 --- a/examples/ipcam2/code.py +++ b/examples/ipcam2/code.py @@ -16,6 +16,11 @@ from adafruit_httpserver import (BAD_REQUEST_400, GET, NOT_FOUND_404, POST, FileResponse, JSONResponse, Request, Response, Server) +# Disable autoreload. this is very handy while editing the js & html files +# as you want to just reload the web browser, not the CircutPython program! +import supervisor +supervisor.runtime.autoreload = False + pycam = adafruit_pycamera.PyCamera() pycam.autofocus_init() @@ -34,7 +39,7 @@ @server.route("/metadata.json", [GET]) def property(request: Request) -> Response: - return FileResponse(request, "/metadata.json") + return FileResponse(request, "/metadata.js") @server.route("/", [GET]) def property(request: Request) -> Response: diff --git a/examples/ipcam2/htdocs/index.html b/examples/ipcam2/htdocs/index.html new file mode 100644 index 0000000..a829b33 --- /dev/null +++ b/examples/ipcam2/htdocs/index.html @@ -0,0 +1,18 @@ + + + + + +
+ +
+
+
+ + + + diff --git a/examples/ipcam2/htdocs/index.js b/examples/ipcam2/htdocs/index.js new file mode 100644 index 0000000..00a1e0d --- /dev/null +++ b/examples/ipcam2/htdocs/index.js @@ -0,0 +1,46 @@ +const html = (strings, ...values) => String.raw({ raw: strings }, ...values); + +var ii = 0; + +function option_change(k1, k2) { + var id_ = k1 + "-" + k2; + var el = document.getElementById(id_) + + url = `/${k1}?k=${k2}&v=${el.value}` + console.log(url) + var req = new XMLHttpRequest(); + req.open("GET", url, false) + req.send(); + + document.getElementById("jpeg").src = `/jpeg?${ii++}` +} + +function make_controls(k1, t) { + console.log(t); + for(var k2 in t) { + var id_ = k1 + "-" + k2; + var options = "" + for(var v in t[k2]) { + options += html` + + ` + } + var ht = html` +
+ + +
+ ` + console.log(ht); + + var el = document.getElementById("controls") + el.insertAdjacentHTML("beforeend", ht) + } +} + +for(var k in tunables) { + console.log(k) + make_controls(k, tunables[k]); +} diff --git a/examples/ipcam2/htdocs/metadata.js b/examples/ipcam2/htdocs/metadata.js new file mode 100644 index 0000000..f0a4727 --- /dev/null +++ b/examples/ipcam2/htdocs/metadata.js @@ -0,0 +1,254 @@ +tunables = { + "property": { + "effect": [ + "Normal", + "Invert", + "B&W", + "Reddish", + "Greenish", + "Bluish", + "Sepia", + "Solarize" + ], + "resolution": [ + "240x240", + "320x240", + "640x480", + "800x600", + "1024x768", + "1280x720", + "1280x1024", + "1600x1200", + "1920x1080", + "2048x1536", + "2560x1440", + "2560x1600", + "2560x1920" + ], + "led_level": [ + 0, + 1, + 2, + 3, + 4 + ], + "led_color": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7 + ] + }, + "property2": { + "contrast": [ + -2, + -1, + 0, + 1, + 2 + ], + "brightness": [ + -2, + -1, + 0, + 1, + 2 + ], + "saturation": [ + -2, + -1, + 0, + 1, + 2 + ], + "sharpness": [ + -2, + -1, + 0, + 1, + 2 + ], + "ae_level": [ + -2, + -1, + 0, + 1, + 2 + ], + "denoise": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "gain_ceiling": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ], + "quality": [ + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 35 + ], + "colorbar": [ + false, + true + ], + "whitebal": [ + false, + true + ], + "gain_ctrl": [ + false, + true + ], + "exposure_ctrl": [ + false, + true + ], + "hmirror": [ + false, + true + ], + "vflip": [ + false, + true + ], + "aec2": [ + false, + true + ], + "awb_gain": [ + false, + true + ], + "dcw": [ + false, + true + ], + "bpc": [ + false, + true + ], + "wpc": [ + false, + true + ], + "raw_gma": [ + false, + true + ], + "lenc": [ + false, + true + ], + "aec_gain": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29 + ], + "aec_value": [ + 0, + 50, + 100, + 150, + 200, + 250, + 300, + 350, + 400, + 450, + 500, + 550, + 600, + 650, + 700, + 750, + 800, + 850, + 900, + 950, + 1000, + 1050, + 1100, + 1150 + ], + "wb_mode": [ + 0, + 1, + 2, + 3, + 4 + ] + } +}; diff --git a/examples/ipcam2/htdocs/metadata.json b/examples/ipcam2/htdocs/metadata.json deleted file mode 100644 index cc48434..0000000 --- a/examples/ipcam2/htdocs/metadata.json +++ /dev/null @@ -1 +0,0 @@ -{"property": {"effect": ["Normal", "Invert", "B&W", "Reddish", "Greenish", "Bluish", "Sepia", "Solarize"], "resolution": ["240x240", "320x240", "640x480", "800x600", "1024x768", "1280x720", "1280x1024", "1600x1200", "1920x1080", "2048x1536", "2560x1440", "2560x1600", "2560x1920"], "led_level": [0, 1, 2, 3, 4], "led_color": [0, 1, 2, 3, 4, 5, 6, 7]}, "property2": {"sensor_name": null, "contrast": [-2, -1, 0, 1, 2], "brightness": [-2, -1, 0, 1, 2], "saturation": [-2, -1, 0, 1, 2], "sharpness": [-2, -1, 0, 1, 2], "ae_level": [-2, -1, 0, 1, 2], "denoise": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], "gain_ceiling": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], "quality": [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35], "colorbar": [false, true], "whitebal": [false, true], "gain_ctrl": [false, true], "exposure_ctrl": [false, true], "hmirror": [false, true], "vflip": [false, true], "aec2": [false, true], "awb_gain": [false, true], "dcw": [false, true], "bpc": [false, true], "wpc": [false, true], "raw_gma": [false, true], "lenc": [false, true], "aec_gain": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29], "aec_value": [0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150], "wb_mode": [0, 1, 2, 3, 4]}} \ No newline at end of file diff --git a/examples/ipcam2/make_web_metadata.py b/examples/ipcam2/make_web_metadata.py index 4b18922..88461a6 100644 --- a/examples/ipcam2/make_web_metadata.py +++ b/examples/ipcam2/make_web_metadata.py @@ -33,7 +33,7 @@ def list_range(*args): return list(range(*args)) "led_color": list_range(8), }, "property2": { - "sensor_name": None, + #"sensor_name": None, "contrast": list_range(-2, 3), "brightness": list_range(-2, 3), "saturation": list_range(-2, 3), @@ -61,5 +61,7 @@ def list_range(*args): return list(range(*args)) }, } -with open("metadata.json", "w", encoding="utf-8") as f: - json.dump(metadata, f) +with open("htdocs/metadata.js", "w", encoding="utf-8") as f: + print(end="tunables = ", file=f) + json.dump(metadata, f, indent=4) + print(";", file=f) From cc9f7c39e862092e6f2d634d0bf4f072186f7393 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 29 Nov 2023 11:09:57 -0600 Subject: [PATCH 04/11] files added from cookiecutter --- .../adafruit_circuitpython_pr.md | 13 + .github/workflows/build.yml | 14 + .github/workflows/failure-help-text.yml | 19 + .github/workflows/release_gh.yml | 19 + .github/workflows/release_pypi.yml | 19 + .gitignore | 48 +++ .pre-commit-config.yaml | 42 ++ .pylintrc | 399 ++++++++++++++++++ .readthedocs.yaml | 19 + CODE_OF_CONDUCT.md | 158 +++++++ LICENSE | 21 + LICENSES/CC-BY-4.0.txt | 324 ++++++++++++++ LICENSES/MIT.txt | 19 + LICENSES/Unlicense.txt | 20 + README.rst | 118 ++++++ README.rst.license | 3 + docs/_static/favicon.ico | Bin 0 -> 4414 bytes docs/_static/favicon.ico.license | 3 + docs/api.rst | 8 + docs/api.rst.license | 4 + docs/conf.py | 190 +++++++++ docs/examples.rst | 8 + docs/examples.rst.license | 4 + docs/index.rst | 53 +++ docs/index.rst.license | 4 + docs/requirements.txt | 7 + optional_requirements.txt | 3 + pyproject.toml | 51 +++ requirements.txt | 7 + 29 files changed, 1597 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/failure-help-text.yml create mode 100644 .github/workflows/release_gh.yml create mode 100644 .github/workflows/release_pypi.yml create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 .pylintrc create mode 100644 .readthedocs.yaml create mode 100644 CODE_OF_CONDUCT.md create mode 100644 LICENSE create mode 100644 LICENSES/CC-BY-4.0.txt create mode 100644 LICENSES/MIT.txt create mode 100644 LICENSES/Unlicense.txt create mode 100644 README.rst create mode 100644 README.rst.license create mode 100644 docs/_static/favicon.ico create mode 100644 docs/_static/favicon.ico.license create mode 100644 docs/api.rst create mode 100644 docs/api.rst.license create mode 100644 docs/conf.py create mode 100644 docs/examples.rst create mode 100644 docs/examples.rst.license create mode 100644 docs/index.rst create mode 100644 docs/index.rst.license create mode 100644 docs/requirements.txt create mode 100644 optional_requirements.txt create mode 100644 pyproject.toml create mode 100644 requirements.txt diff --git a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md new file mode 100644 index 0000000..8de294e --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2021 Adafruit Industries +# +# SPDX-License-Identifier: MIT + +Thank you for contributing! Before you submit a pull request, please read the following. + +Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html + +If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs + +Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code + +Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues. diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..041a337 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main diff --git a/.github/workflows/failure-help-text.yml b/.github/workflows/failure-help-text.yml new file mode 100644 index 0000000..0b1194f --- /dev/null +++ b/.github/workflows/failure-help-text.yml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Failure help text + +on: + workflow_run: + workflows: ["Build CI"] + types: + - completed + +jobs: + post-help: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }} + steps: + - name: Post comment to help + uses: adafruit/circuitpython-action-library-ci-failed@v1 diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml new file mode 100644 index 0000000..9acec60 --- /dev/null +++ b/.github/workflows/release_gh.yml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: GitHub Release Actions + +on: + release: + types: [published] + +jobs: + upload-release-assets: + runs-on: ubuntu-latest + steps: + - name: Run GitHub Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-gh@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + upload-url: ${{ github.event.release.upload_url }} diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml new file mode 100644 index 0000000..c16b495 --- /dev/null +++ b/.github/workflows/release_pypi.yml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: PyPI Release Actions + +on: + release: + types: [published] + +jobs: + upload-release-assets: + runs-on: ubuntu-latest + steps: + - name: Run PyPI Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-pypi@main + with: + pypi-username: ${{ secrets.pypi_username }} + pypi-password: ${{ secrets.pypi_password }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..db3d538 --- /dev/null +++ b/.gitignore @@ -0,0 +1,48 @@ +# SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +# Do not include files and directories created by your personal work environment, such as the IDE +# you use, except for those already listed here. Pull requests including changes to this file will +# not be accepted. + +# This .gitignore file contains rules for files generated by working with CircuitPython libraries, +# including building Sphinx, testing with pip, and creating a virual environment, as well as the +# MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs. + +# If you find that there are files being generated on your machine that should not be included in +# your git commit, you should create a .gitignore_global file on your computer to include the +# files created by your personal setup. To do so, follow the two steps below. + +# First, create a file called .gitignore_global somewhere convenient for you, and add rules for +# the files you want to exclude from git commits. + +# Second, configure Git to use the exclude file for all Git repositories by running the +# following via commandline, replacing "path/to/your/" with the actual path to your newly created +# .gitignore_global file: +# git config --global core.excludesfile path/to/your/.gitignore_global + +# CircuitPython-specific files +*.mpy + +# Python-specific files +__pycache__ +*.pyc + +# Sphinx build-specific files +_build + +# This file results from running `pip -e install .` in a local repository +*.egg-info + +# Virtual environment-specific files +.env +.venv + +# MacOS-specific files +*.DS_Store + +# IDE-specific files +.idea +.vscode +*~ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..70ade69 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,42 @@ +# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# +# SPDX-License-Identifier: Unlicense + +repos: + - repo: https://github.com/python/black + rev: 23.3.0 + hooks: + - id: black + - repo: https://github.com/fsfe/reuse-tool + rev: v1.1.2 + hooks: + - id: reuse + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/pycqa/pylint + rev: v2.17.4 + hooks: + - id: pylint + name: pylint (library code) + types: [python] + args: + - --disable=consider-using-f-string + exclude: "^(docs/|examples/|tests/|setup.py$)" + - id: pylint + name: pylint (example code) + description: Run pylint rules on "examples/*.py" files + types: [python] + files: "^examples/" + args: + - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code + - id: pylint + name: pylint (test code) + description: Run pylint rules on "tests/*.py" files + types: [python] + files: "^tests/" + args: + - --disable=missing-docstring,consider-using-f-string,duplicate-code diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..f945e92 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,399 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +[MASTER] + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code +extension-pkg-whitelist= + +# Add files or directories to the ignore-list. They should be base names, not +# paths. +ignore=CVS + +# Add files or directories matching the regex patterns to the ignore-list. The +# regex matches against base names, not paths. +ignore-patterns= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Use multiple processes to speed up Pylint. +jobs=1 + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins=pylint.extensions.no_self_use + +# Pickle collected data for later comparisons. +persistent=yes + +# Specify a configuration file. +#rcfile= + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED +confidence= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once).You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use"--disable=all --enable=classes +# --disable=W" +# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call +disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable= + + +[REPORTS] + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details +#msg-template= + +# Set the output format. Available formats are text, parseable, colorized, json +# and msvs (visual studio).You can also give a reporter class, eg +# mypackage.mymodule.MyReporterClass. +output-format=text + +# Tells whether to display a full report or only the messages +reports=no + +# Activate the evaluation score. +score=yes + + +[REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 + + +[LOGGING] + +# Logging modules to check that the string format arguments are in logging +# function parameter format +logging-modules=logging + + +[SPELLING] + +# Spelling dictionary name. Available dictionaries: none. To make it working +# install python-enchant package. +spelling-dict= + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to indicated private dictionary in +# --spelling-private-dict-file option instead of raising a message. +spelling-store-unknown-words=no + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +# notes=FIXME,XXX,TODO +notes=FIXME,XXX + + +[TYPECHECK] + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members= + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=yes + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=optparse.Values,thread._local,_thread._local + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis. It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules=board + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=yes + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + + +[VARIABLES] + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=yes + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_,_cb + +# A regular expression matching the name of dummy variables (i.e. expectedly +# not used). +dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore +ignored-argument-names=_.*|^ignored_|^unused_ + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,future.builtins + + +[FORMAT] + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +# expected-line-ending-format= +expected-line-ending-format=LF + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Maximum number of characters on a single line. +max-line-length=100 + +# Maximum number of lines in a module +max-module-lines=1000 + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=no + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + + +[SIMILARITIES] + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=yes + +# Minimum lines number of a similarity. +min-similarity-lines=12 + + +[BASIC] + +# Regular expression matching correct argument names +argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct attribute names +attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Bad variable names which should always be refused, separated by a comma +bad-names=foo,bar,baz,toto,tutu,tata + +# Regular expression matching correct class attribute names +class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ + +# Regular expression matching correct class names +# class-rgx=[A-Z_][a-zA-Z0-9]+$ +class-rgx=[A-Z_][a-zA-Z0-9_]+$ + +# Regular expression matching correct constant names +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + +# Regular expression matching correct function names +function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Good variable names which should always be accepted, separated by a comma +# good-names=i,j,k,ex,Run,_ +good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ + +# Include a hint for the correct naming format with invalid-name +include-naming-hint=no + +# Regular expression matching correct inline iteration names +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ + +# Regular expression matching correct method names +method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct module names +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=^_ + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +property-classes=abc.abstractproperty + +# Regular expression matching correct variable names +variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + + +[IMPORTS] + +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=no + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no + +# Deprecated modules which should not be used, separated by a comma +deprecated-modules=optparse,tkinter.tix + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + + +[CLASSES] + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__,__new__,setUp + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict,_fields,_replace,_source,_make + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + + +[DESIGN] + +# Maximum number of arguments for function / method +max-args=5 + +# Maximum number of attributes for a class (see R0902). +# max-attributes=7 +max-attributes=11 + +# Maximum number of boolean expressions in a if statement +max-bool-expr=5 + +# Maximum number of branch for function / method body +max-branches=12 + +# Maximum number of locals for function / method body +max-locals=15 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + +# Maximum number of return / yield for function / method body +max-returns=6 + +# Maximum number of statements in function / method body +max-statements=50 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=1 + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "Exception" +overgeneral-exceptions=builtins.Exception diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..b79ec5b --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +build: + os: ubuntu-20.04 + tools: + python: "3" + +python: + install: + - requirements: docs/requirements.txt + - requirements: requirements.txt diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..a773adf --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,158 @@ + +# Adafruit Community Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and leaders pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level or type of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. + +## Our Standards + +We are committed to providing a friendly, safe and welcoming environment for +all. + +Examples of behavior that contributes to creating and maintaining a positive environment +include: + +* Be kind and courteous to others +* Using welcoming and inclusive language +* Respecting the identity of every community member, including asking for their + pronouns if uncertain +* Being respectful of differing viewpoints and experiences +* Collaborating with other community members +* Providing desired assistance and knowledge to other community members +* Being open to new information and ideas +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by community members include: + +* The use of sexualized language or imagery and sexual attention or advances +* The use of inappropriate images, including in a community member's avatar +* The use of inappropriate language or profanity, including in a community member's nickname +* Any spamming, flaming, baiting or other attention-stealing behavior +* Excessive or unwelcome helping; answering outside the scope of the question + asked +* Discussion or promotion of activities or projects that intend or pose a risk of + significant harm +* Trolling, insulting/derogatory comments, and attacks of any nature (including, + but not limited to, personal or political attacks) +* Promoting or spreading disinformation, lies, or conspiracy theories against + a person, group, organisation, project, or community +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Engaging in behavior that creates an unwelcoming or uninclusive environment +* Other conduct which could reasonably be considered inappropriate + +The Adafruit Community welcomes everyone and strives to create a safe space for all. It is built +around sharing and contributing to technology. We encourage discussing your thoughts, experiences, +and feelings within the scope of the community. However, there are topics that can sometimes stray +from that scope, and can lead to hurting others and create an unwelcoming, uninclusive environment. + +Examples of discussion topics that have been known to stray outside the scope of the Adafruit +Community include, but are not limited to: + +* Discussions regarding religion and related topics +* Discussions regarding politics and related topics + +The goal of the standards and moderation guidelines outlined here is to build +and maintain a respectful community. We ask that you don’t just aim to be +"technically unimpeachable", but rather try to be your best self. + +We value many things beyond technical expertise, including collaboration and +supporting others within our community. Providing a positive experience for +other community members can have a much more significant impact than simply +providing the correct answer. + +## Our Responsibilities + +Project leaders are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project leaders have the right and responsibility to remove, edit, or +reject messages, comments, commits, code, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any community member for other behaviors that they deem +inappropriate, threatening, offensive, or harmful. + +## Moderation + +Instances of behaviors that violate the Adafruit Community Code of Conduct +may be reported by any member of the community. Community members are +encouraged to report these situations, including situations they witness +involving other community members. + +You may report in the following ways: + +In any situation, you may email . + +On the Adafruit Discord, you may send an open message from any channel +to all Community Moderators by tagging @community moderators. You may +also send an open message from the #help-with-community channel, or a +direct message to any Community Moderator. + +The source of email and direct message reports will be kept confidential. + +In situations on Discord where the issue is particularly offensive, possibly +illegal, requires immediate action, or violates the Discord terms of service, +you should also report the message directly to [Discord](https://discord.com/safety). + +These are the steps for upholding our community’s standards of conduct. + +1. Any member of the community may report any situation that violates the + Adafruit Community Code of Conduct. All reports will be reviewed and + investigated. +2. If the behavior is a severe violation, the community member who + committed the violation may be banned immediately, without warning. +3. Otherwise, moderators will first respond to such behavior with a warning. +4. Moderators follow a soft "three strikes" policy - the community member may + be given another chance, if they are receptive to the warning and change their + behavior. +5. If the community member is unreceptive or unreasonable when warned by a + moderator, or the warning goes unheeded, they may be banned for a first or + second offense. Repeated offenses will result in the community member being + banned. +6. Disciplinary actions (warnings, bans, etc) for Code of Conduct violations apply + to the platform where the violation occurred. However, depending on the severity + of the violation, the disciplinary action may be applied across Adafruit's other + community platforms. For example, a severe violation on the Adafruit Discord + server may result in a ban on not only the Adafruit Discord server, but also on + the Adafruit GitHub organisation, Adafruit Forums, Adafruit Twitter, etc. + +## Scope + +This Code of Conduct and the enforcement policies listed above apply to all +Adafruit Community venues. This includes but is not limited to any community +spaces (both public and private), the entire Adafruit Discord server, and +Adafruit GitHub repositories. Examples of Adafruit Community spaces include +but are not limited to meet-ups, audio chats on the Adafruit Discord, or +interaction at a conference. + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. As a community +member, you are representing our community, and are expected to behave +accordingly. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/), +version 1.4, available on [contributor-covenant.org](https://www.contributor-covenant.org/version/1/4/code-of-conduct.html), +and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). + +For other projects adopting the Adafruit Community Code of +Conduct, please contact the maintainers of those projects for enforcement. +If you wish to use this code of conduct for your own project, consider +explicitly mentioning your moderation policy or making a copy with your +own moderation policy so as to avoid confusion. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0a7b93e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2023 Jeff Epler for Adafruit Industries for Adafruit Industries + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LICENSES/CC-BY-4.0.txt b/LICENSES/CC-BY-4.0.txt new file mode 100644 index 0000000..3f92dfc --- /dev/null +++ b/LICENSES/CC-BY-4.0.txt @@ -0,0 +1,324 @@ +Creative Commons Attribution 4.0 International Creative Commons Corporation +("Creative Commons") is not a law firm and does not provide legal services +or legal advice. Distribution of Creative Commons public licenses does not +create a lawyer-client or other relationship. Creative Commons makes its licenses +and related information available on an "as-is" basis. Creative Commons gives +no warranties regarding its licenses, any material licensed under their terms +and conditions, or any related information. Creative Commons disclaims all +liability for damages resulting from their use to the fullest extent possible. + +Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and conditions +that creators and other rights holders may use to share original works of +authorship and other material subject to copyright and certain other rights +specified in the public license below. The following considerations are for +informational purposes only, are not exhaustive, and do not form part of our +licenses. + +Considerations for licensors: Our public licenses are intended for use by +those authorized to give the public permission to use material in ways otherwise +restricted by copyright and certain other rights. Our licenses are irrevocable. +Licensors should read and understand the terms and conditions of the license +they choose before applying it. Licensors should also secure all rights necessary +before applying our licenses so that the public can reuse the material as +expected. Licensors should clearly mark any material not subject to the license. +This includes other CC-licensed material, or material used under an exception +or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors + +Considerations for the public: By using one of our public licenses, a licensor +grants the public permission to use the licensed material under specified +terms and conditions. If the licensor's permission is not necessary for any +reason–for example, because of any applicable exception or limitation to copyright–then +that use is not regulated by the license. Our licenses grant only permissions +under copyright and certain other rights that a licensor has authority to +grant. Use of the licensed material may still be restricted for other reasons, +including because others have copyright or other rights in the material. A +licensor may make special requests, such as asking that all changes be marked +or described. Although not required by our licenses, you are encouraged to +respect those requests where reasonable. More considerations for the public +: wiki.creativecommons.org/Considerations_for_licensees Creative Commons Attribution +4.0 International Public License + +By exercising the Licensed Rights (defined below), You accept and agree to +be bound by the terms and conditions of this Creative Commons Attribution +4.0 International Public License ("Public License"). To the extent this Public +License may be interpreted as a contract, You are granted the Licensed Rights +in consideration of Your acceptance of these terms and conditions, and the +Licensor grants You such rights in consideration of benefits the Licensor +receives from making the Licensed Material available under these terms and +conditions. + +Section 1 – Definitions. + +a. Adapted Material means material subject to Copyright and Similar Rights +that is derived from or based upon the Licensed Material and in which the +Licensed Material is translated, altered, arranged, transformed, or otherwise +modified in a manner requiring permission under the Copyright and Similar +Rights held by the Licensor. For purposes of this Public License, where the +Licensed Material is a musical work, performance, or sound recording, Adapted +Material is always produced where the Licensed Material is synched in timed +relation with a moving image. + +b. Adapter's License means the license You apply to Your Copyright and Similar +Rights in Your contributions to Adapted Material in accordance with the terms +and conditions of this Public License. + +c. Copyright and Similar Rights means copyright and/or similar rights closely +related to copyright including, without limitation, performance, broadcast, +sound recording, and Sui Generis Database Rights, without regard to how the +rights are labeled or categorized. For purposes of this Public License, the +rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. + +d. Effective Technological Measures means those measures that, in the absence +of proper authority, may not be circumvented under laws fulfilling obligations +under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, +and/or similar international agreements. + +e. Exceptions and Limitations means fair use, fair dealing, and/or any other +exception or limitation to Copyright and Similar Rights that applies to Your +use of the Licensed Material. + +f. Licensed Material means the artistic or literary work, database, or other +material to which the Licensor applied this Public License. + +g. Licensed Rights means the rights granted to You subject to the terms and +conditions of this Public License, which are limited to all Copyright and +Similar Rights that apply to Your use of the Licensed Material and that the +Licensor has authority to license. + +h. Licensor means the individual(s) or entity(ies) granting rights under this +Public License. + +i. Share means to provide material to the public by any means or process that +requires permission under the Licensed Rights, such as reproduction, public +display, public performance, distribution, dissemination, communication, or +importation, and to make material available to the public including in ways +that members of the public may access the material from a place and at a time +individually chosen by them. + +j. Sui Generis Database Rights means rights other than copyright resulting +from Directive 96/9/EC of the European Parliament and of the Council of 11 +March 1996 on the legal protection of databases, as amended and/or succeeded, +as well as other essentially equivalent rights anywhere in the world. + +k. You means the individual or entity exercising the Licensed Rights under +this Public License. Your has a corresponding meaning. + +Section 2 – Scope. + + a. License grant. + +1. Subject to the terms and conditions of this Public License, the Licensor +hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, +irrevocable license to exercise the Licensed Rights in the Licensed Material +to: + + A. reproduce and Share the Licensed Material, in whole or in part; and + + B. produce, reproduce, and Share Adapted Material. + +2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions +and Limitations apply to Your use, this Public License does not apply, and +You do not need to comply with its terms and conditions. + + 3. Term. The term of this Public License is specified in Section 6(a). + +4. Media and formats; technical modifications allowed. The Licensor authorizes +You to exercise the Licensed Rights in all media and formats whether now known +or hereafter created, and to make technical modifications necessary to do +so. The Licensor waives and/or agrees not to assert any right or authority +to forbid You from making technical modifications necessary to exercise the +Licensed Rights, including technical modifications necessary to circumvent +Effective Technological Measures. For purposes of this Public License, simply +making modifications authorized by this Section 2(a)(4) never produces Adapted +Material. + + 5. Downstream recipients. + +A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed +Material automatically receives an offer from the Licensor to exercise the +Licensed Rights under the terms and conditions of this Public License. + +B. No downstream restrictions. You may not offer or impose any additional +or different terms or conditions on, or apply any Effective Technological +Measures to, the Licensed Material if doing so restricts exercise of the Licensed +Rights by any recipient of the Licensed Material. + +6. No endorsement. Nothing in this Public License constitutes or may be construed +as permission to assert or imply that You are, or that Your use of the Licensed +Material is, connected with, or sponsored, endorsed, or granted official status +by, the Licensor or others designated to receive attribution as provided in +Section 3(a)(1)(A)(i). + + b. Other rights. + +1. Moral rights, such as the right of integrity, are not licensed under this +Public License, nor are publicity, privacy, and/or other similar personality +rights; however, to the extent possible, the Licensor waives and/or agrees +not to assert any such rights held by the Licensor to the limited extent necessary +to allow You to exercise the Licensed Rights, but not otherwise. + +2. Patent and trademark rights are not licensed under this Public License. + +3. To the extent possible, the Licensor waives any right to collect royalties +from You for the exercise of the Licensed Rights, whether directly or through +a collecting society under any voluntary or waivable statutory or compulsory +licensing scheme. In all other cases the Licensor expressly reserves any right +to collect such royalties. + +Section 3 – License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the following +conditions. + + a. Attribution. + +1. If You Share the Licensed Material (including in modified form), You must: + +A. retain the following if it is supplied by the Licensor with the Licensed +Material: + +i. identification of the creator(s) of the Licensed Material and any others +designated to receive attribution, in any reasonable manner requested by the +Licensor (including by pseudonym if designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of warranties; + +v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; + +B. indicate if You modified the Licensed Material and retain an indication +of any previous modifications; and + +C. indicate the Licensed Material is licensed under this Public License, and +include the text of, or the URI or hyperlink to, this Public License. + +2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner +based on the medium, means, and context in which You Share the Licensed Material. +For example, it may be reasonable to satisfy the conditions by providing a +URI or hyperlink to a resource that includes the required information. + +3. If requested by the Licensor, You must remove any of the information required +by Section 3(a)(1)(A) to the extent reasonably practicable. + +4. If You Share Adapted Material You produce, the Adapter's License You apply +must not prevent recipients of the Adapted Material from complying with this +Public License. + +Section 4 – Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that apply to +Your use of the Licensed Material: + +a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, +reuse, reproduce, and Share all or a substantial portion of the contents of +the database; + +b. if You include all or a substantial portion of the database contents in +a database in which You have Sui Generis Database Rights, then the database +in which You have Sui Generis Database Rights (but not its individual contents) +is Adapted Material; and + +c. You must comply with the conditions in Section 3(a) if You Share all or +a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not replace +Your obligations under this Public License where the Licensed Rights include +other Copyright and Similar Rights. + +Section 5 – Disclaimer of Warranties and Limitation of Liability. + +a. Unless otherwise separately undertaken by the Licensor, to the extent possible, +the Licensor offers the Licensed Material as-is and as-available, and makes +no representations or warranties of any kind concerning the Licensed Material, +whether express, implied, statutory, or other. This includes, without limitation, +warranties of title, merchantability, fitness for a particular purpose, non-infringement, +absence of latent or other defects, accuracy, or the presence or absence of +errors, whether or not known or discoverable. Where disclaimers of warranties +are not allowed in full or in part, this disclaimer may not apply to You. + +b. To the extent possible, in no event will the Licensor be liable to You +on any legal theory (including, without limitation, negligence) or otherwise +for any direct, special, indirect, incidental, consequential, punitive, exemplary, +or other losses, costs, expenses, or damages arising out of this Public License +or use of the Licensed Material, even if the Licensor has been advised of +the possibility of such losses, costs, expenses, or damages. Where a limitation +of liability is not allowed in full or in part, this limitation may not apply +to You. + +c. The disclaimer of warranties and limitation of liability provided above +shall be interpreted in a manner that, to the extent possible, most closely +approximates an absolute disclaimer and waiver of all liability. + +Section 6 – Term and Termination. + +a. This Public License applies for the term of the Copyright and Similar Rights +licensed here. However, if You fail to comply with this Public License, then +Your rights under this Public License terminate automatically. + +b. Where Your right to use the Licensed Material has terminated under Section +6(a), it reinstates: + +1. automatically as of the date the violation is cured, provided it is cured +within 30 days of Your discovery of the violation; or + + 2. upon express reinstatement by the Licensor. + +c. For the avoidance of doubt, this Section 6(b) does not affect any right +the Licensor may have to seek remedies for Your violations of this Public +License. + +d. For the avoidance of doubt, the Licensor may also offer the Licensed Material +under separate terms or conditions or stop distributing the Licensed Material +at any time; however, doing so will not terminate this Public License. + + e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. + +Section 7 – Other Terms and Conditions. + +a. The Licensor shall not be bound by any additional or different terms or +conditions communicated by You unless expressly agreed. + +b. Any arrangements, understandings, or agreements regarding the Licensed +Material not stated herein are separate from and independent of the terms +and conditions of this Public License. + +Section 8 – Interpretation. + +a. For the avoidance of doubt, this Public License does not, and shall not +be interpreted to, reduce, limit, restrict, or impose conditions on any use +of the Licensed Material that could lawfully be made without permission under +this Public License. + +b. To the extent possible, if any provision of this Public License is deemed +unenforceable, it shall be automatically reformed to the minimum extent necessary +to make it enforceable. If the provision cannot be reformed, it shall be severed +from this Public License without affecting the enforceability of the remaining +terms and conditions. + +c. No term or condition of this Public License will be waived and no failure +to comply consented to unless expressly agreed to by the Licensor. + +d. Nothing in this Public License constitutes or may be interpreted as a limitation +upon, or waiver of, any privileges and immunities that apply to the Licensor +or You, including from the legal processes of any jurisdiction or authority. + +Creative Commons is not a party to its public licenses. Notwithstanding, Creative +Commons may elect to apply one of its public licenses to material it publishes +and in those instances will be considered the "Licensor." The text of the +Creative Commons public licenses is dedicated to the public domain under the +CC0 Public Domain Dedication. Except for the limited purpose of indicating +that material is shared under a Creative Commons public license or as otherwise +permitted by the Creative Commons policies published at creativecommons.org/policies, +Creative Commons does not authorize the use of the trademark "Creative Commons" +or any other trademark or logo of Creative Commons without its prior written +consent including, without limitation, in connection with any unauthorized +modifications to any of its public licenses or any other arrangements, understandings, +or agreements concerning use of licensed material. For the avoidance of doubt, +this paragraph does not form part of the public licenses. + +Creative Commons may be contacted at creativecommons.org. diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 0000000..204b93d --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,19 @@ +MIT License Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/LICENSES/Unlicense.txt b/LICENSES/Unlicense.txt new file mode 100644 index 0000000..24a8f90 --- /dev/null +++ b/LICENSES/Unlicense.txt @@ -0,0 +1,20 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or distribute +this software, either in source code form or as a compiled binary, for any +purpose, commercial or non-commercial, and by any means. + +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and +to the detriment of our heirs and successors. We intend this dedication to +be an overt act of relinquishment in perpetuity of all present and future +rights to this software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH +THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, +please refer to diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..f98a3b6 --- /dev/null +++ b/README.rst @@ -0,0 +1,118 @@ +Introduction +============ + + +.. image:: https://readthedocs.org/projects/adafruit-circuitpython-pycamera/badge/?version=latest + :target: https://docs.circuitpython.org/projects/pycamera/en/latest/ + :alt: Documentation Status + + +.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg + :target: https://adafru.it/discord + :alt: Discord + + +.. image:: https://github.com/adafruit/Adafruit_CircuitPython_PyCamera/workflows/Build%20CI/badge.svg + :target: https://github.com/adafruit/Adafruit_CircuitPython_PyCamera/actions + :alt: Build Status + + +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/psf/black + :alt: Code Style: Black + +Library for the Adafruit PyCamera + + +Dependencies +============= +This driver depends on: + +* `Adafruit CircuitPython `_ +* `Bus Device `_ + +Please ensure all dependencies are available on the CircuitPython filesystem. +This is easily achieved by downloading +`the Adafruit library and driver bundle `_ +or individual libraries can be installed using +`circup `_. + + + +.. todo:: Describe the Adafruit product this library works with. For PCBs, you can also add the +image from the assets folder in the PCB's GitHub repo. + +`Purchase one from the Adafruit shop `_ + +Installing from PyPI +===================== +.. note:: This library is not available on PyPI yet. Install documentation is included + as a standard element. Stay tuned for PyPI availability! + +.. todo:: Remove the above note if PyPI version is/will be available at time of release. + +On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from +PyPI `_. +To install for current user: + +.. code-block:: shell + + pip3 install adafruit-circuitpython-pycamera + +To install system-wide (this may be required in some cases): + +.. code-block:: shell + + sudo pip3 install adafruit-circuitpython-pycamera + +To install in a virtual environment in your current project: + +.. code-block:: shell + + mkdir project-name && cd project-name + python3 -m venv .venv + source .env/bin/activate + pip3 install adafruit-circuitpython-pycamera + +Installing to a Connected CircuitPython Device with Circup +========================================================== + +Make sure that you have ``circup`` installed in your Python environment. +Install it with the following command if necessary: + +.. code-block:: shell + + pip3 install circup + +With ``circup`` installed and your CircuitPython device connected use the +following command to install: + +.. code-block:: shell + + circup install adafruit_pycamera + +Or the following command to update an existing version: + +.. code-block:: shell + + circup update + +Usage Example +============= + +.. todo:: Add a quick, simple example. It and other examples should live in the +examples folder and be included in docs/examples.rst. + +Documentation +============= +API documentation for this library can be found on `Read the Docs `_. + +For information on building library documentation, please check out +`this guide `_. + +Contributing +============ + +Contributions are welcome! Please read our `Code of Conduct +`_ +before contributing to help this project stay welcoming. diff --git a/README.rst.license b/README.rst.license new file mode 100644 index 0000000..ffd1331 --- /dev/null +++ b/README.rst.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +SPDX-FileCopyrightText: Copyright (c) 2023 Jeff Epler for Adafruit Industries for Adafruit Industries +SPDX-License-Identifier: MIT diff --git a/docs/_static/favicon.ico b/docs/_static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..5aca98376a1f7e593ebd9cf41a808512c2135635 GIT binary patch literal 4414 zcmd^BX;4#F6n=SG-XmlONeGrD5E6J{RVh+e928U#MG!$jWvO+UsvWh`x&VqGNx*en zx=qox7Dqv{kPwo%fZC$dDwVpRtz{HzTkSs8QhG0)%Y=-3@Kt!4ag|JcIo?$-F|?bXVS9UDUyev>MVZQ(H8K4#;BQW-t2CPorj8^KJrMX}QK zp+e<;4ldpXz~=)2GxNy811&)gt-}Q*yVQpsxr@VMoA##{)$1~=bZ1MmjeFw?uT(`8 z^g=09<=zW%r%buwN%iHtuKSg|+r7HkT0PYN*_u9k1;^Ss-Z!RBfJ?Un4w(awqp2b3 z%+myoFis_lTlCrGx2z$0BQdh+7?!JK#9K9@Z!VrG zNj6gK5r(b4?YDOLw|DPRoN7bdP{(>GEG41YcN~4r_SUHU2hgVtUwZG@s%edC;k7Sn zC)RvEnlq~raE2mY2ko64^m1KQL}3riixh?#J{o)IT+K-RdHae2eRX91-+g!y`8^># z-zI0ir>P%Xon)!@xp-BK2bDYUB9k613NRrY6%lVjbFcQc*pRqiK~8xtkNPLxt}e?&QsTB}^!39t_%Qb)~Ukn0O%iC;zt z<&A-y;3h++)>c1br`5VFM~5(83!HKx$L+my8sW_c#@x*|*vB1yU)_dt3vH;2hqPWx zAl^6@?ipx&U7pf`a*>Yq6C85nb+B=Fnn+(id$W#WB^uHAcZVG`qg;rWB}ubvi(Y>D z$ei>REw$#xp0SHAd^|1hq&9HJ=jKK8^zTH~nk)G?yUcmTh9vUM6Y0LMw4(gYVY$D$ zGl&WY&H<)BbJ&3sYbKjx1j^=3-0Q#f^}(aP1?8^`&FUWMp|rmtpK)bLQ1Zo?^s4jqK=Lfg*9&geMGVQ z#^-*!V`fG@;H&{M9S8%+;|h&Qrxym0Ar>WT4BCVLR8cGXF=JmEYN(sNT(9vl+S|%g z8r7nXQ(95i^`=+XHo|){$vf2$?=`F$^&wFlYXyXg$B{a>$-Fp+V}+D;9k=~Xl~?C4 zAB-;RKXdUzBJE{V&d&%R>aEfFe;vxqI$0@hwVM}gFeQR@j}a>DDxR+n+-*6|_)k%% z*mSpDV|=5I9!&VC&9tD%fcVygWZV!iIo2qFtm#!*(s|@ZT33*Ad;+<|3^+yrp*;oH zBSYLV(H1zTU?2WjrCQoQW)Z>J2a=dTriuvezBmu16`tM2fm7Q@d4^iqII-xFpwHGI zn9CL}QE*1vdj2PX{PIuqOe5dracsciH6OlAZATvE8rj6ykqdIjal2 z0S0S~PwHb-5?OQ-tU-^KTG@XNrEVSvo|HIP?H;7ZhYeZkhSqh-{reE!5di;1zk$#Y zCe7rOnlzFYJ6Z#Hm$GoidKB=2HBCwm`BbZVeZY4ukmG%1uz7p2URs6c9j-Gjj^oQV zsdDb3@k2e`C$1I5ML5U0Qs0C1GAp^?!*`=|Nm(vWz3j*j*8ucum2;r0^-6Aca=Gv) zc%}&;!+_*S2tlnnJnz0EKeRmw-Y!@9ob!XQBwiv}^u9MkaXHvM=!<3YX;+2#5Cj5pp?FEK750S3BgeSDtaE^ zXUM@xoV6yBFKfzvY20V&Lr0yC + Download Library Bundle + CircuitPython Reference Documentation + CircuitPython Support Forum + Discord Chat + Adafruit Learning System + Adafruit Blog + Adafruit Store + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/index.rst.license b/docs/index.rst.license new file mode 100644 index 0000000..3b17a1d --- /dev/null +++ b/docs/index.rst.license @@ -0,0 +1,4 @@ +SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +SPDX-FileCopyrightText: Copyright (c) 2023 Jeff Epler for Adafruit Industries for Adafruit Industries + +SPDX-License-Identifier: MIT diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..979f568 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +sphinx +sphinxcontrib-jquery +sphinx-rtd-theme diff --git a/optional_requirements.txt b/optional_requirements.txt new file mode 100644 index 0000000..d4e27c4 --- /dev/null +++ b/optional_requirements.txt @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a7d0666 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,51 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney, written for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2023 Jeff Epler for Adafruit Industries for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +[build-system] +requires = [ + "setuptools", + "wheel", + "setuptools-scm", +] + +[project] +name = "adafruit-circuitpython-pycamera" +description = "Library for the Adafruit PyCamera" +version = "0.0.0+auto.0" +readme = "README.rst" +authors = [ + {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} +] +urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_PyCamera"} +keywords = [ + "adafruit", + "blinka", + "circuitpython", + "micropython", + "pycamera", + "camera", + "esp32s3", + "wifi", + "ov5640", +] +license = {text = "MIT"} +classifiers = [ + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Embedded Systems", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", +] +dynamic = ["dependencies", "optional-dependencies"] + +[tool.setuptools] +# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, +# CHANGE `py_modules = ['...']` TO `packages = ['...']` +py-modules = ["adafruit_pycamera"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} +optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d1bd7b9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2023 Jeff Epler for Adafruit Industries for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +Adafruit-Blinka +adafruit-circuitpython-busdevice From f2775ab4eb3592f7995b5a5d611078da039adb09 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 29 Nov 2023 11:10:30 -0600 Subject: [PATCH 05/11] run black --- adafruit_pycamera.py | 302 ++++++++++++++++----------- examples/camera/code.py | 42 ++-- examples/ipcam/code.py | 1 + examples/ipcam2/code.py | 27 ++- examples/ipcam2/htdocs/index.js | 4 +- examples/ipcam2/make_web_metadata.py | 7 +- examples/qrio/code.py | 6 +- 7 files changed, 234 insertions(+), 155 deletions(-) diff --git a/adafruit_pycamera.py b/adafruit_pycamera.py index efcb376..3de4d05 100644 --- a/adafruit_pycamera.py +++ b/adafruit_pycamera.py @@ -49,31 +49,49 @@ _OV5640_CMD_PARA4 = const(0x3028) _OV5640_CMD_FW_STATUS = const(0x3029) + class PyCamera: _finalize_firmware_load = ( - 0x3022, 0x00, - 0x3023, 0x00, - 0x3024, 0x00, - 0x3025, 0x00, - 0x3026, 0x00, - 0x3027, 0x00, - 0x3028, 0x00, - 0x3029, 0x7f, - 0x3000, 0x00, + 0x3022, + 0x00, + 0x3023, + 0x00, + 0x3024, + 0x00, + 0x3025, + 0x00, + 0x3026, + 0x00, + 0x3027, + 0x00, + 0x3028, + 0x00, + 0x3029, + 0x7F, + 0x3000, + 0x00, ) - led_levels = [0., .1, .2, .5, 1.] - - colors = [0xffffff, 0xff0000, 0xffff00, 0x00ff00, 0x00ffff, 0x0000ff, 0xff00ff, - [colorwheel(i*(256//8)) for i in range(8)]] + led_levels = [0.0, 0.1, 0.2, 0.5, 1.0] + + colors = [ + 0xFFFFFF, + 0xFF0000, + 0xFFFF00, + 0x00FF00, + 0x00FFFF, + 0x0000FF, + 0xFF00FF, + [colorwheel(i * (256 // 8)) for i in range(8)], + ] resolutions = ( - #"160x120", - #"176x144", - #"240x176", + # "160x120", + # "176x144", + # "240x176", "240x240", "320x240", - #"400x296", - #"480x320", + # "400x296", + # "480x320", "640x480", "800x600", "1024x768", @@ -81,84 +99,93 @@ class PyCamera: "1280x1024", "1600x1200", "1920x1080", - #"720x1280", - #"864x1536", + # "720x1280", + # "864x1536", "2048x1536", "2560x1440", "2560x1600", - #"1080x1920", + # "1080x1920", "2560x1920", ) resolution_to_frame_size = ( - #espcamera.FrameSize.QQVGA, - #espcamera.FrameSize.QCIF, - #espcamera.FrameSize.HQVGA, - espcamera.FrameSize.R240X240, # 240x240 - espcamera.FrameSize.QVGA, # 320x240 - #espcamera.FrameSize.CIF, # 400x296 - #espcamera.FrameSize.HVGA, # 480x320 - espcamera.FrameSize.VGA, # 640x480 - espcamera.FrameSize.SVGA, # 800x600 - espcamera.FrameSize.XGA, # 1024x768 - espcamera.FrameSize.HD, # 1280x720 - espcamera.FrameSize.SXGA, # 1280x1024 - espcamera.FrameSize.UXGA, # 1600x1200 - espcamera.FrameSize.FHD, # 1920x1080 - #espcamera.FrameSize.P_HD, # 720x1280 + # espcamera.FrameSize.QQVGA, + # espcamera.FrameSize.QCIF, + # espcamera.FrameSize.HQVGA, + espcamera.FrameSize.R240X240, # 240x240 + espcamera.FrameSize.QVGA, # 320x240 + # espcamera.FrameSize.CIF, # 400x296 + # espcamera.FrameSize.HVGA, # 480x320 + espcamera.FrameSize.VGA, # 640x480 + espcamera.FrameSize.SVGA, # 800x600 + espcamera.FrameSize.XGA, # 1024x768 + espcamera.FrameSize.HD, # 1280x720 + espcamera.FrameSize.SXGA, # 1280x1024 + espcamera.FrameSize.UXGA, # 1600x1200 + espcamera.FrameSize.FHD, # 1920x1080 + # espcamera.FrameSize.P_HD, # 720x1280 # espcamera.FrameSize.P_3MP, # 864x1536 - espcamera.FrameSize.QXGA, # 2048x1536 - espcamera.FrameSize.QHD, # 2560x1440 - espcamera.FrameSize.WQXGA, # 2560x1600 - #espcamera.FrameSize.P_FHD, # 1080x1920 - espcamera.FrameSize.QSXGA, # 2560x1920 + espcamera.FrameSize.QXGA, # 2048x1536 + espcamera.FrameSize.QHD, # 2560x1440 + espcamera.FrameSize.WQXGA, # 2560x1600 + # espcamera.FrameSize.P_FHD, # 1080x1920 + espcamera.FrameSize.QSXGA, # 2560x1920 ) combined_list = list(zip(resolutions, resolution_to_frame_size)) print(combined_list) - effects = ("Normal", "Invert", "B&W", "Reddish", "Greenish", "Bluish", "Sepia", "Solarize") + effects = ( + "Normal", + "Invert", + "B&W", + "Reddish", + "Greenish", + "Bluish", + "Sepia", + "Solarize", + ) modes = ("JPEG", "GIF", "STOP") - - _AW_MUTE = const(0) - _AW_SELECT = const(1) - _AW_CARDDET = const(8) - _AW_SDPWR = const(9) + + _AW_MUTE = const(0) + _AW_SELECT = const(1) + _AW_CARDDET = const(8) + _AW_SDPWR = const(9) _AW_DOWN = const(15) - _AW_LEFT = const(14) - _AW_UP = const(13) - _AW_RIGHT = const(12) - _AW_OK = const(11) - #_SS_ALL_BUTTONS_MASK = const(0b000010000000001011100) - #_SS_DOWN_MASK = const(0x10000) - #_SS_LEFT_MASK = const(0x00004) - #_SS_UP_MASK = const(0x00008) - #_SS_RIGHT_MASK = const(0x00040) - #_SS_CARDDET_MASK = const(0x00010) + _AW_LEFT = const(14) + _AW_UP = const(13) + _AW_RIGHT = const(12) + _AW_OK = const(11) + # _SS_ALL_BUTTONS_MASK = const(0b000010000000001011100) + # _SS_DOWN_MASK = const(0x10000) + # _SS_LEFT_MASK = const(0x00004) + # _SS_UP_MASK = const(0x00008) + # _SS_RIGHT_MASK = const(0x00040) + # _SS_CARDDET_MASK = const(0x00010) _NVM_RESOLUTION = const(1) _NVM_EFFECT = const(2) _NVM_MODE = const(3) - + _INIT_SEQUENCE = ( b"\x01\x80\x78" # _SWRESET and Delay 120ms b"\x11\x80\x05" # _SLPOUT and Delay 5ms b"\x3A\x01\x55" # _COLMOD - b"\x21\x00" # _INVON Hack - b"\x13\x00" # _NORON + b"\x21\x00" # _INVON Hack + b"\x13\x00" # _NORON b"\x36\x01\xA0" # _MADCTL b"\x29\x80\x05" # _DISPON and Delay 5ms - ) + ) def i2c_scan(self): while not self._i2c.try_lock(): pass try: - print("I2C addresses found:", - [hex(device_address) for device_address in self._i2c.scan()], - ) + print( + "I2C addresses found:", + [hex(device_address) for device_address in self._i2c.scan()], + ) finally: # unlock the i2c bus when ctrl-c'ing out of the loop self._i2c.unlock() - def __init__(self) -> None: self.t = time.monotonic() @@ -167,9 +194,15 @@ def __init__(self) -> None: self.deinit_display() self.splash = displayio.Group() - self._sd_label = label.Label(terminalio.FONT, text="SD ??", color=0x0, x=150, y=10, scale=2) - self._effect_label = label.Label(terminalio.FONT, text="EFFECT", color=0xFFFFFF, x=4, y=10, scale=2) - self._mode_label = label.Label(terminalio.FONT, text="MODE", color=0xFFFFFF, x=150, y=10, scale=2) + self._sd_label = label.Label( + terminalio.FONT, text="SD ??", color=0x0, x=150, y=10, scale=2 + ) + self._effect_label = label.Label( + terminalio.FONT, text="EFFECT", color=0xFFFFFF, x=4, y=10, scale=2 + ) + self._mode_label = label.Label( + terminalio.FONT, text="MODE", color=0xFFFFFF, x=150, y=10, scale=2 + ) # turn on the display first, its reset line may be shared with the IO expander(?) if not self.display: @@ -191,7 +224,7 @@ def __init__(self) -> None: self._cam_reset.switch_to_output(True) time.sleep(0.01) - print("pre cam @", time.monotonic()-self.t) + print("pre cam @", time.monotonic() - self.t) self.i2c_scan() # AW9523 GPIO expander @@ -213,7 +246,6 @@ def make_debounced_expander_pin(pin_no): pin.switch_to_input() return Debouncer(make_expander_input(pin_no)) - self.up = make_debounced_expander_pin(_AW_UP) self.left = make_debounced_expander_pin(_AW_LEFT) self.right = make_debounced_expander_pin(_AW_RIGHT) @@ -221,7 +253,7 @@ def make_debounced_expander_pin(pin_no): self.select = make_debounced_expander_pin(_AW_SELECT) self.ok = make_debounced_expander_pin(_AW_OK) self.card_detect = make_debounced_expander_pin(_AW_CARDDET) - + self._card_power = make_expander_output(_AW_SDPWR, True) self.mute = make_expander_input(_AW_MUTE) @@ -230,9 +262,9 @@ def make_debounced_expander_pin(pin_no): try: self.mount_sd_card() except RuntimeError: - pass # no card found, its ok! - print("sdcard done @", time.monotonic()-self.t) - + pass # no card found, its ok! + print("sdcard done @", time.monotonic() - self.t) + # lis3dh accelerometer self.accel = adafruit_lis3dh.LIS3DH_I2C(self._i2c, address=0x19) self.accel.range = adafruit_lis3dh.RANGE_2_G @@ -243,7 +275,9 @@ def make_debounced_expander_pin(pin_no): neopix.deinit() # front bezel neopixels - self.pixels = neopixel.NeoPixel(board.A1, 8, brightness=0.1, pixel_order=neopixel.RGBW) + self.pixels = neopixel.NeoPixel( + board.A1, 8, brightness=0.1, pixel_order=neopixel.RGBW + ) self.pixels.fill(0) print("Initializing camera") @@ -257,14 +291,23 @@ def make_debounced_expander_pin(pin_no): frame_size=espcamera.FrameSize.HQVGA, i2c=board.I2C(), external_clock_frequency=20_000_000, - framebuffer_count=2) - - print("Found camera %s (%d x %d) at I2C address %02x" % (self.camera.sensor_name, self.camera.width, self.camera.height, self.camera.address)) - print("camera done @", time.monotonic()-self.t) + framebuffer_count=2, + ) + + print( + "Found camera %s (%d x %d) at I2C address %02x" + % ( + self.camera.sensor_name, + self.camera.width, + self.camera.height, + self.camera.address, + ) + ) + print("camera done @", time.monotonic() - self.t) print(dir(self.camera)) self._camera_device = I2CDevice(self._i2c, self.camera.address) - #display.auto_refresh = False + # display.auto_refresh = False self.camera.hmirror = True self.camera.vflip = True @@ -272,7 +315,9 @@ def make_debounced_expander_pin(pin_no): self._bigbuf = None self._topbar = displayio.Group() - self._res_label = label.Label(terminalio.FONT, text="", color=0xFFFFFF, x=0, y=10, scale=2) + self._res_label = label.Label( + terminalio.FONT, text="", color=0xFFFFFF, x=0, y=10, scale=2 + ) self._topbar.append(self._res_label) self._topbar.append(self._sd_label) @@ -288,15 +333,15 @@ def make_debounced_expander_pin(pin_no): self.led_color = 0 self.led_level = 0 - #self.camera.colorbar = True + # self.camera.colorbar = True self.effect = microcontroller.nvm[_NVM_EFFECT] self.camera.saturation = 3 self.resolution = microcontroller.nvm[_NVM_RESOLUTION] self.mode = microcontroller.nvm[_NVM_MODE] - print("init done @", time.monotonic()-self.t) + print("init done @", time.monotonic() - self.t) def autofocus_init_from_file(self, filename): - with open(filename, mode='rb') as file: + with open(filename, mode="rb") as file: firmware = file.read() self.autofocus_init_from_bitstream(firmware) @@ -330,10 +375,10 @@ def autofocus_init_from_bitstream(self, firmware): if self.camera.sensor_name != "OV5640": raise RuntimeError(f"Autofocus not supported on {self.camera.sensor_name}") - self.write_camera_register(0x3000, 0x20) # reset autofocus coprocessor + self.write_camera_register(0x3000, 0x20) # reset autofocus coprocessor for addr, val in enumerate(firmware): - self.write_camera_register(0x8000+addr, val) + self.write_camera_register(0x8000 + addr, val) self.write_camera_list(self._finalize_firmware_load) for _ in range(100): @@ -345,8 +390,10 @@ def autofocus_init_from_bitstream(self, firmware): raise RuntimeError("Timed out after trying to load autofocus firmware") def autofocus_init(self): - if '/' in __file__: - binfile = __file__.rsplit("/", 1)[0].rsplit(".", 1)[0] + "/ov5640_autofocus.bin" + if "/" in __file__: + binfile = ( + __file__.rsplit("/", 1)[0].rsplit(".", 1)[0] + "/ov5640_autofocus.bin" + ) else: binfile = "ov5640_autofocus.bin" print(binfile) @@ -358,14 +405,16 @@ def autofocus_status(self): def _print_focus_status(self, msg): if False: - print(f"{msg:36} status={self.autofocus_status:02x} busy?={self.read_camera_register(_OV5640_CMD_ACK):02x}") + print( + f"{msg:36} status={self.autofocus_status:02x} busy?={self.read_camera_register(_OV5640_CMD_ACK):02x}" + ) def _send_autofocus_command(self, command, msg): - self.write_camera_register(_OV5640_CMD_ACK, 0x01) # clear command ack - self.write_camera_register(_OV5640_CMD_MAIN, command) # send command + self.write_camera_register(_OV5640_CMD_ACK, 0x01) # clear command ack + self.write_camera_register(_OV5640_CMD_MAIN, command) # send command for _ in range(100): self._print_focus_status(msg) - if self.read_camera_register(_OV5640_CMD_ACK) == 0x0: # command is finished + if self.read_camera_register(_OV5640_CMD_ACK) == 0x0: # command is finished return True time.sleep(0.01) else: @@ -376,7 +425,9 @@ def autofocus(self) -> list[int]: return [False] * 5 if not self._send_autofocus_command(_OV5640_CMD_TRIGGER_AUTOFOCUS, "autofocus"): return [False] * 5 - zone_focus = [self.read_camera_register(_OV5640_CMD_PARA0 + i) for i in range(5)] + zone_focus = [ + self.read_camera_register(_OV5640_CMD_PARA0 + i) for i in range(5) + ] print(f"zones focused: {zone_focus}") return zone_focus @@ -414,7 +465,7 @@ def mode(self): @property def mode_text(self): return self.modes[self._mode] - + @mode.setter def mode(self, setting): setting = (setting + len(self.modes)) % len(self.modes) @@ -425,14 +476,14 @@ def mode(self, setting): if self.modes[setting] == "GIF": self._res_label.text = "" else: - self.resolution = self.resolution # kick it to reset the display + self.resolution = self.resolution # kick it to reset the display microcontroller.nvm[_NVM_MODE] = setting self.display.refresh() - + @property def effect(self): return self._effect - + @effect.setter def effect(self, setting): setting = (setting + len(self.effects)) % len(self.effects) @@ -459,22 +510,29 @@ def resolution(self, res): self._res_label.text = self.resolutions[res] self.display.refresh() - def init_display(self): # construct displayio by hand - displayio.release_displays() - self._display_bus = displayio.FourWire(self._spi, command=board.TFT_DC, - chip_select=board.TFT_CS, - reset=board.TFT_RESET, - baudrate=60_000_000) + displayio.release_displays() + self._display_bus = displayio.FourWire( + self._spi, + command=board.TFT_DC, + chip_select=board.TFT_CS, + reset=board.TFT_RESET, + baudrate=60_000_000, + ) self.display = board.DISPLAY # init specially since we are going to write directly below - self.display = displayio.Display(self._display_bus, self._INIT_SEQUENCE, - width=240, height=240, colstart=80, - auto_refresh=False) + self.display = displayio.Display( + self._display_bus, + self._INIT_SEQUENCE, + width=240, + height=240, + colstart=80, + auto_refresh=False, + ) self.display.root_group = self.splash self.display.refresh() - + def deinit_display(self): # construct displayio by hand displayio.release_displays() @@ -487,7 +545,7 @@ def display_message(self, message, color=0xFF0000, scale=3): if not self.display: self.init_display() text_area.anchored_position = (self.display.width / 2, self.display.height / 2) - + # Show it self.splash.append(text_area) self.display.refresh() @@ -523,16 +581,15 @@ def mount_sd_card(self): # power SD card self._card_power.value = False card_cs.deinit() - print("sdcard init @", time.monotonic()-self.t) + print("sdcard init @", time.monotonic() - self.t) self.sdcard = sdcardio.SDCard(self._spi, board.CARD_CS, baudrate=20_000_000) vfs = storage.VfsFat(self.sdcard) - print("mount vfs @", time.monotonic()-self.t) + print("mount vfs @", time.monotonic() - self.t) storage.mount(vfs, "/sd") self.init_display() self._image_counter = 0 self._sd_label.text = "SD OK" self._sd_label.color = 0x00FF00 - def unmount_sd_card(self): try: @@ -542,7 +599,6 @@ def unmount_sd_card(self): self._sd_label.text = "NO SD" self._sd_label.color = 0xFF0000 - def keys_debounce(self): # shutter button is true GPIO so we debounce as normal self.shutter.update() @@ -557,7 +613,7 @@ def keys_debounce(self): def tone(self, frequency, duration=0.1): with pwmio.PWMOut( board.SPEAKER, frequency=int(frequency), variable_frequency=False - ) as pwm: + ) as pwm: self.mute.value = True pwm.duty_cycle = 0x8000 time.sleep(duration) @@ -567,14 +623,14 @@ def live_preview_mode(self): self.camera.reconfigure( pixel_format=espcamera.PixelFormat.RGB565, frame_size=espcamera.FrameSize.HQVGA, - ) - #self.effect = self._effect + ) + # self.effect = self._effect self.continuous_capture_start() def open_next_image(self, extension="jpg"): try: os.stat("/sd") - except OSError: # no SD card! + except OSError: # no SD card! raise RuntimeError("No SD card mounted") while True: filename = "/sd/img%04d.%s" % (self._image_counter, extension) @@ -589,12 +645,12 @@ def open_next_image(self, extension="jpg"): def capture_jpeg(self): try: os.stat("/sd") - except OSError: # no SD card! + except OSError: # no SD card! raise RuntimeError("No SD card mounted") - + self.camera.reconfigure( pixel_format=espcamera.PixelFormat.JPEG, - frame_size=self.resolution_to_frame_size[self._resolution] + frame_size=self.resolution_to_frame_size[self._resolution], ) time.sleep(0.1) @@ -606,7 +662,7 @@ def capture_jpeg(self): with self.open_next_image() as f: chunksize = 16384 for offset in range(0, len(jpeg), chunksize): - f.write(jpeg[offset:offset+chunksize]) + f.write(jpeg[offset : offset + chunksize]) print(end=".") print("# Wrote image") else: @@ -623,10 +679,8 @@ def continuous_capture(self): return self.camera.take(1) def blit(self, bitmap): - self._display_bus.send(42, struct.pack(">hh", 80, - 80 + bitmap.width - 1)) - self._display_bus.send(43, struct.pack(">hh", 32, - 32 + bitmap.height - 1)) + self._display_bus.send(42, struct.pack(">hh", 80, 80 + bitmap.width - 1)) + self._display_bus.send(43, struct.pack(">hh", 32, 32 + bitmap.height - 1)) self._display_bus.send(44, bitmap) @property diff --git a/examples/camera/code.py b/examples/camera/code.py index f0d1a33..d185a6b 100644 --- a/examples/camera/code.py +++ b/examples/camera/code.py @@ -11,25 +11,26 @@ pycam = adafruit_pycamera.PyCamera() pycam.autofocus_init() -#pycam.live_preview_mode() +# pycam.live_preview_mode() settings = (None, "resolution", "effect", "mode", "led_level", "led_color") curr_setting = 0 print("Starting!") -#pycam.tone(200, 0.1) +# pycam.tone(200, 0.1) last_frame = displayio.Bitmap(pycam.camera.width, pycam.camera.height, 65535) onionskin = displayio.Bitmap(pycam.camera.width, pycam.camera.height, 65535) while True: - if (pycam.mode_text == "STOP" and pycam.stop_motion_frame != 0): + if pycam.mode_text == "STOP" and pycam.stop_motion_frame != 0: # alpha blend new_frame = pycam.continuous_capture() - bitmaptools.alphablend(onionskin, last_frame, new_frame, - displayio.Colorspace.RGB565_SWAPPED) + bitmaptools.alphablend( + onionskin, last_frame, new_frame, displayio.Colorspace.RGB565_SWAPPED + ) pycam.blit(onionskin) else: pycam.blit(pycam.continuous_capture()) - #print("\t\t", capture_time, blit_time) + # print("\t\t", capture_time, blit_time) pycam.keys_debounce() # test shutter button @@ -56,26 +57,31 @@ if pycam.mode_text == "GIF": try: - f = pycam.open_next_image("gif") + f = pycam.open_next_image("gif") except RuntimeError as e: - pycam.display_message("Error\nNo SD Card", color=0xFF0000) - time.sleep(0.5) - continue + pycam.display_message("Error\nNo SD Card", color=0xFF0000) + time.sleep(0.5) + continue i = 0 ft = [] pycam._mode_label.text = "RECORDING" pycam.display.refresh() - with gifio.GifWriter(f, pycam.camera.width, pycam.camera.height, - displayio.Colorspace.RGB565_SWAPPED, dither=True) as g: + with gifio.GifWriter( + f, + pycam.camera.width, + pycam.camera.height, + displayio.Colorspace.RGB565_SWAPPED, + dither=True, + ) as g: t00 = t0 = time.monotonic() while (i < 15) or (pycam.shutter_button.value == False): i += 1 _gifframe = pycam.continuous_capture() - g.add_frame(_gifframe, .12) + g.add_frame(_gifframe, 0.12) pycam.blit(_gifframe) t1 = time.monotonic() - ft.append(1/(t1-t0)) + ft.append(1 / (t1 - t0)) print(end=".") t0 = t1 pycam._mode_label.text = "GIF" @@ -133,16 +139,16 @@ print("LF") curr_setting = (curr_setting + 1) % len(settings) print(settings[curr_setting]) - #new_res = min(len(pycam.resolutions)-1, pycam.get_resolution()+1) - #pycam.set_resolution(pycam.resolutions[new_res]) + # new_res = min(len(pycam.resolutions)-1, pycam.get_resolution()+1) + # pycam.set_resolution(pycam.resolutions[new_res]) pycam.select_setting(settings[curr_setting]) if pycam.right.fell: print("RT") curr_setting = (curr_setting - 1 + len(settings)) % len(settings) print(settings[curr_setting]) pycam.select_setting(settings[curr_setting]) - #new_res = max(1, pycam.get_resolution()-1) - #pycam.set_resolution(pycam.resolutions[new_res]) + # new_res = max(1, pycam.get_resolution()-1) + # pycam.set_resolution(pycam.resolutions[new_res]) if pycam.select.fell: print("SEL") if pycam.ok.fell: diff --git a/examples/ipcam/code.py b/examples/ipcam/code.py index 5de4d7d..917b145 100644 --- a/examples/ipcam/code.py +++ b/examples/ipcam/code.py @@ -62,6 +62,7 @@ async def main(): poll_task = asyncio.create_task(poll(0)) await asyncio.gather(poll_task) + pycam.display_message(f"{wifi.radio.ipv4_address}:{PORT}/", scale=2) asyncio.run(main()) diff --git a/examples/ipcam2/code.py b/examples/ipcam2/code.py index eff169c..f2282c4 100644 --- a/examples/ipcam2/code.py +++ b/examples/ipcam2/code.py @@ -13,12 +13,22 @@ import socketpool import ulab.numpy as np import wifi -from adafruit_httpserver import (BAD_REQUEST_400, GET, NOT_FOUND_404, POST, FileResponse, - JSONResponse, Request, Response, Server) +from adafruit_httpserver import ( + BAD_REQUEST_400, + GET, + NOT_FOUND_404, + POST, + FileResponse, + JSONResponse, + Request, + Response, + Server, +) # Disable autoreload. this is very handy while editing the js & html files # as you want to just reload the web browser, not the CircutPython program! import supervisor + supervisor.runtime.autoreload = False pycam = adafruit_pycamera.PyCamera() @@ -35,16 +45,19 @@ print(wifi.radio.ipv4_address) pool = socketpool.SocketPool(wifi.radio) -server = Server(pool, debug=True, root_path='/htdocs') +server = Server(pool, debug=True, root_path="/htdocs") + @server.route("/metadata.json", [GET]) def property(request: Request) -> Response: return FileResponse(request, "/metadata.js") + @server.route("/", [GET]) def property(request: Request) -> Response: return FileResponse(request, "/index.html") + @server.route("/index.js", [GET]) def property(request: Request) -> Response: return FileResponse(request, "/index.js") @@ -73,10 +86,12 @@ def property(request: Request) -> Response: finally: pycam.live_preview_mode() + @server.route("/focus", [GET]) def focus(request: Request) -> Response: return JSONResponse(request, pycam.autofocus()) + @server.route("/property", [GET, POST]) def property(request: Request) -> Response: return property_common(pycam, request) @@ -98,13 +113,13 @@ def property_common(obj, request): current_value = getattr(obj, key, None) return JSONResponse(request, current_value) except Exception as e: - return Response(request, {'error': str(e)}, status=BAD_REQUEST_400) + return Response(request, {"error": str(e)}, status=BAD_REQUEST_400) else: new_value = json.loads(value) setattr(obj, key, new_value) - return JSONResponse(request, {'status': 'OK'}) + return JSONResponse(request, {"status": "OK"}) except Exception as e: - return JSONResponse(request, {'error': str(e)}, status=BAD_REQUEST_400) + return JSONResponse(request, {"error": str(e)}, status=BAD_REQUEST_400) server.serve_forever(str(wifi.radio.ipv4_address), port) diff --git a/examples/ipcam2/htdocs/index.js b/examples/ipcam2/htdocs/index.js index 00a1e0d..4772186 100644 --- a/examples/ipcam2/htdocs/index.js +++ b/examples/ipcam2/htdocs/index.js @@ -5,7 +5,7 @@ var ii = 0; function option_change(k1, k2) { var id_ = k1 + "-" + k2; var el = document.getElementById(id_) - + url = `/${k1}?k=${k2}&v=${el.value}` console.log(url) var req = new XMLHttpRequest(); @@ -27,7 +27,7 @@ function make_controls(k1, t) { } var ht = html`
- + diff --git a/examples/ipcam2/make_web_metadata.py b/examples/ipcam2/make_web_metadata.py index 88461a6..692ee0c 100644 --- a/examples/ipcam2/make_web_metadata.py +++ b/examples/ipcam2/make_web_metadata.py @@ -1,6 +1,9 @@ import json -def list_range(*args): return list(range(*args)) + +def list_range(*args): + return list(range(*args)) + metadata = { "property": { @@ -33,7 +36,7 @@ def list_range(*args): return list(range(*args)) "led_color": list_range(8), }, "property2": { - #"sensor_name": None, + # "sensor_name": None, "contrast": list_range(-2, 3), "brightness": list_range(-2, 3), "saturation": list_range(-2, 3), diff --git a/examples/qrio/code.py b/examples/qrio/code.py index e007d4d..006eef0 100644 --- a/examples/qrio/code.py +++ b/examples/qrio/code.py @@ -23,7 +23,7 @@ pycam.camera.reconfigure( pixel_format=espcamera.PixelFormat.RGB565, frame_size=espcamera.FrameSize.VGA, - ) +) pycam._mode_label.text = "QR SCAN" pycam._res_label.text = "" pycam.effect = 0 @@ -35,7 +35,7 @@ new_frame = pycam.continuous_capture() if new_frame is None: continue - bitmaptools.blit(zoomed, new_frame, 0, 0, x1=(640-240)//2, y1=(480-176)//2) + bitmaptools.blit(zoomed, new_frame, 0, 0, x1=(640 - 240) // 2, y1=(480 - 176) // 2) pycam.blit(zoomed) for row in qrdecoder.decode(zoomed, qrio.PixelPolicy.RGB565_SWAPPED): payload = row.payload @@ -46,6 +46,6 @@ if payload != old_payload: pycam.tone(200, 0.1) print(payload) - pycam.display_message(payload, color=0xffffff, scale=1) + pycam.display_message(payload, color=0xFFFFFF, scale=1) time.sleep(1) old_payload = payload From c48d0f1e9a838fc58a2f5dc0904797d126c8ab7c Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 29 Nov 2023 11:11:13 -0600 Subject: [PATCH 06/11] tidy imports with isort --- adafruit_pycamera.py | 26 +++++++++++++------------- docs/conf.py | 2 +- examples/camera/code.py | 8 +++++--- examples/ipcam/code.py | 3 ++- examples/ipcam2/code.py | 22 +++++++--------------- examples/qrio/code.py | 10 ++++++---- 6 files changed, 34 insertions(+), 37 deletions(-) diff --git a/adafruit_pycamera.py b/adafruit_pycamera.py index 3de4d05..7e1e2b4 100644 --- a/adafruit_pycamera.py +++ b/adafruit_pycamera.py @@ -1,26 +1,26 @@ import os +import struct import sys import time -import struct -import board -from digitalio import DigitalInOut, Direction, Pull -from adafruit_debouncer import Debouncer, Button + +import adafruit_aw9523 +import adafruit_lis3dh import bitmaptools +import board import busio -import adafruit_lis3dh +import displayio +import espcamera +import microcontroller import neopixel -from rainbowio import colorwheel +import pwmio import sdcardio import storage -import displayio -import espcamera -from adafruit_st7789 import ST7789 import terminalio -from adafruit_display_text import label -import pwmio -import microcontroller -import adafruit_aw9523 from adafruit_bus_device.i2c_device import I2CDevice +from adafruit_debouncer import Button, Debouncer +from adafruit_display_text import label +from adafruit_st7789 import ST7789 +from digitalio import DigitalInOut, Direction, Pull from rainbowio import colorwheel __version__ = "0.0.0-auto.0" diff --git a/docs/conf.py b/docs/conf.py index d1961ea..989c455 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -4,9 +4,9 @@ # # SPDX-License-Identifier: MIT +import datetime import os import sys -import datetime sys.path.insert(0, os.path.abspath("..")) diff --git a/examples/camera/code.py b/examples/camera/code.py index d185a6b..9340207 100644 --- a/examples/camera/code.py +++ b/examples/camera/code.py @@ -1,13 +1,15 @@ import os +import struct import sys import time -import struct + +import bitmaptools import board -import adafruit_pycamera import displayio import gifio import ulab.numpy as np -import bitmaptools + +import adafruit_pycamera pycam = adafruit_pycamera.PyCamera() pycam.autofocus_init() diff --git a/examples/ipcam/code.py b/examples/ipcam/code.py index 917b145..40f8181 100644 --- a/examples/ipcam/code.py +++ b/examples/ipcam/code.py @@ -5,13 +5,14 @@ import sys import time -import adafruit_pycamera import espcamera import socketpool import wifi from adafruit_httpserver.response import ChunkedResponse from adafruit_httpserver.server import Server +import adafruit_pycamera + pycam = adafruit_pycamera.PyCamera() pycam.camera.reconfigure( pixel_format=espcamera.PixelFormat.JPEG, diff --git a/examples/ipcam2/code.py b/examples/ipcam2/code.py index f2282c4..2112ef4 100644 --- a/examples/ipcam2/code.py +++ b/examples/ipcam2/code.py @@ -4,30 +4,22 @@ import sys import time -import adafruit_pycamera import bitmaptools import board import displayio import espcamera import gifio import socketpool -import ulab.numpy as np -import wifi -from adafruit_httpserver import ( - BAD_REQUEST_400, - GET, - NOT_FOUND_404, - POST, - FileResponse, - JSONResponse, - Request, - Response, - Server, -) - # Disable autoreload. this is very handy while editing the js & html files # as you want to just reload the web browser, not the CircutPython program! import supervisor +import ulab.numpy as np +import wifi +from adafruit_httpserver import (BAD_REQUEST_400, GET, NOT_FOUND_404, POST, + FileResponse, JSONResponse, Request, Response, + Server) + +import adafruit_pycamera supervisor.runtime.autoreload = False diff --git a/examples/qrio/code.py b/examples/qrio/code.py index 006eef0..9756f03 100644 --- a/examples/qrio/code.py +++ b/examples/qrio/code.py @@ -7,15 +7,17 @@ ILI9341 display. """ -from terminalio import FONT +import time + +import bitmaptools import board import busio import displayio -import qrio -import time -import bitmaptools import espcamera +import qrio from adafruit_display_text.bitmap_label import Label +from terminalio import FONT + from adafruit_pycamera import PyCamera zoomed = displayio.Bitmap(240, 176, 65535) From 4bba65b4bce902b881d1d7900775d63e877b315d Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 29 Nov 2023 11:15:23 -0600 Subject: [PATCH 07/11] black and isort disagree on this --- examples/ipcam2/code.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/examples/ipcam2/code.py b/examples/ipcam2/code.py index 2112ef4..4083d29 100644 --- a/examples/ipcam2/code.py +++ b/examples/ipcam2/code.py @@ -10,14 +10,23 @@ import espcamera import gifio import socketpool + # Disable autoreload. this is very handy while editing the js & html files # as you want to just reload the web browser, not the CircutPython program! import supervisor import ulab.numpy as np import wifi -from adafruit_httpserver import (BAD_REQUEST_400, GET, NOT_FOUND_404, POST, - FileResponse, JSONResponse, Request, Response, - Server) +from adafruit_httpserver import ( + BAD_REQUEST_400, + GET, + NOT_FOUND_404, + POST, + FileResponse, + JSONResponse, + Request, + Response, + Server, +) import adafruit_pycamera From 84247421ecb344b8173a3d7ebe837eafe82cc5ae Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 29 Nov 2023 11:42:54 -0600 Subject: [PATCH 08/11] annotate this as GPL-2.0 at the moment bsaed on https://android.googlesource.com/kernel/msm.git/+/511b239792d76efc7456ef92735a1257c95eac44/drivers/media/video/msm/ov5640.h#1044 until we have more correct information. --- LICENSES/GPL-2.0-only.txt | 117 +++++++++++++++++++++++++++ README.md | 1 - README.rst | 40 +++------ README.rst.license | 2 + adafruit_pycamera.py | 4 + examples/camera/code.py | 4 + examples/ipcam/code.py | 4 + examples/ipcam2/code.py | 4 + examples/ipcam2/htdocs/index.html | 6 ++ examples/ipcam2/htdocs/index.js | 4 + examples/ipcam2/htdocs/metadata.js | 4 + examples/ipcam2/make_web_metadata.py | 4 + examples/qrio/code.py | 1 + ov5640_autofocus.bin.license | 3 + settings.toml | 1 - 15 files changed, 169 insertions(+), 30 deletions(-) create mode 100644 LICENSES/GPL-2.0-only.txt delete mode 100644 README.md create mode 100644 ov5640_autofocus.bin.license delete mode 100644 settings.toml diff --git a/LICENSES/GPL-2.0-only.txt b/LICENSES/GPL-2.0-only.txt new file mode 100644 index 0000000..17cb286 --- /dev/null +++ b/LICENSES/GPL-2.0-only.txt @@ -0,0 +1,117 @@ +GNU GENERAL PUBLIC LICENSE +Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +Preamble + +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. + +Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and modification follow. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. + +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. + + c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. + +If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + +5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. + +7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. + +10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. + +NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + + one line to give the program's name and an idea of what it does. Copyright (C) yyyy name of author + + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. + +signature of Ty Coon, 1 April 1989 Ty Coon, President of Vice diff --git a/README.md b/README.md deleted file mode 100644 index f318f38..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# Adafruit_CircuitPython_PyCamera \ No newline at end of file diff --git a/README.rst b/README.rst index f98a3b6..cd10ee5 100644 --- a/README.rst +++ b/README.rst @@ -46,33 +46,10 @@ image from the assets folder in the PCB's GitHub repo. Installing from PyPI ===================== -.. note:: This library is not available on PyPI yet. Install documentation is included - as a standard element. Stay tuned for PyPI availability! -.. todo:: Remove the above note if PyPI version is/will be available at time of release. - -On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from -PyPI `_. -To install for current user: - -.. code-block:: shell - - pip3 install adafruit-circuitpython-pycamera - -To install system-wide (this may be required in some cases): - -.. code-block:: shell - - sudo pip3 install adafruit-circuitpython-pycamera - -To install in a virtual environment in your current project: - -.. code-block:: shell - - mkdir project-name && cd project-name - python3 -m venv .venv - source .env/bin/activate - pip3 install adafruit-circuitpython-pycamera +This package is available on PyPI so that it can be installed by Thonny. It is +not useful to install this package from PyPI on a Windows, Mac, or Linux +computer. Installing to a Connected CircuitPython Device with Circup ========================================================== @@ -100,8 +77,15 @@ Or the following command to update an existing version: Usage Example ============= -.. todo:: Add a quick, simple example. It and other examples should live in the -examples folder and be included in docs/examples.rst. +.. code-block: python + + from adafruit_pycamera import PyCamera + + pycam = PyCamera() + + while True: + new_frame = pycam.continuous_capture() + # .. do something with new_frame Documentation ============= diff --git a/README.rst.license b/README.rst.license index ffd1331..dd81d34 100644 --- a/README.rst.license +++ b/README.rst.license @@ -1,3 +1,5 @@ SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries SPDX-FileCopyrightText: Copyright (c) 2023 Jeff Epler for Adafruit Industries for Adafruit Industries + SPDX-License-Identifier: MIT diff --git a/adafruit_pycamera.py b/adafruit_pycamera.py index 7e1e2b4..7d1f80c 100644 --- a/adafruit_pycamera.py +++ b/adafruit_pycamera.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries +# +# SPDX-License-Identifier: MIT + import os import struct import sys diff --git a/examples/camera/code.py b/examples/camera/code.py index 9340207..7b7c82c 100644 --- a/examples/camera/code.py +++ b/examples/camera/code.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + import os import struct import sys diff --git a/examples/ipcam/code.py b/examples/ipcam/code.py index 40f8181..6aae24c 100644 --- a/examples/ipcam/code.py +++ b/examples/ipcam/code.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + import asyncio import binascii import os diff --git a/examples/ipcam2/code.py b/examples/ipcam2/code.py index 4083d29..754596a 100644 --- a/examples/ipcam2/code.py +++ b/examples/ipcam2/code.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + import json import os import struct diff --git a/examples/ipcam2/htdocs/index.html b/examples/ipcam2/htdocs/index.html index a829b33..dc66fbd 100644 --- a/examples/ipcam2/htdocs/index.html +++ b/examples/ipcam2/htdocs/index.html @@ -1,3 +1,9 @@ + + diff --git a/examples/ipcam2/htdocs/index.js b/examples/ipcam2/htdocs/index.js index 4772186..933da52 100644 --- a/examples/ipcam2/htdocs/index.js +++ b/examples/ipcam2/htdocs/index.js @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries +// +// SPDX-License-Identifier: Unlicense + const html = (strings, ...values) => String.raw({ raw: strings }, ...values); var ii = 0; diff --git a/examples/ipcam2/htdocs/metadata.js b/examples/ipcam2/htdocs/metadata.js index f0a4727..d112639 100644 --- a/examples/ipcam2/htdocs/metadata.js +++ b/examples/ipcam2/htdocs/metadata.js @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries +// +// SPDX-License-Identifier: Unlicense + tunables = { "property": { "effect": [ diff --git a/examples/ipcam2/make_web_metadata.py b/examples/ipcam2/make_web_metadata.py index 692ee0c..ee85d24 100644 --- a/examples/ipcam2/make_web_metadata.py +++ b/examples/ipcam2/make_web_metadata.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + import json diff --git a/examples/qrio/code.py b/examples/qrio/code.py index 9756f03..2291ca4 100644 --- a/examples/qrio/code.py +++ b/examples/qrio/code.py @@ -1,3 +1,4 @@ +# SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries # SPDX-FileCopyrightText: Copyright (c) 2021 Jeff Epler for Adafruit Industries # # SPDX-License-Identifier: Unlicense diff --git a/ov5640_autofocus.bin.license b/ov5640_autofocus.bin.license new file mode 100644 index 0000000..bbb9ced --- /dev/null +++ b/ov5640_autofocus.bin.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2023 Unknown + +SPDX-License-Identifier: GPL-2.0-only diff --git a/settings.toml b/settings.toml deleted file mode 100644 index 5c0d5ca..0000000 --- a/settings.toml +++ /dev/null @@ -1 +0,0 @@ -CIRCUITPY_RESERVED_PSRAM=1048576 From d378c178918e845d476d962d0c94ace542f96508 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 29 Nov 2023 12:12:23 -0600 Subject: [PATCH 09/11] fix pylint messages --- adafruit_pycamera.py | 157 +++++++++++++++++++++------------ examples/camera/code.py | 10 +-- examples/ipcam/code.py | 3 - examples/ipcam2/code.py | 189 +++++----------------------------------- examples/qrio/code.py | 8 +- 5 files changed, 127 insertions(+), 240 deletions(-) diff --git a/adafruit_pycamera.py b/adafruit_pycamera.py index 7d1f80c..d71b8e2 100644 --- a/adafruit_pycamera.py +++ b/adafruit_pycamera.py @@ -1,17 +1,21 @@ # SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries # # SPDX-License-Identifier: MIT +"""Library for the Adafruit PyCamera with OV5640 autofocus module""" import os import struct -import sys import time +try: + from typing import Sequence +except ImportError: + pass + import adafruit_aw9523 import adafruit_lis3dh import bitmaptools import board -import busio import displayio import espcamera import microcontroller @@ -23,8 +27,7 @@ from adafruit_bus_device.i2c_device import I2CDevice from adafruit_debouncer import Button, Debouncer from adafruit_display_text import label -from adafruit_st7789 import ST7789 -from digitalio import DigitalInOut, Direction, Pull +from digitalio import DigitalInOut, Pull from rainbowio import colorwheel __version__ = "0.0.0-auto.0" @@ -53,8 +56,30 @@ _OV5640_CMD_PARA4 = const(0x3028) _OV5640_CMD_FW_STATUS = const(0x3029) +_AW_MUTE = const(0) +_AW_SELECT = const(1) +_AW_CARDDET = const(8) +_AW_SDPWR = const(9) +_AW_DOWN = const(15) +_AW_LEFT = const(14) +_AW_UP = const(13) +_AW_RIGHT = const(12) +_AW_OK = const(11) +# _SS_ALL_BUTTONS_MASK = const(0b000010000000001011100) +# _SS_DOWN_MASK = const(0x10000) +# _SS_LEFT_MASK = const(0x00004) +# _SS_UP_MASK = const(0x00008) +# _SS_RIGHT_MASK = const(0x00040) +# _SS_CARDDET_MASK = const(0x00010) + +_NVM_RESOLUTION = const(1) +_NVM_EFFECT = const(2) +_NVM_MODE = const(3) + + +class PyCamera: # pylint: disable=too-many-instance-attributes,too-many-public-methods + """Wrapper class for the PyCamera hardware""" -class PyCamera: _finalize_firmware_load = ( 0x3022, 0x00, @@ -149,26 +174,6 @@ class PyCamera: ) modes = ("JPEG", "GIF", "STOP") - _AW_MUTE = const(0) - _AW_SELECT = const(1) - _AW_CARDDET = const(8) - _AW_SDPWR = const(9) - _AW_DOWN = const(15) - _AW_LEFT = const(14) - _AW_UP = const(13) - _AW_RIGHT = const(12) - _AW_OK = const(11) - # _SS_ALL_BUTTONS_MASK = const(0b000010000000001011100) - # _SS_DOWN_MASK = const(0x10000) - # _SS_LEFT_MASK = const(0x00004) - # _SS_UP_MASK = const(0x00008) - # _SS_RIGHT_MASK = const(0x00040) - # _SS_CARDDET_MASK = const(0x00010) - - _NVM_RESOLUTION = const(1) - _NVM_EFFECT = const(2) - _NVM_MODE = const(3) - _INIT_SEQUENCE = ( b"\x01\x80\x78" # _SWRESET and Delay 120ms b"\x11\x80\x05" # _SLPOUT and Delay 5ms @@ -180,6 +185,7 @@ class PyCamera: ) def i2c_scan(self): + """Print an I2C bus scan""" while not self._i2c.try_lock(): pass @@ -191,8 +197,8 @@ def i2c_scan(self): finally: # unlock the i2c bus when ctrl-c'ing out of the loop self._i2c.unlock() - def __init__(self) -> None: - self.t = time.monotonic() + def __init__(self) -> None: # pylint: disable=too-many-statements + self._timestamp = time.monotonic() self._i2c = board.I2C() self._spi = board.SPI() self.deinit_display() @@ -228,7 +234,7 @@ def __init__(self) -> None: self._cam_reset.switch_to_output(True) time.sleep(0.01) - print("pre cam @", time.monotonic() - self.t) + print("pre cam @", time.monotonic() - self._timestamp) self.i2c_scan() # AW9523 GPIO expander @@ -250,7 +256,7 @@ def make_debounced_expander_pin(pin_no): pin.switch_to_input() return Debouncer(make_expander_input(pin_no)) - self.up = make_debounced_expander_pin(_AW_UP) + self.up = make_debounced_expander_pin(_AW_UP) # pylint: disable=invalid-name self.left = make_debounced_expander_pin(_AW_LEFT) self.right = make_debounced_expander_pin(_AW_RIGHT) self.down = make_debounced_expander_pin(_AW_DOWN) @@ -267,7 +273,7 @@ def make_debounced_expander_pin(pin_no): self.mount_sd_card() except RuntimeError: pass # no card found, its ok! - print("sdcard done @", time.monotonic() - self.t) + print("sdcard done @", time.monotonic() - self._timestamp) # lis3dh accelerometer self.accel = adafruit_lis3dh.LIS3DH_I2C(self._i2c, address=0x19) @@ -307,7 +313,7 @@ def make_debounced_expander_pin(pin_no): self.camera.address, ) ) - print("camera done @", time.monotonic() - self.t) + print("camera done @", time.monotonic() - self._timestamp) print(dir(self.camera)) self._camera_device = I2CDevice(self._i2c, self.camera.address) @@ -342,14 +348,16 @@ def make_debounced_expander_pin(pin_no): self.camera.saturation = 3 self.resolution = microcontroller.nvm[_NVM_RESOLUTION] self.mode = microcontroller.nvm[_NVM_MODE] - print("init done @", time.monotonic() - self.t) + print("init done @", time.monotonic() - self._timestamp) def autofocus_init_from_file(self, filename): + """Initialize the autofocus engine from a .bin file""" with open(filename, mode="rb") as file: firmware = file.read() self.autofocus_init_from_bitstream(firmware) def write_camera_register(self, reg: int, value: int) -> None: + """Write a 1-byte camera register""" b = bytearray(3) b[0] = reg >> 8 b[1] = reg & 0xFF @@ -358,6 +366,7 @@ def write_camera_register(self, reg: int, value: int) -> None: i2c.write(b) def write_camera_list(self, reg_list: Sequence[int]) -> None: + """Write a series of 1-byte camera registers""" for i in range(0, len(reg_list), 2): register = reg_list[i] value = reg_list[i + 1] @@ -367,6 +376,7 @@ def write_camera_list(self, reg_list: Sequence[int]) -> None: self.write_camera_register(register, value) def read_camera_register(self, reg: int) -> int: + """Read a 1-byte camera register""" b = bytearray(2) b[0] = reg >> 8 b[1] = reg & 0xFF @@ -375,7 +385,8 @@ def read_camera_register(self, reg: int) -> int: i2c.readinto(b, end=1) return b[0] - def autofocus_init_from_bitstream(self, firmware): + def autofocus_init_from_bitstream(self, firmware: bytes): + """Initialize the autofocus engine from a bytestring""" if self.camera.sensor_name != "OV5640": raise RuntimeError(f"Autofocus not supported on {self.camera.sensor_name}") @@ -386,7 +397,6 @@ def autofocus_init_from_bitstream(self, firmware): self.write_camera_list(self._finalize_firmware_load) for _ in range(100): - self._print_focus_status("init from bitstream") if self.autofocus_status == _OV5640_STAT_IDLE: break time.sleep(0.01) @@ -394,6 +404,7 @@ def autofocus_init_from_bitstream(self, firmware): raise RuntimeError("Timed out after trying to load autofocus firmware") def autofocus_init(self): + """Initialize the autofocus engine from ov5640_autofocus.bin""" if "/" in __file__: binfile = ( __file__.rsplit("/", 1)[0].rsplit(".", 1)[0] + "/ov5640_autofocus.bin" @@ -405,26 +416,25 @@ def autofocus_init(self): @property def autofocus_status(self): + """Read the camera autofocus status register""" return self.read_camera_register(_OV5640_CMD_FW_STATUS) - def _print_focus_status(self, msg): - if False: - print( - f"{msg:36} status={self.autofocus_status:02x} busy?={self.read_camera_register(_OV5640_CMD_ACK):02x}" - ) - - def _send_autofocus_command(self, command, msg): + def _send_autofocus_command(self, command, msg): # pylint: disable=unused-argument self.write_camera_register(_OV5640_CMD_ACK, 0x01) # clear command ack self.write_camera_register(_OV5640_CMD_MAIN, command) # send command for _ in range(100): - self._print_focus_status(msg) if self.read_camera_register(_OV5640_CMD_ACK) == 0x0: # command is finished return True time.sleep(0.01) - else: - return False + return False def autofocus(self) -> list[int]: + """Perform an autofocus operation. + + If all elements of the list are 0, the autofocus operation failed. Otherwise, + if at least one element is nonzero, the operation succeeded. + + In principle the elements correspond to 5 autofocus regions, if configured.""" if not self._send_autofocus_command(_OV5640_CMD_RELEASE_FOCUS, "release focus"): return [False] * 5 if not self._send_autofocus_command(_OV5640_CMD_TRIGGER_AUTOFOCUS, "autofocus"): @@ -436,6 +446,7 @@ def autofocus(self) -> list[int]: return zone_focus def select_setting(self, setting_name): + """For the point & shoot camera mode, control what setting is being set""" self._effect_label.color = 0xFFFFFF self._effect_label.background_color = 0x0 self._res_label.color = 0xFFFFFF @@ -464,10 +475,12 @@ def select_setting(self, setting_name): @property def mode(self): + """Get or set the capture mode (e.g., JPEG, etc) as a numeric constant""" return self._mode @property def mode_text(self): + """Get the capture mode (e.g., JPEG, etc) as a human string""" return self.modes[self._mode] @mode.setter @@ -486,6 +499,7 @@ def mode(self, setting): @property def effect(self): + """Get or set the effect mode (e.g., B&W, etc) as a numeric constant""" return self._effect @effect.setter @@ -499,6 +513,9 @@ def effect(self, setting): @property def resolution(self): + """Get or set the resolution as a numeric constant + + The resolution can also be set as a string such as "240x240".""" return self._resolution @resolution.setter @@ -515,6 +532,7 @@ def resolution(self, res): self.display.refresh() def init_display(self): + """Initialize the TFT display""" # construct displayio by hand displayio.release_displays() self._display_bus = displayio.FourWire( @@ -538,12 +556,14 @@ def init_display(self): self.display.refresh() def deinit_display(self): + """Release the TFT display""" # construct displayio by hand displayio.release_displays() self._display_bus = None self.display = None def display_message(self, message, color=0xFF0000, scale=3): + """Display a message on the TFT""" text_area = label.Label(terminalio.FONT, text=message, color=color, scale=scale) text_area.anchor_point = (0.5, 0.5) if not self.display: @@ -556,6 +576,7 @@ def display_message(self, message, color=0xFF0000, scale=3): self.splash.pop() def mount_sd_card(self): + """Attempt to mount the SD card""" self._sd_label.text = "NO SD" self._sd_label.color = 0xFF0000 if not self.card_detect.value: @@ -585,10 +606,10 @@ def mount_sd_card(self): # power SD card self._card_power.value = False card_cs.deinit() - print("sdcard init @", time.monotonic() - self.t) + print("sdcard init @", time.monotonic() - self._timestamp) self.sdcard = sdcardio.SDCard(self._spi, board.CARD_CS, baudrate=20_000_000) vfs = storage.VfsFat(self.sdcard) - print("mount vfs @", time.monotonic() - self.t) + print("mount vfs @", time.monotonic() - self._timestamp) storage.mount(vfs, "/sd") self.init_display() self._image_counter = 0 @@ -596,6 +617,7 @@ def mount_sd_card(self): self._sd_label.color = 0x00FF00 def unmount_sd_card(self): + """Unmount the SD card, if mounted""" try: storage.umount("/sd") except OSError: @@ -604,6 +626,10 @@ def unmount_sd_card(self): self._sd_label.color = 0xFF0000 def keys_debounce(self): + """Debounce all keys. + + This updates the values of self.shutter, etc., buttons""" + # shutter button is true GPIO so we debounce as normal self.shutter.update() self.card_detect.update() @@ -615,6 +641,7 @@ def keys_debounce(self): self.ok.update() def tone(self, frequency, duration=0.1): + """Play a tone on the internal speaker""" with pwmio.PWMOut( board.SPEAKER, frequency=int(frequency), variable_frequency=False ) as pwm: @@ -624,6 +651,7 @@ def tone(self, frequency, duration=0.1): self.mute.value = False def live_preview_mode(self): + """Set the camera into live preview mode""" self.camera.reconfigure( pixel_format=espcamera.PixelFormat.RGB565, frame_size=espcamera.FrameSize.HQVGA, @@ -632,10 +660,11 @@ def live_preview_mode(self): self.continuous_capture_start() def open_next_image(self, extension="jpg"): + """Return an opened numbered file on the sdcard, such as "img01234.jpg".""" try: os.stat("/sd") - except OSError: # no SD card! - raise RuntimeError("No SD card mounted") + except OSError as exc: # no SD card! + raise RuntimeError("No SD card mounted") from exc while True: filename = "/sd/img%04d.%s" % (self._image_counter, extension) self._image_counter += 1 @@ -647,10 +676,11 @@ def open_next_image(self, extension="jpg"): return open(filename, "wb") def capture_jpeg(self): + """Capture a jpeg file and save it to the SD card""" try: os.stat("/sd") - except OSError: # no SD card! - raise RuntimeError("No SD card mounted") + except OSError as exc: # no SD card! + raise RuntimeError("No SD card mounted") from exc self.camera.reconfigure( pixel_format=espcamera.PixelFormat.JPEG, @@ -663,32 +693,48 @@ def capture_jpeg(self): print(f"Captured {len(jpeg)} bytes of jpeg data") print("Resolution %d x %d" % (self.camera.width, self.camera.height)) - with self.open_next_image() as f: + with self.open_next_image() as dest: chunksize = 16384 for offset in range(0, len(jpeg), chunksize): - f.write(jpeg[offset : offset + chunksize]) + dest.write(jpeg[offset : offset + chunksize]) print(end=".") print("# Wrote image") else: print("# frame capture failed") def continuous_capture_start(self): - self._bitmap1 = self.camera.take(1) + """Switch the camera to continuous-capture mode""" + pass # pylint: disable=unnecessary-pass def capture_into_bitmap(self, bitmap): - self._bitmap1 = self.camera.take(1) - bitmaptools.blit(bitmap, self._bitmap1, 0, 0) + """Capture an image and blit it into the given bitmap""" + bitmaptools.blit(bitmap, self.continuous_capture(), 0, 0) def continuous_capture(self): + """Capture an image into an internal buffer. + + The image is valid at least until the next image capture, + or the camera's capture mode is changed""" return self.camera.take(1) def blit(self, bitmap): + """Display a bitmap direct to the LCD, bypassing displayio + + This can be more efficient than displaying a bitmap as a displayio + TileGrid, but if any displayio objects overlap the bitmap, the results + can be unpredictable. + + The default preview capture is 240x176, leaving 32 pixel rows at the top and bottom + for status information. + """ + self._display_bus.send(42, struct.pack(">hh", 80, 80 + bitmap.width - 1)) self._display_bus.send(43, struct.pack(">hh", 32, 32 + bitmap.height - 1)) self._display_bus.send(44, bitmap) @property def led_level(self): + """Get or set the LED level, from 0 to 4""" return self._led_level @led_level.setter @@ -700,6 +746,7 @@ def led_level(self, new_level): @property def led_color(self): + """Get or set the LED color, from 0 to 7""" return self._led_color @led_color.setter diff --git a/examples/camera/code.py b/examples/camera/code.py index 7b7c82c..75b2996 100644 --- a/examples/camera/code.py +++ b/examples/camera/code.py @@ -2,13 +2,9 @@ # # SPDX-License-Identifier: Unlicense -import os -import struct -import sys import time import bitmaptools -import board import displayio import gifio import ulab.numpy as np @@ -70,7 +66,7 @@ continue i = 0 ft = [] - pycam._mode_label.text = "RECORDING" + pycam._mode_label.text = "RECORDING" # pylint: disable=protected-access pycam.display.refresh() with gifio.GifWriter( @@ -81,7 +77,7 @@ dither=True, ) as g: t00 = t0 = time.monotonic() - while (i < 15) or (pycam.shutter_button.value == False): + while (i < 15) or not pycam.shutter_button.value: i += 1 _gifframe = pycam.continuous_capture() g.add_frame(_gifframe, 0.12) @@ -90,7 +86,7 @@ ft.append(1 / (t1 - t0)) print(end=".") t0 = t1 - pycam._mode_label.text = "GIF" + pycam._mode_label.text = "GIF" # pylint: disable=protected-access print(f"\nfinal size {f.tell()} for {i} frames") print(f"average framerate {i/(t1-t00)}fps") print(f"best {max(ft)} worst {min(ft)} std. deviation {np.std(ft)}") diff --git a/examples/ipcam/code.py b/examples/ipcam/code.py index 6aae24c..49865b8 100644 --- a/examples/ipcam/code.py +++ b/examples/ipcam/code.py @@ -5,9 +5,6 @@ import asyncio import binascii import os -import struct -import sys -import time import espcamera import socketpool diff --git a/examples/ipcam2/code.py b/examples/ipcam2/code.py index 754596a..ce3c2ce 100644 --- a/examples/ipcam2/code.py +++ b/examples/ipcam2/code.py @@ -4,26 +4,18 @@ import json import os -import struct -import sys -import time -import bitmaptools -import board -import displayio import espcamera -import gifio import socketpool # Disable autoreload. this is very handy while editing the js & html files # as you want to just reload the web browser, not the CircutPython program! import supervisor -import ulab.numpy as np import wifi from adafruit_httpserver import ( BAD_REQUEST_400, GET, - NOT_FOUND_404, + INTERNAL_SERVER_ERROR_500, POST, FileResponse, JSONResponse, @@ -54,40 +46,41 @@ @server.route("/metadata.json", [GET]) -def property(request: Request) -> Response: +def metadata(request: Request) -> Response: return FileResponse(request, "/metadata.js") @server.route("/", [GET]) -def property(request: Request) -> Response: +def index(request: Request) -> Response: return FileResponse(request, "/index.html") @server.route("/index.js", [GET]) -def property(request: Request) -> Response: +def index_js(request: Request) -> Response: return FileResponse(request, "/index.js") @server.route("/lcd", [GET, POST]) -def property(request: Request) -> Response: +def lcd(request: Request) -> Response: pycam.blit(pycam.continuous_capture()) return Response(request, "") @server.route("/jpeg", [GET, POST]) -def property(request: Request) -> Response: +def take_jpeg(request: Request) -> Response: pycam.camera.reconfigure( pixel_format=espcamera.PixelFormat.JPEG, - frame_size=pycam.resolution_to_frame_size[pycam._resolution], + frame_size=pycam.resolution_to_frame_size[ + pycam._resolution # pylint: disable=protected-access + ], ) try: jpeg = pycam.camera.take(1) if jpeg is not None: return Response(request, bytes(jpeg), content_type="image/jpeg") - else: - return Response( - request, "", content_type="text/plain", status=INTERNAL_SERVER_ERROR_500 - ) + return Response( + request, "", content_type="text/plain", status=INTERNAL_SERVER_ERROR_500 + ) finally: pycam.live_preview_mode() @@ -98,7 +91,7 @@ def focus(request: Request) -> Response: @server.route("/property", [GET, POST]) -def property(request: Request) -> Response: +def property1(request: Request) -> Response: return property_common(pycam, request) @@ -110,163 +103,21 @@ def property2(request: Request) -> Response: def property_common(obj, request): try: params = request.query_params or request.form_data - key = params["k"] + propname = params["k"] value = params.get("v", None) if value is None: try: - current_value = getattr(obj, key, None) + current_value = getattr(obj, propname, None) return JSONResponse(request, current_value) - except Exception as e: - return Response(request, {"error": str(e)}, status=BAD_REQUEST_400) + except Exception as exc: # pylint: disable=broad-exception-caught + return Response(request, {"error": str(exc)}, status=BAD_REQUEST_400) else: new_value = json.loads(value) - setattr(obj, key, new_value) + setattr(obj, propname, new_value) return JSONResponse(request, {"status": "OK"}) - except Exception as e: - return JSONResponse(request, {"error": str(e)}, status=BAD_REQUEST_400) + except Exception as exc: # pylint: disable=broad-exception-caught + return JSONResponse(request, {"error": str(exc)}, status=BAD_REQUEST_400) server.serve_forever(str(wifi.radio.ipv4_address), port) - - -server = Server(pool, debug=True) - -last_frame = displayio.Bitmap(pycam.camera.width, pycam.camera.height, 65535) -onionskin = displayio.Bitmap(pycam.camera.width, pycam.camera.height, 65535) -while True: - if pycam.mode_text == "STOP" and pycam.stop_motion_frame != 0: - # alpha blend - new_frame = pycam.continuous_capture() - bitmaptools.alphablend( - onionskin, last_frame, new_frame, displayio.Colorspace.RGB565_SWAPPED - ) - pycam.blit(onionskin) - else: - pycam.blit(pycam.continuous_capture()) - # print("\t\t", capture_time, blit_time) - - pycam.keys_debounce() - print( - f"{pycam.shutter.released=} {pycam.shutter.long_press=} {pycam.shutter.short_count=}" - ) - # test shutter button - if pycam.shutter.long_press: - print("FOCUS") - print(pycam.autofocus_status) - pycam.autofocus() - print(pycam.autofocus_status) - if pycam.shutter.short_count: - print("Shutter released") - if pycam.mode_text == "STOP": - pycam.capture_into_bitmap(last_frame) - pycam.stop_motion_frame += 1 - try: - pycam.display_message("Snap!", color=0x0000FF) - pycam.capture_jpeg() - except TypeError as e: - pycam.display_message("Failed", color=0xFF0000) - time.sleep(0.5) - except RuntimeError as e: - pycam.display_message("Error\nNo SD Card", color=0xFF0000) - time.sleep(0.5) - pycam.live_preview_mode() - - if pycam.mode_text == "GIF": - try: - f = pycam.open_next_image("gif") - except RuntimeError as e: - pycam.display_message("Error\nNo SD Card", color=0xFF0000) - time.sleep(0.5) - continue - i = 0 - ft = [] - pycam._mode_label.text = "RECORDING" - - pycam.display.refresh() - with gifio.GifWriter( - f, - pycam.camera.width, - pycam.camera.height, - displayio.Colorspace.RGB565_SWAPPED, - dither=True, - ) as g: - t00 = t0 = time.monotonic() - while (i < 15) or (pycam.shutter_button.value == False): - i += 1 - _gifframe = pycam.continuous_capture() - g.add_frame(_gifframe, 0.12) - pycam.blit(_gifframe) - t1 = time.monotonic() - ft.append(1 / (t1 - t0)) - print(end=".") - t0 = t1 - pycam._mode_label.text = "GIF" - print(f"\nfinal size {f.tell()} for {i} frames") - print(f"average framerate {i/(t1-t00)}fps") - print(f"best {max(ft)} worst {min(ft)} std. deviation {np.std(ft)}") - f.close() - pycam.display.refresh() - - if pycam.mode_text == "JPEG": - pycam.tone(200, 0.1) - try: - pycam.display_message("Snap!", color=0x0000FF) - pycam.capture_jpeg() - pycam.live_preview_mode() - except TypeError as e: - pycam.display_message("Failed", color=0xFF0000) - time.sleep(0.5) - pycam.live_preview_mode() - except RuntimeError as e: - pycam.display_message("Error\nNo SD Card", color=0xFF0000) - time.sleep(0.5) - if pycam.card_detect.fell: - print("SD card removed") - pycam.unmount_sd_card() - pycam.display.refresh() - if pycam.card_detect.rose: - print("SD card inserted") - pycam.display_message("Mounting\nSD Card", color=0xFFFFFF) - for _ in range(3): - try: - print("Mounting card") - pycam.mount_sd_card() - print("Success!") - break - except OSError as e: - print("Retrying!", e) - time.sleep(0.5) - else: - pycam.display_message("SD Card\nFailed!", color=0xFF0000) - time.sleep(0.5) - pycam.display.refresh() - - if pycam.up.fell: - print("UP") - key = settings[curr_setting] - if key: - setattr(pycam, key, getattr(pycam, key) + 1) - if pycam.down.fell: - print("DN") - key = settings[curr_setting] - if key: - setattr(pycam, key, getattr(pycam, key) - 1) - if pycam.left.fell: - print("LF") - curr_setting = (curr_setting + 1) % len(settings) - print(settings[curr_setting]) - # new_res = min(len(pycam.resolutions)-1, pycam.get_resolution()+1) - # pycam.set_resolution(pycam.resolutions[new_res]) - pycam.select_setting(settings[curr_setting]) - if pycam.right.fell: - print("RT") - curr_setting = (curr_setting - 1 + len(settings)) % len(settings) - print(settings[curr_setting]) - pycam.select_setting(settings[curr_setting]) - # new_res = max(1, pycam.get_resolution()-1) - # pycam.set_resolution(pycam.resolutions[new_res]) - if pycam.select.fell: - print("SEL") - if pycam.ok.fell: - print("OK") diff --git a/examples/qrio/code.py b/examples/qrio/code.py index 2291ca4..c63bad6 100644 --- a/examples/qrio/code.py +++ b/examples/qrio/code.py @@ -11,13 +11,9 @@ import time import bitmaptools -import board -import busio import displayio import espcamera import qrio -from adafruit_display_text.bitmap_label import Label -from terminalio import FONT from adafruit_pycamera import PyCamera @@ -27,8 +23,8 @@ pixel_format=espcamera.PixelFormat.RGB565, frame_size=espcamera.FrameSize.VGA, ) -pycam._mode_label.text = "QR SCAN" -pycam._res_label.text = "" +pycam._mode_label.text = "QR SCAN" # pylint: disable=protected-access +pycam._res_label.text = "" # pylint: disable=protected-access pycam.effect = 0 pycam.display.refresh() qrdecoder = qrio.QRDecoder(zoomed.width, zoomed.height) From 91f7502967c7521ae2055692abeae8d7264e9144 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 29 Nov 2023 12:12:31 -0600 Subject: [PATCH 10/11] remove extra license spec --- examples/ipcam2/htdocs/index.html | 1 + examples/ipcam2/htdocs/index.js | 1 + examples/ipcam2/htdocs/metadata.js | 1 + 3 files changed, 3 insertions(+) diff --git a/examples/ipcam2/htdocs/index.html b/examples/ipcam2/htdocs/index.html index dc66fbd..1a93c94 100644 --- a/examples/ipcam2/htdocs/index.html +++ b/examples/ipcam2/htdocs/index.html @@ -1,6 +1,7 @@ diff --git a/examples/ipcam2/htdocs/index.js b/examples/ipcam2/htdocs/index.js index 933da52..76857e0 100644 --- a/examples/ipcam2/htdocs/index.js +++ b/examples/ipcam2/htdocs/index.js @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries // +// SPDX-License-Identifier: MIT // SPDX-License-Identifier: Unlicense const html = (strings, ...values) => String.raw({ raw: strings }, ...values); diff --git a/examples/ipcam2/htdocs/metadata.js b/examples/ipcam2/htdocs/metadata.js index d112639..c1424c8 100644 --- a/examples/ipcam2/htdocs/metadata.js +++ b/examples/ipcam2/htdocs/metadata.js @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: 2023 Jeff Epler for Adafruit Industries // +// SPDX-License-Identifier: MIT // SPDX-License-Identifier: Unlicense tunables = { From 43ef2d3a5ad57e72a138f45223e20024bdd86d3e Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 29 Nov 2023 16:03:18 -0600 Subject: [PATCH 11/11] Make the docs build (locally at any rate) --- README.rst | 6 ++---- docs/conf.py | 17 ++++++++++++++++- docs/examples.rst | 4 ++-- docs/index.rst | 6 ------ requirements.txt | 1 + 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/README.rst b/README.rst index cd10ee5..af6a199 100644 --- a/README.rst +++ b/README.rst @@ -39,10 +39,8 @@ or individual libraries can be installed using -.. todo:: Describe the Adafruit product this library works with. For PCBs, you can also add the -image from the assets folder in the PCB's GitHub repo. - -`Purchase one from the Adafruit shop `_ +.. :: + `Purchase one from the Adafruit shop `_ Installing from PyPI ===================== diff --git a/docs/conf.py b/docs/conf.py index 989c455..03efd7f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -27,7 +27,22 @@ # Uncomment the below if you use native CircuitPython modules such as # digitalio, micropython and busio. List the modules you use. Without it, the # autodoc module docs will fail to generate with a warning. -# autodoc_mock_imports = ["digitalio", "busio"] +autodoc_mock_imports = [ + "bitmaptools", + "adafruit_aw9523", + "adafruit_lis3dh", + "displayio", + "espcamera", + "neopixel", + "sdcardio", + "storage", + "terminalio", + "adafruit_debouncer", + "adafruit_display_text", + "digitalio", + "busio", + "micropython", +] autodoc_preserve_defaults = True diff --git a/docs/examples.rst b/docs/examples.rst index 9dba02d..5d991f2 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -3,6 +3,6 @@ Simple test Ensure your device works with this simple test. -.. literalinclude:: ../examples/pycamera_simpletest.py - :caption: examples/pycamera_simpletest.py +.. literalinclude:: ../examples/camera/code.py + :caption: examples/camera/code.py :linenos: diff --git a/docs/index.rst b/docs/index.rst index 1c4ff36..8b61ba8 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -24,15 +24,9 @@ Table of Contents .. toctree:: :caption: Tutorials -.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave - the toctree above for use later. - .. toctree:: :caption: Related Products -.. todo:: Add any product links here. If there are none, then simply delete this todo and leave - the toctree above for use later. - .. toctree:: :caption: Other Links diff --git a/requirements.txt b/requirements.txt index d1bd7b9..c55340f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ Adafruit-Blinka adafruit-circuitpython-busdevice +adafruit-circuitpython-aw9523