@ -121,14 +121,14 @@ class HmRadio : public Radio { 
			
		
	
		
		
			
				
					                if ( ! mNRFloopChannels  & &  ( ( mTimeslotStart  -  mLastIrqTime )  >  ( DURATION_TXFRAME ) ) )  //(DURATION_TXFRAME+DURATION_ONEFRAME)))
                 if ( ! mNRFloopChannels  & &  ( ( mTimeslotStart  -  mLastIrqTime )  >  ( DURATION_TXFRAME ) ) )  //(DURATION_TXFRAME+DURATION_ONEFRAME)))
  
			
		
	
		
		
			
				
					                    mNRFloopChannels  =  true ;                     mNRFloopChannels  =  true ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
					                rxPendular  =  ! r xPendular;                 mRxPendular  =  ! mR xPendular;  
			
				
				
			
		
	
		
		
	
		
		
			
				
					                //innerLoopTimeout = (rxPendular ? 1 : 2)*DURATION_LISTEN_MIN;
                 //innerLoopTimeout = (rxPendular ? 1 : 2)*DURATION_LISTEN_MIN;
  
			
		
	
		
		
			
				
					
					                //innerLoopTimeout = DURATION_LISTEN_MIN;
                 innerLoopTimeout  =  DURATION_LISTEN_MIN ;  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					                if ( mNRFloopChannels )                 if ( mNRFloopChannels )  
			
		
	
		
		
			
				
					                    tempRxChIdx  =  ( tempRxChIdx  +  4 )  %  RF_CHANNELS ;                     tempRxChIdx  =  ( tempRxChIdx  +  4 )  %  RF_CHANNELS ;  
			
		
	
		
		
			
				
					                else                 else  
			
		
	
		
		
			
				
					
					                    tempRxChIdx  =  ( mRxChIdx  +  r xPendular* 4 )  %  RF_CHANNELS ;                     tempRxChIdx  =  ( mRxChIdx  +  mR xPendular* 4 )  %  RF_CHANNELS ;  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					                mNrf24 - > setChannel ( mRfChLst [ tempRxChIdx ] ) ;                 mNrf24 - > setChannel ( mRfChLst [ tempRxChIdx ] ) ;  
			
		
	
		
		
			
				
					                isRxInit  =  false ;                 isRxInit  =  false ;  
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -142,7 +142,7 @@ class HmRadio : public Radio { 
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					                if ( tx_ok  | |  tx_fail )  {  // tx related interrupt, basically we should start listening
                 if ( tx_ok  | |  tx_fail )  {  // tx related interrupt, basically we should start listening
  
			
		
	
		
		
			
				
					                    mNrf24 - > flush_tx ( ) ;                          // empty TX FIFO
                     mNrf24 - > flush_tx ( ) ;                          // empty TX FIFO
  
			
		
	
		
		
			
				
					
					                    mTxSetupTime  =  millis ( )  -  mMillis ;                     //mTxSetupTime = millis() - mMillis;
  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					                    if ( mNRFisInRX )  {                     if ( mNRFisInRX )  {  
			
		
	
		
		
			
				
					                        DPRINTLN ( DBG_WARN ,  F ( " unexpected tx irq! " ) ) ;                         DPRINTLN ( DBG_WARN ,  F ( " unexpected tx irq! " ) ) ;  
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -153,17 +153,21 @@ class HmRadio : public Radio { 
			
		
	
		
		
			
				
					                    if ( tx_ok )                     if ( tx_ok )  
			
		
	
		
		
			
				
					                        mLastIv - > mAckCount + + ;                         mLastIv - > mAckCount + + ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
					                    //mRxChIdx = (mTxChIdx + 2) % RF_CHANNELS; 
                     //#ifdef DYNAMIC_OFFSET 
  
			
				
				
			
		
	
		
		
	
		
		
			
				
					                    mRxChIdx  =  ( mTxChIdx  +  mLastIv - > rxOffset )  %  RF_CHANNELS ;                     mRxChIdx  =  ( mTxChIdx  +  mLastIv - > rxOffset )  %  RF_CHANNELS ;  
			
		
	
		
		
			
				
					                    /*#else
  
			
		
	
		
		
			
				
					                    mRxChIdx  =  ( mTxChIdx  +  2 )  %  RF_CHANNELS ;  
			
		
	
		
		
			
				
					                    # endif* /  
			
		
	
		
		
			
				
					                    mNrf24 - > setChannel ( mRfChLst [ mRxChIdx ] ) ;                     mNrf24 - > setChannel ( mRfChLst [ mRxChIdx ] ) ;  
			
		
	
		
		
			
				
					                    mNrf24 - > startListening ( ) ;                     mNrf24 - > startListening ( ) ;  
			
		
	
		
		
			
				
					                    mTimeslotStart  =  millis ( ) ;                     mTimeslotStart  =  millis ( ) ;  
			
		
	
		
		
			
				
					                    tempRxChIdx  =  mRxChIdx ;   // might be better to start off with one channel less?
                     tempRxChIdx  =  mRxChIdx ;   // might be better to start off with one channel less?
  
			
		
	
		
		
			
				
					
					                    rxPendular  =  false ;                     mRxPendular =  false ;  
			
				
				
			
		
	
		
		
	
		
		
			
				
					                    mNRFloopChannels  =  ( mLastIv - > ivGen  = =  IV_MI ) ;                     mNRFloopChannels  =  ( mLastIv - > ivGen  = =  IV_MI ) ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					                    //innerLoopTimeout = mLastIv->ivGen != IV_MI ? DURATION_TXFRAME : DURATION_ONEFRAME;
                     //innerLoopTimeout = mLastIv->ivGen != IV_MI ? DURATION_TXFRAME : DURATION_ONEFRAME;
  
			
		
	
		
		
			
				
					
					                    innerLoopTimeout  =  mLastIv - > ivGen  ! =  IV_MI  ?  DURATION_LISTEN_MIN  :  4 ;                     //innerLoopTimeout = mLastIv->ivGen != IV_MI ? DURATION_LISTEN_MIN : 4;
  
			
				
				
			
		
	
		
		
	
		
		
			
				
					                    innerLoopTimeout  =  ( mLastIv - > mIsSingleframeReq  | |  mLastIv - > ivGen  = =  IV_MI )  ?  DURATION_LISTEN_MIN  :  DURATION_TXFRAME ;  
			
		
	
		
		
			
				
					                }                 }  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					                if ( rx_ready )  {                 if ( rx_ready )  {  
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -176,7 +180,7 @@ class HmRadio : public Radio { 
			
		
	
		
		
			
				
					                        innerLoopTimeout  =  DURATION_LISTEN_MIN ;                         innerLoopTimeout  =  DURATION_LISTEN_MIN ;  
			
		
	
		
		
			
				
					                        mTimeslotStart  =  millis ( ) ;                         mTimeslotStart  =  millis ( ) ;  
			
		
	
		
		
			
				
					                        if  ( ! mNRFloopChannels )  {                         if  ( ! mNRFloopChannels )  {  
			
		
	
		
		
			
				
					
					                            //r xPendular = true; // stay longer on the next rx channel
                             //mR xPendular = true; // stay longer on the next rx channel
  
			
				
				
			
		
	
		
		
	
		
		
			
				
					                            if  ( isRxInit )  {                             if  ( isRxInit )  {  
			
		
	
		
		
			
				
					                                isRxInit  =  false ;                                 isRxInit  =  false ;  
			
		
	
		
		
			
				
					                                tempRxChIdx  =  ( mRxChIdx  +  4 )  %  RF_CHANNELS ;                                 tempRxChIdx  =  ( mRxChIdx  +  4 )  %  RF_CHANNELS ;  
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -325,12 +329,14 @@ class HmRadio : public Radio { 
			
		
	
		
		
			
				
					                                    isRetransmitAnswer  =  true ;                                     isRetransmitAnswer  =  true ;  
			
		
	
		
		
			
				
					                                if ( isLastPackage )                                 if ( isLastPackage )  
			
		
	
		
		
			
				
					                                    setExpectedFrames ( p . packet [ 9 ]  -  ALL_FRAMES ) ;                                     setExpectedFrames ( p . packet [ 9 ]  -  ALL_FRAMES ) ;  
			
		
	
		
		
			
				
					                                # ifdef DYNAMIC_OFFSET  
			
		
	
		
		
			
				
					                                if ( p . packet [ 9 ]  = =  1  & &  p . millis  <  DURATION_ONEFRAME )                                 if ( p . packet [ 9 ]  = =  1  & &  p . millis  <  DURATION_ONEFRAME )  
			
		
	
		
		
			
				
					                                    mLastIv - > rxOffset  =  ( RF_CHANNELS  +  mTxChIdx  -  tempRxChIdx  +  1 )  %  RF_CHANNELS ;                                     mLastIv - > rxOffset  =  ( RF_CHANNELS  +  mTxChIdx  -  tempRxChIdx  +  1 )  %  RF_CHANNELS ;  
			
		
	
		
		
			
				
					                                else  if ( mNRFloopChannels  & &  mLastIv - > rxOffset  >  RF_CHANNELS )  {  // unsure setting?
                                 else  if ( mNRFloopChannels  & &  mLastIv - > rxOffset  >  RF_CHANNELS )  {  // unsure setting?
  
			
		
	
		
		
			
				
					                                    mLastIv - > rxOffset  =  ( RF_CHANNELS  +  mTxChIdx  -  tempRxChIdx  +  ( isLastPackage  ?  mFramesExpected  :  p . packet [ 9 ] ) ) ;   // make clear it's not sure, start with one more offset
                                     mLastIv - > rxOffset  =  ( RF_CHANNELS  +  mTxChIdx  -  tempRxChIdx  +  ( isLastPackage  ?  mFramesExpected  :  p . packet [ 9 ] ) ) ;   // make clear it's not sure, start with one more offset
  
			
		
	
		
		
			
				
					                                    mNRFloopChannels  =  false ;                                     mNRFloopChannels  =  false ;  
			
		
	
		
		
			
				
					                                }                                 }  
			
		
	
		
		
			
				
					                                # endif  
			
		
	
		
		
			
				
					                            }                             }  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					                            if ( IV_MI  = =  mLastIv - > ivGen )  {                             if ( IV_MI  = =  mLastIv - > ivGen )  {  
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -338,8 +344,10 @@ class HmRadio : public Radio { 
			
		
	
		
		
			
				
					                                    isLastPackage  =  ( p . packet [ 9 ]  >  0x10 ) ;                 // > 0x10 indicates last packet received
                                     isLastPackage  =  ( p . packet [ 9 ]  >  0x10 ) ;                 // > 0x10 indicates last packet received
  
			
		
	
		
		
			
				
					                                else  if  ( ( p . packet [ 0 ]  ! =  0x88 )  & &  ( p . packet [ 0 ]  ! =  0x92 ) )  // ignore MI status messages //#0 was p.packet[0] != 0x00 &&
                                 else  if  ( ( p . packet [ 0 ]  ! =  0x88 )  & &  ( p . packet [ 0 ]  ! =  0x92 ) )  // ignore MI status messages //#0 was p.packet[0] != 0x00 &&
  
			
		
	
		
		
			
				
					                                    isLastPackage  =  true ;                                 // response from dev control command
                                     isLastPackage  =  true ;                                 // response from dev control command
  
			
		
	
		
		
			
				
					                                # ifdef DYNAMIC_OFFSET  
			
		
	
		
		
			
				
					                                if ( p . packet [ 9 ]  = =  0x00  & &  p . millis  <  DURATION_ONEFRAME )                                 if ( p . packet [ 9 ]  = =  0x00  & &  p . millis  <  DURATION_ONEFRAME )  
			
		
	
		
		
			
				
					                                    mLastIv - > rxOffset  =  ( RF_CHANNELS  +  mTxChIdx  -  tempRxChIdx  -  1 )  %  RF_CHANNELS ;                                     mLastIv - > rxOffset  =  ( RF_CHANNELS  +  mTxChIdx  -  tempRxChIdx  -  1 )  %  RF_CHANNELS ;  
			
		
	
		
		
			
				
					                                # endif  
			
		
	
		
		
			
				
					                            }                             }  
			
		
	
		
		
			
				
					                            rx_ready  =  true ;  //reset in case we first read messages from other inverter or ACK zero payloads
                             rx_ready  =  true ;  //reset in case we first read messages from other inverter or ACK zero payloads
  
			
		
	
		
		
			
				
					                        }                         }  
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -347,9 +355,8 @@ class HmRadio : public Radio { 
			
		
	
		
		
			
				
					                }                 }  
			
		
	
		
		
			
				
					                yield ( ) ;                 yield ( ) ;  
			
		
	
		
		
			
				
					            }             }  
			
		
	
		
		
			
				
					
					            if ( isLastPackage )  {              if ( isLastPackage )  
			
				
				
			
		
	
		
		
	
		
		
			
				
					                mLastIv - > mGotLastMsg  =  true ;                 mLastIv - > mGotLastMsg  =  true ;  
			
		
	
		
		
			
				
					            }  
			
		
	
		
		
			
				
					            return  isLastPackage  | |  isRetransmitAnswer ;             return  isLastPackage  | |  isRetransmitAnswer ;  
			
		
	
		
		
			
				
					        }         }  
			
		
	
		
		
			
				
					
 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -361,10 +368,7 @@ class HmRadio : public Radio { 
			
		
	
		
		
			
				
					            mTxChIdx  =  iv - > heuristics . txRfChId ;             mTxChIdx  =  iv - > heuristics . txRfChId ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					            if ( * mSerialDebug )  {             if ( * mSerialDebug )  {  
			
		
	
		
		
			
				
					
					                /* remark rejoe2: imo this has no added value here.
                 /*if(!isRetransmit) {
  
			
				
				
			
		
	
		
		
			
				
					                As  this  belongs  to  the  last  tx  cycle ,  we  should  print  that  info  
			
		
	
		
		
			
				
					                directly  when  switching  from  tx  to  rx .  Otherwise  we  might  confuse  users .  
			
		
	
		
		
			
				
					                if ( ! isRetransmit )  {  
			
		
	
		
		
	
		
		
			
				
					                    DPRINT ( DBG_INFO ,  " last tx setup:  " ) ;                     DPRINT ( DBG_INFO ,  " last tx setup:  " ) ;  
			
		
	
		
		
			
				
					                    DBGPRINT ( String ( mTxSetupTime ) ) ;                     DBGPRINT ( String ( mTxSetupTime ) ) ;  
			
		
	
		
		
			
				
					                    DBGPRINTLN ( " ms " ) ;                     DBGPRINTLN ( " ms " ) ;  
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -374,13 +378,19 @@ class HmRadio : public Radio { 
			
		
	
		
		
			
				
					                DBGPRINT ( F ( " TX  " ) ) ;                 DBGPRINT ( F ( " TX  " ) ) ;  
			
		
	
		
		
			
				
					                DBGPRINT ( String ( len ) ) ;                 DBGPRINT ( String ( len ) ) ;  
			
		
	
		
		
			
				
					                DBGPRINT ( "  CH " ) ;                 DBGPRINT ( "  CH " ) ;  
			
		
	
		
		
			
				
					                if ( mTxChIdx  = =  0 )  
			
		
	
		
		
			
				
					                    DBGPRINT ( " 0 " ) ;  
			
		
	
		
		
			
				
					                DBGPRINT ( String ( mRfChLst [ mTxChIdx ] ) ) ;                 DBGPRINT ( String ( mRfChLst [ mTxChIdx ] ) ) ;  
			
		
	
		
		
			
				
					                DBGPRINT ( F ( " ,  " ) ) ;                 DBGPRINT ( F ( " ,  " ) ) ;  
			
		
	
		
		
			
				
					                DBGPRINT ( String ( mTxRetriesNext ) ) ;                 DBGPRINT ( String ( mTxRetriesNext ) ) ;  
			
		
	
		
		
			
				
					                //DBGPRINT(F(" retries | "));
                 //DBGPRINT(F(" retries | "));
  
			
		
	
		
		
			
				
					                //#ifdef DYNAMIC_OFFSET
  
			
		
	
		
		
			
				
					                DBGPRINT ( F ( "  ret., rx offset:  " ) ) ;                 DBGPRINT ( F ( "  ret., rx offset:  " ) ) ;  
			
		
	
		
		
			
				
					                DBGPRINT ( String ( iv - > rxOffset ) ) ;                 DBGPRINT ( String ( iv - > rxOffset ) ) ;  
			
		
	
		
		
			
				
					                DBGPRINT ( F ( "  |  " ) ) ;                 DBGPRINT ( F ( "  |  " ) ) ;  
			
		
	
		
		
			
				
					                /*#else
  
			
		
	
		
		
			
				
					                DBGPRINT ( F ( "  ret. |  " ) ) ;  
			
		
	
		
		
			
				
					                # endif* /  
			
		
	
		
		
			
				
					                if ( * mPrintWholeTrace )  {                 if ( * mPrintWholeTrace )  {  
			
		
	
		
		
			
				
					                    if ( * mPrivacyMode )                     if ( * mPrivacyMode )  
			
		
	
		
		
			
				
					                        ah : : dumpBuf ( mTxBuf ,  len ,  1 ,  4 ) ;                         ah : : dumpBuf ( mTxBuf ,  len ,  1 ,  4 ) ;  
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -396,6 +406,7 @@ class HmRadio : public Radio { 
			
		
	
		
		
			
				
					            }             }  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					            mNrf24 - > stopListening ( ) ;             mNrf24 - > stopListening ( ) ;  
			
		
	
		
		
			
				
					            mNrf24 - > flush_rx ( ) ;  
			
		
	
		
		
			
				
					            if ( ! isRetransmit  & &  mTxRetries  ! =  mTxRetriesNext )  {             if ( ! isRetransmit  & &  mTxRetries  ! =  mTxRetriesNext )  {  
			
		
	
		
		
			
				
					                mNrf24 - > setRetries ( 3 ,  mTxRetriesNext ) ;                 mNrf24 - > setRetries ( 3 ,  mTxRetriesNext ) ;  
			
		
	
		
		
			
				
					                mTxRetries  =  mTxRetriesNext ;                 mTxRetries  =  mTxRetriesNext ;  
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -439,9 +450,9 @@ class HmRadio : public Radio { 
			
		
	
		
		
			
				
					        bool  mNRFloopChannels  =  false ;         bool  mNRFloopChannels  =  false ;  
			
		
	
		
		
			
				
					        bool  mNRFisInRX  =  false ;         bool  mNRFisInRX  =  false ;  
			
		
	
		
		
			
				
					        bool  isRxInit  =  true ;         bool  isRxInit  =  true ;  
			
		
	
		
		
			
				
					
					        bool  r xPendular=  false ;         bool  mR xPendular=  false ;  
			
				
				
			
		
	
		
		
	
		
		
			
				
					        uint32_t  innerLoopTimeout  =  DURATION_LISTEN_MIN ;         uint32_t  innerLoopTimeout  =  DURATION_LISTEN_MIN ;  
			
		
	
		
		
			
				
					
					        uint8_t  mTxSetupTime  =  0 ;         //uint8_t mTxSetupTime = 0;
  
			
				
				
			
		
	
		
		
	
		
		
			
				
					        uint8_t  mTxRetries  =  15 ;                             // memorize last setting for mNrf24->setRetries(3, 15);
         uint8_t  mTxRetries  =  15 ;                             // memorize last setting for mNrf24->setRetries(3, 15);
  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					        std : : unique_ptr < SPIClass >  mSpi ;         std : : unique_ptr < SPIClass >  mSpi ;