Skip to content

Commit ea58f54

Browse files
committed
Fixed up some of the testing code.
1 parent 90e178b commit ea58f54

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

Devlpr.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ void Devlpr::tick()
2424
// NOTE do we want to do some sort of remainder on
2525
// NOTE the micros - ie do we want to play catch up
2626
// NOTE or just make a best effort to run on sched?
27-
dummy = lastValueFiltered();
2827
}
2928
// just pretend no time has passed since function start
3029
lastTickMicros = currMicros;

Devlpr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class Devlpr
1111
int lastValue();
1212
float lastValueFiltered();
1313
float windowAvg();
14-
float dummy;
1514
private:
1615
// general buffer bookkeeping
1716
static const byte BUFSIZE = 155; // size of filter

libdevlpr.ino

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@ void setup() {
66
Serial.begin(9600);
77
}
88

9+
unsigned long microsSinceFilteredCall = 0;
10+
unsigned long prevLoopMicros = 0;
11+
float result = 0.0;
912
void loop() {
13+
// let the DEVLPR library do its job
1014
devlpr.tick();
15+
16+
// try to sample filtered data at 1000Hz
17+
unsigned long currMicros = micros();
18+
unsigned long microsDelta = currMicros - prevLoopMicros;
19+
microsSinceFilteredCall += microsDelta;
20+
// has 1ms passed
21+
if (microsSinceFilteredCall > 1000) {
22+
// 1ms has passed, get the value
23+
result = devlpr.lastValueFiltered();
24+
Serial.println(result);
25+
// update our last filtered call
26+
microsSinceFilteredCall = 0;
27+
}
28+
// update our last loop time
29+
prevLoopMicros = currMicros;
1130
}

0 commit comments

Comments
 (0)