mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2025-10-11 07:32:34 +02:00
github: support bound and symlinked devices (#4163)
* Fix unaccessible flipper for binded access points workaround to work with symlinked devices * Fix return None if Flipper not started * exception handling * decreased timeouts * Check environment variables for flipper path
This commit is contained in:
@@ -4,6 +4,8 @@ import time
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from serial.serialutil import SerialException
|
||||
|
||||
from flipper.app import App
|
||||
from flipper.storage import FlipperStorage
|
||||
from flipper.utils.cdc import resolve_port
|
||||
@@ -34,23 +36,34 @@ class Main(App):
|
||||
|
||||
def _get_flipper(self, retry_count: Optional[int] = 1):
|
||||
port = None
|
||||
self.logger.info(f"Attempting to find flipper with {retry_count} attempts.")
|
||||
|
||||
for i in range(retry_count):
|
||||
time.sleep(1)
|
||||
self.logger.info(f"Attempt to find flipper #{i}.")
|
||||
self.logger.info(
|
||||
f"Attempting to find flipper (Attempt {i + 1}/{retry_count})."
|
||||
)
|
||||
|
||||
if port := resolve_port(self.logger, self.args.port):
|
||||
self.logger.info(f"Found flipper at {port}")
|
||||
break
|
||||
|
||||
if not port:
|
||||
self.logger.info(f"Failed to find flipper {port}")
|
||||
self.logger.info(f"Failed to find flipper")
|
||||
return None
|
||||
|
||||
flipper = FlipperStorage(port)
|
||||
flipper.start()
|
||||
return flipper
|
||||
for i in range(retry_count):
|
||||
try:
|
||||
flipper.start()
|
||||
self.logger.info("Flipper successfully started.")
|
||||
return flipper
|
||||
except IOError as e:
|
||||
self.logger.info(
|
||||
f"Failed to start flipper (Attempt {i + 1}/{retry_count}): {e}"
|
||||
)
|
||||
time.sleep(1)
|
||||
|
||||
self.logger.error("Flipper failed to start after all retries.")
|
||||
return None
|
||||
|
||||
def await_flipper(self):
|
||||
if not (flipper := self._get_flipper(retry_count=self.args.timeout)):
|
||||
|
Reference in New Issue
Block a user