def handleReset(): global idle_start if current != (0, 0, 0, 0): idle_start = cur_time() if cur_time() - startup_monotonic > RESTART_THRESHOLD and cur_time( ) - idle_start > IDLE_THRESHOLD: microcontroller.reset()
def enter_bootloader(): global ctrl, disp disp.fill(0) disp.text(10, 10, '''Bootloader Mode Entered''', size=2) ctrl.on_next_reset(ctrl.RunMode.BOOTLOADER) ctrl.reset()
def reset_keyboard(): try: import machine machine.reset() except ImportError: import microcontroller microcontroller.reset()
def loop(): fade() singleCursor() sparkle() glitchPulse() # For some reason, this program freezes occasionally. # I don't want to debug CircuitPython. microcontroller.reset()
def reset_bootloader(): try: import machine machine.bootloader() except ImportError: import microcontroller microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER) microcontroller.reset()
def reset(*args, **kwargs): try: import machine machine.reset() except ImportError: import microcontroller microcontroller.reset()
def _try_reconnect(e): print(f"Failed mqtt loop: {e}") _inc_counter("fail_loop") time.sleep(3) try: client.disconnect() client.connect() except Exception as e: # bye bye cruel world print(f"FATAL! Failed reconnect: {e}") microcontroller.reset()
def get_pressed(self): buttons = self.buttons.get_pressed() if buttons & K_Z: now = time.monotonic() if self.last_z_press: if now - self.last_z_press > 5: import microcontroller microcontroller.reset() else: self.last_z_press = now else: self.last_z_press = None return buttons
def _receive_uart(self, keyboard): if self._uart is not None and self._uart.in_waiting > 0 or self._uart_buffer: if self._uart.in_waiting >= 60: # This is a dirty hack to prevent crashes in unrealistic cases import microcontroller microcontroller.reset() while self._uart.in_waiting >= 3: self._uart_buffer.append(self._uart.read(3)) if self._uart_buffer: keyboard.secondary_matrix_update = bytearray(self._uart_buffer.pop(0)) return
def _receive_uart(self, keyboard): if self._uart is not None and self._uart.in_waiting > 0 or self._uart_buffer: if self._uart.in_waiting >= 60: # This is a dirty hack to prevent crashes in unrealistic cases import microcontroller microcontroller.reset() while self._uart.in_waiting >= 4: # Check the header if self._uart.read(1) == self.uart_header: update = self._uart.read(2) # check the checksum if self._checksum(update) == self._uart.read(1): self._uart_buffer.append( self._deserialize_update(update)) if self._uart_buffer: keyboard.secondary_matrix_update = self._uart_buffer.pop(0)
def poll_for_host_comms(self): poll_time = time.monotonic() cmd, name, value = self.get_memory() if cmd == _CMD_GET: self._process_host_get(name) elif cmd == _CMD_SET: self._process_host_set(name, value) elif cmd == _CMD_RESET: if value == _CMD_RESET_USB: stdout("Host resetting USB IC") self.reset() self.configure() elif value == _CMD_RESET_MCU: stdout("Host rebooting MCU") microcontroller.reset() elif value == _CMD_RESET_BOOTLOADER: stdout("Host rebooting MCU into bootloader mode") microcontroller.on_next_reset( microcontroller.RunMode.BOOTLOADER) microcontroller.reset() elif cmd == _CMD_SAVE: stdout("Saving configuration to INI file") result = self._save_config_to_ini() self.set_memory(_CMD_SAVE, 0, result) if self._last_poll_time is not None and self.config["reset_on_delay"]: if poll_time - self._last_poll_time > self.config[ "loop_delay"] * 10: ## Still need to reset history, otherwise RuntimeError will be ## continously raised once the first delay occurs. self._last_poll_time = poll_time raise RuntimeError("Excessive loop delay") self._last_poll_time = poll_time
def _receive_from_slave(self): if self.uart is not None and self.uart.in_waiting > 0 or self.uart_buffer: if self.uart.in_waiting >= 60: # This is a dirty hack to prevent crashes in unrealistic cases import microcontroller microcontroller.reset() while self.uart.in_waiting >= 3: self.uart_buffer.append(self.uart.read(3)) if self.uart_buffer: update = bytearray(self.uart_buffer.pop(0)) # Built in debug mode switch if update == b'DEB': print(self.uart.readline()) return None return update return None
using a different board or form of NeoPixels. This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket). """ import time import microcontroller import board import neopixel from adafruit_led_animation.animation.comet import Comet from adafruit_led_animation.color import PURPLE # Update to match the pin connected to your NeoPixels pixel_pin = board.A3 # Update to match the number of NeoPixels you have connected pixel_num = 30 pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False) comet = Comet(pixels, speed=0.02, color=PURPLE, tail_length=10, bounce=True) while True: comet.animate() if time.monotonic() > 3600: # After an hour passes, reset the board. microcontroller.reset() # pylint: disable=no-member
def reset_into_bootloader(): import microcontroller microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER) microcontroller.reset()
if not ss.digital_read(BUTTON_1): selection = "Yanny" ss.digital_write(LED_1, True) myservo.angle = LOOKLEFT break if not ss.digital_read(BUTTON_2): selection = "Laurel" ss.digital_write(LED_2, True) myservo.angle = LOOKRIGHT break # if we havent selected, wait until they do! if a.playing and time.monotonic() - t > 15.5: a.pause() # now we have a selection! with open(logfile, "a") as fp: print("Writing!" + selection + ", 1\n") fp.write(selection + ", 1\n") fp.flush() print("Written") # OK play the rest of the music a.resume() while a.playing: pass ss.digital_write(LED_1, False) ss.digital_write(LED_2, False) microcontroller.reset()
def restart_tests(num_test_bytes): nvm[0:num_test_bytes] = bytearray(num_test_bytes) reset()
def reset_on_pin(): if safe.value is False: import microcontroller microcontroller.on_next_reset(microcontroller.RunMode.SAFE_MODE) microcontroller.reset()
dial.update() if dial.rose: pulse_count = pulse_count + 1 last_pulse_time = time.monotonic() return pulse_count pixel = neopixel.NeoPixel(board.NEOPIXEL, 1) print("Rotary phone USB keypad") while True: receiver.update() if receiver.fell: # only dial when receiver is off hook print("Off hook") pixel[0] = 0x00ff00 microcontroller.reset() # the boot.py enables usb_hid if off hook if receiver.rose: print("On hook") pixel[0] = 0xff0000 microcontroller.reset() # the boot.py disables usb_hid if on hook # if not on_hook: num_pulses = read_rotary_dial_pulses() if num_pulses: print("pulse count:", num_pulses) if not on_hook: kbd.send(keymap[num_pulses - 1])
play_file("Explosion3.wav") for g in range(224, -1, -16): PAD((g, g, g)) np[BOMB] = (g, g, g) np.show() sleep(.1) np.fill((0, 0, 0)) BOMB = randint(9, 14) if life == 0: scroll('end.txt', 'down') while btn_a.value != True: picdraw('end.txt') sleep(1) picdraw('a.txt') sleep(1) reset() if life > 0: for i in range(life): scroll(PICTURES[6], 'down') play_file('Beep1.wav') sleep(.3) elif BOMB == DIG: break elif BOMB == PAD_pos + 1: np[PAD_pos + 1] = color break if btn_a.value == True and DIG > 48: DIG -= 1 PAD_pos -= 1 if btn_a.value == True and DIG == 48: DIG = 54
def reset(*args, **kwargs): import microcontroller microcontroller.reset()
def bootloader(*args, **kwargs): import microcontroller microcontroller.on_next_reset(microcontroller.RunMode.BOOTLOADER) microcontroller.reset()