Sanjay Govind 1 год назад
Родитель
Сommit
6d205bdab6
4 измененных файлов с 20 добавлено и 8 удалено
  1. 6 4
      helpers/pof_usb.c
  2. 3 0
      helpers/pof_usb.h
  3. 8 4
      helpers/pof_usb_xbox360.c
  4. 3 0
      virtual_portal.c

+ 6 - 4
helpers/pof_usb.c

@@ -40,8 +40,7 @@ static int32_t pof_thread_worker(void* context) {
 
     uint32_t len_data = 0;
     uint8_t tx_data[POF_USB_TX_MAX_SIZE] = {0};
-    uint32_t timeout = 32; // FuriWaitForever; //ms
-    uint32_t timeoutResponse = 100; // FuriWaitForever; //ms
+    uint32_t timeout = TIMEOUT_NORMAL; // FuriWaitForever; //ms
     uint32_t next = furi_get_tick() + timeout;
 
     while(true) {
@@ -71,13 +70,15 @@ static int32_t pof_thread_worker(void* context) {
                     virtual_portal_process_message(virtual_portal, pof_usb->data, tx_data);
                 if(send_len > 0) {
                     pof_usb_send(dev, tx_data, POF_USB_ACTUAL_OUTPUT_SIZE);
-                    next = now + timeoutResponse;
+                    timeout = TIMEOUT_AFTER_RESPONSE;
+                    next = now + timeout;
                 }
                 pof_usb->dataAvailable = 0;
             }
 
             // Check next status time since the timeout based one might be starved by incoming packets.
             if(now > next) {
+                timeout = TIMEOUT_NORMAL;
                 next = now + timeout;
                 memset(tx_data, 0, sizeof(tx_data));
                 len_data = virtual_portal_send_status(virtual_portal, tx_data);
@@ -114,12 +115,13 @@ static int32_t pof_thread_worker(void* context) {
             }
         }
 
-        if(flags == (uint32_t)FuriFlagErrorISR && now > next) { // timeout
+        if(flags == (uint32_t)FuriFlagErrorISR) { // timeout
             memset(tx_data, 0, sizeof(tx_data));
             len_data = virtual_portal_send_status(virtual_portal, tx_data);
             if(len_data > 0) {
                 pof_usb_send(dev, tx_data, POF_USB_ACTUAL_OUTPUT_SIZE);
             }
+            timeout = TIMEOUT_NORMAL;
             next = now + timeout;
         }
     }

+ 3 - 0
helpers/pof_usb.h

@@ -20,6 +20,9 @@
 #define POF_USB_RX_MAX_SIZE (POF_USB_EP_OUT_SIZE)
 #define POF_USB_TX_MAX_SIZE (POF_USB_EP_IN_SIZE)
 
+#define TIMEOUT_NORMAL 32
+#define TIMEOUT_AFTER_RESPONSE 100
+
 typedef struct PoFUsb PoFUsb;
 
 PoFUsb* pof_usb_start(VirtualPortal* virtual_portal);

+ 8 - 4
helpers/pof_usb_xbox360.c

@@ -19,6 +19,9 @@
 
 #define POF_USB_ACTUAL_OUTPUT_SIZE 0x20
 
+#define TIMEOUT_NORMAL 32
+#define TIMEOUT_AFTER_RESPONSE 100
+
 static const struct usb_string_descriptor dev_manuf_desc =
     USB_ARRAY_DESC(0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x00);
 static const struct usb_string_descriptor dev_product_desc =
@@ -49,8 +52,7 @@ static int32_t pof_thread_worker(void* context) {
 
     uint32_t len_data = 0;
     uint8_t tx_data[POF_USB_TX_MAX_SIZE] = {0};
-    uint32_t timeout = 32; // FuriWaitForever; //ms
-    uint32_t timeoutResponse = 100; // FuriWaitForever; //ms
+    uint32_t timeout = TIMEOUT_NORMAL; // FuriWaitForever; //ms
     uint32_t next = furi_get_tick() + timeout;
 
     while(true) {
@@ -70,7 +72,8 @@ static int32_t pof_thread_worker(void* context) {
                     tx_data[0] = 0x0b;
                     tx_data[1] = 0x14;
                     pof_usb_send(dev, tx_data, POF_USB_ACTUAL_OUTPUT_SIZE);
-                    next = now + timeoutResponse;
+                    timeout = TIMEOUT_AFTER_RESPONSE;
+                    next = now + timeout;
                 }
             } else if (len_data > 0 && buf[0] == 0x0b && buf[1] == 0x17) {
                 // 360 audio packets start with 0b 17, samples start after the two byte header
@@ -123,7 +126,7 @@ static int32_t pof_thread_worker(void* context) {
             }
         }
 
-        if(flags == (uint32_t)FuriFlagErrorISR && now > next) { // timeout
+        if(flags == (uint32_t)FuriFlagErrorISR) { // timeout
             memset(tx_data, 0, sizeof(tx_data));
             len_data = virtual_portal_send_status(virtual_portal, tx_data + 2);
             if(len_data > 0) {
@@ -131,6 +134,7 @@ static int32_t pof_thread_worker(void* context) {
                 tx_data[1] = 0x14;
                 pof_usb_send(dev, tx_data, POF_USB_ACTUAL_OUTPUT_SIZE);
             }
+            timeout = TIMEOUT_NORMAL;
             next = now + timeout;
         }
     }

+ 3 - 0
virtual_portal.c

@@ -67,6 +67,9 @@ static int32_t pof_thread_worker(void* context) {
             last_r = target_r;
             last_g = target_g;
             last_b = target_b;
+            furi_hal_light_set(LightRed, target_r);
+            furi_hal_light_set(LightBlue, target_g);
+            furi_hal_light_set(LightGreen, target_b);
             running = false;
         }
     }