Parcourir la source

Add ui element to swap type

Sanjay Govind il y a 1 an
Parent
commit
60fd576531
3 fichiers modifiés avec 41 ajouts et 4 suppressions
  1. 12 4
      portal_of_flipper_i.c
  2. 7 0
      portal_of_flipper_i.h
  3. 22 0
      scenes/pof_scene_main.c

+ 12 - 4
portal_of_flipper_i.c

@@ -7,13 +7,21 @@
 void pof_start(PoFApp* app) {
     furi_assert(app);
 
-    // app->pof_usb = pof_usb_start(app->virtual_portal);
-    app->pof_usb = pof_usb_start_xbox360(app->virtual_portal);
+    if (app->type == PoFHid) {
+        app->pof_usb = pof_usb_start(app->virtual_portal);
+    }
+    if (app->type == PoFXbox360) {
+        app->pof_usb = pof_usb_start_xbox360(app->virtual_portal);
+    }
 }
 
 void pof_stop(PoFApp* app) {
     furi_assert(app);
 
-    // pof_usb_stop(app->pof_usb);
-    pof_usb_stop_xbox360(app->pof_usb);
+    if (app->type == PoFHid) {
+        pof_usb_stop(app->pof_usb);
+    }
+    if (app->type == PoFXbox360) {
+        pof_usb_stop_xbox360(app->pof_usb);
+    }
 }

+ 7 - 0
portal_of_flipper_i.h

@@ -19,6 +19,11 @@
 
 typedef struct PoFApp PoFApp;
 
+typedef enum {
+    PoFHid,
+    PoFXbox360
+} PoFType;
+
 struct PoFApp {
     Gui* gui;
     ViewDispatcher* view_dispatcher;
@@ -32,6 +37,8 @@ struct PoFApp {
     VirtualPortal* virtual_portal;
 
     PoFUsb* pof_usb;
+    PoFType type;
+    
 };
 
 typedef enum {

+ 22 - 0
scenes/pof_scene_main.c

@@ -10,6 +10,13 @@ void pof_scene_main_submenu_callback(void* context, uint32_t index) {
     view_dispatcher_send_custom_event(pof->view_dispatcher, index);
 }
 
+void pof_scene_main_submenu_type_callback(void* context, PoFType type) {
+    PoFApp* pof = context;
+    pof_stop(pof);
+    pof->type = type;
+    pof_start(pof);
+}
+
 void pof_scene_main_on_update(void* context) {
     PoFApp* pof = context;
     VirtualPortal* virtual_portal = pof->virtual_portal;
@@ -19,6 +26,21 @@ void pof_scene_main_on_update(void* context) {
     FuriString* token_name = furi_string_alloc();
 
     if(pof->pof_usb) {
+        if (pof->type == PoFHid) {
+            submenu_add_item(
+            submenu,
+            "Emulate Xbox 360",
+            PoFXbox360,
+            pof_scene_main_submenu_callback,
+            pof);
+        } else if (pof->type == PoFXbox360) {
+            submenu_add_item(
+            submenu,
+            "Emulate HID",
+            PoFHid,
+            pof_scene_main_submenu_callback,
+            pof);
+        }
         int count = 0;
         for(int i = 0; i < POF_TOKEN_LIMIT; i++) {
             if(virtual_portal->tokens[i]->loaded) {