1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 12:42:30 +04:00

Merge remote-tracking branch 'OFW/dev' into dev

This commit is contained in:
MX
2024-06-23 17:39:44 +03:00
16 changed files with 291 additions and 109 deletions

View File

@@ -1,69 +0,0 @@
#!/usr/bin/env python3
import os
import posixpath
from flipper.app import App
from flipper.storage import FlipperStorage, FlipperStorageOperations
from flipper.utils.cdc import resolve_port
class Main(App):
def init(self):
self.parser.add_argument("-p", "--port", help="CDC Port", default="auto")
self.parser.add_argument(
"-n",
"--no-launch",
dest="launch_app",
action="store_false",
help="Don't launch app",
)
self.parser.add_argument("fap_src_path", help="App file to upload")
self.parser.add_argument(
"--fap_dst_dir", help="Upload path", default="/ext/apps", required=False
)
self.parser.set_defaults(func=self.install)
def install(self):
if not (port := resolve_port(self.logger, self.args.port)):
return 1
try:
with FlipperStorage(port) as storage:
storage_ops = FlipperStorageOperations(storage)
fap_local_path = self.args.fap_src_path
self.args.fap_dst_dir = self.args.fap_dst_dir.rstrip("/\\")
if not os.path.isfile(fap_local_path):
self.logger.error(
f"Error: source .fap ({fap_local_path}) not found"
)
return 2
fap_dst_path = posixpath.join(
self.args.fap_dst_dir, os.path.basename(fap_local_path)
)
self.logger.info(f'Installing "{fap_local_path}" to {fap_dst_path}')
storage_ops.recursive_send(fap_dst_path, fap_local_path, False)
if not self.args.launch_app:
return 0
storage.send_and_wait_eol(f"loader open {fap_dst_path}\r")
if len(result := storage.read.until(storage.CLI_EOL)):
self.logger.error(f"Unexpected response: {result.decode('ascii')}")
return 3
return 0
except Exception as e:
self.logger.error(f"Error: {e}")
# raise
return 4
if __name__ == "__main__":
Main()()

View File

@@ -2,6 +2,7 @@
import operator
from functools import reduce
import time
from flipper.app import App
from flipper.storage import FlipperStorage, FlipperStorageOperations
@@ -9,6 +10,8 @@ from flipper.utils.cdc import resolve_port
class Main(App):
APP_POST_CLOSE_DELAY_SEC = 0.2
def init(self):
self.parser.add_argument("-p", "--port", help="CDC Port", default="auto")
self.parser.add_argument(
@@ -67,6 +70,23 @@ class Main(App):
if self.args.host_app:
startup_command = self.args.host_app
self.logger.info("Closing current app, if any")
for _ in range(10):
storage.send_and_wait_eol("loader close\r")
result = storage.read.until(storage.CLI_EOL)
if b"was closed" in result:
self.logger.info("App closed")
storage.read.until(storage.CLI_EOL)
time.sleep(self.APP_POST_CLOSE_DELAY_SEC)
elif result.startswith(b"No application"):
storage.read.until(storage.CLI_EOL)
break
else:
self.logger.error(
f"Unexpected response: {result.decode('ascii')}"
)
return 4
self.logger.info(f"Launching app: {startup_command}")
storage.send_and_wait_eol(f"loader open {startup_command}\r")