Changes/additions regarding output addressing and CVChange callback

Change Flag FLAGS_OUTPUT_ADDRESS_MODE accordingly, when CV29 Bit 6 (output addressing) is changed.
New callback 'notifyDccCVChange' which is NOT called if the CV is changed by means of the setCV() method
This commit is contained in:
MicroBahner
2018-04-23 17:11:45 +02:00
parent 7c85303368
commit 1be4ede559
2 changed files with 24 additions and 3 deletions

View File

@@ -581,11 +581,14 @@ uint8_t writeCV( unsigned int CV, uint8_t Value)
{ {
switch( CV ) 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_LSB: // Also same CV for CV_MULTIFUNCTION_PRIMARY_ADDRESS
case CV_ACCESSORY_DECODER_ADDRESS_MSB: case CV_ACCESSORY_DECODER_ADDRESS_MSB:
case CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB: case CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB:
case CV_MULTIFUNCTION_EXTENDED_ADDRESS_LSB: case CV_MULTIFUNCTION_EXTENDED_ADDRESS_LSB:
case CV_29_CONFIG:
DccProcState.myDccAddress = -1; // Assume any CV Write Operation might change the Address 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 ) if( notifyCVChange )
notifyCVChange( CV, Value) ; notifyCVChange( CV, Value) ;
if( notifyDccCVChange && !(DccProcState.Flags & FLAGS_SETCV_CALLED) )
notifyDccCVChange( CV, Value );
DccProcState.Flags &= ~FLAGS_SETCV_CALLED;
} }
return readEEPROM( CV ) ; return readEEPROM( CV ) ;
} }
@@ -1323,6 +1330,7 @@ uint8_t NmraDcc::getCV( uint16_t CV )
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
uint8_t NmraDcc::setCV( uint16_t CV, uint8_t Value) uint8_t NmraDcc::setCV( uint16_t CV, uint8_t Value)
{ {
DccProcState.Flags |= FLAGS_SETCV_CALLED;
return writeCV(CV,Value); return writeCV(CV,Value);
} }

View File

@@ -202,6 +202,7 @@ class NmraDcc
// Flag values to be logically ORed together and passed into the init() method // 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_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_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_OUTPUT_ADDRESS_MODE 0x40 // CV 29/541 bit 6
#define FLAGS_DCC_ACCESSORY_DECODER 0x80 // CV 29/541 bit 7 #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. * notifyCVChange() Called when a CV value is changed.
* This is called whenever a CV's 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 * Note: It is not called if notifyCVWrite() is defined
* or if the value in the EEPROM is the same as the value * or if the value in the EEPROM is the same as the value
* in the write command. * in the write command.
@@ -642,6 +645,7 @@ extern uint8_t notifyIsSetCVReady(void) __attribute__ ((weak));
* None * None
*/ */
extern void notifyCVChange( uint16_t CV, uint8_t Value) __attribute__ ((weak)); 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. * notifyCVResetFactoryDefault() Called when CVs must be reset.
@@ -654,7 +658,7 @@ extern void notifyCVChange( uint16_t CV, uint8_t Value) __attribute__ ((weak)
* *
* Inputs: * Inputs:
* None * None
* * * *
* Returns: * Returns:
* None * None
*/ */
@@ -667,11 +671,20 @@ extern void notifyCVResetFactoryDefault(void) __attribute__ ((weak));
* *
* Inputs: * Inputs:
* None * None
* * * *
* Returns: * Returns:
* None * None
*/ */
extern void notifyCVAck(void) __attribute__ ((weak)); 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)); extern void notifyServiceMode(bool) __attribute__ ((weak));
// Deprecated, only for backward compatibility with version 1.4.2. Don't use in new designs // Deprecated, only for backward compatibility with version 1.4.2. Don't use in new designs