v7303 Fix waveform length when merging pulses (#223)
authorPhil Wright <phlipped@gmail.com>
Fri, 13 Jul 2018 00:04:09 +0000 (00:04 +0000)
committerGuy McSwain <guy.mcswain@gmail.com>
Sun, 26 Jan 2020 02:52:43 +0000 (20:52 -0600)
pigpio.c
pigpio.h

index 261e540a7506971d967adc678903be36864f6dda..942a4cc60955cdab92693c5ad5a1549eec24dd32 100644 (file)
--- a/pigpio.c
+++ b/pigpio.c
@@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 For more information, please refer to <http://unlicense.org/>
 */
 
-/* pigpio version 73 */
+/* pigpio version 7303 */
 
 /* include ------------------------------------------------------- */
 
@@ -3242,7 +3242,7 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1)
 
    unsigned numIn2, numOut;
 
-   uint32_t tNow, tNext1, tNext2, tDelay;
+   uint32_t tNow, tNext1, tNext2, tDelay, tMax;
 
    rawWave_t *in2, *out;
 
@@ -3253,6 +3253,7 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1)
    out   = wf[1-wfcur];
 
    tNow = 0;
+   tMax = 0;
 
    if (!numIn1) tNext1 = -1; else tNext1 = 0;
    if (!numIn2) tNext2 = -1; else tNext2 = 0;
@@ -3275,6 +3276,7 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1)
          out[outPos].flags   = in1[inPos1].flags;
 
          tNext1 = tNow + in1[inPos1].usDelay; ++inPos1;
+         if (tMax < tNext1) tMax = tNext1;
       }
       else if (tNext2 < tNext1)
       {
@@ -3292,6 +3294,7 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1)
          out[outPos].flags   = in2[inPos2].flags;
 
          tNext2 = tNow + in2[inPos2].usDelay; ++inPos2;
+         if (tMax < tNext2) tMax = tNext2;
       }
       else
       {
@@ -3310,6 +3313,8 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1)
 
          tNext1 = tNow + in1[inPos1].usDelay; ++inPos1;
          tNext2 = tNow + in2[inPos2].usDelay; ++inPos2;
+         if (tMax < tNext1) tMax = tNext1;
+         if (tMax < tNext2) tMax = tNext2;
       }
 
       if (tNext1 <= tNext2) { tDelay = tNext1 - tNow; tNow = tNext1; }
@@ -3342,6 +3347,13 @@ int rawWaveAddGeneric(unsigned numIn1, rawWave_t *in1)
 
    }
 
+   if (tNow < tMax)
+   {
+      /* extend previous delay */
+      out[outPos-1].usDelay += (tMax - tNow);
+      tNow = tMax;
+   }
+
    if ((outPos < numOut) && (outPos < level))
    {
       wfStats.micros = tNow;
index 5817460f3e6bd4f9a204ca02ea45050e7aeae924..f58373ca1dd3ca10d56924373c693075c1d75854 100644 (file)
--- a/pigpio.h
+++ b/pigpio.h
@@ -30,7 +30,7 @@ For more information, please refer to <http://unlicense.org/>
 #include <stdint.h>
 #include <pthread.h>
 
-#define PIGPIO_VERSION 7302
+#define PIGPIO_VERSION 7303
 
 /*TEXT