diff --git a/examples/sparkles.py b/examples/sparkles.py index 19a7c00..a797c22 100644 --- a/examples/sparkles.py +++ b/examples/sparkles.py @@ -17,42 +17,38 @@ period = math.pi * EFFECT_SPEED -try: - while True: - t = time.ticks_ms() / 1000 * period - t *= 0.5 - - for i in range(NUM_LEDS): - led_offset = i / NUM_LEDS - led_offset *= math.pi - led_offset *= 3 - led_offset += t - - # A sine with a 2x period, shifted to 0 to 254 - # This provides a brightness cycling effect phase-locked to the LEDs - br = (math.sin(t / 2 + led_offset) + 1) * 127 - - # Calculate slightly out of phase sine waves for the red, green and blue channels - r = (math.sin(led_offset + (period * 0.85)) + 1) / 2 - g = (math.sin(led_offset + (period * 0.90)) + 1) / 2 - b = (math.sin(led_offset + (period * 0.95)) + 1) / 2 - - # Convert the slow procession of the sine wave into a brief pulse - # by raising it by a power we've called EFFECT_SHARPNESS - # https://www.wolframalpha.com/input?i=plot+pow%28%28sin%28x%29+%2B+1%29+%2F+2.0%2C+10%29%2C+%28sin%28x%29+%2B+1%29+%2F+2.0 - r = min(1, max(0, math.pow(r, EFFECT_SHARPNESS))) - g = min(1, max(0, math.pow(g, EFFECT_SHARPNESS))) - b = min(1, max(0, math.pow(b, EFFECT_SHARPNESS))) - - # Tune the output colours and apply brightness - # This is a nice greeny teal - r = 0 - g = int(g * br) - b = int(g * 0.6) - - led_strip.set_rgb(i, g, r, b) - - time.sleep(1.0 / EFFECT_FPS) -finally: - led_strip.clear() - led_strip.stop() +while True: + t = time.ticks_ms() / 1000 * period + t *= 0.5 + + for i in range(NUM_LEDS): + led_offset = i / NUM_LEDS + led_offset *= math.pi + led_offset *= 3 + led_offset += t + + # A sine with a 2x period, shifted to 0 to 254 + # This provides a brightness cycling effect phase-locked to the LEDs + br = (math.sin(t / 2 + led_offset) + 1) * 127 + + # Calculate slightly out of phase sine waves for the red, green and blue channels + r = (math.sin(led_offset + (period * 0.85)) + 1) / 2 + g = (math.sin(led_offset + (period * 0.90)) + 1) / 2 + b = (math.sin(led_offset + (period * 0.95)) + 1) / 2 + + # Convert the slow procession of the sine wave into a brief pulse + # by raising it by a power we've called EFFECT_SHARPNESS + # https://www.wolframalpha.com/input?i=plot+pow%28%28sin%28x%29+%2B+1%29+%2F+2.0%2C+10%29%2C+%28sin%28x%29+%2B+1%29+%2F+2.0 + r = min(1, max(0, math.pow(r, EFFECT_SHARPNESS))) + g = min(1, max(0, math.pow(g, EFFECT_SHARPNESS))) + b = min(1, max(0, math.pow(b, EFFECT_SHARPNESS))) + + # Tune the output colours and apply brightness + # This is a nice greeny teal + r = 0 + g = int(g * br) + b = int(g * 0.6) + + led_strip.set_rgb(i, g, r, b) + + time.sleep(1.0 / EFFECT_FPS) diff --git a/modules/wireless/ezwifi.py b/modules/wireless/ezwifi.py index 0706dd5..54ff83f 100644 --- a/modules/wireless/ezwifi.py +++ b/modules/wireless/ezwifi.py @@ -20,6 +20,8 @@ def __init__(self, **kwargs): self._verbose = get("verbose", False) + self._spce = get("spce", False) + self._events = { "connected": get("connected", None), "failed": get("failed", None), @@ -28,7 +30,14 @@ def __init__(self, **kwargs): "error": get("error", None) } - self._if = network.WLAN(network.STA_IF) + if self._spce: + # Use the SP/CE pins for this board + wifi_pins = {"pin_on": 8, "pin_out": 11, "pin_in": 11, "pin_wake": 11, "pin_clock": 10, "pin_cs": 9} + else: + # Try to get custom pins from kwargs + wifi_pins = {key: kwargs[key] for key in kwargs if key.startswith("pin_")} + + self._if = network.WLAN(network.STA_IF, **wifi_pins) self._if.active(True) # self._if.config(pm=0xa11140) # TODO: ??? self._statuses = {v: k[5:] for (k, v) in network.__dict__.items() if k.startswith("STAT_")} @@ -120,5 +129,8 @@ def _secrets(self): raise ImportError("secrets.py: missing or invalid!") from e -def connect(**kwargs): - return asyncio.get_event_loop().run_until_complete(EzWiFi(**kwargs).connect(retries=kwargs.get("retries", 10))) +def connect(*args, **kwargs): + ssid, password = None, None + if len(args) == 2: + ssid, password = args + return asyncio.get_event_loop().run_until_complete(EzWiFi(**kwargs).connect(ssid, password, retries=kwargs.get("retries", 10))) diff --git a/modules/wireless/lte.py b/modules/wireless/lte.py index 986d9c5..0f0e1a0 100644 --- a/modules/wireless/lte.py +++ b/modules/wireless/lte.py @@ -33,6 +33,7 @@ def __init__(self, apn, uart=None, reset_pin=None, netlight_pin=None, netlight_l # Set PPP timeouts and rxbuf self._uart.init( + baudrate=DEFAULT_UART_STARTUP_BAUD, timeout=DEFAULT_UART_TIMEOUT, timeout_char=DEFAULT_UART_TIMEOUT_CHAR, rxbuf=DEFAULT_UART_RXBUF) @@ -80,6 +81,11 @@ def stop_ppp(self): self._ppp.disconnect() self._send_at_command(f"AT+IPR={DEFAULT_UART_STARTUP_BAUD}") self._flush_uart() + self._uart.init( + baudrate=DEFAULT_UART_STARTUP_BAUD, + timeout=DEFAULT_UART_TIMEOUT, + timeout_char=DEFAULT_UART_TIMEOUT_CHAR, + rxbuf=DEFAULT_UART_RXBUF) def start_ppp(self, baudrate=DEFAULT_UART_BAUD, connect=True): self._wait_ready(poll_time=1.0, timeout=30)