diff --git a/NmraDcc.cpp b/NmraDcc.cpp index 9086fef..cf66bdc 100644 --- a/NmraDcc.cpp +++ b/NmraDcc.cpp @@ -581,11 +581,14 @@ uint8_t writeCV( unsigned int CV, uint8_t Value) { switch( CV ) { + case CV_29_CONFIG: + // copy addressmode Bit to Flags + DccProcState.Flags = ( DccProcState.Flags & ~FLAGS_OUTPUT_ADDRESS_MODE) | (Value & FLAGS_OUTPUT_ADDRESS_MODE); + // no break, because myDccAdress must also be reset case CV_ACCESSORY_DECODER_ADDRESS_LSB: // Also same CV for CV_MULTIFUNCTION_PRIMARY_ADDRESS case CV_ACCESSORY_DECODER_ADDRESS_MSB: case CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB: case CV_MULTIFUNCTION_EXTENDED_ADDRESS_LSB: - case CV_29_CONFIG: DccProcState.myDccAddress = -1; // Assume any CV Write Operation might change the Address } @@ -598,6 +601,10 @@ uint8_t writeCV( unsigned int CV, uint8_t Value) if( notifyCVChange ) notifyCVChange( CV, Value) ; + if( notifyDccCVChange && !(DccProcState.Flags & FLAGS_SETCV_CALLED) ) + notifyDccCVChange( CV, Value ); + + DccProcState.Flags &= ~FLAGS_SETCV_CALLED; } return readEEPROM( CV ) ; } @@ -1323,6 +1330,7 @@ uint8_t NmraDcc::getCV( uint16_t CV ) //////////////////////////////////////////////////////////////////////// uint8_t NmraDcc::setCV( uint16_t CV, uint8_t Value) { + DccProcState.Flags |= FLAGS_SETCV_CALLED; return writeCV(CV,Value); } diff --git a/NmraDcc.h b/NmraDcc.h index 3f74178..2b224e4 100644 --- a/NmraDcc.h +++ b/NmraDcc.h @@ -202,6 +202,7 @@ class NmraDcc // Flag values to be logically ORed together and passed into the init() method #define FLAGS_MY_ADDRESS_ONLY 0x01 // Only process DCC Packets with My Address #define FLAGS_AUTO_FACTORY_DEFAULT 0x02 // Call notifyCVResetFactoryDefault() if CV 7 & 8 == 255 +#define FLAGS_SETCV_CALLED 0x10 // only used internally !! #define FLAGS_OUTPUT_ADDRESS_MODE 0x40 // CV 29/541 bit 6 #define FLAGS_DCC_ACCESSORY_DECODER 0x80 // CV 29/541 bit 7 @@ -630,6 +631,8 @@ extern uint8_t notifyIsSetCVReady(void) __attribute__ ((weak)); /*+ * notifyCVChange() Called when a CV value is changed. * This is called whenever a CV's value is changed. + * notifyDccCVChange() Called only when a CV value is changed by a Dcc packet or a internal lib function. + * it is NOT called if the CV is chaged by means of the setCV() method. * Note: It is not called if notifyCVWrite() is defined * or if the value in the EEPROM is the same as the value * in the write command. @@ -642,6 +645,7 @@ extern uint8_t notifyIsSetCVReady(void) __attribute__ ((weak)); * None */ extern void notifyCVChange( uint16_t CV, uint8_t Value) __attribute__ ((weak)); +extern void notifyDccCVChange( uint16_t CV, uint8_t Value) __attribute__ ((weak)); /*+ * notifyCVResetFactoryDefault() Called when CVs must be reset. @@ -654,7 +658,7 @@ extern void notifyCVChange( uint16_t CV, uint8_t Value) __attribute__ ((weak) * * Inputs: * None - * * + * * * Returns: * None */ @@ -667,11 +671,20 @@ extern void notifyCVResetFactoryDefault(void) __attribute__ ((weak)); * * Inputs: * None - * * + * * * Returns: * None */ extern void notifyCVAck(void) __attribute__ ((weak)); +/*+ + * notifyServiceMode(bool) Called when state of 'inServiceMode' changes + * + * Inputs: + * bool state of inServiceMode + * * + * Returns: + * None + */ extern void notifyServiceMode(bool) __attribute__ ((weak)); // Deprecated, only for backward compatibility with version 1.4.2. Don't use in new designs