Skip to content

Commit

Permalink
[FL-3346] fbt: added Flipper selection when multiple are connected ov…
Browse files Browse the repository at this point in the history
…er USB (#2723)

* fbt: added Flipper selection when multiple are connected over USB
* scripts: serial_cli: added --port (-p) option
  • Loading branch information
hedger authored Jun 8, 2023
1 parent 09fae62 commit 436194e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 9 deletions.
6 changes: 4 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ distenv.Depends(firmware_env["FW_RESOURCES"], external_apps_artifacts.resources_

fap_deploy = distenv.PhonyTarget(
"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"),
)

Expand Down Expand Up @@ -323,7 +323,9 @@ distenv.PhonyTarget(
)

# 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
Expand Down
2 changes: 1 addition & 1 deletion scripts/fbt_tools/fbt_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def generate(env):
"UsbInstall": Builder(
action=[
Action(
'${PYTHON3} "${SELFUPDATE_SCRIPT}" ${UPDATE_BUNDLE_DIR}/update.fuf'
'${PYTHON3} "${SELFUPDATE_SCRIPT}" -p ${FLIP_PORT} ${UPDATE_BUNDLE_DIR}/update.fuf'
),
Touch("${TARGET}"),
]
Expand Down
3 changes: 1 addition & 2 deletions scripts/fbt_tools/fbt_extapps.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def _add_host_app_to_targets(host_app):
# print(deploy_sources, flipp_dist_paths)
env.PhonyTarget(
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,
FLIPPER_FILE_TARGETS=flipp_dist_paths,
EXTRA_ARGS=run_script_extra_ars,
Expand All @@ -443,7 +443,6 @@ def generate(env, **kw):
env.SetDefault(
EXT_APPS_WORK_DIR="${FBT_FAP_DEBUG_ELF_ROOT}",
APP_RUN_SCRIPT="${FBT_SCRIPT_DIR}/runfap.py",
STORAGE_SCRIPT="${FBT_SCRIPT_DIR}/storage.py",
)
if not env["VERBOSE"]:
env.SetDefault(
Expand Down
2 changes: 1 addition & 1 deletion scripts/flipper/utils/cdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def resolve_port(logger, portname: str = "auto"):
if portname != "auto":
return portname
# Try guessing
flippers = list(list_ports.grep("flip"))
flippers = list(list_ports.grep("flip_"))
if len(flippers) == 1:
flipper = flippers[0]
logger.info(f"Using {flipper.serial_number} on {flipper.device}")
Expand Down
6 changes: 5 additions & 1 deletion scripts/serial_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import logging
import os
import subprocess
Expand All @@ -8,7 +9,10 @@

def main():
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?")
return 1
subprocess.call(
Expand Down
4 changes: 2 additions & 2 deletions scripts/ufbt/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ else:

appenv.PhonyTarget(
"cli",
'${PYTHON3} "${FBT_SCRIPT_DIR}/serial_cli.py"',
'${PYTHON3} "${FBT_SCRIPT_DIR}/serial_cli.py" -p ${FLIP_PORT}',
)

# Linter
Expand Down Expand Up @@ -469,7 +469,7 @@ if dolphin_src_dir.exists():
)
dist_env.PhonyTarget(
"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"),
)
else:
Expand Down
5 changes: 5 additions & 0 deletions scripts/ufbt/commandline.scons
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ vars.AddVariables(
validator=PathVariable.PathIsDir,
default="",
),
(
"FLIP_PORT",
"CDC Port of Flipper to use, if multiple are connected",
"auto",
),
)

Return("vars")
5 changes: 5 additions & 0 deletions site_scons/commandline.scons
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ vars.AddVariables(
" app can check what version it is being built for.",
"Official",
),
(
"FLIP_PORT",
"Full port name of Flipper to use, if multiple Flippers are connected",
"auto",
),
)

Return("vars")

0 comments on commit 436194e

Please sign in to comment.