File tree Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change @@ -27,20 +27,18 @@ func (tune *autoTune) Sample(bit bool, seq uint32) {
27
27
// Period
28
28
// Falling Edge Rising Edge
29
29
func (tune * autoTune ) FindPeriod (bit bool ) int {
30
- // find left and right edges for a bit
30
+ // last pulse and initial index setup
31
31
lastPulse := tune .pulses [0 ]
32
32
idx := 1
33
33
34
34
// left edge
35
35
var leftEdge int
36
36
for ; idx < len (tune .pulses ); idx ++ {
37
- if lastPulse .seq + 1 == tune .pulses [idx ].seq {
38
- if lastPulse .bit != bit && tune .pulses [idx ].bit == bit {
37
+ if lastPulse .bit != bit && tune .pulses [idx ].bit == bit { // edge found
38
+ if lastPulse .seq + 1 == tune .pulses [idx ].seq { // ensure edge continuity
39
39
leftEdge = idx
40
40
break
41
41
}
42
- } else {
43
- return - 1
44
42
}
45
43
lastPulse = tune .pulses [idx ]
46
44
}
@@ -51,8 +49,8 @@ func (tune *autoTune) FindPeriod(bit bool) int {
51
49
idx = leftEdge + 1
52
50
53
51
for ; idx < len (tune .pulses ); idx ++ {
54
- if lastPulse .seq + 1 == tune .pulses [idx ].seq {
55
- if lastPulse .bit == bit && tune .pulses [idx ].bit != bit {
52
+ if lastPulse .seq + 1 == tune .pulses [idx ].seq { // ensure pulses in this level monotonic
53
+ if lastPulse .bit == bit && tune .pulses [idx ].bit != bit { // edge found
56
54
rightEdge = idx
57
55
break
58
56
}
You can’t perform that action at this time.
0 commit comments