14 /* Set the bit for the current period to true and update the running LQ */
19 LQArray
[index
] |= LQmask
;
23 /* Start a new period */
24 void ICACHE_RAM_ATTR
inc()
26 // Increment the counter by shifting one bit higher
27 // If we've shifted out all the bits, move to next idx
35 // At idx N / 32 and bit N % 32, wrap back to idx=0, bit=0
36 if ((index
== (N
/ 32)) && (LQmask
& (1 << (N
% 32))))
42 if ((LQArray
[index
] & LQmask
) != 0)
44 LQArray
[index
] &= ~LQmask
;
52 /* Return the current running total of bits set, in percent */
53 uint8_t ICACHE_RAM_ATTR
getLQ() const
55 return (uint32_t)LQ
* 100U / count
;
58 /* Return the current running total of bits set, up to N */
59 uint8_t getLQRaw() const
64 /* Return the number of periods recorded so far, up to N */
65 uint8_t getCount() const
70 /* Return N, the size of the LQ history */
71 uint8_t getSize() const
76 /* Initialize and zero the history */
79 // count is intentonally not zeroed here to start LQ counting up from 0
80 // after a failsafe, instead of down from 100. Use reset100() to start from 100
84 for (uint8_t i
= 0; i
< (sizeof(LQArray
)/sizeof(LQArray
[0])); i
++)
88 /* Reset and start at 100% */
95 /* Return true if the current period was add()ed */
96 bool ICACHE_RAM_ATTR
currentIsSet() const
98 return LQArray
[index
] & LQmask
;
103 uint8_t index
; // current position in LQArray
106 uint32_t LQArray
[(N
+ 31)/32];