ESP8266 Support
This commit is contained in:
52
NmraDcc.cpp
52
NmraDcc.cpp
@@ -29,8 +29,13 @@
|
|||||||
//
|
//
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "NmraDcc.h"
|
#include "NmraDcc.h"
|
||||||
|
|
||||||
|
#if defined(ESP8266)
|
||||||
|
#include <EEPROM.h>
|
||||||
|
#else
|
||||||
#include <avr/eeprom.h>
|
#include <avr/eeprom.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
// DCC Receive Routine
|
// DCC Receive Routine
|
||||||
@@ -449,6 +454,32 @@ void ackCV(void)
|
|||||||
notifyCVAck() ;
|
notifyCVAck() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t readEEPROM( unsigned int CV ) {
|
||||||
|
#if defined(ESP8266)
|
||||||
|
return EEPROM.read(CV) ;
|
||||||
|
#else
|
||||||
|
return eeprom_read_byte( (uint8_t*) CV );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeEEPROM( unsigned int CV, uint8_t Value ) {
|
||||||
|
#if defined(ESP8266)
|
||||||
|
EEPROM.write(CV, Value) ;
|
||||||
|
EEPROM.commit();
|
||||||
|
#else
|
||||||
|
eeprom_write_byte( (uint8_t*) CV, Value ) ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool readyEEPROM() {
|
||||||
|
#if defined(ESP8266)
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return eeprom_is_ready();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t validCV( uint16_t CV, uint8_t Writable )
|
uint8_t validCV( uint16_t CV, uint8_t Writable )
|
||||||
{
|
{
|
||||||
if( notifyCVResetFactoryDefault && (CV == CV_MANUFACTURER_ID ) && Writable )
|
if( notifyCVResetFactoryDefault && (CV == CV_MANUFACTURER_ID ) && Writable )
|
||||||
@@ -459,7 +490,7 @@ uint8_t validCV( uint16_t CV, uint8_t Writable )
|
|||||||
|
|
||||||
uint8_t Valid = 1 ;
|
uint8_t Valid = 1 ;
|
||||||
|
|
||||||
if( CV > E2END )
|
if( CV > MAXCV )
|
||||||
Valid = 0 ;
|
Valid = 0 ;
|
||||||
|
|
||||||
if( Writable && ( ( CV ==CV_VERSION_ID ) || (CV == CV_MANUFACTURER_ID ) ) )
|
if( Writable && ( ( CV ==CV_VERSION_ID ) || (CV == CV_MANUFACTURER_ID ) ) )
|
||||||
@@ -475,8 +506,7 @@ uint8_t readCV( unsigned int CV )
|
|||||||
if( notifyCVRead )
|
if( notifyCVRead )
|
||||||
return notifyCVRead( CV ) ;
|
return notifyCVRead( CV ) ;
|
||||||
|
|
||||||
Value = eeprom_read_byte( (uint8_t*) CV ) ;
|
Value = readEEPROM(CV);
|
||||||
|
|
||||||
return Value ;
|
return Value ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,16 +515,16 @@ uint8_t writeCV( unsigned int CV, uint8_t Value)
|
|||||||
if( notifyCVWrite )
|
if( notifyCVWrite )
|
||||||
return notifyCVWrite( CV, Value ) ;
|
return notifyCVWrite( CV, Value ) ;
|
||||||
|
|
||||||
if( eeprom_read_byte( (uint8_t*) CV ) != Value )
|
if( readEEPROM( CV ) != Value )
|
||||||
{
|
{
|
||||||
eeprom_write_byte( (uint8_t*) CV, Value ) ;
|
writeEEPROM( CV, Value ) ;
|
||||||
|
|
||||||
if( notifyCVChange )
|
if( notifyCVChange )
|
||||||
notifyCVChange( CV, Value) ;
|
notifyCVChange( CV, Value) ;
|
||||||
}
|
}
|
||||||
return eeprom_read_byte( (uint8_t*) CV ) ;
|
return readEEPROM( CV ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t getMyAddr(void)
|
uint16_t getMyAddr(void)
|
||||||
{
|
{
|
||||||
uint16_t Addr ;
|
uint16_t Addr ;
|
||||||
@@ -980,6 +1010,9 @@ void NmraDcc::initAccessoryDecoder( uint8_t ManufacturerId, uint8_t VersionId, u
|
|||||||
|
|
||||||
void NmraDcc::init( uint8_t ManufacturerId, uint8_t VersionId, uint8_t Flags, uint8_t OpsModeAddressBaseCV )
|
void NmraDcc::init( uint8_t ManufacturerId, uint8_t VersionId, uint8_t Flags, uint8_t OpsModeAddressBaseCV )
|
||||||
{
|
{
|
||||||
|
#if defined(ESP8266)
|
||||||
|
EEPROM.begin(4096);
|
||||||
|
#endif
|
||||||
// Clear all the static member variables
|
// Clear all the static member variables
|
||||||
memset( &DccRx, 0, sizeof( DccRx) );
|
memset( &DccRx, 0, sizeof( DccRx) );
|
||||||
|
|
||||||
@@ -1025,8 +1058,7 @@ uint8_t NmraDcc::isSetCVReady(void)
|
|||||||
{
|
{
|
||||||
if(notifyIsSetCVReady)
|
if(notifyIsSetCVReady)
|
||||||
return notifyIsSetCVReady();
|
return notifyIsSetCVReady();
|
||||||
|
return readyEEPROM();
|
||||||
return eeprom_is_ready();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DCC_DEBUG
|
#ifdef DCC_DEBUG
|
||||||
|
@@ -89,7 +89,12 @@ typedef struct
|
|||||||
#define CV_VERSION_ID 7
|
#define CV_VERSION_ID 7
|
||||||
#define CV_MANUFACTURER_ID 8
|
#define CV_MANUFACTURER_ID 8
|
||||||
#define CV_29_CONFIG 29
|
#define CV_29_CONFIG 29
|
||||||
|
|
||||||
|
#if defined(ESP8266)
|
||||||
|
#define MAXCV 4096
|
||||||
|
#else
|
||||||
#define MAXCV E2END // the upper limit of the CV value currently defined to max memory.
|
#define MAXCV E2END // the upper limit of the CV value currently defined to max memory.
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CV29_LOCO_DIR = 0b00000001, /** bit 0: Locomotive Direction: "0" = normal, "1" = reversed */
|
CV29_LOCO_DIR = 0b00000001, /** bit 0: Locomotive Direction: "0" = normal, "1" = reversed */
|
||||||
|
Reference in New Issue
Block a user