mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 04:34:43 +04:00
Merge remote-tracking branch 'OFW/dev' into dev
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
import serial.tools.list_ports as list_ports
|
||||
|
||||
|
||||
@@ -15,3 +16,8 @@ def resolve_port(logger, portname: str = "auto"):
|
||||
logger.error("Failed to find connected Flipper")
|
||||
elif len(flippers) > 1:
|
||||
logger.error("More than one Flipper is attached")
|
||||
env_path = os.environ.get("FLIPPER_PATH")
|
||||
if env_path:
|
||||
if os.path.exists(env_path):
|
||||
logger.info(f"Using FLIPPER_PATH from environment: {env_path}")
|
||||
return env_path
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
import time
|
||||
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
|
||||
@@ -32,11 +34,11 @@ 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"Attempting 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}")
|
||||
@@ -47,8 +49,16 @@ class Main(App):
|
||||
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)
|
||||
|
||||
def power_off(self):
|
||||
if not (flipper := self._get_flipper(retry_count=10)):
|
||||
|
||||
@@ -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