From 5a760d908ea6572899569e9649934fc70a43e016 Mon Sep 17 00:00:00 2001 From: Kevin Whitaker <eyecreate@eyecreate.org> Date: Sun, 5 Nov 2023 16:12:23 -0500 Subject: [PATCH] Set min jpeg size. Organize logging into single method. Use auto GC instead of manual. Better file handling. --- inky_convert.sh | 2 +- main.py | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/inky_convert.sh b/inky_convert.sh index 858c77c..09e2297 100644 --- a/inky_convert.sh +++ b/inky_convert.sh @@ -1,2 +1,2 @@ #!/bin/bash -convert "$1" -resize '800x480!' -define modulate:colorspace=HSB -modulate 100,120 -level 2% -quality 70 "${1%.*}.inky.jpeg" +convert "$1" -resize '800x480!' -define modulate:colorspace=HSB -modulate 100,120 -level 2% -quality 60 -define jpeg:extent=120kb "${1%.*}.inky.jpeg" diff --git a/main.py b/main.py index 34d08ea..a91fd0a 100644 --- a/main.py +++ b/main.py @@ -5,20 +5,25 @@ import inky_frame import gc import random +def write_err(text): + with open('/sd/errors.log', 'a+') as error_log: + error_log.write(f'{text} \n') + +gc.enable() +gc.threshold(50000) sd_spi = machine.SPI(0, sck=machine.Pin(18, machine.Pin.OUT), mosi=machine.Pin(19, machine.Pin.OUT), miso=machine.Pin(16, machine.Pin.OUT)) sd = sdcard.SDCard(sd_spi, machine.Pin(22)) uos.mount(sd, "/sd") -gc.collect() from secrets import WIFI_SSID, WIFI_PASSWORD, NEXTCLOUD_USERNAME, NEXTCLOUD_PASSWORD try: ih.network_connect_better(WIFI_SSID, WIFI_PASSWORD) except RuntimeError as e: print(e) - with open('/sd/errors.log', 'a+') as error_log: - error_log.write(f'{e} \n') + write_err(e) #Likely a network oops, try starting again + uos.umount("/sd") machine.soft_reset() try: @@ -27,9 +32,9 @@ try: response = nc.get_folder_items("eink-frame") except OSError as e: print(e) - with open('/sd/errors.log', 'a+') as error_log: - error_log.write(f'{e} \n') + write_err(e) #Likely a network oops, try starting again + uos.umount("/sd") machine.soft_reset() try: @@ -48,9 +53,8 @@ if response != None: with open('/sd/last_wallpaper', 'w+') as update_last: update_last.write(ran.url_path) print(ran.url_path) - gc.collect() + print(gc.mem_free()) nc.download_file_to_path(ran.url_path, "/sd/current_image.jpg") - gc.collect() from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY from jpegdec import JPEG graphics = PicoGraphics(DISPLAY) @@ -60,4 +64,5 @@ if response != None: j.decode() graphics.update() +uos.umount("/sd") inky_frame.sleep_for(180) -- GitLab