Add in more garbage collecting and initial implementation of file download.

This commit is contained in:
2023-10-29 17:00:19 -04:00
parent ae8bafc8c3
commit e28f647a60
2 changed files with 74 additions and 9 deletions

53
main.py
View File

@@ -1,8 +1,51 @@
import sdcard
import uNextcloud
import inky_helper as ih
import gc
import sdcard, uos
import random
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY
from jpegdec import JPEG
from secrets import WIFI_SSID, WIFI_PASSWORD, NEXTCLOUD_USERNAME, NEXTCLOUD_PASSWORD
def get_new_image():
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()
ih.network_connect(WIFI_SSID, WIFI_PASSWORD)
nc = uNextcloud.uNextcloud("https://cloud.eyecreate.org")
nc.set_auth(NEXTCLOUD_USERNAME, NEXTCLOUD_PASSWORD)
response = nc.get_folder_items("eink-frame")
try:
last = open('/sd/last_wallpaper', 'r')
last_file = last.read()
last.close()
except OSError:
last_file = ""
if response != None:
for item in response:
if item.url_path == last_file:
response.remove(item)
ran = random.choice(response)
if ran.mimetype == "image/jpeg":
update_last = open('/sd/last_wallpaper', 'w+')
update_last.write(ran.url_path)
update_last.close()
print(ran.url_path)
gc.collect()
nc.download_file_to_path(ran.url_path, "/sd/current_image.jpg")
graphics = PicoGraphics(DISPLAY)
j = JPEG(graphics)
j.open_file("/sd/current_image.jpg")
j.decode()
graphics.update()
#sleep?
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()