Explorar o código

Squashed 'cli_bridge/' changes from aa42c1af8..75c07544d

75c07544d fix cli and remove broken app
763415699 oops
REVERT: aa42c1af8 I'm sorry
REVERT: 5535ef175 Update internal_defs.h
REVERT: 2411f4aee Allow keyboard long-presses
REVERT: b790ecf06 Update README.md
REVERT: bf48d8958 Update README.md
REVERT: 12d5551ee Merge branch 'main' of https://github.com/ranchordo/flipperzero-cli-bridge
REVERT: 93c32ce8c Add persistent exits
REVERT: 85ed38a55 Update README.md
REVERT: 582432093 Initial commit
REVERT: f86e359d2 Initial commit

git-subtree-dir: cli_bridge
git-subtree-split: 75c07544dc3ad4445cdcc1248ac0e469b5869bf8
Willy-JL %!s(int64=2) %!d(string=hai) anos
pai
achega
19f6646569
Modificáronse 8 ficheiros con 25 adicións e 59 borrados
  1. 0 1
      .gitignore
  2. 0 24
      README.md
  3. 1 1
      application.fam
  4. 1 13
      cli_control.c
  5. 15 1
      cligui_main.c
  6. 0 1
      console_output.c
  7. 6 17
      internal_defs.h
  8. 2 1
      text_input.c

+ 0 - 1
.gitignore

@@ -1 +0,0 @@
-.vscode

+ 0 - 24
README.md

@@ -1,24 +0,0 @@
-# flipperzero-cli-bridge
-Allows CLI control from GUI, giving untethered access to sub-ghz chat, system diagnostics, and more.
-# Installation
-## Easy way - get a .fap file from the releases page
-Swing by the [releases](https://github.com/ranchordo/flipperzero-cli-bridge/releases) page, and download a pre-built .fap file for the latest flipperzero firmware. Use [qFlipper](https://flipperzero.one/update) to copy the .fap file into SD Card/apps/Tools/. MAKE SURE TO UPGRADE FLIPPERZERO FIRMWARE TO NEWEST VERSION BEFORE INSTALLING.
-## Hard way - building from source
-The following commands will (probably) not work on Windows. If you run Windows, use wsl or a linux vm or something.
-```sh
-git clone https://github.com/flipperdevices/flipperzero-firmware
-cd ./flipperzero-firmware
-git clone https://github.com/ranchordo/flipperzero-cli-bridge ./applications_user/flipperzero-cli-bridge/
-./fbt fap_dist APPSRC=applications_user/flipperzero-cli-bridge
-# If everything went well, the built .fap file can be found in ./dist/f7-D/apps/apps/Tools/cli_gui.fap
-```
-# Usage
-On the flipperzero, you should be able to find a new application (CLI-GUI Bridge) under Applications->Tools. Opening it will result in a text prompt - the prompt for the command line. Enter a suitable command (quickly pressing the back button or holding `_` on the keyboard will input a space) such as `subghz chat [freq in hz, e.g. 310000000]`, etc, then navigate to and press the SAVE key. You should then see the command window. Use Up and Down to scroll, and use Left or Center to get back to the text input prompt. A quick tap of the back key while viewing the console output sends a Ctrl-C to the console, and a long press of the left or right keys during text input will navigate back to the console output without executing.
-## Exiting the app
-Holding and then releasing the back key for at least a second or so (long press) will exit the app normally, meaning that the inner terminal will send Ctrl-C and close. Any sessions will be disconnected.  
-  
-  
-Holding and then releasing the OK key while focusing on the console output for at least a second or so (long press) will exit the app while keeping the terminal open. Terminal output will be cleared the next time you launch the app, but whatever command or session was running previously will be resumed. This is especially handy with subghz chat - exiting the app while keeping the terminal open will not disconnect you from the chat, and the flipper will still vibrate briefly whenever a new message comes in (even if the app is closed).  
-  
-  
-NOTE: USB functionality (qFlipper, normal USB CLI) may not work after running the app (especially after exiting without closing the terminal), simply restart your flipper and all USB functionality will return to normal.

+ 1 - 1
application.fam

@@ -3,7 +3,7 @@ App(
     name="CLI-GUI Bridge",
     apptype=FlipperAppType.EXTERNAL,
     entry_point="cligui_main",
-    requires=["gui","cli"],
+    requires=["gui", "cli"],
     stack_size=8 * 1024,
     fap_icon="cligui.png",
     fap_category="Tools",

+ 1 - 13
cli_control.c

@@ -11,7 +11,6 @@ volatile bool gotCallbackSet = false;
 FuriStreamBuffer* tx_stream;
 FuriStreamBuffer* rx_stream;
 static FuriThread* volatile cliThread = NULL;
-static FuriThread* prev_appthread = NULL;
 static void tx_handler_stdout(const char* buffer, size_t size) {
     furi_stream_buffer_send(tx_stream, buffer, size, FuriWaitForever);
 }
@@ -73,12 +72,6 @@ void latch_tx_handler() {
     session.is_connected = &session_connected;
     cli_session_close(global_cli);
     cli_session_open(global_cli, &session);
-    // Unlock loader-lock
-    Loader* loader = furi_record_open(RECORD_LOADER);
-    Loader_internal* loader_i = (Loader_internal*)loader;
-    prev_appthread = loader_i->app.thread;
-    loader_i->app.thread = NULL;
-    furi_record_close(RECORD_LOADER);
     furi_record_close(RECORD_CLI);
 }
 void unlatch_tx_handler(bool persist) {
@@ -108,9 +101,4 @@ void unlatch_tx_handler(bool persist) {
     // At this point, all cli_vcp functions should be back.
     furi_stream_buffer_free(rx_stream);
     furi_stream_buffer_free(tx_stream);
-    // Re-lock loader (to avoid crash on automatic unlock)
-    Loader* loader = furi_record_open(RECORD_LOADER);
-    Loader_internal* loader_i = (Loader_internal*)loader;
-    loader_i->app.thread = prev_appthread;
-    furi_record_close(RECORD_LOADER);
-}
+}

+ 15 - 1
cligui_main.c

@@ -2,6 +2,7 @@
 #include "cli_control.h"
 #include "text_input.h"
 #include "console_output.h"
+#include <loader/loader_i.h>
 
 static bool cligui_custom_event_cb(void* context, uint32_t event) {
     UNUSED(event);
@@ -65,6 +66,14 @@ static void input_callback_wrapper(InputEvent* event, void* context) {
 
 int32_t cligui_main(void* p) {
     UNUSED(p);
+
+    // Unlock loader-lock and save app thread
+    FuriThread* temp_save_appthr;
+    Loader* loader = furi_record_open(RECORD_LOADER);
+    temp_save_appthr = loader->app.thread;
+    loader->app.thread = NULL;
+    furi_record_close(RECORD_LOADER);
+
     CliguiApp* cligui = malloc(sizeof(CliguiApp));
     cligui->data = malloc(sizeof(CliguiData));
 
@@ -129,5 +138,10 @@ int32_t cligui_main(void* p) {
     free(cligui->data);
     free(cligui);
 
+    // We restoring previous app thread here, we love kostily and velosipedy, bydlo kod forever!
+    loader = furi_record_open(RECORD_LOADER);
+    loader->app.thread = temp_save_appthr;
+    furi_record_close(RECORD_LOADER);
+
     return 0;
-}
+}

+ 0 - 1
console_output.c

@@ -9,5 +9,4 @@ void console_output_input_handler(CliguiApp* app, InputEvent* event) {
         char eot = 0x03;
         furi_stream_buffer_send(app->data->streams.app_tx, &eot, 1, FuriWaitForever);
     }
-    
 }

+ 6 - 17
internal_defs.h

@@ -5,6 +5,10 @@
 #include <m-bptree.h>
 #include <m-array.h>
 #include <cli/cli.h>
+#include <gui/gui.h>
+#include <gui/view_dispatcher.h>
+#include <gui/modules/menu.h>
+#include <gui/modules/submenu.h>
 
 typedef struct {
     FuriThreadStdoutWriteCallback write_callback;
@@ -54,6 +58,7 @@ typedef struct {
 
 typedef struct {
     Gui* gui;
+    FuriMutex* mutex;
     bool is_enabled;
     ViewPortOrientation orientation;
 
@@ -67,22 +72,6 @@ typedef struct {
     void* input_callback_context;
 } ViewPort_internal;
 
-typedef struct {
-    char* args;
-    FuriThread* thread;
-    bool insomniac;
-    void* fap;
-} LoaderAppData_internal;
-
-typedef struct {
-    void* pubsub;
-    void* queue;
-    void* loader_menu;
-    void* loader_applications;
-    LoaderAppData_internal app;
-} Loader_internal;
-
-
 typedef struct {
     CliCallback callback;
     void* context;
@@ -109,4 +98,4 @@ typedef struct {
     void* session;
 
     size_t cursor_position;
-} Cli_internal;
+} Cli_internal;

+ 2 - 1
text_input.c

@@ -26,7 +26,8 @@ void text_input_input_handler(CliguiApp* app, InputEvent* event) {
         app->text_input_store[len] = ' ';
         app->text_input_store[len + 1] = 0;
     }
-    if(event->type == InputTypeLong && (event->key == InputKeyLeft || event->key == InputKeyRight)) {
+    if(event->type == InputTypeLong &&
+       (event->key == InputKeyLeft || event->key == InputKeyRight)) {
         view_dispatcher_switch_to_view(app->view_dispatcher, ViewConsoleOutput);
         app->data->state = ViewConsoleOutput;
     }