From f171dd389428a25edbb29ee9277a86b96c196448 Mon Sep 17 00:00:00 2001 From: Alex Shepherd Date: Wed, 18 Apr 2018 23:53:01 +1200 Subject: [PATCH] Added new FLAGS_AUTO_FACTORY_DEFAULT flag to enable checking CV 7 & 8 and if value of both is 255 then call notifyCVResetFactoryDefault() if defined --- NmraDcc.cpp | 13 ++++++++++--- NmraDcc.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/NmraDcc.cpp b/NmraDcc.cpp index 2dfb294..9df1429 100644 --- a/NmraDcc.cpp +++ b/NmraDcc.cpp @@ -1290,12 +1290,19 @@ void NmraDcc::init( uint8_t ManufacturerId, uint8_t VersionId, uint8_t Flags, ui // Set the Bits that control Multifunction or Accessory behaviour // and if the Accessory decoder optionally handles Output Addressing uint8_t cv29Mask = CV29_ACCESSORY_DECODER | CV29_OUTPUT_ADDRESS_MODE ; // peal off the top two bits - writeCV( CV_29_CONFIG, ( readCV( CV_29_CONFIG ) & ~cv29Mask ) | (Flags & ~FLAGS_MY_ADDRESS_ONLY) ) ; // KGW: Don't write bit 0 to CV. + writeCV( CV_29_CONFIG, ( readCV( CV_29_CONFIG ) & ~cv29Mask ) | (Flags & cv29Mask) ) ; - writeCV( 7, VersionId ) ; - writeCV( 8, ManufacturerId ) ; + uint8_t doAutoFactoryDefault = 0; + if((Flags & FLAGS_AUTO_FACTORY_DEFAULT) && (readCV(CV_VERSION_ID) == 255) && (readCV(CV_MANUFACTURER_ID) == 255)) + doAutoFactoryDefault = 1; + + writeCV( CV_VERSION_ID, VersionId ) ; + writeCV( CV_MANUFACTURER_ID, ManufacturerId ) ; clearDccProcState( 0 ); + + if(notifyCVResetFactoryDefault && doAutoFactoryDefault) + notifyCVResetFactoryDefault(); } //////////////////////////////////////////////////////////////////////// diff --git a/NmraDcc.h b/NmraDcc.h index d5673ee..3f74178 100644 --- a/NmraDcc.h +++ b/NmraDcc.h @@ -201,6 +201,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_OUTPUT_ADDRESS_MODE 0x40 // CV 29/541 bit 6 #define FLAGS_DCC_ACCESSORY_DECODER 0x80 // CV 29/541 bit 7