mirror of
https://github.com/pdxlocations/contact.git
synced 2026-03-28 17:12:35 +01:00
23 lines
999 B
Python
23 lines
999 B
Python
import logging
|
|
import meshtastic.serial_interface, meshtastic.tcp_interface, meshtastic.ble_interface
|
|
import globals
|
|
|
|
def initialize_interface(args):
|
|
try:
|
|
if args.ble:
|
|
return meshtastic.ble_interface.BLEInterface(args.ble if args.ble != "any" else None)
|
|
elif args.host:
|
|
return meshtastic.tcp_interface.TCPInterface(args.host)
|
|
else:
|
|
try:
|
|
return meshtastic.serial_interface.SerialInterface(args.port)
|
|
except PermissionError as ex:
|
|
logging.error(f"You probably need to add yourself to the `dialout` group to use a serial connection. {ex}")
|
|
except Exception as ex:
|
|
logging.error(f"Unexpected error initializing interface: {ex}")
|
|
if globals.interface.devPath is None:
|
|
return meshtastic.tcp_interface.TCPInterface("meshtastic.local")
|
|
|
|
except Exception as ex:
|
|
logging.critical(f"Fatal error initializing interface: {ex}")
|
|
|