@@ -57,13 +57,13 @@ THE SOFTWARE.
5757class Nec : public CIRLData {
5858public:
5959 Nec (void ){
60- // Empty
60+ // Empty
6161 }
62-
62+
6363 // Hide anything that is inside this class so the user dont accidently uses this class
6464 template <typename protocol, typename ...protocols>
6565 friend class CIRLremote ;
66-
66+
6767private:
6868 static inline uint8_t getSingleFlag (void ) __attribute__((always_inline));
6969 static inline bool requiresCheckTimeout (void ) __attribute__((always_inline));
@@ -105,7 +105,7 @@ bool Nec::available(void)
105105 if (IRLProtocol == IR_NEC || IRLProtocol == IR_NEC_EXTENDED || IRLProtocol == IR_NEC_REPEAT)
106106 return true ;
107107 else
108- return false ;
108+ return false ;
109109}
110110
111111
@@ -164,7 +164,7 @@ void Nec::decodeSingle(const uint16_t &duration){
164164 // to not trigger wrong buttons (1 Nec signal timespawn)
165165 if ((IRLLastTime - IRLLastEvent) >= NEC_TIMEOUT_REPEAT)
166166 return ;
167-
167+
168168 // received a Nec Repeat signal
169169 // next mark (stop bit) ignored due to detecting techniques
170170 IRLProtocol = IR_NEC_REPEAT;
@@ -260,7 +260,7 @@ void Nec::decode(const uint16_t &duration) {
260260 // to not trigger wrong buttons (1 Nec signal timespawn)
261261 if ((IRLLastTime - IRLLastEvent) >= NEC_TIMEOUT_REPEAT)
262262 return ;
263-
263+
264264 // Check if last protocol was also NEC
265265 // (only for multiple protocol decoding)
266266 uint8_t lastProtocol = IRLProtocol | IR_NEW_PROTOCOL;
@@ -342,21 +342,22 @@ class CNecAPI : public CIRLData{
342342 uint8_t lastholdCount = 0 ;
343343
344344 public:
345- bool releaseButton ( void ) {
346- // Triggers when the button is released.
347- // Anything else than a normal press indicates the key was released .
348- // This occurs on a timeout, new button, same button press .
349- // In most cases pressTimeout makes still more sense.
350- if (NecTimeoutType != NO_TIMEOUT) {
351- return true ;
352- }
353- return false ;
354- }
345+ // Triggers when the button is released.
346+ // Anything else than a normal press indicates the key was released.
347+ // This occurs on a timeout, new button, same button press .
348+ // In most cases pressTimeout makes more sense .
349+ bool releaseButton ( void ) {
350+ if (NecTimeoutType != NO_TIMEOUT) {
351+ return true ;
352+ }
353+ return false ;
354+ }
355355
356356
357- uint8_t pressTimeout (void ) {
358- // Check if a key was released (via timeout or another key got pressed).
359- // Return how often the key was pressed.
357+ // Check if a key was released (via timeout or another key got pressed).
358+ // Return how often the key was pressed.
359+ uint8_t pressTimeout (void )
360+ {
360361 if (NecTimeoutType == TIMEOUT || NecTimeoutType == NEW_BUTTON) {
361362 return lastPressCount;
362363 }
@@ -369,12 +370,17 @@ class CNecAPI : public CIRLData{
369370 }
370371
371372
373+ // Returns the current button press streak.
374+ // How many times have you pressed again the same button?
372375 uint8_t pressCount (void ) {
373376 return lastPressCount;
374377 }
375378
376379
377- uint8_t pressDebounce (const uint8_t debounce = 4 ) {
380+ // Counts how long a button press streak has been holding down.
381+ // A debounce input param can be used to only count every Xth time.
382+ uint8_t holdDebounce (const uint8_t debounce = 4 )
383+ {
378384 // Only recognize the actual keydown event
379385 if (NecTimeoutType == NO_TIMEOUT)
380386 {
@@ -390,18 +396,22 @@ class CNecAPI : public CIRLData{
390396 }
391397 return 0 ;
392398 }
393-
394-
395- void reset (void ) {
396- // Reset the button press and hold count.
397- // Attention: No release/timeout event will trigger!
398- // This is important if you want to end a chain,
399- // which starts again with the next press.
400- // Differenciate between 1 or 2 presses is a good usecase.
399+
400+
401+ // Reset the button press and hold count.
402+ // Attention: No release/timeout event will trigger!
403+ // This is important if you want to end a chain,
404+ // which starts again with the next press.
405+ // Differenciate between 1 or 2 presses is a good usecase.
406+ // Hold a button -> event A triggers
407+ // Hold the button again -> event B triggers
408+ // If A (with a longer hold count) was already triggered, reset the API
409+ void reset (void )
410+ {
401411 lastPressCount = 0 ;
402412 lastholdCount = 0 ;
403413 }
404-
414+
405415
406416 void read (const IR_data_t data) {
407417 // Check if the correct protocol and address (optional) is used
@@ -462,7 +472,7 @@ class CNecAPI : public CIRLData{
462472 if (!lastPressCount){
463473 return ;
464474 }
465-
475+
466476 // Increment holding count
467477 if (lastholdCount < 255 ) {
468478 lastholdCount++;
0 commit comments