Skip to content

Commit

Permalink
Several fixes
Browse files Browse the repository at this point in the history
- Now detects Xiao EPS32C3
- Set Pico buffer size to 32
- Fixed timezone adjustment for Pico
- No longer tries telnet if port contains a /
  • Loading branch information
dhylands committed Jan 20, 2024
1 parent b87878c commit bfacb5b
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions rshell/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def num_devices():
def is_micropython_usb_device(port):
"""Checks a USB device to see if it looks like a MicroPython device.
"""
global USB_BUFFER_SIZE
if type(port).__name__ == 'Device':
# Assume its a pyudev.device.Device
if ('ID_BUS' not in port or port['ID_BUS'] != 'usb' or
Expand All @@ -242,9 +243,12 @@ def is_micropython_usb_device(port):
return True
# Check Raspberry Pi Pico
if usb_id.startswith('usb vid:pid=2e8a:0005'):
global USB_BUFFER_SIZE
USB_BUFFER_SIZE = RPI_PICO_USB_BUFFER_SIZE
return True
# Check for XIAO ESP32C3
if usb_id.startswith('usb vid:pid=303a:4001'):
USB_BUFFER_SIZE = 256
return True
# Check for Teensy VID:PID
if usb_id.startswith('usb vid:pid=16c0:0483'):
return True
Expand Down Expand Up @@ -325,8 +329,10 @@ def autoscan():
"""autoscan will check all of the serial ports to see if they have
a matching VID:PID for a MicroPython board.
"""
global BUFFER_SIZE
for port in serial.tools.list_ports.comports():
if is_micropython_usb_device(port):
BUFFER_SIZE = USB_BUFFER_SIZE
connect_serial(port[0])


Expand Down Expand Up @@ -1386,14 +1392,17 @@ def add_arg(*args, **kwargs):

def connect(port, baud=115200, user='micro', password='python', wait=0):
"""Tries to connect automagically via network or serial."""
try:
ip_address = socket.gethostbyname(port)
#print('Connecting to ip', ip_address)
connect_telnet(port, ip_address, user=user, password=password)
except (socket.gaierror, ValueError):
# Doesn't look like a hostname or IP-address, assume its a serial port
#print('connecting to serial', port)
if '/' in port:
connect_serial(port, baud=baud, wait=wait)
else:
try:
ip_address = socket.gethostbyname(port)
#print('Connecting to ip', ip_address)
connect_telnet(port, ip_address, user=user, password=password)
except (socket.gaierror, ValueError):
# Doesn't look like a hostname or IP-address, assume its a serial port
#print('connecting to serial', port)
connect_serial(port, baud=baud, wait=wait)


def connect_telnet(name, ip_address=None, user='micro', password='python'):
Expand Down Expand Up @@ -1535,8 +1544,12 @@ def __init__(self, pyb):

self.time_offset = calendar.timegm(epoch_tuple)
# The pyboard maintains its time as localtime, whereas unix and
# esp32 maintain their time as GMT
self.adjust_for_timezone = (epoch_tuple[0] != 1970)
# esp32 maintain their time as GMT.
if self.sysname == 'rp2':
# The Pico uses a 1970 epoch, but uses localtime
self.adjust_for_timezone = True
else:
self.adjust_for_timezone = (epoch_tuple[0] != 1970)


def check_pyb(self):
Expand Down

0 comments on commit bfacb5b

Please sign in to comment.