Skip to content

Commit 55ef822

Browse files
committed
Add enter_bootloader
1 parent 0a9350b commit 55ef822

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pslab/sciencelab.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
if you need to use several at once the ScienceLab class provides a convenient
55
collection.
66
"""
7+
import time
78
from typing import Iterable, List
89

910
import pslab.protocol as CP
@@ -126,6 +127,17 @@ def reset(self):
126127
self.send_byte(CP.COMMON)
127128
self.send_byte(CP.RESTORE_STANDALONE)
128129

130+
def enter_bootloader(self):
131+
"""Reboot and stay in bootloader mode."""
132+
self.reset()
133+
self.interface.baudrate = 460800
134+
# The PSLab's RGB LED flashes some colors on boot.
135+
boot_lightshow_time = 0.6
136+
# Wait before sending magic number to make sure UART is initialized.
137+
time.sleep(boot_lightshow_time / 2)
138+
# PIC24 UART RX buffer is four bytes deep; no need to time it perfectly.
139+
self.write(CP.Integer.pack(0xDECAFBAD))
140+
129141
def rgb_led(self, colors: List, output: str = "RGB", order: str = "GRB"):
130142
"""Set shade of a WS2812B RGB LED.
131143

0 commit comments

Comments
 (0)