12 // count is reset here only once on construction to start LQ counting
13 // at 100% on first connect, but 0 out of N after a failsafe
17 /* Set the bit for the current period to true and update the running LQ */
22 LQArray
[index
] |= LQmask
;
26 /* Start a new period */
29 // Increment the counter by shifting one bit higher
30 // If we've shifted out all the bits, move to next idx
38 // At idx N / 32 and bit N % 32, wrap back to idx=0, bit=0
39 if ((index
== (N
/ 32)) && (LQmask
& (1 << (N
% 32))))
45 if ((LQArray
[index
] & LQmask
) != 0)
47 LQArray
[index
] &= ~LQmask
;
55 /* Return the current running total of bits set, in percent */
58 return (uint32_t)LQ
* 100U / count
;
61 /* Return the current running total of bits set, up to N */
62 uint8_t getLQRaw() const
67 /* Return the number of periods recorded so far, up to N */
68 uint8_t getCount() const
73 /* Return N, the size of the LQ history */
74 uint8_t getSize() const
79 /* Initialize and zero the history */
82 // count is intentonally not zeroed here to start LQ counting up from 0
83 // after a failsafe, instead of down from 100
87 for (uint8_t i
= 0; i
< (sizeof(LQArray
)/sizeof(LQArray
[0])); i
++)
91 /* Return true if the current period was add()ed */
92 bool currentIsSet() const
94 return LQArray
[index
] & LQmask
;
99 uint8_t index
; // current position in LQArray
102 uint32_t LQArray
[(N
+ 31)/32];