浏览代码

Initiator mode: change to fast LED blink during read

Petteri Aimonen 3 年之前
父节点
当前提交
8f54a70a30
共有 2 个文件被更改,包括 26 次插入14 次删除
  1. 1 1
      README.md
  2. 25 13
      src/ZuluSCSI_initiator.cpp

+ 1 - 1
README.md

@@ -90,7 +90,7 @@ When enabled by the DIP switch, ZuluSCSI RP2040 will scan for SCSI drives on the
 LED indications in initiator mode:
 
 - Short blink once a second: idle, searching for SCSI drives
-- Slow blink every 5 seconds: copying data. The blink acts as a progress bar: first it is short and becomes longer when data copying progresses.
+- Fast blink 4 times per second: copying data. The blink acts as a progress bar: first it is short and becomes longer when data copying progresses.
 
 The firmware retries reads up to 5 times and attempts to skip any sectors that have problems.
 Any read errors are logged into `zululog.txt`.

+ 25 - 13
src/ZuluSCSI_initiator.cpp

@@ -84,6 +84,28 @@ void scsiInitiatorInit()
     g_initiator_state.failposition = 0;
 }
 
+// Update progress bar LED during transfers
+static void scsiInitiatorUpdateLed()
+{
+    // Update status indicator, the led blinks every 5 seconds and is on the longer the more data has been transferred
+    const int period = 256;
+    int phase = (millis() % period);
+    int duty = g_initiator_state.sectors_done * period / g_initiator_state.sectorcount;
+
+    // Minimum and maximum time to verify that the blink is visible
+    if (duty < 50) duty = 50;
+    if (duty > period - 50) duty = period - 50;
+
+    if (phase <= duty)
+    {
+        LED_ON();
+    }
+    else
+    {
+        LED_OFF();
+    }
+}
+
 // High level logic of the initiator mode
 void scsiInitiatorMainLoop()
 {
@@ -169,19 +191,7 @@ void scsiInitiatorMainLoop()
             return;
         }
 
-        // Update status indicator, the led blinks every 5 seconds and is on the longer the more data has been transferred
-        uint32_t time_start = millis();
-        int phase = (time_start % 5000);
-        int duty = g_initiator_state.sectors_done * 5000 / g_initiator_state.sectorcount;
-        if (duty < 100) duty = 100;
-        if (phase <= duty)
-        {
-            LED_ON();
-        }
-        else
-        {
-            LED_OFF();
-        }
+        scsiInitiatorUpdateLed();
 
         // How many sectors to read in one batch?
         int numtoread = g_initiator_state.sectorcount - g_initiator_state.sectors_done;
@@ -191,6 +201,7 @@ void scsiInitiatorMainLoop()
         if (g_initiator_state.sectors_done < g_initiator_state.failposition)
             numtoread = 1;
 
+        uint32_t time_start = millis();
         bool status = scsiInitiatorReadDataToFile(g_initiator_state.target_id,
             g_initiator_state.sectors_done, numtoread, g_initiator_state.sectorsize,
             g_initiator_state.target_file);
@@ -609,6 +620,7 @@ bool scsiInitiatorReadDataToFile(int target_id, uint32_t start_sector, uint32_t
         else
         {
             // Write data to SD card and simultaneously read more from SCSI
+            scsiInitiatorUpdateLed();
             scsiInitiatorWriteDataToSd(file, true);
         }
     }