[FL-3346] fbt: added Flipper selection when multiple are connected over USB (#2723)

* fbt: added Flipper selection when multiple are connected over USB
* scripts: serial_cli: added --port (-p) option
This commit is contained in:
hedger 2023-06-08 08:47:27 +04:00 committed by GitHub
parent 09fae620d9
commit 436194e6c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 9 deletions

View File

@ -171,7 +171,7 @@ distenv.Depends(firmware_env["FW_RESOURCES"], external_apps_artifacts.resources_
fap_deploy = distenv.PhonyTarget( fap_deploy = distenv.PhonyTarget(
"fap_deploy", "fap_deploy",
"${PYTHON3} ${ROOT_DIR}/scripts/storage.py send ${SOURCE} /ext/apps", "${PYTHON3} ${FBT_SCRIPT_DIR}/storage.py -p ${FLIP_PORT} send ${SOURCE} /ext/apps",
source=Dir("#/assets/resources/apps"), source=Dir("#/assets/resources/apps"),
) )
@ -323,7 +323,9 @@ distenv.PhonyTarget(
) )
# Start Flipper CLI via PySerial's miniterm # Start Flipper CLI via PySerial's miniterm
distenv.PhonyTarget("cli", "${PYTHON3} ${FBT_SCRIPT_DIR}/serial_cli.py") distenv.PhonyTarget(
"cli", "${PYTHON3} ${FBT_SCRIPT_DIR}/serial_cli.py -p ${FLIP_PORT}"
)
# Find blackmagic probe # Find blackmagic probe

View File

@ -132,7 +132,7 @@ def generate(env):
"UsbInstall": Builder( "UsbInstall": Builder(
action=[ action=[
Action( Action(
'${PYTHON3} "${SELFUPDATE_SCRIPT}" ${UPDATE_BUNDLE_DIR}/update.fuf' '${PYTHON3} "${SELFUPDATE_SCRIPT}" -p ${FLIP_PORT} ${UPDATE_BUNDLE_DIR}/update.fuf'
), ),
Touch("${TARGET}"), Touch("${TARGET}"),
] ]

View File

@ -431,7 +431,7 @@ def AddAppLaunchTarget(env, appname, launch_target_name):
# print(deploy_sources, flipp_dist_paths) # print(deploy_sources, flipp_dist_paths)
env.PhonyTarget( env.PhonyTarget(
launch_target_name, launch_target_name,
'${PYTHON3} "${APP_RUN_SCRIPT}" ${EXTRA_ARGS} -s ${SOURCES} -t ${FLIPPER_FILE_TARGETS}', '${PYTHON3} "${APP_RUN_SCRIPT}" -p ${FLIP_PORT} ${EXTRA_ARGS} -s ${SOURCES} -t ${FLIPPER_FILE_TARGETS}',
source=deploy_sources, source=deploy_sources,
FLIPPER_FILE_TARGETS=flipp_dist_paths, FLIPPER_FILE_TARGETS=flipp_dist_paths,
EXTRA_ARGS=run_script_extra_ars, EXTRA_ARGS=run_script_extra_ars,
@ -443,7 +443,6 @@ def generate(env, **kw):
env.SetDefault( env.SetDefault(
EXT_APPS_WORK_DIR="${FBT_FAP_DEBUG_ELF_ROOT}", EXT_APPS_WORK_DIR="${FBT_FAP_DEBUG_ELF_ROOT}",
APP_RUN_SCRIPT="${FBT_SCRIPT_DIR}/runfap.py", APP_RUN_SCRIPT="${FBT_SCRIPT_DIR}/runfap.py",
STORAGE_SCRIPT="${FBT_SCRIPT_DIR}/storage.py",
) )
if not env["VERBOSE"]: if not env["VERBOSE"]:
env.SetDefault( env.SetDefault(

View File

@ -6,7 +6,7 @@ def resolve_port(logger, portname: str = "auto"):
if portname != "auto": if portname != "auto":
return portname return portname
# Try guessing # Try guessing
flippers = list(list_ports.grep("flip")) flippers = list(list_ports.grep("flip_"))
if len(flippers) == 1: if len(flippers) == 1:
flipper = flippers[0] flipper = flippers[0]
logger.info(f"Using {flipper.serial_number} on {flipper.device}") logger.info(f"Using {flipper.serial_number} on {flipper.device}")

View File

@ -1,3 +1,4 @@
import argparse
import logging import logging
import os import os
import subprocess import subprocess
@ -8,7 +9,10 @@ from flipper.utils.cdc import resolve_port
def main(): def main():
logger = logging.getLogger() logger = logging.getLogger()
if not (port := resolve_port(logger, "auto")): parser = argparse.ArgumentParser()
parser.add_argument("-p", "--port", help="CDC Port", default="auto")
args = parser.parse_args()
if not (port := resolve_port(logger, args.port)):
logger.error("Is Flipper connected via USB and not in DFU mode?") logger.error("Is Flipper connected via USB and not in DFU mode?")
return 1 return 1
subprocess.call( subprocess.call(

View File

@ -342,7 +342,7 @@ else:
appenv.PhonyTarget( appenv.PhonyTarget(
"cli", "cli",
'${PYTHON3} "${FBT_SCRIPT_DIR}/serial_cli.py"', '${PYTHON3} "${FBT_SCRIPT_DIR}/serial_cli.py" -p ${FLIP_PORT}',
) )
# Linter # Linter
@ -469,7 +469,7 @@ if dolphin_src_dir.exists():
) )
dist_env.PhonyTarget( dist_env.PhonyTarget(
"dolphin_ext", "dolphin_ext",
'${PYTHON3} ${FBT_SCRIPT_DIR}/storage.py send "${SOURCE}" /ext/dolphin', '${PYTHON3} ${FBT_SCRIPT_DIR}/storage.py -p ${FLIP_PORT} send "${SOURCE}" /ext/dolphin',
source=ufbt_build_dir.Dir("dolphin"), source=ufbt_build_dir.Dir("dolphin"),
) )
else: else:

View File

@ -71,6 +71,11 @@ vars.AddVariables(
validator=PathVariable.PathIsDir, validator=PathVariable.PathIsDir,
default="", default="",
), ),
(
"FLIP_PORT",
"CDC Port of Flipper to use, if multiple are connected",
"auto",
),
) )
Return("vars") Return("vars")

View File

@ -243,6 +243,11 @@ vars.AddVariables(
" app can check what version it is being built for.", " app can check what version it is being built for.",
"Official", "Official",
), ),
(
"FLIP_PORT",
"Full port name of Flipper to use, if multiple Flippers are connected",
"auto",
),
) )
Return("vars") Return("vars")