diff --git a/.github/workflows/python-linting.yml b/.github/workflows/python-linting.yml index d03c56a..c90caf2 100644 --- a/.github/workflows/python-linting.yml +++ b/.github/workflows/python-linting.yml @@ -7,18 +7,22 @@ on: jobs: build: name: Python Linting - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + + - name: Install Python + uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 + with: + python-version: '3.13' - name: Install Python Deps - run: | - python3 -m venv .venv - source .venv/bin/activate - python -m pip install flake8 + run: source ci/python.sh && qa_prepare_all - name: Lint MicroPython Examples shell: bash - run: | - source .venv/bin/activate - python -m flake8 --show-source --ignore E501 examples/ \ No newline at end of file + run: source ci/python.sh && qa_examples_check + + - name: Lint MicroPython Modules + shell: bash + run: source ci/python.sh && qa_modules_check \ No newline at end of file diff --git a/README.md b/README.md index 449b393..ecb215e 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,10 @@ You can find the latest release at [https://github.com/pimoroni/unicorn/releases * [Stellar 16x16 (Pico W)](https://shop.pimoroni.com/products/space-unicorns?variant=40842632953939) * [Galactic 53x11 (Pico W)](https://shop.pimoroni.com/products/space-unicorns?variant=40842033561683) -* [Cosmic 32x32 (Pico W)](https://shop.pimoroni.com/products/space-unicorns?variant=40842626596947) \ No newline at end of file +* [Cosmic 32x32 (Pico W)](https://shop.pimoroni.com/products/space-unicorns?variant=40842626596947) + +## Other Resources + +* [(C++) Galactic Unicorn Scrolling Quote Demo](https://github.com/ahnlak-rp2040/gu-scrolling-quote) +* [(C++) Multiple Unicorns as a single display](https://github.com/gadgetoid/gu-multiverse) +* [(C++) Galactic Unicorn Bluetooth Audio Visualizer](https://github.com/Gadgetoid/galactic-bluetooth-audio) \ No newline at end of file diff --git a/boards/usermod-common.cmake b/boards/usermod-common.cmake index dfcb3bd..728b34e 100644 --- a/boards/usermod-common.cmake +++ b/boards/usermod-common.cmake @@ -30,7 +30,36 @@ include(jpegdec/micropython) include(qrcode/micropython/micropython) # Sensors & Breakouts -include(micropython-common-breakouts) + +# Include in Pico 2 W only, these make the build too big for Pico W :( +# Do you really need to connect a matrix to your matrix!? +if(PICO_BOARD EQUAL "pico2_w") +include(breakout_dotmatrix/micropython) +include(breakout_rgbmatrix5x5/micropython) +include(breakout_matrix11x7/micropython) +endif() + +include(breakout_encoder/micropython) +include(breakout_encoder_wheel/micropython) +include(breakout_ioexpander/micropython) +include(breakout_ltr559/micropython) +include(breakout_as7262/micropython) +include(breakout_as7343/micropython) +include(breakout_msa301/micropython) +include(breakout_pmw3901/micropython) +include(breakout_mics6814/micropython) +include(breakout_potentiometer/micropython) +include(breakout_rtc/micropython) +include(breakout_trackball/micropython) +include(breakout_sgp30/micropython) +include(breakout_bh1745/micropython) +include(breakout_bme69x/micropython) +include(breakout_bme68x/micropython) +include(breakout_bme280/micropython) +include(breakout_bmp280/micropython) +include(breakout_icp10125/micropython) +include(breakout_scd41/micropython) +include(breakout_vl53l5cx/micropython) # Utility include(adcfft/micropython) diff --git a/ci/micropython.sh b/ci/micropython.sh index 46da9c6..3648925 100644 --- a/ci/micropython.sh +++ b/ci/micropython.sh @@ -1,7 +1,7 @@ export TERM=${TERM:="xterm-256color"} MICROPYTHON_FLAVOUR="micropython" -MICROPYTHON_VERSION="master" +MICROPYTHON_VERSION="v1.25.0" PIMORONI_PICO_FLAVOUR="pimoroni" PIMORONI_PICO_VERSION="feature/picovector2-and-layers" diff --git a/ci/python.sh b/ci/python.sh new file mode 100644 index 0000000..0d2c41e --- /dev/null +++ b/ci/python.sh @@ -0,0 +1,52 @@ +# Include: +# F = Pyflakes +# Q = Quotes +# E/W = pycodestyle (Whitespace, Line lengths etc) +# B - flake8-bugbear = Unused loop variables, sloppy code +# COM - flake8-commas +# BLE - flake8-blind-except +# C4 - flake8-comprehensions +# ISC - flake8-implicit-str-concat = Implicit string concat, eg: `"hello" "world"` on one line +# ICN - flake8-import-conventions = Import conventions +# PIE - flake8-pie = Misc silliness, catches range with a 0 start argument +# RET - flake8-return = Enforces straight-forward code around return statements +# SLF - flake8-self +# ARG - flake8-unused-arguments + +# Ignore: +# E501 - "line too long". How narrow is your screen!? +# E402 - "module level import not at top of file". Needs must! +# COM812 - "Add trailing comma". These are a little obnoxious and weird. +# ICN001 - "numpy should be imported as np". No. No it should not. + +QA_INCLUDE="F,Q,W,E,B,COM,BLE,C4,ISC,ICN,PIE,RSE,RET,SLF,ARG" +QA_IGNORE="E501,E402,COM812,ICN001" +QA_EXCLUDE="" + +function qa_prepare_all { + pip install ruff +} + +function qa_check { + ruff check --select "$QA_INCLUDE" --ignore "$QA_IGNORE" --exclude "$QA_EXCLUDE" "$1" +} + +function qa_fix { + ruff check --select "$QA_INCLUDE" --ignore "$QA_IGNORE" --exclude "$QA_EXCLUDE" --fix "$1" +} + +function qa_examples_check { + qa_check examples +} + +function qa_examples_fix { + qa_fix examples +} + +function qa_modules_check { + qa_check modules +} + +function qa_modules_fix { + qa_fix modules +} diff --git a/examples/cosmic_unicorn/audio/audio.py b/examples/cosmic_unicorn/audio/audio.py index 10ce585..4297e8d 100644 --- a/examples/cosmic_unicorn/audio/audio.py +++ b/examples/cosmic_unicorn/audio/audio.py @@ -185,9 +185,9 @@ def __stop_i2s(self): if self.__audio_out is not None: self.__audio_out.deinit() # Deinit any active I2S comms - self.__state == WavPlayer.NONE # Return to the none state + self.__state = WavPlayer.NONE # Return to the none state - def __i2s_callback(self, arg): + def __i2s_callback(self, arg): # noqa ARG002 # PLAY if self.__state == WavPlayer.PLAY: if self.__mode == WavPlayer.MODE_WAV: diff --git a/examples/cosmic_unicorn/audio/countdown_with_alarm.py b/examples/cosmic_unicorn/audio/countdown_with_alarm.py index 2828ae0..e94f40f 100644 --- a/examples/cosmic_unicorn/audio/countdown_with_alarm.py +++ b/examples/cosmic_unicorn/audio/countdown_with_alarm.py @@ -74,8 +74,7 @@ def reset(self): self.timer.deinit() self.timer_running = False - def countdown(self, arg): - + def countdown(self, _arg): if self.total_seconds == 0: audio.play_wav("doorbell.wav", False) self.reset() diff --git a/examples/cosmic_unicorn/cheerlights_history.py b/examples/cosmic_unicorn/cheerlights_history.py index eea8336..5521da7 100644 --- a/examples/cosmic_unicorn/cheerlights_history.py +++ b/examples/cosmic_unicorn/cheerlights_history.py @@ -15,7 +15,7 @@ from cosmic import CosmicUnicorn from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN as DISPLAY -URL = 'http://api.thingspeak.com/channels/1417/field/2/last.json' +URL = "http://api.thingspeak.com/channels/1417/field/2/last.json" UPDATE_INTERVAL = 113 # refresh interval in secs. Be nice to free APIs! # this esoteric number is used so that a column of LEDs equates (approximately) to an hour @@ -24,28 +24,28 @@ def status_handler(mode, status, ip): # reports wifi connection status print(mode, status, ip) - print('Connecting to wifi...') + print("Connecting to wifi...") if status is not None: if status: - print('Wifi connection successful!') + print("Wifi connection successful!") else: - print('Wifi connection failed!') + print("Wifi connection failed!") def hex_to_rgb(hex): # converts a hex colour code into RGB - h = hex.lstrip('#') + h = hex.lstrip("#") r, g, b = (int(h[i:i + 2], 16) for i in (0, 2, 4)) return r, g, b -def get_data(): +def get_data(_t=None): # open the json file - print(f'Requesting URL: {URL}') + print(f"Requesting URL: {URL}") r = urequests.get(URL) # open the json data j = r.json() - print('Data obtained!') + print("Data obtained!") r.close() # flash the onboard LED after getting data @@ -54,11 +54,11 @@ def get_data(): pico_led.value(False) # extract hex colour from the json data - hex = j['field2'] + hex = j["field2"] # add the new hex colour to the end of the array colour_array.append(hex) - print(f'Colour added to array: {hex}') + print(f"Colour added to array: {hex}") # remove the oldest colour in the array colour_array.pop(0) update_leds() @@ -90,7 +90,7 @@ def update_leds(): cu.set_brightness(0.5) # set up the Pico W's onboard LED -pico_led = Pin('LED', Pin.OUT) +pico_led = Pin("LED", Pin.OUT) current_colour = graphics.create_pen(0, 0, 0) @@ -101,15 +101,15 @@ def update_leds(): try: network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler) uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK)) -except Exception as e: - print(f'Wifi connection failed! {e}') +except Exception as e: # noqa: BLE001 + print(f"Wifi connection failed! {e}") # get the first lot of data get_data() # start timer (the timer will call the function to update our data every UPDATE_INTERVAL) timer = Timer(-1) -timer.init(period=UPDATE_INTERVAL * 1000, mode=Timer.PERIODIC, callback=lambda t: get_data()) +timer.init(period=UPDATE_INTERVAL * 1000, mode=Timer.PERIODIC, callback=get_data) while True: # adjust brightness with LUX + and - diff --git a/examples/cosmic_unicorn/clock.py b/examples/cosmic_unicorn/clock.py index f514042..36117af 100644 --- a/examples/cosmic_unicorn/clock.py +++ b/examples/cosmic_unicorn/clock.py @@ -72,26 +72,26 @@ def from_hsv(h, s, v): return int(p), int(q), int(v) if i == 4: return int(t), int(p), int(v) - if i == 5: - return int(v), int(p), int(q) + # if i == 5: + return int(v), int(p), int(q) # function for drawing a gradient background def gradient_background(start_hue, start_sat, start_val, end_hue, end_sat, end_val): half_width = width // 2 - for x in range(0, half_width): + for x in range(half_width): hue = ((end_hue - start_hue) * (x / half_width)) + start_hue sat = ((end_sat - start_sat) * (x / half_width)) + start_sat val = ((end_val - start_val) * (x / half_width)) + start_val colour = from_hsv(hue, sat, val) graphics.set_pen(graphics.create_pen(int(colour[0]), int(colour[1]), int(colour[2]))) - for y in range(0, height): + for y in range(height): graphics.pixel(x, y) graphics.pixel(width - x - 1, y) colour = from_hsv(end_hue, end_sat, end_val) graphics.set_pen(graphics.create_pen(int(colour[0]), int(colour[1]), int(colour[2]))) - for y in range(0, height): + for y in range(height): graphics.pixel(half_width, y) @@ -127,7 +127,7 @@ def sync_time(): if wlan.status() < 0 or wlan.status() >= 3: break max_wait -= 1 - print('waiting for connection...') + print("waiting for connection...") time.sleep(0.2) redraw_display_if_reqd() diff --git a/examples/cosmic_unicorn/cosmic_paint/cosmic_paint.py b/examples/cosmic_unicorn/cosmic_paint/cosmic_paint.py index 30a17f9..745b4c9 100644 --- a/examples/cosmic_unicorn/cosmic_paint/cosmic_paint.py +++ b/examples/cosmic_unicorn/cosmic_paint/cosmic_paint.py @@ -22,12 +22,12 @@ @server.route("/", methods=["GET"]) -def route_index(request): +def route_index(_request): return send_file("cosmic_paint/index.html") @server.route("/static/", methods=["GET"]) -def route_static(request, path): +def route_static(_request, path): return send_file(f"cosmic_paint/static/{path}") @@ -38,7 +38,7 @@ def get_pixel(x, y): return None -def flood_fill(x, y, r, g, b): +def flood_fill(x, y): todo = [] def fill(x, y, c): @@ -73,9 +73,9 @@ def fill(x, y, c): fill(x, y, c) -@server.route('/paint') +@server.route("/paint") @websocket.with_websocket -async def echo(request, ws): +async def echo(_request, ws): while True: data = await ws.receive() try: @@ -91,7 +91,7 @@ async def echo(request, ws): data = await ws.receive() x, y, r, g, b = [int(n) for n in data[0:5]] graphics.set_pen(graphics.create_pen(r, g, b)) - flood_fill(x, y, r, g, b) + flood_fill(x, y) if data == "clear": graphics.set_pen(graphics.create_pen(0, 0, 0)) diff --git a/examples/cosmic_unicorn/eighties_super_computer.py b/examples/cosmic_unicorn/eighties_super_computer.py index 725980e..4da519a 100644 --- a/examples/cosmic_unicorn/eighties_super_computer.py +++ b/examples/cosmic_unicorn/eighties_super_computer.py @@ -3,12 +3,12 @@ from cosmic import CosmicUnicorn from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN as DISPLAY -''' +""" Random LEDs blink on and off mimicing the look of a movie super computer doing its work in the eighties. You can adjust the brightness with LUX + and -. -''' +""" cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) diff --git a/examples/cosmic_unicorn/exchange_ticker.py b/examples/cosmic_unicorn/exchange_ticker.py index 6b910a4..071dd81 100644 --- a/examples/cosmic_unicorn/exchange_ticker.py +++ b/examples/cosmic_unicorn/exchange_ticker.py @@ -13,7 +13,7 @@ from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN as DISPLAY import gc -URL = 'https://api.coinbase.com/v2/exchange-rates?currency={0}' +URL = "https://api.coinbase.com/v2/exchange-rates?currency={0}" currencies = {"Bitcoin": "BTC", "Ethereun": "ETH", "Pound": "GBP", "Dollar": "USD", "Dogecoin": "DOGE"} currency_keys = list(currencies.keys()) @@ -41,19 +41,19 @@ def status_handler(mode, status, ip): # reports wifi connection status print(mode, status, ip) - print('Connecting to wifi...') + print("Connecting to wifi...") if status is not None: if status: - print('Wifi connection successful!') + print("Wifi connection successful!") else: - print('Wifi connection failed!') + print("Wifi connection failed!") try: network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler) uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK)) -except Exception as e: - print(f'Wifi connection failed! {e}') +except Exception as e: # noqa: BLE001 + print(f"Wifi connection failed! {e}") def get_data(currency_selected): @@ -66,25 +66,23 @@ def get_data(currency_selected): cu.update(graphics) gc.collect() # open the json file - print('Requesting URL:') + print("Requesting URL:") print(URL.format(currencies[currency_selected])) r = urequests.get(URL.format(currencies[currency_selected])) gc.collect() # open the json data data_obj = r.json() - print('Data obtained!') + print("Data obtained!") r.close() return data_obj def calculate_xpos(length, cycle): cycle_phase = math.cos(math.pi * cycle / (cycles_per_sequence / 2)) - pos_x = int((-(length / 2) * 10) - (length / 2) * 10 * cycle_phase) - return pos_x + return int((-(length / 2) * 10) - (length / 2) * 10 * cycle_phase) def update_display(cycle): - graphics.set_pen(graphics.create_pen(20, 20, 20)) graphics.clear() graphics.set_pen(graphics.create_pen(100, 0, 0)) @@ -102,7 +100,7 @@ def update_base_currency(index): fetched_data = 0 global rates, rate_keys, currency_symbol, currency_rate, ref_currency_name fetched_data = get_data(currency_keys[index]) - rates = fetched_data['data']['rates'] + rates = fetched_data["data"]["rates"] rate_keys = list(rates.keys()) currency_symbol = rate_keys[index] currency_rate = str(rates[rate_keys[index]]) diff --git a/examples/cosmic_unicorn/feature_test.py b/examples/cosmic_unicorn/feature_test.py index 3ba5d0a..dd89168 100644 --- a/examples/cosmic_unicorn/feature_test.py +++ b/examples/cosmic_unicorn/feature_test.py @@ -3,11 +3,11 @@ from cosmic import CosmicUnicorn from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN as DISPLAY -''' +""" Displays some text, gradients and colours and demonstrates button use. You can adjust the brightness with LUX + and -. -''' +""" cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) @@ -17,15 +17,15 @@ def gradient(r, g, b): - for y in range(0, height): - for x in range(0, width): + for y in range(height): + for x in range(width): graphics.set_pen(graphics.create_pen(int((r * x) / 32), int((g * x) / 32), int((b * x) / 32))) graphics.pixel(x, y) def grid(r, g, b): - for y in range(0, height): - for x in range(0, width): + for y in range(height): + for x in range(width): if (x + y) % 2 == 0: graphics.set_pen(graphics.create_pen(r, g, b)) else: diff --git a/examples/cosmic_unicorn/feature_test_with_audio.py b/examples/cosmic_unicorn/feature_test_with_audio.py index 70fb2c1..d534144 100644 --- a/examples/cosmic_unicorn/feature_test_with_audio.py +++ b/examples/cosmic_unicorn/feature_test_with_audio.py @@ -5,7 +5,7 @@ from cosmic import CosmicUnicorn, Channel from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN as DISPLAY -''' +""" Displays some text, gradients and colours and demonstrates button use. Also demonstrates some of the audio / synth features. @@ -14,7 +14,7 @@ - Button C plays a sinewave (it's frequency can be adjusted with VOL + and -) - Button D plays a second sinewave (it's frequency can be adjusted with LUX + and -) - Sleep button stops the sounds -''' +""" gc.collect() @@ -96,15 +96,15 @@ def gradient(r, g, b): - for y in range(0, height): - for x in range(0, width): + for y in range(height): + for x in range(width): graphics.set_pen(graphics.create_pen(int((r * x) / 52), int((g * x) / 52), int((b * x) / 52))) graphics.pixel(x, y) def grid(r, g, b): - for y in range(0, height): - for x in range(0, width): + for y in range(height): + for x in range(width): if (x + y) % 2 == 0: graphics.set_pen(graphics.create_pen(r, g, b)) else: @@ -165,7 +165,7 @@ def next_beat(): beat = (beat + 1) % SONG_LENGTH -def tick(timer): +def tick(_timer): next_beat() diff --git a/examples/cosmic_unicorn/fire_effect.py b/examples/cosmic_unicorn/fire_effect.py index 510c499..316a004 100644 --- a/examples/cosmic_unicorn/fire_effect.py +++ b/examples/cosmic_unicorn/fire_effect.py @@ -3,11 +3,11 @@ from cosmic import CosmicUnicorn from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN as DISPLAY -''' +""" A pretty, procedural fire effect. You can adjust the brightness with LUX + and -. -''' +""" cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) @@ -30,7 +30,7 @@ def update(): _heat[x][height - 1] = 0.0 _heat[x][height - 2] = 0.0 - for c in range(fire_spawns): + for _ in range(fire_spawns): x = random.randint(0, width - 4) + 2 _heat[x + 0][height - 1] = 1.0 _heat[x + 1][height - 1] = 1.0 @@ -40,7 +40,7 @@ def update(): _heat[x - 1][height - 2] = 1.0 factor = damping_factor / 5.0 - for y in range(0, height - 2): + for y in range(height - 2): for x in range(1, width - 1): _heat[x][y] += _heat[x][y + 1] + _heat[x][y + 2] + _heat[x - 1][y + 1] + _heat[x + 1][y + 1] _heat[x][y] *= factor diff --git a/examples/cosmic_unicorn/http_text/html_text.py b/examples/cosmic_unicorn/http_text/html_text.py index 5f51c83..5298a8e 100644 --- a/examples/cosmic_unicorn/http_text/html_text.py +++ b/examples/cosmic_unicorn/http_text/html_text.py @@ -7,14 +7,14 @@ import uasyncio.core from tinyweb.server import webserver -''' +""" Display scrolling wisdom, quotes or greetz... from the internetz! You can adjust the brightness with LUX + and -. Requires network_manager.py , WIFI_CONFIG.py, logging.mpy and tinyweb from micropython/examples/common You'll also need index.html to be saved alongside this file. -''' +""" # Server Settings host = "0.0.0.0" @@ -22,7 +22,7 @@ def convert_colour(colour_str): - colour_str = colour_str.split(',') + colour_str = colour_str.split(",") print(colour_str) return colour_str[0], colour_str[1], colour_str[2] @@ -32,20 +32,19 @@ class text: def get(self, data): global MESSAGE, MESSAGE_COLOUR, BACKGROUND_COLOUR print(data) - if 'text' in data.keys(): - MESSAGE = data['text'] - if 'colourfg' in data.keys(): - MESSAGE_COLOUR = convert_colour(data['colourfg']) - if 'colourbg' in data.keys(): - BACKGROUND_COLOUR = convert_colour(data['colourbg']) - return {'message': 'text updated'}, 201 + if "text" in data.keys(): + MESSAGE = data["text"] + if "colourfg" in data.keys(): + MESSAGE_COLOUR = convert_colour(data["colourfg"]) + if "colourbg" in data.keys(): + BACKGROUND_COLOUR = convert_colour(data["colourbg"]) + return {"message": "text updated"}, 201 - def post(self, data): + def post(self, _data): + return {"message": "text updated"}, 201 - return {'message': 'text updated'}, 201 - -def status_handler(mode, status, ip): +def status_handler(_mode, status, ip): global MESSAGE print("Network: {}".format(WIFI_CONFIG.SSID)) status_text = "Connecting..." @@ -65,17 +64,17 @@ def status_handler(mode, status, ip): # Index page -@app.route('/') -async def index(request, response): +@app.route("/") +async def index(_request, response): # Send actual HTML page - await response.send_file('index.html', content_type='text/html') + await response.send_file("index.html", content_type="text/html") # HTTP redirection -@app.route('/redirect') -async def redirect(request, response): +@app.route("/redirect") +async def redirect(_request, response): # Start HTTP response with content-type text/html - await response.redirect('/') + await response.redirect("/") # constants for controlling scrolling text PADDING = 5 @@ -114,7 +113,7 @@ def run(): # Setup wifi network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler) - app.add_resource(text, '/update') + app.add_resource(text, "/update") # Connect to Wifi network asyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK)) @@ -183,8 +182,8 @@ async def message_update(): # The following is required to run both the web server and the scrolling text coherently -app._server_coro = app._tcp_server(host, port, app.backlog) +app._server_coro = app._tcp_server(host, port, app.backlog) # noqa: SLF001 loop = asyncio.get_event_loop() t1 = loop.create_task(message_update()) -t2 = loop.create_task(app._server_coro) +t2 = loop.create_task(app._server_coro) # noqa: SLF001 loop.run_forever() diff --git a/examples/cosmic_unicorn/launch/fire.py b/examples/cosmic_unicorn/launch/fire.py index da7b163..5c12a86 100644 --- a/examples/cosmic_unicorn/launch/fire.py +++ b/examples/cosmic_unicorn/launch/fire.py @@ -29,11 +29,11 @@ def init(): def pen_from_value(value): if value < 0.15: return palette[0] - elif value < 0.25: + if value < 0.25: return palette[1] - elif value < 0.35: + if value < 0.35: return palette[2] - elif value < 0.45: + if value < 0.45: return palette[3] return palette[4] @@ -46,7 +46,7 @@ def draw(): heat[x][height - 2] = 0.0 # add new fire spawns - for c in range(fire_spawns): + for _ in range(fire_spawns): x = random.randint(0, width - 4) + 2 heat[x + 0][height - 1] = 1.0 heat[x + 1][height - 1] = 1.0 @@ -56,7 +56,7 @@ def draw(): heat[x - 1][height - 2] = 1.0 # average and damp out each value to create rising flame effect - for y in range(0, height - 2): + for y in range(height - 2): for x in range(1, width - 1): # update this pixel by averaging the below pixels average = ( diff --git a/examples/cosmic_unicorn/launch/rainbow.py b/examples/cosmic_unicorn/launch/rainbow.py index 9008e25..e65f0b2 100644 --- a/examples/cosmic_unicorn/launch/rainbow.py +++ b/examples/cosmic_unicorn/launch/rainbow.py @@ -28,8 +28,8 @@ def from_hsv(h, s, v): return int(p), int(q), int(v) if i == 4: return int(t), int(p), int(v) - if i == 5: - return int(v), int(p), int(q) + # if i == 5: + return int(v), int(p), int(q) phase = 0 diff --git a/examples/cosmic_unicorn/launch/today.py b/examples/cosmic_unicorn/launch/today.py index d54a568..bf03f57 100644 --- a/examples/cosmic_unicorn/launch/today.py +++ b/examples/cosmic_unicorn/launch/today.py @@ -43,7 +43,7 @@ def network_connect(SSID, PSK): if wlan.status() < 0 or wlan.status() >= 3: break max_wait -= 1 - print('waiting for connection...') + print("waiting for connection...") time.sleep(1) # Handle connection error. Switches the Warn LED on. diff --git a/examples/cosmic_unicorn/lava_lamp.py b/examples/cosmic_unicorn/lava_lamp.py index 853d58e..6058002 100644 --- a/examples/cosmic_unicorn/lava_lamp.py +++ b/examples/cosmic_unicorn/lava_lamp.py @@ -4,11 +4,11 @@ from cosmic import CosmicUnicorn from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN as DISPLAY -''' +""" A 70s-tastic, procedural rainbow lava lamp. You can adjust the brightness with LUX + and -. -''' +""" cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) @@ -57,8 +57,8 @@ def from_hsv(h, s, v): return graphics.create_pen(int(p), int(q), int(v)) if i == 4: return graphics.create_pen(int(t), int(p), int(v)) - if i == 5: - return graphics.create_pen(int(v), int(p), int(q)) + # if i == 5: + return graphics.create_pen(int(v), int(p), int(q)) @micropython.native # noqa: F821 diff --git a/examples/cosmic_unicorn/nostalgia_prompt.py b/examples/cosmic_unicorn/nostalgia_prompt.py index 21080fa..9479b5c 100644 --- a/examples/cosmic_unicorn/nostalgia_prompt.py +++ b/examples/cosmic_unicorn/nostalgia_prompt.py @@ -2,12 +2,12 @@ from cosmic import CosmicUnicorn from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN as DISPLAY -''' +""" A collection of copies of classic terminal styles including C64, MS-DOS, Spectrum, and more. Images and text are drawn pixel by pixel from a pattern of Os and Xs. You can adjust the brightness with LUX + and -. -''' +""" cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) @@ -113,11 +113,11 @@ def draw(image, fg, bg, time_ms): for x in range(len(row)): pixel = row[x] # draw the prompt text - if pixel == 'O': + if pixel == "O": graphics.set_pen(fg_pen) # draw the caret blinking - elif pixel == 'X' and (time_ms // 300) % 2: + elif pixel == "X" and (time_ms // 300) % 2: graphics.set_pen(fg_pen) else: diff --git a/examples/cosmic_unicorn/numpy/fire_effect.py b/examples/cosmic_unicorn/numpy/fire_effect.py index 76cd5db..c68fbc0 100644 --- a/examples/cosmic_unicorn/numpy/fire_effect.py +++ b/examples/cosmic_unicorn/numpy/fire_effect.py @@ -56,7 +56,7 @@ def update(): heat[height - 2][:] = 0.0 # Add random fire spawns - for c in range(FIRE_SPAWNS): + for _ in range(FIRE_SPAWNS): x = random.randint(0, width - 4) + 2 heat[height - 1][x - 1:x + 1] = HEAT / 2.0 heat[height - 2][x - 1:x + 1] = HEAT diff --git a/examples/cosmic_unicorn/numpy/rgb_channels.py b/examples/cosmic_unicorn/numpy/rgb_channels.py index 77b596d..aa7a0ab 100644 --- a/examples/cosmic_unicorn/numpy/rgb_channels.py +++ b/examples/cosmic_unicorn/numpy/rgb_channels.py @@ -53,7 +53,7 @@ def draw(): blue = numpy.zeros((height, width)) # Reserved for combined channels -rgb = numpy.zeros((width * height * 4),) +rgb = numpy.zeros((width * height * 4)) # Stick some gradients in the channels so we have something to look at red[::] = numpy.linspace(0, 1, width) @@ -61,7 +61,7 @@ def draw(): # There has to be a better way!? for x in range(width): green[::, x] = numpy.linspace(0, 1, width) - blue[::, x] = numpy.linspace(1, 0, width,) + blue[::, x] = numpy.linspace(1, 0, width) t_count = 0 t_total = 0 diff --git a/examples/cosmic_unicorn/numpy/this_is_fine.py b/examples/cosmic_unicorn/numpy/this_is_fine.py index 9d64b5f..014ebf3 100644 --- a/examples/cosmic_unicorn/numpy/this_is_fine.py +++ b/examples/cosmic_unicorn/numpy/this_is_fine.py @@ -55,7 +55,7 @@ def update(): heat[height - 2][:] = 0.0 # Add random fire spawns - for c in range(FIRE_SPAWNS): + for _ in range(FIRE_SPAWNS): x = random.randint(0, width - 4) + 2 heat[height - 1][x - 1:x + 1] = HEAT / 2.0 heat[height - 2][x - 1:x + 1] = HEAT diff --git a/examples/cosmic_unicorn/rainbow.py b/examples/cosmic_unicorn/rainbow.py index 021c989..4c7e9f5 100644 --- a/examples/cosmic_unicorn/rainbow.py +++ b/examples/cosmic_unicorn/rainbow.py @@ -3,14 +3,14 @@ from cosmic import CosmicUnicorn from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN as DISPLAY -''' +""" Some good old fashioned rainbows! You can adjust the cycling speed with A and B, stripe width with C and D, hue with VOL + and -, and the brightness with LUX + and -. The sleep button stops the animation (can be started again with A or B). -''' +""" cu = CosmicUnicorn() graphics = PicoGraphics(DISPLAY) @@ -39,8 +39,8 @@ def from_hsv(h, s, v): return int(p), int(q), int(v) if i == 4: return int(t), int(p), int(v) - if i == 5: - return int(v), int(p), int(q) + # if i == 5: + return int(v), int(p), int(q) @micropython.native # noqa: F821 diff --git a/examples/cosmic_unicorn/scrolling_text.py b/examples/cosmic_unicorn/scrolling_text.py index 80c591c..516b741 100644 --- a/examples/cosmic_unicorn/scrolling_text.py +++ b/examples/cosmic_unicorn/scrolling_text.py @@ -2,11 +2,11 @@ from cosmic import CosmicUnicorn from picographics import PicoGraphics, DISPLAY_COSMIC_UNICORN as DISPLAY -''' +""" Display scrolling wisdom, quotes or greetz. You can adjust the brightness with LUX + and -. -''' +""" # constants for controlling scrolling text PADDING = 5 diff --git a/examples/cosmic_unicorn/today.py b/examples/cosmic_unicorn/today.py index 974ee58..719ce14 100644 --- a/examples/cosmic_unicorn/today.py +++ b/examples/cosmic_unicorn/today.py @@ -51,7 +51,7 @@ def network_connect(SSID, PSK): if wlan.status() < 0 or wlan.status() >= 3: break max_wait -= 1 - print('waiting for connection...') + print("waiting for connection...") time.sleep(1) # Handle connection error. Switches the Warn LED on. diff --git a/examples/cosmic_unicorn/weather/weather.py b/examples/cosmic_unicorn/weather/weather.py index 6f4a3e2..b2e91ac 100644 --- a/examples/cosmic_unicorn/weather/weather.py +++ b/examples/cosmic_unicorn/weather/weather.py @@ -13,7 +13,7 @@ TIMEZONE = "auto" # determines time zone from lat/long URL = "http://api.open-meteo.com/v1/forecast?latitude=" + str(LAT) + "&longitude=" + str(LNG) + "¤t_weather=true&timezone=" + TIMEZONE -WEATHER_TEXT = '' +WEATHER_TEXT = "" user_icon = None @@ -40,12 +40,12 @@ def get_data(): def calculate_bearing(d): # calculates a compass direction from the wind direction in degrees - dirs = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'] + dirs = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"] ix = round(d / (360. / len(dirs))) return dirs[ix % len(dirs)] -def status_handler(mode, status, ip): +def status_handler(_mode, _status, _ip): global MESSAGE print("Network: {}".format(WIFI_CONFIG.SSID)) diff --git a/examples/galactic_unicorn/audio/audio.py b/examples/galactic_unicorn/audio/audio.py index 10ce585..6646584 100644 --- a/examples/galactic_unicorn/audio/audio.py +++ b/examples/galactic_unicorn/audio/audio.py @@ -185,9 +185,9 @@ def __stop_i2s(self): if self.__audio_out is not None: self.__audio_out.deinit() # Deinit any active I2S comms - self.__state == WavPlayer.NONE # Return to the none state + self.__state = WavPlayer.NONE # Return to the none state - def __i2s_callback(self, arg): + def __i2s_callback(self, _arg): # PLAY if self.__state == WavPlayer.PLAY: if self.__mode == WavPlayer.MODE_WAV: diff --git a/examples/galactic_unicorn/audio/countdown_with_alarm.py b/examples/galactic_unicorn/audio/countdown_with_alarm.py index a08ee8b..3a097b2 100644 --- a/examples/galactic_unicorn/audio/countdown_with_alarm.py +++ b/examples/galactic_unicorn/audio/countdown_with_alarm.py @@ -69,8 +69,7 @@ def reset(self): self.timer.deinit() self.timer_running = False - def countdown(self, arg): - + def countdown(self, _arg): if self.total_seconds == 0: audio.play_wav("doorbell.wav", False) self.reset() diff --git a/examples/galactic_unicorn/cheerlights.py b/examples/galactic_unicorn/cheerlights.py index 62a06ee..a75c90b 100644 --- a/examples/galactic_unicorn/cheerlights.py +++ b/examples/galactic_unicorn/cheerlights.py @@ -26,37 +26,37 @@ def draw(colour): def status_handler(mode, status, ip): # reports wifi connection status print(mode, status, ip) - print('Connecting to wifi...') + print("Connecting to wifi...") if status is not None: if status: - print('Wifi connection successful!') + print("Wifi connection successful!") else: - print('Wifi connection failed!') + print("Wifi connection failed!") # set up wifi try: network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler) uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK)) -except Exception as e: - print(f'Wifi connection failed! {e}') +except Exception as e: # noqa: BLE001 + print(f"Wifi connection failed! {e}") # cheerlights # cheerlights colours -colours = {b'red': graphics.create_pen(0xff, 0x00, 0x00), b'green': graphics.create_pen(0x00, 0x80, 0x00), - b'blue': graphics.create_pen(0x00, 0x00, 0xff), - b'cyan': graphics.create_pen(0x00, 0xff, 0xff), b'white': graphics.create_pen(0xff, 0xff, 0xff), - b'oldlace': graphics.create_pen(0xfd, 0xf5, 0xe6), - b'purple': graphics.create_pen(0x80, 0x00, 0x80), b'magenta': graphics.create_pen(0xff, 0x00, 0xff), - b'yellow': graphics.create_pen(0xff, 0xff, 0x00), - b'orange': graphics.create_pen(0xff, 0xa5, 0x00), b'pink': graphics.create_pen(0xff, 0xc0, 0xcb)} +colours = {b"red": graphics.create_pen(0xff, 0x00, 0x00), b"green": graphics.create_pen(0x00, 0x80, 0x00), + b"blue": graphics.create_pen(0x00, 0x00, 0xff), + b"cyan": graphics.create_pen(0x00, 0xff, 0xff), b"white": graphics.create_pen(0xff, 0xff, 0xff), + b"oldlace": graphics.create_pen(0xfd, 0xf5, 0xe6), + b"purple": graphics.create_pen(0x80, 0x00, 0x80), b"magenta": graphics.create_pen(0xff, 0x00, 0xff), + b"yellow": graphics.create_pen(0xff, 0xff, 0x00), + b"orange": graphics.create_pen(0xff, 0xa5, 0x00), b"pink": graphics.create_pen(0xff, 0xc0, 0xcb)} # get request while True: - r = urequests.get('http://api.thingspeak.com/channels/1417/field/1/last.txt') - print(f'Colour: {r.content}') + r = urequests.get("http://api.thingspeak.com/channels/1417/field/1/last.txt") + print(f"Colour: {r.content}") if r.content in colours: draw(colours[r.content]) r.close() diff --git a/examples/galactic_unicorn/cheerlights_history.py b/examples/galactic_unicorn/cheerlights_history.py index aed2c55..7e0398a 100644 --- a/examples/galactic_unicorn/cheerlights_history.py +++ b/examples/galactic_unicorn/cheerlights_history.py @@ -15,7 +15,7 @@ from galactic import GalacticUnicorn from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY -URL = 'http://api.thingspeak.com/channels/1417/field/2/last.json' +URL = "http://api.thingspeak.com/channels/1417/field/2/last.json" UPDATE_INTERVAL = 327 # refresh interval in secs. Be nice to free APIs! # this esoteric number is used so that a column of LEDs equates (approximately) to an hour @@ -24,28 +24,28 @@ def status_handler(mode, status, ip): # reports wifi connection status print(mode, status, ip) - print('Connecting to wifi...') + print("Connecting to wifi...") if status is not None: if status: - print('Wifi connection successful!') + print("Wifi connection successful!") else: - print('Wifi connection failed!') + print("Wifi connection failed!") def hex_to_rgb(hex): # converts a hex colour code into RGB - h = hex.lstrip('#') + h = hex.lstrip("#") r, g, b = (int(h[i:i + 2], 16) for i in (0, 2, 4)) return r, g, b -def get_data(): +def get_data(_t=None): # open the json file - print(f'Requesting URL: {URL}') + print(f"Requesting URL: {URL}") r = urequests.get(URL) # open the json data j = r.json() - print('Data obtained!') + print("Data obtained!") r.close() # flash the onboard LED after getting data @@ -54,11 +54,11 @@ def get_data(): pico_led.value(False) # extract hex colour from the json data - hex = j['field2'] + hex = j["field2"] # add the new hex colour to the end of the array colour_array.append(hex) - print(f'Colour added to array: {hex}') + print(f"Colour added to array: {hex}") # remove the oldest colour in the array colour_array.pop(0) update_leds() @@ -91,7 +91,7 @@ def update_leds(): gu.set_brightness(0.5) # set up the Pico W's onboard LED -pico_led = Pin('LED', Pin.OUT) +pico_led = Pin("LED", Pin.OUT) current_colour = graphics.create_pen(0, 0, 0) @@ -102,15 +102,15 @@ def update_leds(): try: network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler) uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK)) -except Exception as e: - print(f'Wifi connection failed! {e}') +except Exception as e: # noqa: BLE001 + print(f"Wifi connection failed! {e}") # get the first lot of data get_data() # start timer (the timer will call the function to update our data every UPDATE_INTERVAL) timer = Timer(-1) -timer.init(period=UPDATE_INTERVAL * 1000, mode=Timer.PERIODIC, callback=lambda t: get_data()) +timer.init(period=UPDATE_INTERVAL * 1000, mode=Timer.PERIODIC, callback=get_data) while True: # adjust brightness with LUX + and - diff --git a/examples/galactic_unicorn/clock.py b/examples/galactic_unicorn/clock.py index 2d85c2d..4758fae 100644 --- a/examples/galactic_unicorn/clock.py +++ b/examples/galactic_unicorn/clock.py @@ -72,26 +72,26 @@ def from_hsv(h, s, v): return int(p), int(q), int(v) if i == 4: return int(t), int(p), int(v) - if i == 5: - return int(v), int(p), int(q) + # if i == 5: + return int(v), int(p), int(q) # function for drawing a gradient background def gradient_background(start_hue, start_sat, start_val, end_hue, end_sat, end_val): half_width = width // 2 - for x in range(0, half_width): + for x in range(half_width): hue = ((end_hue - start_hue) * (x / half_width)) + start_hue sat = ((end_sat - start_sat) * (x / half_width)) + start_sat val = ((end_val - start_val) * (x / half_width)) + start_val colour = from_hsv(hue, sat, val) graphics.set_pen(graphics.create_pen(int(colour[0]), int(colour[1]), int(colour[2]))) - for y in range(0, height): + for y in range(height): graphics.pixel(x, y) graphics.pixel(width - x - 1, y) colour = from_hsv(end_hue, end_sat, end_val) graphics.set_pen(graphics.create_pen(int(colour[0]), int(colour[1]), int(colour[2]))) - for y in range(0, height): + for y in range(height): graphics.pixel(half_width, y) @@ -128,7 +128,7 @@ def sync_time(): if wlan.status() < 0 or wlan.status() >= 3: break max_wait -= 1 - print('waiting for connection...') + print("waiting for connection...") time.sleep(0.2) redraw_display_if_reqd() diff --git a/examples/galactic_unicorn/eighties_super_computer.py b/examples/galactic_unicorn/eighties_super_computer.py index 501e5eb..d59a305 100644 --- a/examples/galactic_unicorn/eighties_super_computer.py +++ b/examples/galactic_unicorn/eighties_super_computer.py @@ -3,12 +3,12 @@ from galactic import GalacticUnicorn from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY -''' +""" Random LEDs blink on and off mimicing the look of a movie super computer doing its work in the eighties. You can adjust the brightness with LUX + and -. -''' +""" gu = GalacticUnicorn() graphics = PicoGraphics(DISPLAY) diff --git a/examples/galactic_unicorn/feature_test.py b/examples/galactic_unicorn/feature_test.py index 891076e..a4908c8 100644 --- a/examples/galactic_unicorn/feature_test.py +++ b/examples/galactic_unicorn/feature_test.py @@ -3,11 +3,11 @@ from galactic import GalacticUnicorn from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY -''' +""" Displays some text, gradients and colours and demonstrates button use. You can adjust the brightness with LUX + and -. -''' +""" gu = GalacticUnicorn() graphics = PicoGraphics(DISPLAY) @@ -17,15 +17,15 @@ def gradient(r, g, b): - for y in range(0, height): - for x in range(0, width): + for y in range(height): + for x in range(width): graphics.set_pen(graphics.create_pen(int((r * x) / 52), int((g * x) / 52), int((b * x) / 52))) graphics.pixel(x, y) def grid(r, g, b): - for y in range(0, height): - for x in range(0, width): + for y in range(height): + for x in range(width): if (x + y) % 2 == 0: graphics.set_pen(graphics.create_pen(r, g, b)) else: diff --git a/examples/galactic_unicorn/feature_test_with_audio.py b/examples/galactic_unicorn/feature_test_with_audio.py index bc246ab..e82fbab 100644 --- a/examples/galactic_unicorn/feature_test_with_audio.py +++ b/examples/galactic_unicorn/feature_test_with_audio.py @@ -5,7 +5,7 @@ from galactic import GalacticUnicorn, Channel from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY -''' +""" Displays some text, gradients and colours and demonstrates button use. Also demonstrates some of the audio / synth features. @@ -14,7 +14,7 @@ - Button C plays a sinewave (it's frequency can be adjusted with VOL + and -) - Button D plays a second sinewave (it's frequency can be adjusted with LUX + and -) - Sleep button stops the sounds -''' +""" gc.collect() @@ -60,15 +60,15 @@ def gradient(r, g, b): - for y in range(0, height): - for x in range(0, width): + for y in range(height): + for x in range(width): graphics.set_pen(graphics.create_pen(int((r * x) / 52), int((g * x) / 52), int((b * x) / 52))) graphics.pixel(x, y) def grid(r, g, b): - for y in range(0, height): - for x in range(0, width): + for y in range(height): + for x in range(width): if (x + y) % 2 == 0: graphics.set_pen(graphics.create_pen(r, g, b)) else: @@ -129,7 +129,7 @@ def next_beat(): beat = (beat + 1) % SONG_LENGTH -def tick(timer): +def tick(_timer): next_beat() diff --git a/examples/galactic_unicorn/fire_effect.py b/examples/galactic_unicorn/fire_effect.py index 9c12bd1..2b6bfd9 100644 --- a/examples/galactic_unicorn/fire_effect.py +++ b/examples/galactic_unicorn/fire_effect.py @@ -3,12 +3,12 @@ from galactic import GalacticUnicorn from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY -''' +""" A pretty, procedural fire effect. Switch between landscape fire and vertical fire using the A and B buttons! You can adjust the brightness with LUX + and -. -''' +""" gu = GalacticUnicorn() graphics = PicoGraphics(DISPLAY) @@ -47,7 +47,7 @@ def update(): heat[x][height - 1] = 0.0 heat[x][height - 2] = 0.0 - for c in range(fire_spawns): + for _ in range(fire_spawns): x = random.randint(0, width - 4) + 2 heat[x + 0][height - 1] = 1.0 heat[x + 1][height - 1] = 1.0 @@ -56,7 +56,7 @@ def update(): heat[x + 1][height - 2] = 1.0 heat[x - 1][height - 2] = 1.0 - for y in range(0, height - 2): + for y in range(height - 2): for x in range(1, width - 1): # update this pixel by averaging the below pixels average = ( diff --git a/examples/galactic_unicorn/galactic_paint/galactic_paint.py b/examples/galactic_unicorn/galactic_paint/galactic_paint.py index 91e034c..ac35936 100644 --- a/examples/galactic_unicorn/galactic_paint/galactic_paint.py +++ b/examples/galactic_unicorn/galactic_paint/galactic_paint.py @@ -22,12 +22,12 @@ @server.route("/", methods=["GET"]) -def route_index(request): +def route_index(_request): return send_file("galactic_paint/index.html") @server.route("/static/", methods=["GET"]) -def route_static(request, path): +def route_static(_request, path): return send_file(f"galactic_paint/static/{path}") @@ -38,7 +38,7 @@ def get_pixel(x, y): return None -def flood_fill(x, y, r, g, b): +def flood_fill(x, y): todo = [] def fill(x, y, c): @@ -73,9 +73,9 @@ def fill(x, y, c): fill(x, y, c) -@server.route('/paint') +@server.route("/paint") @websocket.with_websocket -async def echo(request, ws): +async def echo(_request, ws): while True: data = await ws.receive() try: @@ -91,7 +91,7 @@ async def echo(request, ws): data = await ws.receive() x, y, r, g, b = [int(n) for n in data[0:5]] graphics.set_pen(graphics.create_pen(r, g, b)) - flood_fill(x, y, r, g, b) + flood_fill(x, y) if data == "clear": graphics.set_pen(graphics.create_pen(0, 0, 0)) diff --git a/examples/galactic_unicorn/launch/fire.py b/examples/galactic_unicorn/launch/fire.py index 31238a5..78dda0d 100644 --- a/examples/galactic_unicorn/launch/fire.py +++ b/examples/galactic_unicorn/launch/fire.py @@ -29,11 +29,11 @@ def init(): def pen_from_value(value): if value < 0.15: return palette[0] - elif value < 0.25: + if value < 0.25: return palette[1] - elif value < 0.35: + if value < 0.35: return palette[2] - elif value < 0.45: + if value < 0.45: return palette[3] return palette[4] @@ -46,7 +46,7 @@ def draw(): heat[x][height - 2] = 0.0 # add new fire spawns - for c in range(fire_spawns): + for _ in range(fire_spawns): x = random.randint(0, width - 4) + 2 heat[x + 0][height - 1] = 1.0 heat[x + 1][height - 1] = 1.0 @@ -56,7 +56,7 @@ def draw(): heat[x - 1][height - 2] = 1.0 # average and damp out each value to create rising flame effect - for y in range(0, height - 2): + for y in range(height - 2): for x in range(1, width - 1): # update this pixel by averaging the below pixels average = ( diff --git a/examples/galactic_unicorn/launch/rainbow.py b/examples/galactic_unicorn/launch/rainbow.py index 388e9e0..da0dfc6 100644 --- a/examples/galactic_unicorn/launch/rainbow.py +++ b/examples/galactic_unicorn/launch/rainbow.py @@ -28,8 +28,8 @@ def from_hsv(h, s, v): return int(p), int(q), int(v) if i == 4: return int(t), int(p), int(v) - if i == 5: - return int(v), int(p), int(q) + # if i == 5: + return int(v), int(p), int(q) phase = 0 diff --git a/examples/galactic_unicorn/launch/retroprompt.py b/examples/galactic_unicorn/launch/retroprompt.py index 58c2cd3..bb0b515 100644 --- a/examples/galactic_unicorn/launch/retroprompt.py +++ b/examples/galactic_unicorn/launch/retroprompt.py @@ -87,11 +87,11 @@ def draw(): for x in range(len(row)): pixel = row[x] # draw the prompt text - if pixel == 'O': + if pixel == "O": graphics.set_pen(fg_pen) # draw the caret blinking - elif pixel == 'X' and (time_ms // 300) % 2: + elif pixel == "X" and (time_ms // 300) % 2: graphics.set_pen(fg_pen) else: diff --git a/examples/galactic_unicorn/lava_lamp.py b/examples/galactic_unicorn/lava_lamp.py index ed577e5..3840495 100644 --- a/examples/galactic_unicorn/lava_lamp.py +++ b/examples/galactic_unicorn/lava_lamp.py @@ -4,11 +4,11 @@ from galactic import GalacticUnicorn from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY -''' +""" A 70s-tastic, procedural rainbow lava lamp. You can adjust the brightness with LUX + and -. -''' +""" gu = GalacticUnicorn() graphics = PicoGraphics(DISPLAY) @@ -57,8 +57,8 @@ def from_hsv(h, s, v): return graphics.create_pen(int(p), int(q), int(v)) if i == 4: return graphics.create_pen(int(t), int(p), int(v)) - if i == 5: - return graphics.create_pen(int(v), int(p), int(q)) + # if i == 5: + return graphics.create_pen(int(v), int(p), int(q)) @micropython.native # noqa: F821 diff --git a/examples/galactic_unicorn/nostalgia_prompt.py b/examples/galactic_unicorn/nostalgia_prompt.py index 5cb23aa..a9086d4 100644 --- a/examples/galactic_unicorn/nostalgia_prompt.py +++ b/examples/galactic_unicorn/nostalgia_prompt.py @@ -2,13 +2,13 @@ from galactic import GalacticUnicorn from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY -''' +""" A collection of copies of classic terminal styles including C64, MS-DOS, Spectrum, and more. Images and text are drawn pixel by pixel from a pattern of Os and Xs. You can adjust the brightness with LUX + and -. -''' +""" gu = GalacticUnicorn() graphics = PicoGraphics(DISPLAY) @@ -77,11 +77,11 @@ def draw(image, fg, bg, time_ms): for x in range(len(row)): pixel = row[x] # draw the prompt text - if pixel == 'O': + if pixel == "O": graphics.set_pen(fg_pen) # draw the caret blinking - elif pixel == 'X' and (time_ms // 300) % 2: + elif pixel == "X" and (time_ms // 300) % 2: graphics.set_pen(fg_pen) else: diff --git a/examples/galactic_unicorn/numpy/fire_effect.py b/examples/galactic_unicorn/numpy/fire_effect.py index 8e1c5db..a9d0b80 100644 --- a/examples/galactic_unicorn/numpy/fire_effect.py +++ b/examples/galactic_unicorn/numpy/fire_effect.py @@ -58,7 +58,7 @@ def update(): heat[height - 2][:] = 0.0 # Add random fire spawns - for c in range(FIRE_SPAWNS): + for _ in range(FIRE_SPAWNS): x = random.randint(0, width - 4) + 2 heat[height - 1][x - 1:x + 1] = HEAT / 2.0 heat[height - 2][x - 1:x + 1] = HEAT diff --git a/examples/galactic_unicorn/numpy/this_is_fine.py b/examples/galactic_unicorn/numpy/this_is_fine.py index 16ae9e1..34a248c 100644 --- a/examples/galactic_unicorn/numpy/this_is_fine.py +++ b/examples/galactic_unicorn/numpy/this_is_fine.py @@ -58,7 +58,7 @@ def update(): heat[height - 2][:] = 0.0 # Add random fire spawns - for c in range(FIRE_SPAWNS): + for _ in range(FIRE_SPAWNS): x = random.randint(0, width - 4) + 2 heat[height - 1][x - 1:x + 1] = HEAT / 2.0 heat[height - 2][x - 1:x + 1] = HEAT diff --git a/examples/galactic_unicorn/rainbow.py b/examples/galactic_unicorn/rainbow.py index 019132b..90ff7bb 100644 --- a/examples/galactic_unicorn/rainbow.py +++ b/examples/galactic_unicorn/rainbow.py @@ -3,14 +3,14 @@ from galactic import GalacticUnicorn from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY -''' +""" Some good old fashioned rainbows! You can adjust the cycling speed with A and B, stripe width with C and D, hue with VOL + and -, and the brightness with LUX + and -. The sleep button stops the animation (can be started again with A or B). -''' +""" gu = GalacticUnicorn() graphics = PicoGraphics(DISPLAY) @@ -39,8 +39,8 @@ def from_hsv(h, s, v): return int(p), int(q), int(v) if i == 4: return int(t), int(p), int(v) - if i == 5: - return int(v), int(p), int(q) + # if i == 5: + return int(v), int(p), int(q) @micropython.native # noqa: F821 diff --git a/examples/galactic_unicorn/scrolling_text.py b/examples/galactic_unicorn/scrolling_text.py index 40d8c76..13c6b54 100644 --- a/examples/galactic_unicorn/scrolling_text.py +++ b/examples/galactic_unicorn/scrolling_text.py @@ -2,11 +2,11 @@ from galactic import GalacticUnicorn from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY -''' +""" Display scrolling wisdom, quotes or greetz. You can adjust the brightness with LUX + and -. -''' +""" # constants for controlling scrolling text PADDING = 5 diff --git a/examples/stellar_unicorn/audio/audio.py b/examples/stellar_unicorn/audio/audio.py index 10ce585..6646584 100644 --- a/examples/stellar_unicorn/audio/audio.py +++ b/examples/stellar_unicorn/audio/audio.py @@ -185,9 +185,9 @@ def __stop_i2s(self): if self.__audio_out is not None: self.__audio_out.deinit() # Deinit any active I2S comms - self.__state == WavPlayer.NONE # Return to the none state + self.__state = WavPlayer.NONE # Return to the none state - def __i2s_callback(self, arg): + def __i2s_callback(self, _arg): # PLAY if self.__state == WavPlayer.PLAY: if self.__mode == WavPlayer.MODE_WAV: diff --git a/examples/stellar_unicorn/audio/countdown_with_alarm.py b/examples/stellar_unicorn/audio/countdown_with_alarm.py index 08dbdc2..4017734 100644 --- a/examples/stellar_unicorn/audio/countdown_with_alarm.py +++ b/examples/stellar_unicorn/audio/countdown_with_alarm.py @@ -76,8 +76,7 @@ def reset(self): self.timer.deinit() self.timer_running = False - def countdown(self, arg): - + def countdown(self, _arg): if self.total_seconds == 0: audio.play_wav("doorbell.wav", False) self.reset() diff --git a/examples/stellar_unicorn/cheerlights_history.py b/examples/stellar_unicorn/cheerlights_history.py index f66f569..67845fd 100644 --- a/examples/stellar_unicorn/cheerlights_history.py +++ b/examples/stellar_unicorn/cheerlights_history.py @@ -16,7 +16,7 @@ from stellar import StellarUnicorn from picographics import PicoGraphics, DISPLAY_STELLAR_UNICORN as DISPLAY, PEN_P8 as PEN -URL = 'http://api.thingspeak.com/channels/1417/field/1/last.txt' +URL = "http://api.thingspeak.com/channels/1417/field/1/last.txt" UPDATE_INTERVAL = 60 * 60 / 16 # refresh interval in secs. Be nice to free APIs! # Calculated as 60 minutes * 60 seconds divided by number of pixels per row @@ -56,23 +56,23 @@ def status_handler(mode, status, ip): # reports wifi connection status print(mode, status, ip) - print('Connecting to wifi...') + print("Connecting to wifi...") if status is not None: if status: - print('Wifi connection successful!') + print("Wifi connection successful!") else: - print('Wifi connection failed!') + print("Wifi connection failed!") -def get_data(): +def get_data(_t=None): global index # open the json file if UPDATE_INTERVAL >= 60: - print(f'Requesting URL: {URL}') + print(f"Requesting URL: {URL}") r = urequests.get(URL) name = r.content.decode("utf-8").strip() r.close() - print('Data obtained!') + print("Data obtained!") else: print("Random test colour!") @@ -91,7 +91,7 @@ def get_data(): colour_array[index] = CHEERLIGHTS_COLOR_NAMES.index(name) index += 1 - print(f'Colour added to array: {name}') + print(f"Colour added to array: {name}") su.update(graphics) print("LEDs updated!") @@ -118,21 +118,21 @@ def get_data(): su.set_brightness(0.5) # set up the Pico W's onboard LED -pico_led = Pin('LED', Pin.OUT) +pico_led = Pin("LED", Pin.OUT) # set up wifi try: network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler) uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK)) -except Exception as e: - print(f'Wifi connection failed! {e}') +except Exception as e: # noqa: BLE001 + print(f"Wifi connection failed! {e}") # get the first lot of data get_data() # start timer (the timer will call the function to update our data every UPDATE_INTERVAL) timer = Timer(-1) -timer.init(period=int(UPDATE_INTERVAL * 1000), mode=Timer.PERIODIC, callback=lambda t: get_data()) +timer.init(period=int(UPDATE_INTERVAL * 1000), mode=Timer.PERIODIC, callback=get_data) while True: # adjust brightness with LUX + and - diff --git a/examples/stellar_unicorn/clock.py b/examples/stellar_unicorn/clock.py index 173ee70..9ae34bf 100644 --- a/examples/stellar_unicorn/clock.py +++ b/examples/stellar_unicorn/clock.py @@ -74,26 +74,26 @@ def from_hsv(h, s, v): return int(p), int(q), int(v) if i == 4: return int(t), int(p), int(v) - if i == 5: - return int(v), int(p), int(q) + # if i == 5: + return int(v), int(p), int(q) # function for drawing a gradient background def gradient_background(start_hue, start_sat, start_val, end_hue, end_sat, end_val): half_width = width // 2 - for x in range(0, half_width): + for x in range(half_width): hue = ((end_hue - start_hue) * (x / half_width)) + start_hue sat = ((end_sat - start_sat) * (x / half_width)) + start_sat val = ((end_val - start_val) * (x / half_width)) + start_val colour = from_hsv(hue, sat, val) graphics.set_pen(graphics.create_pen(int(colour[0]), int(colour[1]), int(colour[2]))) - for y in range(0, height): + for y in range(height): graphics.pixel(x, y) graphics.pixel(width - x - 1, y) colour = from_hsv(end_hue, end_sat, end_val) graphics.set_pen(graphics.create_pen(int(colour[0]), int(colour[1]), int(colour[2]))) - for y in range(0, height): + for y in range(height): graphics.pixel(half_width, y) @@ -129,7 +129,7 @@ def sync_time(): if wlan.status() < 0 or wlan.status() >= 3: break max_wait -= 1 - print('waiting for connection...') + print("waiting for connection...") time.sleep(0.2) redraw_display_if_reqd() diff --git a/examples/stellar_unicorn/eighties_super_computer.py b/examples/stellar_unicorn/eighties_super_computer.py index 351f301..4a35326 100644 --- a/examples/stellar_unicorn/eighties_super_computer.py +++ b/examples/stellar_unicorn/eighties_super_computer.py @@ -3,12 +3,12 @@ from stellar import StellarUnicorn from picographics import PicoGraphics, DISPLAY_STELLAR_UNICORN as DISPLAY -''' +""" Random LEDs blink on and off mimicking the look of a movie super computer doing its work in the eighties. You can adjust the brightness with LUX + and -. -''' +""" su = StellarUnicorn() graphics = PicoGraphics(DISPLAY) diff --git a/examples/stellar_unicorn/encoder_wheel.py b/examples/stellar_unicorn/encoder_wheel.py index 7ccd6d1..5dab208 100644 --- a/examples/stellar_unicorn/encoder_wheel.py +++ b/examples/stellar_unicorn/encoder_wheel.py @@ -63,8 +63,8 @@ def hsv_to_rgb(h, s, v): return p, q, v if i == 4: return t, p, v - if i == 5: - return v, p, q + # if i == 5: + return v, p, q # Simple function to clamp a value between 0.0 and 1.0 @@ -133,7 +133,7 @@ def sleep_until(end_time): wheel.set_rgb(position, 255, 255, 255) # Set the LEDs below the current position - for i in range(0, position): + for i in range(position): wheel.set_hsv(i, i / NUM_LEDS, saturation, brightness) # Set the LEDs after the current position diff --git a/examples/stellar_unicorn/exchange_ticker.py b/examples/stellar_unicorn/exchange_ticker.py index eb59332..348fb39 100644 --- a/examples/stellar_unicorn/exchange_ticker.py +++ b/examples/stellar_unicorn/exchange_ticker.py @@ -13,7 +13,7 @@ from picographics import PicoGraphics, DISPLAY_STELLAR_UNICORN as DISPLAY import gc -URL = 'https://api.coinbase.com/v2/exchange-rates?currency={0}' +URL = "https://api.coinbase.com/v2/exchange-rates?currency={0}" currencies = {"Bitcoin": "BTC", "Ethereun": "ETH", "Pound": "GBP", "Dollar": "USD", "Dogecoin": "DOGE"} currency_keys = list(currencies.keys()) @@ -41,23 +41,22 @@ def status_handler(mode, status, ip): # reports wifi connection status print(mode, status, ip) - print('Connecting to wifi...') + print("Connecting to wifi...") if status is not None: if status: - print('Wifi connection successful!') + print("Wifi connection successful!") else: - print('Wifi connection failed!') + print("Wifi connection failed!") try: network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler) uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK)) -except Exception as e: - print(f'Wifi connection failed! {e}') +except Exception as e: # noqa: BLE001 + print(f"Wifi connection failed! {e}") def get_data(currency_selected): - graphics.set_pen(graphics.create_pen(20, 20, 20)) graphics.clear() graphics.set_pen(graphics.create_pen(100, 100, 100)) @@ -66,25 +65,23 @@ def get_data(currency_selected): su.update(graphics) gc.collect() # open the json file - print('Requesting URL:') + print("Requesting URL:") print(URL.format(currencies[currency_selected])) r = urequests.get(URL.format(currencies[currency_selected])) gc.collect() # open the json data data_obj = r.json() - print('Data obtained!') + print("Data obtained!") r.close() return data_obj def calculate_xpos(length, cycle): cycle_phase = math.cos(math.pi * cycle / (cycles_per_sequence / 2)) - pos_x = int((-(length / 2) * 10) - (length / 2) * 10 * cycle_phase) - return pos_x + return int((-(length / 2) * 10) - (length / 2) * 10 * cycle_phase) def update_display(cycle): - graphics.set_pen(graphics.create_pen(20, 20, 20)) graphics.clear() graphics.set_pen(graphics.create_pen(100, 0, 0)) @@ -99,7 +96,7 @@ def update_base_currency(index): fetched_data = 0 global rates, rate_keys, currency_symbol, currency_rate, ref_currency_name fetched_data = get_data(currency_keys[index]) - rates = fetched_data['data']['rates'] + rates = fetched_data["data"]["rates"] rate_keys = list(rates.keys()) currency_symbol = rate_keys[index] currency_rate = str(rates[rate_keys[index]]) diff --git a/examples/stellar_unicorn/feature_test.py b/examples/stellar_unicorn/feature_test.py index 868d832..4ac5628 100644 --- a/examples/stellar_unicorn/feature_test.py +++ b/examples/stellar_unicorn/feature_test.py @@ -3,11 +3,11 @@ from stellar import StellarUnicorn from picographics import PicoGraphics, DISPLAY_STELLAR_UNICORN as DISPLAY -''' +""" Displays some text, gradients and colours and demonstrates button use. You can adjust the brightness with LUX + and -. -''' +""" su = StellarUnicorn() graphics = PicoGraphics(DISPLAY) @@ -17,15 +17,15 @@ def gradient(r, g, b): - for y in range(0, height): - for x in range(0, width): + for y in range(height): + for x in range(width): graphics.set_pen(graphics.create_pen(int((r * x) / 16), int((g * x) / 16), int((b * x) / 16))) graphics.pixel(x, y) def grid(r, g, b): - for y in range(0, height): - for x in range(0, width): + for y in range(height): + for x in range(width): if (x + y) % 2 == 0: graphics.set_pen(graphics.create_pen(r, g, b)) else: diff --git a/examples/stellar_unicorn/feature_test_with_audio.py b/examples/stellar_unicorn/feature_test_with_audio.py index 1c67de4..243e342 100644 --- a/examples/stellar_unicorn/feature_test_with_audio.py +++ b/examples/stellar_unicorn/feature_test_with_audio.py @@ -5,7 +5,7 @@ from stellar import StellarUnicorn, Channel from picographics import PicoGraphics, DISPLAY_STELLAR_UNICORN as DISPLAY -''' +""" Displays some text, gradients and colours and demonstrates button use. Also demonstrates some of the audio / synth features. @@ -14,7 +14,7 @@ - Button C plays a sinewave (it's frequency can be adjusted with VOL + and -) - Button D plays a second sinewave (it's frequency can be adjusted with LUX + and -) - Sleep button stops the sounds -''' +""" gc.collect() @@ -96,15 +96,15 @@ def gradient(r, g, b): - for y in range(0, height): - for x in range(0, width): + for y in range(height): + for x in range(width): graphics.set_pen(graphics.create_pen(int((r * x) / 52), int((g * x) / 52), int((b * x) / 52))) graphics.pixel(x, y) def grid(r, g, b): - for y in range(0, height): - for x in range(0, width): + for y in range(height): + for x in range(width): if (x + y) % 2 == 0: graphics.set_pen(graphics.create_pen(r, g, b)) else: @@ -165,7 +165,7 @@ def next_beat(): beat = (beat + 1) % SONG_LENGTH -def tick(timer): +def tick(_timer): next_beat() diff --git a/examples/stellar_unicorn/fire_effect.py b/examples/stellar_unicorn/fire_effect.py index d32d9c5..e94da89 100644 --- a/examples/stellar_unicorn/fire_effect.py +++ b/examples/stellar_unicorn/fire_effect.py @@ -3,11 +3,11 @@ from stellar import StellarUnicorn from picographics import PicoGraphics, DISPLAY_STELLAR_UNICORN as DISPLAY -''' +""" A pretty, procedural fire effect. You can adjust the brightness with LUX + and -. -''' +""" su = StellarUnicorn() graphics = PicoGraphics(DISPLAY) @@ -30,7 +30,7 @@ def update(): _heat[x][height - 1] = 0.0 _heat[x][height - 2] = 0.0 - for c in range(fire_spawns): + for _ in range(fire_spawns): x = random.randint(0, width - 4) + 2 _heat[x + 0][height - 1] = 1.0 _heat[x + 1][height - 1] = 1.0 @@ -40,7 +40,7 @@ def update(): _heat[x - 1][height - 2] = 1.0 factor = damping_factor / 5.0 - for y in range(0, height - 2): + for y in range(height - 2): for x in range(1, width - 1): _heat[x][y] += _heat[x][y + 1] + _heat[x][y + 2] + _heat[x - 1][y + 1] + _heat[x + 1][y + 1] _heat[x][y] *= factor diff --git a/examples/stellar_unicorn/http_text/html_text.py b/examples/stellar_unicorn/http_text/html_text.py index 33b0843..869a98c 100644 --- a/examples/stellar_unicorn/http_text/html_text.py +++ b/examples/stellar_unicorn/http_text/html_text.py @@ -7,14 +7,14 @@ import uasyncio.core from tinyweb.server import webserver -''' +""" Display scrolling wisdom, quotes or greetz... from the internetz! You can adjust the brightness with LUX + and -. Requires network_manager.py , WIFI_CONFIG.py, logging.mpy and tinyweb from micropython/examples/common You'll also need index.html to be saved alongside this file. -''' +""" # Server Settings host = "0.0.0.0" @@ -22,7 +22,7 @@ def convert_colour(colour_str): - colour_str = colour_str.split(',') + colour_str = colour_str.split(",") print(colour_str) return colour_str[0], colour_str[1], colour_str[2] @@ -32,20 +32,19 @@ class text: def get(self, data): global MESSAGE, MESSAGE_COLOUR, BACKGROUND_COLOUR print(data) - if 'text' in data.keys(): - MESSAGE = data['text'] - if 'colourfg' in data.keys(): - MESSAGE_COLOUR = convert_colour(data['colourfg']) - if 'colourbg' in data.keys(): - BACKGROUND_COLOUR = convert_colour(data['colourbg']) - return {'message': 'text updated'}, 201 + if "text" in data.keys(): + MESSAGE = data["text"] + if "colourfg" in data.keys(): + MESSAGE_COLOUR = convert_colour(data["colourfg"]) + if "colourbg" in data.keys(): + BACKGROUND_COLOUR = convert_colour(data["colourbg"]) + return {"message": "text updated"}, 201 - def post(self, data): + def post(self, _data): + return {"message": "text updated"}, 201 - return {'message': 'text updated'}, 201 - -def status_handler(mode, status, ip): +def status_handler(_mode, status, ip): global MESSAGE print("Network: {}".format(WIFI_CONFIG.SSID)) status_text = "Connecting..." @@ -65,17 +64,17 @@ def status_handler(mode, status, ip): # Index page -@app.route('/') -async def index(request, response): +@app.route("/") +async def index(_request, response): # Send actual HTML page - await response.send_file('index.html', content_type='text/html') + await response.send_file("index.html", content_type="text/html") # HTTP redirection -@app.route('/redirect') -async def redirect(request, response): +@app.route("/redirect") +async def redirect(_request, response): # Start HTTP response with content-type text/html - await response.redirect('/') + await response.redirect("/") # constants for controlling scrolling text PADDING = 5 @@ -114,7 +113,7 @@ def run(): # Setup wifi network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler) - app.add_resource(text, '/update') + app.add_resource(text, "/update") # Connect to Wifi network asyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK)) @@ -183,8 +182,8 @@ async def message_update(): # The following is required to run both the web server and the scrolling text coherently -app._server_coro = app._tcp_server(host, port, app.backlog) +app._server_coro = app._tcp_server(host, port, app.backlog) # noqa: SLF001 loop = asyncio.get_event_loop() t1 = loop.create_task(message_update()) -t2 = loop.create_task(app._server_coro) +t2 = loop.create_task(app._server_coro) # noqa: SLF001 loop.run_forever() diff --git a/examples/stellar_unicorn/launch/fire.py b/examples/stellar_unicorn/launch/fire.py index 2403458..12b197e 100644 --- a/examples/stellar_unicorn/launch/fire.py +++ b/examples/stellar_unicorn/launch/fire.py @@ -29,11 +29,11 @@ def init(): def pen_from_value(value): if value < 0.15: return palette[0] - elif value < 0.25: + if value < 0.25: return palette[1] - elif value < 0.35: + if value < 0.35: return palette[2] - elif value < 0.45: + if value < 0.45: return palette[3] return palette[4] @@ -46,7 +46,7 @@ def draw(): heat[x][height - 2] = 0.0 # add new fire spawns - for c in range(fire_spawns): + for _ in range(fire_spawns): x = random.randint(0, width - 4) + 2 heat[x + 0][height - 1] = 1.0 heat[x + 1][height - 1] = 1.0 @@ -56,7 +56,7 @@ def draw(): heat[x - 1][height - 2] = 1.0 # average and damp out each value to create rising flame effect - for y in range(0, height - 2): + for y in range(height - 2): for x in range(1, width - 1): # update this pixel by averaging the below pixels average = ( diff --git a/examples/stellar_unicorn/launch/rainbow.py b/examples/stellar_unicorn/launch/rainbow.py index 637c6ee..e4a1c80 100644 --- a/examples/stellar_unicorn/launch/rainbow.py +++ b/examples/stellar_unicorn/launch/rainbow.py @@ -28,8 +28,8 @@ def from_hsv(h, s, v): return int(p), int(q), int(v) if i == 4: return int(t), int(p), int(v) - if i == 5: - return int(v), int(p), int(q) + # if i == 5: + return int(v), int(p), int(q) phase = 0 diff --git a/examples/stellar_unicorn/launch/today.py b/examples/stellar_unicorn/launch/today.py index 59eba38..666cdaa 100644 --- a/examples/stellar_unicorn/launch/today.py +++ b/examples/stellar_unicorn/launch/today.py @@ -44,7 +44,7 @@ def network_connect(ssid, psk): if wlan.status() < 0 or wlan.status() >= 3: break max_wait -= 1 - print('waiting for connection...') + print("waiting for connection...") time.sleep(1) # Handle connection error. Switches the Warn LED on. diff --git a/examples/stellar_unicorn/lava_lamp.py b/examples/stellar_unicorn/lava_lamp.py index c7a1d26..2ac526a 100644 --- a/examples/stellar_unicorn/lava_lamp.py +++ b/examples/stellar_unicorn/lava_lamp.py @@ -4,11 +4,11 @@ from stellar import StellarUnicorn from picographics import PicoGraphics, DISPLAY_STELLAR_UNICORN as DISPLAY -''' +""" A 70s-tastic, procedural rainbow lava lamp. You can adjust the brightness with LUX + and -. -''' +""" su = StellarUnicorn() graphics = PicoGraphics(DISPLAY) @@ -57,8 +57,8 @@ def from_hsv(h, s, v): return graphics.create_pen(int(p), int(q), int(v)) if i == 4: return graphics.create_pen(int(t), int(p), int(v)) - if i == 5: - return graphics.create_pen(int(v), int(p), int(q)) + # if i == 5: + return graphics.create_pen(int(v), int(p), int(q)) @micropython.native # noqa: F821 diff --git a/examples/stellar_unicorn/nostalgia_prompt.py b/examples/stellar_unicorn/nostalgia_prompt.py index 8484f9c..680265e 100644 --- a/examples/stellar_unicorn/nostalgia_prompt.py +++ b/examples/stellar_unicorn/nostalgia_prompt.py @@ -2,12 +2,12 @@ from stellar import StellarUnicorn from picographics import PicoGraphics, DISPLAY_STELLAR_UNICORN as DISPLAY -''' +""" A collection of copies of classic terminal styles including C64, MS-DOS, Spectrum, and more. Images and text are drawn pixel by pixel from a pattern of Os and Xs. You can adjust the brightness with LUX + and -. -''' +""" su = StellarUnicorn() graphics = PicoGraphics(DISPLAY) @@ -113,11 +113,11 @@ def draw(image, fg, bg, time_ms): for x in range(len(row)): pixel = row[x] # draw the prompt text - if pixel == 'O': + if pixel == "O": graphics.set_pen(fg_pen) # draw the caret blinking - elif pixel == 'X' and (time_ms // 300) % 2: + elif pixel == "X" and (time_ms // 300) % 2: graphics.set_pen(fg_pen) else: diff --git a/examples/stellar_unicorn/numpy/fire_effect.py b/examples/stellar_unicorn/numpy/fire_effect.py index 851ada0..d6d62d7 100644 --- a/examples/stellar_unicorn/numpy/fire_effect.py +++ b/examples/stellar_unicorn/numpy/fire_effect.py @@ -56,7 +56,7 @@ def update(): heat[height - 2][:] = 0.0 # Add random fire spawns - for c in range(FIRE_SPAWNS): + for _ in range(FIRE_SPAWNS): x = random.randint(0, width - 4) + 2 heat[height - 1][x - 1:x + 1] = HEAT / 2.0 heat[height - 2][x - 1:x + 1] = HEAT diff --git a/examples/stellar_unicorn/numpy/rgb_channels.py b/examples/stellar_unicorn/numpy/rgb_channels.py index 44d6ce7..5f5b7fb 100644 --- a/examples/stellar_unicorn/numpy/rgb_channels.py +++ b/examples/stellar_unicorn/numpy/rgb_channels.py @@ -53,7 +53,7 @@ def draw(): blue = numpy.zeros((height, width)) # Reserved for combined channels -rgb = numpy.zeros((width * height * 4),) +rgb = numpy.zeros((width * height * 4)) # Stick some gradients in the channels so we have something to look at red[::] = numpy.linspace(0, 1, width) @@ -61,7 +61,7 @@ def draw(): # There has to be a better way!? for x in range(width): green[::, x] = numpy.linspace(0, 1, width) - blue[::, x] = numpy.linspace(1, 0, width,) + blue[::, x] = numpy.linspace(1, 0, width) t_count = 0 t_total = 0 diff --git a/examples/stellar_unicorn/numpy/this_is_fine.py b/examples/stellar_unicorn/numpy/this_is_fine.py index ee933a4..d369946 100644 --- a/examples/stellar_unicorn/numpy/this_is_fine.py +++ b/examples/stellar_unicorn/numpy/this_is_fine.py @@ -55,7 +55,7 @@ def update(): heat[height - 2][:] = 0.0 # Add random fire spawns - for c in range(FIRE_SPAWNS): + for _ in range(FIRE_SPAWNS): x = random.randint(0, width - 4) + 2 heat[height - 1][x - 1:x + 1] = HEAT / 2.0 heat[height - 2][x - 1:x + 1] = HEAT diff --git a/examples/stellar_unicorn/rainbow.py b/examples/stellar_unicorn/rainbow.py index 5619e0e..dcbf468 100644 --- a/examples/stellar_unicorn/rainbow.py +++ b/examples/stellar_unicorn/rainbow.py @@ -3,14 +3,14 @@ from stellar import StellarUnicorn from picographics import PicoGraphics, DISPLAY_STELLAR_UNICORN as DISPLAY -''' +""" Some good old fashioned rainbows! You can adjust the cycling speed with A and B, stripe width with C and D, hue with VOL + and -, and the brightness with LUX + and -. The sleep button stops the animation (can be started again with A or B). -''' +""" su = StellarUnicorn() graphics = PicoGraphics(DISPLAY) @@ -39,8 +39,8 @@ def from_hsv(h, s, v): return int(p), int(q), int(v) if i == 4: return int(t), int(p), int(v) - if i == 5: - return int(v), int(p), int(q) + # if i == 5: + return int(v), int(p), int(q) @micropython.native # noqa: F821 diff --git a/examples/stellar_unicorn/scrolling_text.py b/examples/stellar_unicorn/scrolling_text.py index 6235670..aa617b6 100644 --- a/examples/stellar_unicorn/scrolling_text.py +++ b/examples/stellar_unicorn/scrolling_text.py @@ -2,11 +2,11 @@ from stellar import StellarUnicorn from picographics import PicoGraphics, DISPLAY_STELLAR_UNICORN as DISPLAY -''' +""" Display scrolling wisdom, quotes or greetz. You can adjust the brightness with LUX + and -. -''' +""" # constants for controlling scrolling text PADDING = 5 diff --git a/examples/stellar_unicorn/stellar_paint/stellar_paint.py b/examples/stellar_unicorn/stellar_paint/stellar_paint.py index 6b72083..8c83153 100644 --- a/examples/stellar_unicorn/stellar_paint/stellar_paint.py +++ b/examples/stellar_unicorn/stellar_paint/stellar_paint.py @@ -22,12 +22,12 @@ @server.route("/", methods=["GET"]) -def route_index(request): +def route_index(_request): return send_file("stellar_paint/index.html") @server.route("/static/", methods=["GET"]) -def route_static(request, path): +def route_static(_request, path): return send_file(f"stellar_paint/static/{path}") @@ -38,7 +38,7 @@ def get_pixel(x, y): return None -def flood_fill(x, y, r, g, b): +def flood_fill(x, y): todo = [] def fill(x, y, c): @@ -73,9 +73,9 @@ def fill(x, y, c): fill(x, y, c) -@server.route('/paint') +@server.route("/paint") @websocket.with_websocket -async def echo(request, ws): +async def echo(_request, ws): while True: data = await ws.receive() try: @@ -91,7 +91,7 @@ async def echo(request, ws): data = await ws.receive() x, y, r, g, b = [int(n) for n in data[0:5]] graphics.set_pen(graphics.create_pen(r, g, b)) - flood_fill(x, y, r, g, b) + flood_fill(x, y) if data == "clear": graphics.set_pen(graphics.create_pen(0, 0, 0)) diff --git a/examples/stellar_unicorn/today.py b/examples/stellar_unicorn/today.py index e957ee2..a37fa04 100644 --- a/examples/stellar_unicorn/today.py +++ b/examples/stellar_unicorn/today.py @@ -51,7 +51,7 @@ def network_connect(SSID, PSK): if wlan.status() < 0 or wlan.status() >= 3: break max_wait -= 1 - print('waiting for connection...') + print("waiting for connection...") time.sleep(1) # Handle connection error. Switches the Warn LED on. diff --git a/examples/stellar_unicorn/weather/weather.py b/examples/stellar_unicorn/weather/weather.py index 2be0355..f0fd3ab 100644 --- a/examples/stellar_unicorn/weather/weather.py +++ b/examples/stellar_unicorn/weather/weather.py @@ -54,7 +54,7 @@ def get_data(): def calculate_bearing(d): # calculates a compass direction from the wind direction in degrees - dirs = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW'] + dirs = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"] ix = round(d / (360. / len(dirs))) return dirs[ix % len(dirs)] @@ -62,12 +62,12 @@ def calculate_bearing(d): def status_handler(mode, status, ip): # reports wifi connection status print(mode, status, ip) - print('Connecting to wifi...') + print("Connecting to wifi...") if status is not None: if status: - print('Wifi connection successful!') + print("Wifi connection successful!") else: - print('Wifi connection failed!') + print("Wifi connection failed!") # create objects and picographics surface for drawing @@ -103,8 +103,8 @@ def status_handler(mode, status, ip): try: network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler) uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK)) -except Exception as e: - print(f'Wifi connection failed! {e}') +except Exception as e: # noqa: BLE001 + print(f"Wifi connection failed! {e}") while True: # adjust brightness with LUX + and - diff --git a/modules/wireless/ezwifi.py b/modules/wireless/ezwifi.py index a840a32..cbbac98 100644 --- a/modules/wireless/ezwifi.py +++ b/modules/wireless/ezwifi.py @@ -48,7 +48,7 @@ async def _log(self, text, level=LogLevel.INFO): def on(self, handler_name, handler=None): if handler_name not in self._events.keys(): - raise ValueError(f"Invalid event: \"{handler_name}\"") + raise ValueError(f'Invalid event: "{handler_name}"') def _on(handler): self._events[handler_name] = handler @@ -115,8 +115,8 @@ def _secrets(self): if not WIFI_SSID: raise ValueError("secrets.py: WIFI_SSID is empty!") return WIFI_SSID, WIFI_PASSWORD - except ImportError: - raise ImportError("secrets.py: missing or invalid!") + except ImportError as err: + raise ImportError("secrets.py: missing or invalid!") from err def connect(**kwargs):