Skip to content

Commit

Permalink
Add support for SoftUART
Browse files Browse the repository at this point in the history
 - add a type to the uart config in json SoftUART (or default)
 - Tested with https://github.com/dmascord/micropython/blob/master/ports/esp8266/machine_softuart.c
  • Loading branch information
dmascord committed Aug 15, 2019
1 parent fa9b3a0 commit 891604a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions us2n.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ def parse_bind_address(addr, default=None):

def UART(config):
config = dict(config)
uart_type = config.pop('type')
port = config.pop('port')
uart = machine.UART(port)
uart.init(**config)
if uart_type == 'SoftUART':
print('Using SoftUART...')
uart = machine.SoftUART(machine.Pin(config.pop('tx')),machine.Pin(config.pop('rx')),timeout=config.pop('timeout'),timeout_char=config.pop('timeout_char'),baudrate=config.pop('baudrate'))
else:
print('Using HW UART...')
uart = machine.UART(port)
uart.init(**config)
return uart


Expand Down Expand Up @@ -104,9 +110,10 @@ def close_client(self):
self.uart = None

def open_client(self):
print('Accepted connection from ', self.client_address)
self.uart = UART(self.config['uart'])
self.client, self.client_address = self.tcp.accept()
print('Accepted connection from ', self.client_address)
print('UART opened ', self.uart)

def close(self):
self.close_client()
Expand Down

0 comments on commit 891604a

Please sign in to comment.