Skip to content

armgit / flix

Public Imported from GitHub
0

Making an ESP32-based quadcopter from scratch

Support ESP-NOW connection in pyflix Set arbitrary pymavlink connection string using device parameter or FLIX_DEVICE env variable. [email protected].

Oleg Kalachev4e32414daef7
diff --git a/tools/pyflix/README.md b/tools/pyflix/README.md
index eff2ab1..ea79714 100644
--- a/tools/pyflix/README.md
+++ b/tools/pyflix/README.md
@@ -28,6 +28,8 @@ from pyflix import Flix
flix = Flix() # create a Flix object and wait for connection
```
+If using ESP-NOW connection, specify the proxy's device name in `FLIX_DEVICE` environment variable or pass it to the constructor: `Flix(device='/dev/cu.usbserial-0001')`.
+
### Telemetry
Basic telemetry is available through object properties. The property names generally match the corresponding variables in the firmware code:
diff --git a/tools/pyflix/flix.py b/tools/pyflix/flix.py
index a6b44a3..b7166f1 100644
--- a/tools/pyflix/flix.py
+++ b/tools/pyflix/flix.py
@@ -44,22 +44,27 @@ class Flix:
_print_buffer: str = ''
_modes = ['RAW', 'ACRO', 'STAB', 'AUTO']
- def __init__(self, system_id: int=1, wait_connection: bool=True):
+ def __init__(self, system_id: int=1, wait_connection: bool=True, device=os.getenv('FLIX_DEVICE')):
if not (0 <= system_id < 256):
raise ValueError('system_id must be in range [0, 255]')
self._setup_mavlink()
self.system_id = system_id
self._init_state()
- try:
- # Direct connection
- logger.debug('Listening on port 14550')
- self.connection: mavutil.mavfile = mavutil.mavlink_connection('udpin:0.0.0.0:14550', source_system=255) # type: ignore
- except OSError as e:
- if e.errno != errno.EADDRINUSE:
- raise
- # Port busy - using proxy
- logger.debug('Listening on port 14555 (proxy)')
- self.connection: mavutil.mavfile = mavutil.mavlink_connection('udpin:0.0.0.0:14555', source_system=254) # type: ignore
+ if device is not None:
+ # User defined connection
+ logger.debug(f'Connecting to {device}')
+ self.connection: mavutil.mavfile = mavutil.mavlink_connection(device, source_system=255) # type: ignore
+ else:
+ try:
+ # Direct connection
+ logger.debug('Listening on port 14550')
+ self.connection: mavutil.mavfile = mavutil.mavlink_connection('udpin:0.0.0.0:14550', source_system=255) # type: ignore
+ except OSError as e:
+ if e.errno != errno.EADDRINUSE:
+ raise
+ # Port busy - using proxy
+ logger.debug('Listening on port 14555 (proxy)')
+ self.connection: mavutil.mavfile = mavutil.mavlink_connection('udpin:0.0.0.0:14555', source_system=254) # type: ignore
self.connection.target_system = system_id
self.mavlink: mavlink.MAVLink = self.connection.mav
self._event_listeners: Dict[str, List[Callable[..., Any]]] = {}
diff --git a/tools/pyproject.toml b/tools/pyproject.toml
index 7b6031c..d81174b 100644
--- a/tools/pyproject.toml
+++ b/tools/pyproject.toml
@@ -1,6 +1,6 @@
[project]
name = "pyflix"
-version = "0.15"
+version = "0.16"
description = "Python API for Flix drone"
authors = [{ name="Oleg Kalachev", email="[email protected]" }]
license = "MIT"