Просмотр исходного кода

EvilPortal: Xtreme tweaks, app icon, otg power

Willy-JL 2 лет назад
Родитель
Сommit
43892f9f0b

+ 1 - 2
evil_portal/application.fam

@@ -9,8 +9,7 @@ App(
     order=90,
 	fap_author="bigbrodude6119",
 	fap_description="Create an evil captive portal Wi-Fi access point",
-    fap_libs=["assets"],
     fap_icon_assets="icons",
     fap_icon="icons/evil_portal_10px.png",
-    fap_category="GPIO",
+    fap_category="WiFi",
 )

+ 15 - 0
evil_portal/evil_portal_app.c

@@ -128,11 +128,26 @@ int32_t evil_portal_app(void *p) {
   UNUSED(p);
   Evil_PortalApp *evil_portal_app = evil_portal_app_alloc();
 
+  bool otg_was_enabled = furi_hal_power_is_otg_enabled();
+  // turn off 5v, so it gets reset on startup
+  if(otg_was_enabled) {
+    furi_hal_power_disable_otg();
+  }
+  uint8_t attempts = 0;
+  while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
+    furi_hal_power_enable_otg();
+    furi_delay_ms(10);
+  }
+
   evil_portal_app->uart = evil_portal_uart_init(evil_portal_app);
 
   view_dispatcher_run(evil_portal_app->view_dispatcher);  
 
   evil_portal_app_free(evil_portal_app);
 
+  if(furi_hal_power_is_otg_enabled() && !otg_was_enabled) {
+    furi_hal_power_disable_otg();
+  }
+
   return 0;
 }

+ 5 - 4
evil_portal/evil_portal_app_i.h

@@ -16,18 +16,19 @@
 #include <gui/view_stack.h>
 #include <dialogs/dialogs.h>
 
+#include <xtreme.h>
+
 #define NUM_MENU_ITEMS (6)
 
 #define EVIL_PORTAL_TEXT_BOX_STORE_SIZE (4096)
-#define UART_CH (FuriHalUartIdUSART1)
+#define UART_CH                                                                 \
+    (XTREME_SETTINGS()->uart_esp_channel == UARTDefault ? FuriHalUartIdUSART1 : \
+                                                          FuriHalUartIdLPUART1)
 
 #define SET_HTML_CMD "sethtml"
 #define SET_AP_CMD "setap"
 #define RESET_CMD "reset"
 
-#define HTML_EXTENSION ".html"
-#define HTML_FOLDER ANY_PATH("apps_data/evil_portal/html")
-
 struct Evil_PortalApp {
   Gui *gui;
   ViewDispatcher *view_dispatcher;

+ 14 - 2
evil_portal/evil_portal_uart.c

@@ -101,6 +101,7 @@ static int32_t uart_worker(void *context) {
     }
   }
 
+  furi_hal_uart_set_irq_cb(UART_CH, NULL, NULL);
   furi_stream_buffer_free(uart->rx_stream);
 
   return 0;
@@ -123,6 +124,12 @@ Evil_PortalUart *evil_portal_uart_init(Evil_PortalApp *app) {
 
   furi_thread_start(uart->rx_thread);
 
+  if(UART_CH == FuriHalUartIdUSART1) {
+    furi_hal_console_disable();
+  } else if(UART_CH == FuriHalUartIdLPUART1) {
+    furi_hal_uart_init(UART_CH, app->BAUDRATE);
+  }
+
   furi_hal_console_disable();
   if (app->BAUDRATE == 0) {
     app->BAUDRATE = 115200;
@@ -130,6 +137,8 @@ Evil_PortalUart *evil_portal_uart_init(Evil_PortalApp *app) {
   furi_hal_uart_set_br(UART_CH, app->BAUDRATE);
   furi_hal_uart_set_irq_cb(UART_CH, evil_portal_uart_on_irq_cb, uart);
 
+  evil_portal_uart_tx((uint8_t*)("XFW#EVILPORTAL=1\n"), strlen("XFW#EVILPORTAL=1\n"));
+
   return uart;
 }
 
@@ -140,8 +149,11 @@ void evil_portal_uart_free(Evil_PortalUart *uart) {
   furi_thread_join(uart->rx_thread);
   furi_thread_free(uart->rx_thread);
 
-  furi_hal_uart_set_irq_cb(UART_CH, NULL, NULL);
-  furi_hal_console_enable();
+  if(UART_CH == FuriHalUartIdLPUART1) {
+    furi_hal_uart_deinit(UART_CH);
+  } else {
+    furi_hal_console_enable();
+  }
 
   free(uart);
 }

+ 6 - 0
evil_portal/helpers/evil_portal_storage.c

@@ -12,6 +12,12 @@ void evil_portal_read_index_html(void *context) {
   Storage *storage = evil_portal_open_storage();
   FileInfo fi;
 
+  if(!storage_common_exists(storage, EVIL_PORTAL_INDEX_SAVE_PATH)) {
+    FuriString* tmp = furi_string_alloc_set(EVIL_PORTAL_INDEX_DEFAULT_PATH);
+    evil_portal_replace_index_html(tmp);
+    furi_string_free(tmp);
+  }
+
   if (storage_common_stat(storage, EVIL_PORTAL_INDEX_SAVE_PATH, &fi) ==
       FSE_OK) {
     File *index_html = storage_file_alloc(storage);

+ 3 - 0
evil_portal/helpers/evil_portal_storage.h

@@ -6,7 +6,10 @@
 #include <string.h>
 
 #define PORTAL_FILE_DIRECTORY_PATH EXT_PATH("apps_data/evil_portal")
+#define HTML_EXTENSION ".html"
+#define HTML_FOLDER PORTAL_FILE_DIRECTORY_PATH "/html"
 #define EVIL_PORTAL_INDEX_SAVE_PATH PORTAL_FILE_DIRECTORY_PATH "/index.html"
+#define EVIL_PORTAL_INDEX_DEFAULT_PATH HTML_FOLDER "/xtreme.html"
 #define EVIL_PORTAL_AP_SAVE_PATH PORTAL_FILE_DIRECTORY_PATH "/ap.config.txt"
 #define EVIL_PORTAL_LOG_SAVE_PATH PORTAL_FILE_DIRECTORY_PATH "/logs"
 

BIN
evil_portal/icons/evil_portal_10px.png