summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBradley Pankow <btpankow@gmail.com>2020-05-25 16:00:22 -0400
committerGuy McSwain <guy.mcswain@gmail.com>2020-06-26 13:25:25 -0500
commitb9e57f60478a24200ab3ec35897058b547a5b1dc (patch)
treeee942f2345989cc2c6ef958dea3faee238351619
parentbea536389f38dfd57ea565c4af1197a2800b077d (diff)
Fix issue #353, initialising glitch filter
-rw-r--r--pigpio.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/pigpio.c b/pigpio.c
index 2c52870..6ef6ce9 100644
--- a/pigpio.c
+++ b/pigpio.c
@@ -950,6 +950,7 @@ typedef struct
uint32_t nfRBitV;
uint32_t gfSteadyUs;
+ uint8_t gfInitialised;
uint32_t gfTick;
uint32_t gfLBitV;
uint32_t gfRBitV;
@@ -5685,7 +5686,7 @@ unsigned alert_delays[]=
static void alertGlitchFilter(gpioSample_t *sample, int numSamples)
{
int i, j, diff;
- uint32_t steadyUs, changedTick, RBitV, LBitV;
+ uint32_t steadyUs, changedTick, RBitV, LBitV, initialised;
uint32_t bit, bitV;
for (i=0; i<=PI_MAX_USER_GPIO; i++)
@@ -5694,6 +5695,17 @@ static void alertGlitchFilter(gpioSample_t *sample, int numSamples)
if (monitorBits & bit & gFilterBits)
{
+ initialised = gpioAlert[i].gfInitialised;
+ if (!initialised && numSamples > 0)
+ {
+ /* Initialise filter with first sample */
+ bitV = sample[0].level & bit;
+ gpioAlert[i].gfRBitV = bitV;
+ gpioAlert[i].gfLBitV = bitV;
+ gpioAlert[i].gfTick = sample[0].tick;
+ gpioAlert[i].gfInitialised = 1;
+ }
+
steadyUs = gpioAlert[i].gfSteadyUs;
RBitV = gpioAlert[i].gfRBitV;
LBitV = gpioAlert[i].gfLBitV;
@@ -12335,18 +12347,8 @@ int gpioGlitchFilter(unsigned gpio, unsigned steady)
if (steady)
{
- gpioAlert[gpio].gfTick = systReg[SYST_CLO];
-
- if (gpioRead_Bits_0_31() & (1<<gpio))
- {
- gpioAlert[gpio].gfLBitV = (1<<gpio);
- gpioAlert[gpio].gfRBitV = 0 ;
- }
- else
- {
- gpioAlert[gpio].gfLBitV = 0 ;
- gpioAlert[gpio].gfRBitV = (1<<gpio);
- }
+ /* Initialise values next time we process alerts */
+ gpioAlert[gpio].gfInitialised = 0;
}
gpioAlert[gpio].gfSteadyUs = steady;