Kaynağa Gözat

fix typos, copy load string

Sanjay Govind 10 ay önce
ebeveyn
işleme
10e5cdeae4
3 değiştirilmiş dosya ile 22 ekleme ve 32 silme
  1. 2 3
      helpers/pof_usb.c
  2. 19 28
      virtual_portal.c
  3. 1 1
      virtual_portal.h

+ 2 - 3
helpers/pof_usb.c

@@ -47,8 +47,7 @@ static int32_t pof_thread_worker(void* context) {
         uint32_t now = furi_get_tick();
         uint32_t flags = furi_thread_flags_wait(EventAll, FuriFlagWaitAny, timeout);
         if(flags & EventRx) { //fast flag
-
-            // if(virtual_portal->speaker) {
+            if(virtual_portal->speaker) {
                 uint8_t buf[POF_USB_RX_MAX_SIZE];
                 len_data = pof_usb_receive(dev, buf, POF_USB_RX_MAX_SIZE);
                 // https://github.com/xMasterX/all-the-plugins/blob/dev/base_pack/wav_player/wav_player_hal.c
@@ -62,7 +61,7 @@ static int32_t pof_thread_worker(void* context) {
                     */
                    virtual_portal_process_audio(virtual_portal, buf, len_data);
                 }
-            // }
+            }
 
             if(pof_usb->dataAvailable > 0) {
                 memset(tx_data, 0, sizeof(tx_data));

+ 19 - 28
virtual_portal.c

@@ -37,12 +37,10 @@ static void wav_player_dma_isr(void* ctx) {
     // half of transfer
     if (LL_DMA_IsActiveFlag_HT1(DMA1)) {
         LL_DMA_ClearFlag_HT1(DMA1);
-        if (!virtual_portal->playing_audio) {
-            return;
-        }
         if (virtual_portal->count < SAMPLES_COUNT / 2) {
-            virtual_portal->playing_audio = false;
-            wav_player_speaker_stop();
+            for (int i = 0; i < SAMPLES_COUNT / 2; i++) {
+                virtual_portal->audio_buffer[i] = 0;
+            }
             return;
         }
         // fill first half of buffer
@@ -59,12 +57,10 @@ static void wav_player_dma_isr(void* ctx) {
     if (LL_DMA_IsActiveFlag_TC1(DMA1)) {
         LL_DMA_ClearFlag_TC1(DMA1);
 
-        if (!virtual_portal->playing_audio) {
-            return;
-        }
         if (virtual_portal->count < SAMPLES_COUNT / 2) {
-            virtual_portal->playing_audio = false;
-            wav_player_speaker_stop();
+            for (int i = SAMPLES_COUNT / 2; i < SAMPLES_COUNT; i++) {
+                virtual_portal->audio_buffer[i] = 0;
+            }
             return;
         }
         // fill second half of buffer
@@ -226,6 +222,7 @@ VirtualPortal* virtual_portal_alloc(NotificationApp* notifications) {
 
         furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch1, wav_player_dma_isr, virtual_portal);
 
+        wav_player_speaker_start();
         wav_player_dma_start();
     }
 
@@ -255,12 +252,12 @@ void virtual_portal_free(VirtualPortal* virtual_portal) {
     free(virtual_portal);
 }
 
-void virtaul_portal_set_leds(uint8_t r, uint8_t g, uint8_t b) {
+void virtual_portal_set_leds(uint8_t r, uint8_t g, uint8_t b) {
     furi_hal_light_set(LightRed, r);
     furi_hal_light_set(LightGreen, g);
     furi_hal_light_set(LightBlue, b);
 }
-void virtaul_portal_set_backlight(uint8_t brightness) {
+void virtual_portal_set_backlight(uint8_t brightness) {
     furi_hal_light_set(LightBacklight, brightness);
 }
 
@@ -320,6 +317,8 @@ void virtual_portal_load_token(VirtualPortal* virtual_portal, PoFToken* pof_toke
     memcpy(target->dev_name, pof_token->dev_name, sizeof(pof_token->dev_name));
     memcpy(target->UID, pof_token->UID, sizeof(pof_token->UID));
 
+    furi_string_set(target->load_path, pof_token->load_path);
+
     const NfcDeviceData* data = nfc_device_get_data(pof_token->nfc_device, NfcProtocolMfClassic);
     nfc_device_set_data(target->nfc_device, NfcProtocolMfClassic, data);
 }
@@ -355,15 +354,11 @@ int virtual_portal_reset(VirtualPortal* virtual_portal, uint8_t* message, uint8_
 
     uint8_t index = 0;
     response[index++] = 'R';
-    response[index++] = 0x02;
-    response[index++] = 0x1B;
-    // response[index++] = 0x0a;
-    // response[index++] = 0x03;
-    // response[index++] = 0x02;
-    //  https://github.com/tresni/PoweredPortals/wiki/USB-Protocols
-    //  Wii Wireless: 01 29 00 00
-    //  Wii Wired: 02 0a 03 02 (Giants: works)
-    //  Arduboy: 02 19 (Trap team: works)
+    response[index++] = 0x02; // Trap Team Xbox One
+    response[index++] = 0x27; // Trap Team Xbox One
+
+    // response[index++] = 0x02; // Swap Force 3DS
+    // response[index++] = 0x02; // Swap Force 3DS
     return index;
 }
 
@@ -447,11 +442,11 @@ int virtual_portal_l(VirtualPortal* virtual_portal, uint8_t* message) {
             break;
         case 1:
             brightness = message[2];
-            virtaul_portal_set_backlight(brightness);
+            virtual_portal_set_backlight(brightness);
             break;
         case 3:
             brightness = 0xff;
-            virtaul_portal_set_backlight(brightness);
+            virtual_portal_set_backlight(brightness);
             break;
     }
     return 0;
@@ -555,7 +550,7 @@ void virtual_portal_process_audio(
         data /= UINT8_MAX / 2;  // scale -1..1
 
         data *= virtual_portal->volume;  // volume
-        data = tanhf(data);   // hyperbolic tangent limiter
+        data = tanhf(data);              // hyperbolic tangent limiter
 
         data *= UINT8_MAX / 2;  // scale -128..127
         data += UINT8_MAX / 2;  // to unsigned
@@ -573,10 +568,6 @@ void virtual_portal_process_audio(
             virtual_portal->head = virtual_portal->current_audio_buffer;
         }
     }
-    if (!virtual_portal->playing_audio && virtual_portal->count > SAMPLES_COUNT / 2) {
-        wav_player_speaker_start();
-        virtual_portal->playing_audio = true;
-    }
 }
 
 // 32 byte message, 32 byte response;

+ 1 - 1
virtual_portal.h

@@ -7,7 +7,7 @@
 
 #define SAMPLE_RATE 8000
 #define POF_TOKEN_LIMIT 16
-#define SAMPLES_COUNT 1024
+#define SAMPLES_COUNT 8096
 #define SAMPLES_COUNT_BUFFERED SAMPLES_COUNT * 4
 
 typedef enum {