Initial commit
Initial commit
This commit is contained in:
@@ -0,0 +1,692 @@
|
||||
// for ATMEGA328P
|
||||
#include <NmraDcc.h>
|
||||
|
||||
// Uncomment to force CV Reset to Factory Defaults
|
||||
//#define RESET_FACTORY_DEFAULTS
|
||||
|
||||
// Uncomment any of the lines below to enable debug messages for different parts of the code
|
||||
//#define DEBUG_FUNCTIONS
|
||||
//#define DEBUG_SPEED
|
||||
//#define DEBUG_PWM
|
||||
//#define DEBUG_DCC_ACK
|
||||
//#define DEBUG_DCC_MSG
|
||||
//#define DEBUG_STATE
|
||||
|
||||
#if defined(DEBUG_FUNCTIONS) or defined(DEBUG_SPEED) or defined(DEBUG_PWM) or defined(DEBUG_DCC_ACK) or defined(DEBUG_DCC_MSG) or defined(DEBUG_STATE)
|
||||
#define DEBUG_PRINT
|
||||
#endif
|
||||
|
||||
#define DECODER_ADDRESS 3
|
||||
#define LONG_ADDRESS 123
|
||||
|
||||
#define CV_VSTART 2
|
||||
#define START_VOLTAGE 10 // 255 is full rectified voltage
|
||||
|
||||
#define CV_ACC_RATE 3
|
||||
#define ACC_RATE 3 // value*0.896/speed_steps sec/step 3->2.688 sec to full speed
|
||||
|
||||
#define CV_DEC_RATE 4
|
||||
#define DEC_RATE 3 // value*0.896/speed_steps sec/step 3->2.688 sec from full speed
|
||||
|
||||
#define CV_VHIGH 5
|
||||
#define HIGH_VOLTAGE 255 // 255 is full rectified voltage
|
||||
|
||||
#define CV_VMID 6
|
||||
#define MID_VOLTAGE 127 // 255 is full rectified voltage
|
||||
|
||||
#define VERSION 1 // CV 7
|
||||
|
||||
#define CV_PWM_PERIOD 9
|
||||
#define PWM_PERIOD 1
|
||||
|
||||
#define CV_PACKET_TIMEOUT 11
|
||||
#define PACKET_TIMEOUT 100 // in 10 ms
|
||||
#define CV_UNLOCK_NUMBER 15
|
||||
#define CV_LOCKING_NUMBER 16
|
||||
#define CV_AUTO_STOP_CONFIG 27
|
||||
#define CV_OUTPUT_LOCATION_F0f 33
|
||||
#define CV_OUTPUT_LOCATION_F0r 34
|
||||
#define CV_OUTPUT_LOCATION_F1 35
|
||||
#define CV_OUTPUT_LOCATION_F2 36
|
||||
#define CV_OUTPUT_LOCATION_F3 37
|
||||
#define CV_OUTPUT_LOCATION_F4 38
|
||||
#define CV_OUTPUT_LOCATION_F5 39
|
||||
#define CV_OUTPUT_LOCATION_F6 40
|
||||
#define CV_OUTPUT_LOCATION_F7 41
|
||||
#define CV_OUTPUT_LOCATION_F8 42
|
||||
#define CV_OUTPUT_LOCATION_F9 43
|
||||
#define CV_OUTPUT_LOCATION_F10 44
|
||||
#define CV_OUTPUT_LOCATION_F11 45
|
||||
#define CV_OUTPUT_LOCATION_F12 46
|
||||
#define CV_PRODUCT_ID 47 //Product ID: 47-50 (CV47<<24 + CV48<<16 + CV49<<8 + CV50)
|
||||
#define CV_KICK_START 65
|
||||
#define CV_FWD_TRIM 66
|
||||
#define CV_SPEED_MAP 67 //67-94
|
||||
#define CV_REV_TRIM 95
|
||||
#define CV_USER_ID1 105
|
||||
#define CV_USER_ID2 106
|
||||
|
||||
//todo
|
||||
// function effects 57-61, dimming, inverting, 0-speed activate/deactivate
|
||||
// SW_IN function mapping, minimum time
|
||||
// overload amplitude, time
|
||||
|
||||
#define DCC_PIN 2
|
||||
#define MOTOR_IN1_PIN 9
|
||||
#define MOTOR_IN2_PIN 10
|
||||
#define MOTOR_nFAULT_PIN 8
|
||||
#define LED_F0f_PIN 5
|
||||
#define LED_F0r_PIN 6
|
||||
#define LED_AUX1_PIN 3
|
||||
#define LED_AUX2_PIN 11
|
||||
#define LED_AUX3_PIN A0
|
||||
#define LED_AUX4_PIN A1
|
||||
#define LED_AUX5_PIN A2
|
||||
#define LED_AUX6_PIN A3
|
||||
#define LED_AUX7_PIN A4
|
||||
#define LED_AUX8_PIN A5
|
||||
#define LED_GREEN_PIN 12
|
||||
#define LED_YELLOW_PIN 13
|
||||
#define LED_RED_PIN 7
|
||||
#define LED_BLUE_PIN 4
|
||||
#define DCC1_PK_PIN A6
|
||||
#define DCC2_PK_PIN A7
|
||||
|
||||
NmraDcc dcc;
|
||||
|
||||
struct CVPair{
|
||||
uint16_t CV;
|
||||
uint8_t Value;
|
||||
};
|
||||
|
||||
CVPair factoryDefaultCVs [] =
|
||||
{
|
||||
{CV_MULTIFUNCTION_PRIMARY_ADDRESS, DECODER_ADDRESS&0x7F },//CV1
|
||||
{CV_VSTART, START_VOLTAGE },//CV2
|
||||
{CV_ACC_RATE, ACC_RATE },//CV3
|
||||
{CV_DEC_RATE, DEC_RATE },//CV4
|
||||
{CV_VHIGH, HIGH_VOLTAGE },//CV5
|
||||
{CV_VMID, MID_VOLTAGE },//CV6, (CV7, CV8 implicit in dcc.init())
|
||||
{CV_PWM_PERIOD, PWM_PERIOD},//CV9
|
||||
{CV_PACKET_TIMEOUT, PACKET_TIMEOUT},//CV11
|
||||
{CV_UNLOCK_NUMBER, 0},
|
||||
{CV_LOCKING_NUMBER, 0},
|
||||
{CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB, highByte(LONG_ADDRESS) + 0xC0},
|
||||
{CV_MULTIFUNCTION_EXTENDED_ADDRESS_LSB, lowByte(LONG_ADDRESS)},
|
||||
{CV_AUTO_STOP_CONFIG, 0b00110011},//7,6: reserved, 5: DC+, 4: DC-, 3: unused, 2: Signal, 1: Asym left, 0: Asym right
|
||||
{CV_29_CONFIG, 0x00
|
||||
//| CV29_LOCO_DIR // 0: normal direction, 1: reversed direction
|
||||
| CV29_F0_LOCATION // 0: 14 speed steps, 1:28/128 speed steps
|
||||
//| CV29_APS // 0: only DCC, 1: analogue enabled
|
||||
//| CV29_ADV_ACK // 0: Railcom disabled, 1: Railcom enabled
|
||||
//| CV29_SPEED_TABLE_ENABLE // 0: simple speed curve (CV2, CV5, CV6)
|
||||
#ifdef LONG_ADDRESS
|
||||
| CV29_EXT_ADDRESSING // 0: one byte addressing, 1: two byte addressing
|
||||
#endif
|
||||
//| CV29_OUTPUT_ADDRESS_MODE // 0: Decoder Address Mode, 1: Output Address Mode
|
||||
//| CV29_ACCESSORY_DECODER // 0: Multi-Function Decoder Mode, 1: Accessory Decoder Mode
|
||||
},
|
||||
{CV_OUTPUT_LOCATION_F0f, 1},// 1:F0f, 2:F0r, 4:AUX1, 8:AUX2, 16:AUX3, 32:AUX4, 64:AUX5, 128:AUX6
|
||||
{CV_OUTPUT_LOCATION_F0r, 2},// 1:F0f, 2:F0r, 4:AUX1, 8:AUX2, 16:AUX3, 32:AUX4, 64:AUX5, 128:AUX6
|
||||
{CV_OUTPUT_LOCATION_F1, 4}, // 1:F0f, 2:F0r, 4:AUX1, 8:AUX2, 16:AUX3, 32:AUX4, 64:AUX5, 128:AUX6
|
||||
{CV_OUTPUT_LOCATION_F2, 8}, // 1:F0f, 2:F0r, 4:AUX1, 8:AUX2, 16:AUX3, 32:AUX4, 64:AUX5, 128:AUX6
|
||||
{CV_OUTPUT_LOCATION_F3, 16},// 1:F0f, 2:F0r, 4:AUX1, 8:AUX2, 16:AUX3, 32:AUX4, 64:AUX5, 128:AUX6
|
||||
{CV_OUTPUT_LOCATION_F4, 4}, // 1:AUX2, 2:AUX3, 4:AUX4, 8:AUX5, 16:AUX6, 32:AUX7, 64:AUX8
|
||||
{CV_OUTPUT_LOCATION_F5, 8}, // 1:AUX2, 2:AUX3, 4:AUX4, 8:AUX5, 16:AUX6, 32:AUX7, 64:AUX8
|
||||
{CV_OUTPUT_LOCATION_F6, 16},// 1:AUX2, 2:AUX3, 4:AUX4, 8:AUX5, 16:AUX6, 32:AUX7, 64:AUX8
|
||||
{CV_OUTPUT_LOCATION_F7, 32},// 1:AUX2, 2:AUX3, 4:AUX4, 8:AUX5, 16:AUX6, 32:AUX7, 64:AUX8
|
||||
{CV_OUTPUT_LOCATION_F8, 64},// 1:AUX2, 2:AUX3, 4:AUX4, 8:AUX5, 16:AUX6, 32:AUX7, 64:AUX8
|
||||
{CV_OUTPUT_LOCATION_F9, 0}, // 1:AUX5, 2:AUX6, 4:AUX7, 8:AUX8
|
||||
{CV_OUTPUT_LOCATION_F10, 0},// 1:AUX5, 2:AUX6, 4:AUX7, 8:AUX8
|
||||
{CV_OUTPUT_LOCATION_F11, 0},// 1:AUX5, 2:AUX6, 4:AUX7, 8:AUX8
|
||||
{CV_OUTPUT_LOCATION_F12, 0},// 1:AUX5, 2:AUX6, 4:AUX7, 8:AUX8
|
||||
{CV_PRODUCT_ID+0, 0}, // product ID highest byte
|
||||
{CV_PRODUCT_ID+1, 0}, // product ID high byte
|
||||
{CV_PRODUCT_ID+2, 1}, // product ID low byte
|
||||
{CV_PRODUCT_ID+3, 2}, // product ID lowest byte
|
||||
{CV_KICK_START, 100},
|
||||
{CV_FWD_TRIM, 128},
|
||||
{CV_SPEED_MAP+0, 43},
|
||||
{CV_SPEED_MAP+1, 46},
|
||||
{CV_SPEED_MAP+2, 50},
|
||||
{CV_SPEED_MAP+3, 54},
|
||||
{CV_SPEED_MAP+4, 58},
|
||||
{CV_SPEED_MAP+5, 62},
|
||||
{CV_SPEED_MAP+6, 66},
|
||||
{CV_SPEED_MAP+7, 71},
|
||||
{CV_SPEED_MAP+8, 76},
|
||||
{CV_SPEED_MAP+9, 81},
|
||||
{CV_SPEED_MAP+10, 87},
|
||||
{CV_SPEED_MAP+11, 93},
|
||||
{CV_SPEED_MAP+12, 99},
|
||||
{CV_SPEED_MAP+13, 106},
|
||||
{CV_SPEED_MAP+14, 113},
|
||||
{CV_SPEED_MAP+15, 121},
|
||||
{CV_SPEED_MAP+16, 129},
|
||||
{CV_SPEED_MAP+17, 137},
|
||||
{CV_SPEED_MAP+18, 146},
|
||||
{CV_SPEED_MAP+19, 155},
|
||||
{CV_SPEED_MAP+20, 165},
|
||||
{CV_SPEED_MAP+21, 176},
|
||||
{CV_SPEED_MAP+22, 187},
|
||||
{CV_SPEED_MAP+23, 199},
|
||||
{CV_SPEED_MAP+24, 212},
|
||||
{CV_SPEED_MAP+25, 226},
|
||||
{CV_SPEED_MAP+26, 240},
|
||||
{CV_SPEED_MAP+27, 255},
|
||||
{CV_REV_TRIM, 128},
|
||||
{CV_USER_ID1, 42},
|
||||
{CV_USER_ID2, 42},
|
||||
};
|
||||
|
||||
uint8_t factoryDefaultCVIndex = 0;
|
||||
// state variables
|
||||
uint8_t numSpeedSteps = SPEED_STEP_128;
|
||||
uint32_t lastFunctionState;
|
||||
uint32_t newFunctionState;
|
||||
bool lastDirection; // DCC_DIR_FWD(1): (a+/b-), DCC_DIR_REV(0): rev (a-/b+)
|
||||
bool newDirection; // DCC_DIR_FWD(1): (a+/b-), DCC_DIR_REV(0): rev (a-/b+)
|
||||
bool actualDirection; // DCC_DIR_FWD(1): (a+/b-), DCC_DIR_REV(0): rev (a-/b+)
|
||||
uint8_t lastSpeed; // 0-127, 0:EMCY stop, 1: normal stop, 2-127: drive
|
||||
uint8_t newSpeed; // 0-127, 0:EMCY stop, 1: normal stop, 2-127: drive
|
||||
uint8_t actualSpeed;
|
||||
uint8_t targetSpeed;
|
||||
uint8_t savedSpeed;
|
||||
uint16_t maxOCR;
|
||||
// timing for acceleration / deceleration
|
||||
uint32_t lastSpeedStep = 0;
|
||||
uint32_t newSpeedStep = 0;
|
||||
uint32_t packetTimeout;
|
||||
uint32_t lastPacket;
|
||||
// configuration variables
|
||||
uint8_t vStart;
|
||||
uint8_t vMid;
|
||||
uint8_t vHigh;
|
||||
uint8_t accRate;
|
||||
uint8_t decRate;
|
||||
uint8_t pwmPeriod;
|
||||
uint8_t functionMapping[14];
|
||||
uint8_t lastOutputState = 0;
|
||||
uint8_t newOutputState = 0;
|
||||
|
||||
void notifyCVResetFactoryDefault(){
|
||||
/*+
|
||||
* notifyCVResetFactoryDefault() Called when CVs must be reset.
|
||||
* This is called when CVs must be reset
|
||||
* to their factory defaults. This callback
|
||||
* should write the factory default value of
|
||||
* relevent CVs using the setCV() method.
|
||||
* setCV() must not block whens this is called.
|
||||
* Test with isSetCVReady() prior to calling setCV()
|
||||
*
|
||||
* Inputs:
|
||||
* None
|
||||
* *
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
// Make FactoryDefaultCVIndex non-zero and equal to num CV's to be reset
|
||||
// to flag to the loop() function that a reset to Factory Defaults needs to be done
|
||||
factoryDefaultCVIndex = sizeof(factoryDefaultCVs)/sizeof(CVPair);
|
||||
};
|
||||
|
||||
void notifyDccReset(uint8_t hardReset){
|
||||
/*+
|
||||
* notifyDccReset(uint8_t hardReset) Callback for a DCC reset command.
|
||||
*
|
||||
* Inputs:
|
||||
* hardReset - 0 normal reset command.
|
||||
* 1 hard reset command.
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
;
|
||||
}
|
||||
|
||||
void notifyDccIdle(void){
|
||||
/*+
|
||||
* notifyDccIdle() Callback for a DCC idle command.
|
||||
*
|
||||
* Inputs:
|
||||
* None
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
;
|
||||
}
|
||||
|
||||
void notifyCVChange( uint16_t CV, uint8_t Value){
|
||||
/*+
|
||||
* 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 changed 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.
|
||||
*
|
||||
* Inputs:
|
||||
* CV - CV number.
|
||||
* Value - Value of the CV.
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
switch(CV){
|
||||
case CV_VSTART:
|
||||
vStart = Value;
|
||||
break;
|
||||
case CV_ACC_RATE:
|
||||
accRate = Value;
|
||||
break;
|
||||
case CV_DEC_RATE:
|
||||
decRate = Value;
|
||||
break;
|
||||
case CV_VMID:
|
||||
vMid = Value;
|
||||
break;
|
||||
case CV_VHIGH:
|
||||
vHigh = Value;
|
||||
break;
|
||||
case CV_PWM_PERIOD:
|
||||
pwmPeriod = Value;
|
||||
break;
|
||||
case CV_OUTPUT_LOCATION_F0f:
|
||||
case CV_OUTPUT_LOCATION_F0r:
|
||||
case CV_OUTPUT_LOCATION_F1:
|
||||
case CV_OUTPUT_LOCATION_F2:
|
||||
case CV_OUTPUT_LOCATION_F3:
|
||||
case CV_OUTPUT_LOCATION_F4:
|
||||
case CV_OUTPUT_LOCATION_F5:
|
||||
case CV_OUTPUT_LOCATION_F6:
|
||||
case CV_OUTPUT_LOCATION_F7:
|
||||
case CV_OUTPUT_LOCATION_F8:
|
||||
case CV_OUTPUT_LOCATION_F9:
|
||||
case CV_OUTPUT_LOCATION_F10:
|
||||
case CV_OUTPUT_LOCATION_F11:
|
||||
case CV_OUTPUT_LOCATION_F12:
|
||||
functionMapping[CV - CV_OUTPUT_LOCATION_F0f] = Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void notifyDccSpeed(uint16_t Addr, DCC_ADDR_TYPE AddrType, uint8_t Speed, DCC_DIRECTION Dir, DCC_SPEED_STEPS SpeedSteps){
|
||||
/*+
|
||||
* notifyDccSpeed() Callback for a multifunction decoder speed command.
|
||||
* The received speed and direction are unpacked to separate values.
|
||||
*
|
||||
* Inputs:
|
||||
* Addr - Active decoder address.
|
||||
* AddrType - DCC_ADDR_SHORT or DCC_ADDR_LONG.
|
||||
* Speed - Decoder speed. 0 = Emergency stop
|
||||
* 1 = Regular stop
|
||||
* 2 to SpeedSteps = Speed step 1 to max.
|
||||
* Dir - DCC_DIR_REV or DCC_DIR_FWD
|
||||
* SpeedSteps - Highest speed, SPEED_STEP_14 = 15
|
||||
* SPEED_STEP_28 = 29
|
||||
* SPEED_STEP_128 = 127
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
#ifdef DEBUG_SPEED
|
||||
Serial.print("notifyDccSpeed: Addr: ");
|
||||
Serial.print(Addr,DEC);
|
||||
Serial.print( (AddrType == DCC_ADDR_SHORT) ? "-S" : "-L" );
|
||||
Serial.print(" Speed: ");
|
||||
Serial.print(Speed,DEC);
|
||||
Serial.print(" Steps: ");
|
||||
Serial.print(SpeedSteps,DEC);
|
||||
Serial.print(" Dir: ");
|
||||
Serial.println( (Dir == DCC_DIR_FWD) ? "Forward" : "Reverse" );
|
||||
#endif
|
||||
newDirection = Dir;
|
||||
newSpeed = Speed;
|
||||
numSpeedSteps = SpeedSteps;
|
||||
}
|
||||
|
||||
void notifyDccFunc(uint16_t Addr, DCC_ADDR_TYPE AddrType, FN_GROUP FuncGrp, uint8_t FuncState){
|
||||
/*+
|
||||
* notifyDccFunc() Callback for a multifunction decoder function command.
|
||||
*
|
||||
* Inputs:
|
||||
* Addr - Active decoder address.
|
||||
* AddrType - DCC_ADDR_SHORT or DCC_ADDR_LONG.
|
||||
* FuncGrp - Function group. FN_0 - 14 speed step headlight function.
|
||||
* Mask FN_BIT_00.
|
||||
* FN_0_4 - Functions 0 to 4. Mask FN_BIT_00 - FN_BIT_04
|
||||
* FN_5_8 - Functions 5 to 8. Mask FN_BIT_05 - FN_BIT_08
|
||||
* FN_9_12 - Functions 9 to 12. Mask FN_BIT_09 - FN_BIT_12
|
||||
* FN_13_20 - Functions 13 to 20. Mask FN_BIT_13 - FN_BIT_20
|
||||
* FN_21_28 - Functions 21 to 28. Mask FN_BIT_21 - FN_BIT_28
|
||||
* FuncState - Function state. Bitmask where active functions have a 1 at that bit.
|
||||
* You must & FuncState with the appropriate
|
||||
* FN_BIT_nn value to isolate a given bit.
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
#ifdef DEBUG_FUNCTIONS
|
||||
Serial.print("notifyDccFunc: Addr: ");
|
||||
Serial.print(Addr,DEC);
|
||||
Serial.print( (AddrType == DCC_ADDR_SHORT) ? 'S' : 'L' );
|
||||
Serial.print(" Function Group: ");
|
||||
Serial.print(FuncGrp,DEC);
|
||||
#endif
|
||||
|
||||
switch(FuncGrp){
|
||||
case FN_0_4:
|
||||
bitWrite(newFunctionState, 0, FuncState & FN_BIT_00);
|
||||
bitWrite(newFunctionState, 1, FuncState & FN_BIT_01);
|
||||
bitWrite(newFunctionState, 2, FuncState & FN_BIT_02);
|
||||
bitWrite(newFunctionState, 3, FuncState & FN_BIT_03);
|
||||
bitWrite(newFunctionState, 4, FuncState & FN_BIT_04);
|
||||
#ifdef DEBUG_FUNCTIONS
|
||||
Serial.print(" FN 0-4: ");
|
||||
Serial.print(newFunctionState & 0x1F);
|
||||
#endif
|
||||
break;
|
||||
case FN_5_8:
|
||||
bitWrite(newFunctionState, 5, FuncState & FN_BIT_05);
|
||||
bitWrite(newFunctionState, 6, FuncState & FN_BIT_06);
|
||||
bitWrite(newFunctionState, 7, FuncState & FN_BIT_07);
|
||||
bitWrite(newFunctionState, 8, FuncState & FN_BIT_08);
|
||||
#ifdef DEBUG_FUNCTIONS
|
||||
Serial.print(" FN 5-8: ");
|
||||
Serial.print((newFunctionState >> 5) & 0xF);
|
||||
#endif
|
||||
break;
|
||||
case FN_9_12:
|
||||
bitWrite(newFunctionState, 9, FuncState & FN_BIT_09);
|
||||
bitWrite(newFunctionState, 10, FuncState & FN_BIT_10);
|
||||
bitWrite(newFunctionState, 11, FuncState & FN_BIT_11);
|
||||
bitWrite(newFunctionState, 12, FuncState & FN_BIT_12);
|
||||
#ifdef DEBUG_FUNCTIONS
|
||||
Serial.print(" FN 9-12: ");
|
||||
Serial.print((newFunctionState >> 9) & 0xF);
|
||||
#endif
|
||||
break;
|
||||
case FN_13_20:
|
||||
bitWrite(newFunctionState, 13, FuncState & FN_BIT_13);
|
||||
bitWrite(newFunctionState, 14, FuncState & FN_BIT_14);
|
||||
bitWrite(newFunctionState, 15, FuncState & FN_BIT_15);
|
||||
bitWrite(newFunctionState, 16, FuncState & FN_BIT_16);
|
||||
bitWrite(newFunctionState, 17, FuncState & FN_BIT_17);
|
||||
bitWrite(newFunctionState, 18, FuncState & FN_BIT_18);
|
||||
bitWrite(newFunctionState, 19, FuncState & FN_BIT_19);
|
||||
bitWrite(newFunctionState, 20, FuncState & FN_BIT_20);
|
||||
#ifdef DEBUG_FUNCTIONS
|
||||
Serial.print(" FN 13-20: ");
|
||||
Serial.print((newFunctionState >> 13) & 0xFF);
|
||||
#endif
|
||||
break;
|
||||
case FN_21_28:
|
||||
bitWrite(newFunctionState, 21, FuncState & FN_BIT_21);
|
||||
bitWrite(newFunctionState, 22, FuncState & FN_BIT_22);
|
||||
bitWrite(newFunctionState, 23, FuncState & FN_BIT_23);
|
||||
bitWrite(newFunctionState, 24, FuncState & FN_BIT_24);
|
||||
bitWrite(newFunctionState, 25, FuncState & FN_BIT_25);
|
||||
bitWrite(newFunctionState, 26, FuncState & FN_BIT_26);
|
||||
bitWrite(newFunctionState, 27, FuncState & FN_BIT_27);
|
||||
bitWrite(newFunctionState, 28, FuncState & FN_BIT_28);
|
||||
#ifdef DEBUG_FUNCTIONS
|
||||
Serial.print(" FN 21-28: ");
|
||||
Serial.print((newFunctionState >> 21) & 0xFF);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#ifdef DEBUG_FUNCTIONS
|
||||
Serial.println();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DCC_MSG
|
||||
void notifyDccMsg( DCC_MSG * Msg){
|
||||
/*+
|
||||
* notifyDccMsg() Raw DCC packet callback.
|
||||
* Called with raw DCC packet bytes.
|
||||
*
|
||||
* Inputs:
|
||||
* Msg - Pointer to DCC_MSG structure. The values are:
|
||||
* Msg->Size - Number of Data bytes in the packet.
|
||||
* Msg->PreambleBits - Number of preamble bits in the packet.
|
||||
* Msg->Data[] - Array of data bytes in the packet.
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
Serial.print("notifyDccMsg: ") ;
|
||||
for(uint8_t i = 0; i < Msg->Size; i++){
|
||||
Serial.print(Msg->Data[i], HEX);
|
||||
Serial.write(' ');
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
#endif
|
||||
|
||||
void notifyCVAck(void){
|
||||
/*+
|
||||
* notifyCVAck() Called when a CV write must be acknowledged.
|
||||
* This callback must increase the current drawn by this
|
||||
* decoder by at least 60mA for 6ms +/- 1ms.
|
||||
*
|
||||
* Inputs:
|
||||
* None
|
||||
* *
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
static bool ackDir = true;
|
||||
#ifdef DEBUG_DCC_ACK
|
||||
Serial.println("notifyCVAck") ;
|
||||
#endif
|
||||
|
||||
digitalWrite(MOTOR_IN1_PIN, ackDir);
|
||||
digitalWrite(MOTOR_IN2_PIN, !ackDir);
|
||||
delay(6);
|
||||
digitalWrite(MOTOR_IN1_PIN, 1);
|
||||
digitalWrite(MOTOR_IN2_PIN, 1);
|
||||
ackDir = !ackDir;
|
||||
}
|
||||
|
||||
void setup(){
|
||||
#ifdef DEBUG_PRINT
|
||||
Serial.begin(115200);
|
||||
Serial.println("NMRA Dcc Multifunction Motor Decoder Demo");
|
||||
#endif
|
||||
|
||||
pinMode(MOTOR_IN1_PIN, OUTPUT);
|
||||
pinMode(MOTOR_IN2_PIN, OUTPUT);
|
||||
pinMode(LED_F0f_PIN, OUTPUT);
|
||||
pinMode(LED_F0r_PIN, OUTPUT);
|
||||
pinMode(LED_AUX1_PIN, OUTPUT);
|
||||
pinMode(LED_AUX2_PIN, OUTPUT);
|
||||
pinMode(LED_AUX3_PIN, OUTPUT);
|
||||
pinMode(LED_AUX4_PIN, OUTPUT);
|
||||
pinMode(LED_AUX5_PIN, OUTPUT);
|
||||
pinMode(LED_AUX6_PIN, OUTPUT);
|
||||
pinMode(LED_AUX7_PIN, OUTPUT);
|
||||
pinMode(LED_AUX8_PIN, OUTPUT);
|
||||
pinMode(LED_GREEN_PIN, OUTPUT);
|
||||
pinMode(LED_YELLOW_PIN, OUTPUT);
|
||||
pinMode(LED_RED_PIN, OUTPUT);
|
||||
pinMode(LED_BLUE_PIN, OUTPUT);
|
||||
pinMode(MOTOR_nFAULT_PIN, INPUT_PULLUP);
|
||||
|
||||
newDirection = DCC_DIR_FWD;
|
||||
actualDirection = DCC_DIR_FWD;
|
||||
digitalWrite(MOTOR_IN1_PIN, 1);
|
||||
digitalWrite(MOTOR_IN2_PIN, 1);
|
||||
newSpeed = lastSpeed = 0;
|
||||
targetSpeed = actualSpeed = 0;
|
||||
|
||||
dcc.pin(DCC_PIN, false); // interrupt pin 2, no pullup
|
||||
// only process DCC Packets with My Address
|
||||
// Call notifyCVResetFactoryDefault() if CV 7 & 8 == 255
|
||||
dcc.init(MAN_ID_DIY, VERSION, FLAGS_MY_ADDRESS_ONLY | FLAGS_AUTO_FACTORY_DEFAULT, 0);
|
||||
|
||||
#ifdef RESET_FACTORY_DEFAULTS
|
||||
notifyCVResetFactoryDefault();
|
||||
#endif
|
||||
// Read the current CV values for vStart and vHigh
|
||||
vStart = dcc.getCV(CV_VSTART);
|
||||
vMid = dcc.getCV(CV_VMID);
|
||||
vHigh = dcc.getCV(CV_VHIGH);
|
||||
accRate = dcc.getCV(CV_ACC_RATE);
|
||||
decRate = dcc.getCV(CV_DEC_RATE);
|
||||
packetTimeout = 10*dcc.getCV(CV_PACKET_TIMEOUT);
|
||||
pwmPeriod = dcc.getCV(CV_PWM_PERIOD);
|
||||
TCCR1A = _BV(COM1A1) | _BV(COM1A0) | _BV(COM1B1) | _BV(COM1B0); // TIMER1 A and B invert PWM
|
||||
TCCR1B = _BV(WGM13) | _BV(CS10); // TIMER1 prescaler=1, phase and frequency correct mode PWM, TOP=ICR1
|
||||
switch(pwmPeriod){ // f = 8 MHz / TOP
|
||||
case 0: // 40 kHz
|
||||
maxOCR = 200;
|
||||
break;
|
||||
case 1: // 35 kHz
|
||||
maxOCR = 229;
|
||||
break;
|
||||
case 2: // 30 kHz
|
||||
maxOCR = 267;
|
||||
break;
|
||||
case 3: // 25 kHz
|
||||
maxOCR = 320;
|
||||
break;
|
||||
case 4: // 20 kHz
|
||||
maxOCR = 400;
|
||||
break;
|
||||
}
|
||||
ICR1 = maxOCR;
|
||||
|
||||
for(byte i=0;i<14;i++){
|
||||
functionMapping[i] = dcc.getCV(CV_OUTPUT_LOCATION_F0f + i);
|
||||
}
|
||||
}
|
||||
|
||||
void loop(){
|
||||
if(dcc.process()){ // update last valid packet reception time
|
||||
lastPacket = millis();
|
||||
}
|
||||
if((millis()-lastPacket) > packetTimeout){ // timeout since last valid packet
|
||||
newSpeed = 0;
|
||||
}
|
||||
switch(dcc.getDccPolarity()){
|
||||
case RISING:
|
||||
digitalWrite(LED_GREEN_PIN, LOW);
|
||||
digitalWrite(LED_BLUE_PIN, HIGH);
|
||||
break;
|
||||
case FALLING:
|
||||
digitalWrite(LED_GREEN_PIN, HIGH);
|
||||
digitalWrite(LED_BLUE_PIN, LOW);
|
||||
break;
|
||||
}
|
||||
// handle direction changes
|
||||
if(newDirection != actualDirection){
|
||||
if(lastDirection != newDirection){
|
||||
savedSpeed = targetSpeed;
|
||||
lastDirection = newDirection;
|
||||
}
|
||||
targetSpeed = 0;
|
||||
if(actualSpeed == 0){
|
||||
actualDirection = newDirection;
|
||||
targetSpeed = savedSpeed;
|
||||
}
|
||||
}else{
|
||||
targetSpeed = savedSpeed;
|
||||
}
|
||||
digitalWrite(LED_YELLOW_PIN, (actualDirection == DCC_DIR_FWD) || (newDirection == DCC_DIR_FWD));
|
||||
digitalWrite(LED_RED_PIN, (actualDirection == DCC_DIR_REV) || (newDirection == DCC_DIR_REV));
|
||||
// handle speed change
|
||||
if(lastSpeed != newSpeed){
|
||||
lastSpeed = newSpeed;
|
||||
if(newSpeed == 0){ // Stop if speed = 0
|
||||
targetSpeed = actualSpeed = 0;
|
||||
OCR1A = 0;
|
||||
OCR1B = 0;
|
||||
#ifdef DEBUG_PWM
|
||||
Serial.println("Emergency stop");
|
||||
#endif
|
||||
}else if(newSpeed == 1){ // Stop if speed = 1
|
||||
targetSpeed = 0;
|
||||
#ifdef DEBUG_PWM
|
||||
Serial.println("Regular stop");
|
||||
#endif
|
||||
}else{ // Calculate PWM value in the range 1..255
|
||||
uint8_t vScF1; // start to mid
|
||||
uint8_t vScF2; // mid to high
|
||||
uint8_t modSpeed = newSpeed - 1; // 1-126
|
||||
uint8_t modSteps = numSpeedSteps - 1; // 14/28/126
|
||||
|
||||
if((vHigh > 1) && (vHigh > vStart)){ // vHigh is valid
|
||||
if((vMid > 1) && (vHigh > vMid)){ // vMid is valid too, using vStart, vMid and vHigh
|
||||
vScF1 = vMid - vStart;
|
||||
vScF2 = vHigh - vMid;
|
||||
}else{ // vMid invalid, using vStart and vHigh
|
||||
vScF2 = vScF1 = (vHigh - vStart)/2;
|
||||
}
|
||||
}else{ // vHigh invalid, using only vStart
|
||||
vScF2 = vScF1 = (255 - vStart)/2;
|
||||
}
|
||||
|
||||
if(modSpeed<modSteps/2){
|
||||
targetSpeed = (int16_t) vStart + 2*modSpeed*vScF1/modSteps;
|
||||
}else{
|
||||
targetSpeed = (int16_t) vStart + 2*modSpeed*vScF2/modSteps + vScF1 - vScF2;
|
||||
}
|
||||
}
|
||||
savedSpeed = targetSpeed;
|
||||
}
|
||||
|
||||
// ramp up/down PWM
|
||||
if(targetSpeed != actualSpeed){
|
||||
newSpeedStep = millis();
|
||||
if(targetSpeed > actualSpeed){ // accelerating
|
||||
if((newSpeedStep - lastSpeedStep) > accRate*896/(numSpeedSteps-1)){
|
||||
lastSpeedStep = newSpeedStep;
|
||||
actualSpeed++;
|
||||
}
|
||||
}else{ // decelerating
|
||||
if((newSpeedStep - lastSpeedStep) > decRate*896/(numSpeedSteps-1)){
|
||||
lastSpeedStep = newSpeedStep;
|
||||
actualSpeed--;
|
||||
}
|
||||
}
|
||||
if(actualDirection == DCC_DIR_FWD){ // DCC FWD
|
||||
OCR1B = 0;
|
||||
OCR1A = map(actualSpeed, 0, 255, 0, maxOCR);
|
||||
}else{ // DCC REV
|
||||
OCR1A = 0;
|
||||
OCR1B = map(actualSpeed, 0, 255, 0, maxOCR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if((newFunctionState != lastFunctionState)||(actualSpeed == 0)){ // handle function change, map to outputs
|
||||
lastFunctionState = newFunctionState;
|
||||
newOutputState = 0;
|
||||
if(actualDirection){ // F0f
|
||||
newOutputState |= (bitRead(newFunctionState, 0) ? functionMapping[0] : 0);
|
||||
}else{ // F0r
|
||||
newOutputState |= (bitRead(newFunctionState, 0) ? functionMapping[1] : 0);
|
||||
}
|
||||
for(byte i=1;i<=12;i++){ //F1-F12
|
||||
newOutputState |= (bitRead(newFunctionState, i) ? functionMapping[i+1] : 0);
|
||||
}
|
||||
}
|
||||
|
||||
if(newOutputState != lastOutputState){ // actualise outputs
|
||||
lastOutputState = newOutputState;
|
||||
digitalWrite(LED_F0f_PIN, bitRead(newOutputState, 0));
|
||||
digitalWrite(LED_F0r_PIN, bitRead(newOutputState, 1));
|
||||
digitalWrite(LED_AUX1_PIN, bitRead(newOutputState, 2));
|
||||
digitalWrite(LED_AUX2_PIN, bitRead(newOutputState, 3));
|
||||
digitalWrite(LED_AUX3_PIN, bitRead(newOutputState, 4));
|
||||
}
|
||||
|
||||
|
||||
if( factoryDefaultCVIndex && dcc.isSetCVReady()){ // handle factory default
|
||||
factoryDefaultCVIndex--; // Decrement first as initially it is the size of the array
|
||||
dcc.setCV( factoryDefaultCVs[factoryDefaultCVIndex].CV, factoryDefaultCVs[factoryDefaultCVIndex].Value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,505 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
(This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.)
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{description}
|
||||
Copyright (C) {year} {fullname}
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random
|
||||
Hacker.
|
||||
|
||||
{signature of Ty Coon}, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,757 @@
|
||||
//------------------------------------------------------------------------
|
||||
//
|
||||
// Model Railroading with Arduino - NmraDcc.h
|
||||
//
|
||||
// Copyright (c) 2008 - 2020 Alex Shepherd
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
//
|
||||
// file: NmraDcc.h
|
||||
// author: Alex Shepherd
|
||||
// webpage: http://mrrwa.org/
|
||||
// history: 2008-03-20 Initial Version
|
||||
// 2011-06-26 Migrated into Arduino library from OpenDCC codebase
|
||||
// 2014 Added getAddr to NmraDcc Geoff Bunza
|
||||
// 2015-11-06 Martin Pischky (martin@pischky.de):
|
||||
// Experimental Version to support 14 speed steps
|
||||
// and new signature of notifyDccSpeed and notifyDccFunc
|
||||
// 2017-11-29 Ken West (kgw4449@gmail.com):
|
||||
// Added method and callback headers.
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
//
|
||||
// purpose: Provide a simplified interface to decode NMRA DCC packets
|
||||
// and build DCC MutliFunction and Stationary Decoders
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
// Uncomment the following Line to Enable Service Mode CV Programming
|
||||
#define NMRA_DCC_PROCESS_SERVICEMODE
|
||||
|
||||
// Uncomment the following line to Enable MultiFunction Decoder Operations
|
||||
#define NMRA_DCC_PROCESS_MULTIFUNCTION
|
||||
|
||||
// Uncomment the following line to Enable 14 Speed Step Support
|
||||
//#define NMRA_DCC_ENABLE_14_SPEED_STEP_MODE
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#ifndef NMRADCC_IS_IN
|
||||
#define NMRADCC_IS_IN
|
||||
|
||||
#define NMRADCC_VERSION 206 // Version 2.0.6
|
||||
|
||||
#define MAX_DCC_MESSAGE_LEN 6 // including XOR-Byte
|
||||
|
||||
//#define ALLOW_NESTED_IRQ // uncomment to enable nested IRQ's ( only for AVR! )
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Size ;
|
||||
uint8_t PreambleBits ;
|
||||
uint8_t Data[MAX_DCC_MESSAGE_LEN] ;
|
||||
} DCC_MSG ;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// This section contains the NMRA Assigned DCC Manufacturer Id Codes that
|
||||
// are used in projects
|
||||
//
|
||||
// This value is to be used for CV8
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
#define MAN_ID_JMRI 0x12
|
||||
#define MAN_ID_DIY 0x0D
|
||||
#define MAN_ID_SILICON_RAILWAY 0x21
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// This section contains the Product/Version Id Codes for projects
|
||||
//
|
||||
// This value is to be used for CV7
|
||||
//
|
||||
// NOTE: Each Product/Version Id Code needs to be UNIQUE for that particular
|
||||
// the DCC Manufacturer Id Code
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
// Product/Version Id Codes allocated under: MAN_ID_JMRI
|
||||
|
||||
// Product/Version Id Codes allocated under: MAN_ID_DIY
|
||||
|
||||
// Standard CV Addresses
|
||||
#define CV_ACCESSORY_DECODER_ADDRESS_LSB 1
|
||||
#define CV_ACCESSORY_DECODER_ADDRESS_MSB 9
|
||||
|
||||
#define CV_MULTIFUNCTION_PRIMARY_ADDRESS 1
|
||||
#define CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB 17
|
||||
#define CV_MULTIFUNCTION_EXTENDED_ADDRESS_LSB 18
|
||||
|
||||
#define CV_VERSION_ID 7
|
||||
#define CV_MANUFACTURER_ID 8
|
||||
#define CV_29_CONFIG 29
|
||||
|
||||
#if defined(ESP32)
|
||||
#include <esp_spi_flash.h>
|
||||
#define MAXCV SPI_FLASH_SEC_SIZE
|
||||
#elif defined(ESP8266)
|
||||
#include <spi_flash.h>
|
||||
#define MAXCV SPI_FLASH_SEC_SIZE
|
||||
#elif defined( __STM32F1__)
|
||||
#define MAXCV (EEPROM_PAGE_SIZE/4 - 1) // number of storage places (CV address could be larger
|
||||
// because STM32 uses virtual adresses)
|
||||
#undef ALLOW_NESTED_IRQ // This is done with NVIC on STM32
|
||||
#define PRIO_DCC_IRQ 9
|
||||
#define PRIO_SYSTIC 8 // MUST be higher priority than DCC Irq
|
||||
#else
|
||||
#define MAXCV E2END // the upper limit of the CV value currently defined to max memory.
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
CV29_LOCO_DIR = 0b00000001, /** bit 0: Locomotive Direction: "0" = normal, "1" = reversed */
|
||||
CV29_F0_LOCATION = 0b00000010, /** bit 1: F0 location: "0" = bit 4 in Speed and Direction instructions, "1" = bit 4 in function group one instruction */
|
||||
CV29_APS = 0b00000100, /** bit 2: Alternate Power Source (APS) "0" = NMRA Digital only, "1" = Alternate power source set by CV12 */
|
||||
CV29_RAILCOM_ENABLE = 0b00001000, /** bit 3: BiDi ( RailCom ) is active */
|
||||
CV29_SPEED_TABLE_ENABLE = 0b00010000, /** bit 4: STE, Speed Table Enable, "0" = values in CVs 2, 4 and 6, "1" = Custom table selected by CV 25 */
|
||||
CV29_EXT_ADDRESSING = 0b00100000, /** bit 5: "0" = one byte addressing, "1" = two byte addressing */
|
||||
CV29_OUTPUT_ADDRESS_MODE = 0b01000000, /** bit 6: "0" = Decoder Address Mode "1" = Output Address Mode */
|
||||
CV29_ACCESSORY_DECODER = 0b10000000, /** bit 7: "0" = Multi-Function Decoder Mode "1" = Accessory Decoder Mode */
|
||||
} CV_29_BITS;
|
||||
|
||||
typedef enum {
|
||||
#ifdef NMRA_DCC_ENABLE_14_SPEED_STEP_MODE
|
||||
SPEED_STEP_14 = 15, /**< ESTOP=0, 1 to 15 */
|
||||
#endif
|
||||
SPEED_STEP_28 = 29, /**< ESTOP=0, 1 to 29 */
|
||||
SPEED_STEP_128 = 127 /**< ESTOP=0, 1 to 127 */
|
||||
} DCC_SPEED_STEPS;
|
||||
|
||||
typedef enum {
|
||||
DCC_DIR_REV = 0, /** The locomotive to go in the reverse direction */
|
||||
DCC_DIR_FWD = 1, /** The locomotive should move in the forward direction */
|
||||
} DCC_DIRECTION;
|
||||
|
||||
typedef enum {
|
||||
DCC_ADDR_SHORT, /** Short address is used. The range is 0 to 127. */
|
||||
DCC_ADDR_LONG, /** Long Address is used. The range is 1 to 10239 */
|
||||
} DCC_ADDR_TYPE;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FN_0_4 = 1,
|
||||
FN_5_8,
|
||||
FN_9_12,
|
||||
FN_13_20,
|
||||
FN_21_28,
|
||||
#ifdef NMRA_DCC_ENABLE_14_SPEED_STEP_MODE
|
||||
FN_0 /** function light is controlled by base line package (14 speed steps) */
|
||||
#endif
|
||||
} FN_GROUP;
|
||||
|
||||
#define FN_BIT_00 0x10
|
||||
#define FN_BIT_01 0x01
|
||||
#define FN_BIT_02 0x02
|
||||
#define FN_BIT_03 0x04
|
||||
#define FN_BIT_04 0x08
|
||||
|
||||
#define FN_BIT_05 0x01
|
||||
#define FN_BIT_06 0x02
|
||||
#define FN_BIT_07 0x04
|
||||
#define FN_BIT_08 0x08
|
||||
|
||||
#define FN_BIT_09 0x01
|
||||
#define FN_BIT_10 0x02
|
||||
#define FN_BIT_11 0x04
|
||||
#define FN_BIT_12 0x08
|
||||
|
||||
#define FN_BIT_13 0x01
|
||||
#define FN_BIT_14 0x02
|
||||
#define FN_BIT_15 0x04
|
||||
#define FN_BIT_16 0x08
|
||||
#define FN_BIT_17 0x10
|
||||
#define FN_BIT_18 0x20
|
||||
#define FN_BIT_19 0x40
|
||||
#define FN_BIT_20 0x80
|
||||
|
||||
#define FN_BIT_21 0x01
|
||||
#define FN_BIT_22 0x02
|
||||
#define FN_BIT_23 0x04
|
||||
#define FN_BIT_24 0x08
|
||||
#define FN_BIT_25 0x10
|
||||
#define FN_BIT_26 0x20
|
||||
#define FN_BIT_27 0x40
|
||||
#define FN_BIT_28 0x80
|
||||
|
||||
//#define DCC_DBGVAR
|
||||
#ifdef DCC_DBGVAR
|
||||
typedef struct countOf_t {
|
||||
unsigned long Tel;
|
||||
unsigned long Err;
|
||||
}countOf_t ;
|
||||
|
||||
extern struct countOf_t countOf;
|
||||
#endif
|
||||
|
||||
class NmraDcc
|
||||
{
|
||||
private:
|
||||
DCC_MSG Msg ;
|
||||
|
||||
public:
|
||||
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
|
||||
|
||||
// Flag Bits that are cloned from CV29 relating the DCC Accessory Decoder
|
||||
#define FLAGS_CV29_BITS (FLAGS_OUTPUT_ADDRESS_MODE | FLAGS_DCC_ACCESSORY_DECODER)
|
||||
|
||||
|
||||
/*+
|
||||
* pin() is called from setup() and sets up the pin used to receive DCC packets.
|
||||
*
|
||||
* Inputs:
|
||||
* ExtIntNum - Interrupt number of the pin. Use digitalPinToInterrupt(ExtIntPinNum).
|
||||
* ExtIntPinNum - Input pin number.
|
||||
* EnablePullup - Set true to enable the pins pullup resistor.
|
||||
*
|
||||
* Returns:
|
||||
* None.
|
||||
*/
|
||||
void pin( uint8_t ExtIntNum, uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
|
||||
/*+
|
||||
* pin() is called from setup() and sets up the pin used to receive DCC packets.
|
||||
* This relies on the internal function: digitalPinToInterrupt() to map the input pin number to the right interrupt
|
||||
*
|
||||
* Inputs:
|
||||
* ExtIntPinNum - Input pin number.
|
||||
* EnablePullup - Set true to enable the pins pullup resistor.
|
||||
*
|
||||
* Returns:
|
||||
* None.
|
||||
*/
|
||||
#ifdef digitalPinToInterrupt
|
||||
void pin( uint8_t ExtIntPinNum, uint8_t EnablePullup);
|
||||
#endif
|
||||
|
||||
/*+
|
||||
* init() is called from setup() after the pin() command is called.
|
||||
* It initializes the NmDcc object and makes it ready to process packets.
|
||||
*
|
||||
* Inputs:
|
||||
* ManufacturerId - Manufacturer ID returned in CV 8.
|
||||
* Commonly MAN_ID_DIY.
|
||||
* VersionId - Version ID returned in CV 7.
|
||||
* Flags - ORed flags beginning with FLAGS_...
|
||||
* FLAGS_MY_ADDRESS_ONLY - Only process packets with My Address.
|
||||
* FLAGS_DCC_ACCESSORY_DECODER - Decoder is an accessory decoder.
|
||||
* FLAGS_OUTPUT_ADDRESS_MODE - This flag applies to accessory decoders only.
|
||||
* Accessory decoders normally have 4 paired outputs
|
||||
* and a single address refers to all 4 outputs.
|
||||
* Setting FLAGS_OUTPUT_ADDRESS_MODE causes each
|
||||
* address to refer to a single output.
|
||||
* OpsModeAddressBaseCV - Ops Mode base address. Set it to 0?
|
||||
*
|
||||
* Returns:
|
||||
* None.
|
||||
*/
|
||||
void init( uint8_t ManufacturerId, uint8_t VersionId, uint8_t Flags, uint8_t OpsModeAddressBaseCV );
|
||||
|
||||
/*+
|
||||
* initAccessoryDecoder() is called from setup() for accessory decoders.
|
||||
* It calls init() with FLAGS_DCC_ACCESSORY_DECODER ORed into Flags.
|
||||
*
|
||||
* Inputs:
|
||||
* ManufacturerId - Manufacturer ID returned in CV 8.
|
||||
* Commonly MAN_ID_DIY.
|
||||
* VersionId - Version ID returned in CV 7.
|
||||
* Flags - ORed flags beginning with FLAGS_...
|
||||
* FLAGS_DCC_ACCESSORY_DECODER will be set for init() call.
|
||||
* OpsModeAddressBaseCV - Ops Mode base address. Set it to 0?
|
||||
*
|
||||
* Returns:
|
||||
* None.
|
||||
*/
|
||||
void initAccessoryDecoder( uint8_t ManufacturerId, uint8_t VersionId, uint8_t Flags, uint8_t OpsModeAddressBaseCV );
|
||||
|
||||
/*+
|
||||
* process() is called from loop() to process DCC packets.
|
||||
* It must be called very frequently to keep up with the packets.
|
||||
*
|
||||
* Inputs:
|
||||
* None.
|
||||
*
|
||||
* Returns:
|
||||
* 1 - Packet succesfully parsed on this call to process().
|
||||
* 0 - Packet not ready or received packet had an error.
|
||||
*/
|
||||
uint8_t process();
|
||||
|
||||
/*+
|
||||
* getCV() returns the selected CV value.
|
||||
*
|
||||
* Inputs:
|
||||
* CV - CV number. It must point to a valid CV.
|
||||
*
|
||||
* Returns:
|
||||
* Value - CV value. Invalid CV numbers will return an undefined result
|
||||
* since nothing will have been set in that EEPROM position.
|
||||
* Calls notifyCVRead() if it is defined.
|
||||
*/
|
||||
uint8_t getCV( uint16_t CV );
|
||||
|
||||
/*+
|
||||
* setCV() sets the value of a CV.
|
||||
*
|
||||
* Inputs:
|
||||
* CV - CV number. It must point to a valid CV.
|
||||
* Value - CV value.
|
||||
*
|
||||
* Returns:
|
||||
* Value - CV value set by this call.
|
||||
* since nothing will have been set in that EEPROM position.
|
||||
* Calls notifyCVWrite() if it is defined.
|
||||
* Calls notifyCVChange() if the value is changed by this call.
|
||||
*/
|
||||
uint8_t setCV( uint16_t CV, uint8_t Value);
|
||||
|
||||
/*+
|
||||
* setAccDecDCCAddrNextReceived() enables/disables the setting of the board address from the next received turnout command
|
||||
*
|
||||
* Inputs:
|
||||
* enable- boolean to enable or disable the mode
|
||||
*
|
||||
* Returns:
|
||||
*/
|
||||
void setAccDecDCCAddrNextReceived(uint8_t enable);
|
||||
|
||||
/*+
|
||||
* isSetCVReady() returns 1 if EEPROM is ready to write.
|
||||
*
|
||||
* Inputs:
|
||||
* CV - CV number. It must point to a valid CV.
|
||||
* Value - CV value.
|
||||
*
|
||||
* Returns:
|
||||
* ready - 1 if ready to write, 0 otherwise. AVR processor will block
|
||||
* for several ms. for each write cycle so you should check this to avoid blocks.
|
||||
* Note: It returns the value returned by notifyIsSetCVReady() if it is defined.
|
||||
* Calls notifyIsSetCVReady() if it is defined.
|
||||
*/
|
||||
uint8_t isSetCVReady( void );
|
||||
|
||||
/*+
|
||||
* getAddr() return the currently active decoder address.
|
||||
* based on decoder type and current address size.
|
||||
*
|
||||
* Inputs:
|
||||
* None.
|
||||
*
|
||||
* Returns:
|
||||
* Adr - The current decoder address based on decoder type(Multifunction, Accessory)
|
||||
* and short or long address selection for Multifunction decoders.
|
||||
*/
|
||||
uint16_t getAddr(void);
|
||||
|
||||
/*+
|
||||
* getDccPolarity() return the DCC polarity.
|
||||
*
|
||||
* Inputs:
|
||||
* None.
|
||||
*
|
||||
* Returns:
|
||||
* FALLING 2
|
||||
* RISING 3
|
||||
*/
|
||||
uint8_t getDccPolarity(void);
|
||||
|
||||
/*+
|
||||
* getX() return debugging data if DCC_DEBUG is defined.
|
||||
* You would really need to be modifying the library to need them.
|
||||
*
|
||||
* Inputs:
|
||||
* None.
|
||||
*
|
||||
* Returns:
|
||||
* getIntCount - Init to 0 and apparently never incremented?
|
||||
* getTickCount - Init to 0 and incremented each time interrupt handler
|
||||
* completes without an error.
|
||||
* getBitCount - Bit count of valid packet, 0 otherwise. Only valid until
|
||||
* start of the next packet.
|
||||
* getState - Current WAIT_... state as defined by DccRxWaitState in NmraDcc.cpp.
|
||||
* getNestedIrqCount - Init to 0 and incremented each time the interrupt handler
|
||||
* is called before the previous interrupt was complete.
|
||||
* This is an error indication and may indicate the system
|
||||
* is not handling packets fast enough or some other error is occurring.
|
||||
*/
|
||||
// #define DCC_DEBUG
|
||||
#ifdef DCC_DEBUG
|
||||
uint8_t getIntCount(void);
|
||||
uint8_t getTickCount(void);
|
||||
uint8_t getBitCount(void);
|
||||
uint8_t getState(void);
|
||||
uint8_t getNestedIrqCount(void);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
/************************************************************************************
|
||||
Call-back functions
|
||||
************************************************************************************/
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*+
|
||||
* notifyDccReset(uint8_t hardReset) Callback for a DCC reset command.
|
||||
*
|
||||
* Inputs:
|
||||
* hardReset - 0 normal reset command.
|
||||
* 1 hard reset command.
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccReset(uint8_t hardReset ) __attribute__ ((weak));
|
||||
|
||||
/*+
|
||||
* notifyDccIdle() Callback for a DCC idle command.
|
||||
*
|
||||
* Inputs:
|
||||
* None
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccIdle(void) __attribute__ ((weak));
|
||||
|
||||
|
||||
/*+
|
||||
* notifyDccSpeed() Callback for a multifunction decoder speed command.
|
||||
* The received speed and direction are unpacked to separate values.
|
||||
*
|
||||
* Inputs:
|
||||
* Addr - Active decoder address.
|
||||
* AddrType - DCC_ADDR_SHORT or DCC_ADDR_LONG.
|
||||
* Speed - Decoder speed. 0 = Emergency stop
|
||||
* 1 = Regular stop
|
||||
* 2 to SpeedSteps = Speed step 1 to max.
|
||||
* Dir - DCC_DIR_REV or DCC_DIR_FWD
|
||||
* SpeedSteps - Highest speed, SPEED_STEP_14 = 15
|
||||
* SPEED_STEP_28 = 29
|
||||
* SPEED_STEP_128 = 127
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccSpeed( uint16_t Addr, DCC_ADDR_TYPE AddrType, uint8_t Speed, DCC_DIRECTION Dir, DCC_SPEED_STEPS SpeedSteps ) __attribute__ ((weak));
|
||||
|
||||
/*+
|
||||
* notifyDccSpeedRaw() Callback for a multifunction decoder speed command.
|
||||
* The value in Raw is the unpacked speed command.
|
||||
*
|
||||
* Inputs:
|
||||
* Addr - Active decoder address.
|
||||
* AddrType - DCC_ADDR_SHORT or DCC_ADDR_LONG.
|
||||
* Raw - Raw decoder speed command.
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccSpeedRaw( uint16_t Addr, DCC_ADDR_TYPE AddrType, uint8_t Raw) __attribute__ ((weak));
|
||||
|
||||
/*+
|
||||
* notifyDccFunc() Callback for a multifunction decoder function command.
|
||||
*
|
||||
* Inputs:
|
||||
* Addr - Active decoder address.
|
||||
* AddrType - DCC_ADDR_SHORT or DCC_ADDR_LONG.
|
||||
* FuncGrp - Function group. FN_0 - 14 speed step headlight function.
|
||||
* Mask FN_BIT_00.
|
||||
* FN_0_4 - Functions 0 to 4. Mask FN_BIT_00 - FN_BIT_04
|
||||
* FN_5_8 - Functions 5 to 8. Mask FN_BIT_05 - FN_BIT_08
|
||||
* FN_9_12 - Functions 9 to 12. Mask FN_BIT_09 - FN_BIT_12
|
||||
* FN_13_20 - Functions 13 to 20. Mask FN_BIT_13 - FN_BIT_20
|
||||
* FN_21_28 - Functions 21 to 28. Mask FN_BIT_21 - FN_BIT_28
|
||||
* FuncState - Function state. Bitmask where active functions have a 1 at that bit.
|
||||
* You must & FuncState with the appropriate
|
||||
* FN_BIT_nn value to isolate a given bit.
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccFunc( uint16_t Addr, DCC_ADDR_TYPE AddrType, FN_GROUP FuncGrp, uint8_t FuncState) __attribute__ ((weak));
|
||||
|
||||
/*+
|
||||
* notifyDccAccTurnoutBoard() Board oriented callback for a turnout accessory decoder.
|
||||
* Most useful when CV29_OUTPUT_ADDRESS_MODE is not set.
|
||||
* Decoders of this type have 4 paired turnout outputs per board.
|
||||
* OutputPower is 1 if the power is on, and 0 otherwise.
|
||||
*
|
||||
* Inputs:
|
||||
* BoardAddr - Per board address. Equivalent to CV 1 LSB & CV 9 MSB.
|
||||
* OutputPair - Output pair number. It has a range of 0 to 3.
|
||||
* Equivalent to upper 2 bits of the 3 DDD bits in the accessory packet.
|
||||
* Direction - Turnout direction. It has a value of 0 or 1.
|
||||
* It is equivalent to bit 0 of the 3 DDD bits in the accessory packet.
|
||||
* OutputPower - Output On/Off. Equivalent to packet C bit. It has these values:
|
||||
* 0 - Output pair is off.
|
||||
* 1 - Output pair is on.
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
|
||||
extern void notifyDccAccTurnoutBoard( uint16_t BoardAddr, uint8_t OutputPair, uint8_t Direction, uint8_t OutputPower ) __attribute__ ((weak));
|
||||
/*+
|
||||
* notifyDccAccTurnoutOutput() Output oriented callback for a turnout accessory decoder.
|
||||
* Most useful when CV29_OUTPUT_ADDRESS_MODE is not set.
|
||||
* Decoders of this type have 4 paired turnout outputs per board.
|
||||
* OutputPower is 1 if the power is on, and 0 otherwise.
|
||||
*
|
||||
* Inputs:
|
||||
* Addr - Per output address. There will be 4 Addr addresses
|
||||
* per board for a standard accessory decoder with 4 output pairs.
|
||||
* Direction - Turnout direction. It has a value of 0 or 1.
|
||||
* Equivalent to bit 0 of the 3 DDD bits in the accessory packet.
|
||||
* OutputPower - Output On/Off. Equivalent to packet C bit. It has these values:
|
||||
* 0 - Output is off.
|
||||
* 1 - Output is on.
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccAccTurnoutOutput( uint16_t Addr, uint8_t Direction, uint8_t OutputPower ) __attribute__ ((weak));
|
||||
|
||||
/*+
|
||||
* notifyDccAccBoardAddrSet() Board oriented callback for a turnout accessory decoder.
|
||||
* This notification is when a new Board Address is set to the
|
||||
* address of the next DCC Turnout Packet that is received
|
||||
*
|
||||
* This is enabled via the setAccDecDCCAddrNextReceived() method above
|
||||
*
|
||||
* Inputs:
|
||||
* BoardAddr - Per board address. Equivalent to CV 1 LSB & CV 9 MSB.
|
||||
* per board for a standard accessory decoder with 4 output pairs.
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccAccBoardAddrSet( uint16_t BoardAddr) __attribute__ ((weak));
|
||||
|
||||
/*+
|
||||
* notifyDccAccOutputAddrSet() Output oriented callback for a turnout accessory decoder.
|
||||
* This notification is when a new Output Address is set to the
|
||||
* address of the next DCC Turnout Packet that is received
|
||||
*
|
||||
* This is enabled via the setAccDecDCCAddrNextReceived() method above
|
||||
*
|
||||
* Inputs:
|
||||
* Addr - Per output address. There will be 4 Addr addresses
|
||||
* per board for a standard accessory decoder with 4 output pairs.
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccAccOutputAddrSet( uint16_t Addr) __attribute__ ((weak));
|
||||
|
||||
/*+
|
||||
* notifyDccSigOutputState() Callback for a signal aspect accessory decoder.
|
||||
* Defined in S-9.2.1 as the Extended Accessory Decoder Control Packet.
|
||||
*
|
||||
* Inputs:
|
||||
* Addr - Decoder address.
|
||||
* State - 6 bit command equivalent to S-9.2.1 00XXXXXX.
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccSigOutputState( uint16_t Addr, uint8_t State) __attribute__ ((weak));
|
||||
|
||||
/*+
|
||||
* notifyDccMsg() Raw DCC packet callback.
|
||||
* Called with raw DCC packet bytes.
|
||||
*
|
||||
* Inputs:
|
||||
* Msg - Pointer to DCC_MSG structure. The values are:
|
||||
* Msg->Size - Number of Data bytes in the packet.
|
||||
* Msg->PreambleBits - Number of preamble bits in the packet.
|
||||
* Msg->Data[] - Array of data bytes in the packet.
|
||||
*
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyDccMsg( DCC_MSG * Msg ) __attribute__ ((weak));
|
||||
|
||||
/*+
|
||||
* notifyCVValid() Callback to determine if a given CV is valid.
|
||||
* This is called when the library needs to determine
|
||||
* if a CV is valid. Note: If defined, this callback
|
||||
* MUST determine if a CV is valid and return the
|
||||
* appropriate value. If this callback is not defined,
|
||||
* the library will determine validity.
|
||||
*
|
||||
* Inputs:
|
||||
* CV - CV number.
|
||||
* Writable - 1 for CV writes. 0 for CV reads.
|
||||
*
|
||||
* Returns:
|
||||
* 1 - CV is valid.
|
||||
* 0 - CV is not valid.
|
||||
*/
|
||||
extern uint8_t notifyCVValid( uint16_t CV, uint8_t Writable ) __attribute__ ((weak));
|
||||
|
||||
/*+
|
||||
* notifyCVRead() Callback to read a CV.
|
||||
* This is called when the library needs to read
|
||||
* a CV. Note: If defined, this callback
|
||||
* MUST return the value of the CV.
|
||||
* If this callback is not defined,
|
||||
* the library will read the CV from EEPROM.
|
||||
*
|
||||
* Inputs:
|
||||
* CV - CV number.
|
||||
*
|
||||
* Returns:
|
||||
* Value - Value of the CV.
|
||||
*/
|
||||
extern uint8_t notifyCVRead( uint16_t CV) __attribute__ ((weak));
|
||||
|
||||
/*+
|
||||
* notifyCVWrite() Callback to write a value to a CV.
|
||||
* This is called when the library needs to write
|
||||
* a CV. Note: If defined, this callback
|
||||
* MUST write the Value to the CV and return the value of the CV.
|
||||
* If this callback is not defined,
|
||||
* the library will read the CV from EEPROM.
|
||||
*
|
||||
* Inputs:
|
||||
* CV - CV number.
|
||||
* Value - Value of the CV.
|
||||
*
|
||||
* Returns:
|
||||
* Value - Value of the CV.
|
||||
*/
|
||||
extern uint8_t notifyCVWrite( uint16_t CV, uint8_t Value) __attribute__ ((weak));
|
||||
|
||||
/*+
|
||||
* notifyIsSetCVReady() Callback to to determine if CVs can be written.
|
||||
* This is called when the library needs to determine
|
||||
* is ready to write without blocking or failing.
|
||||
* Note: If defined, this callback
|
||||
* MUST determine if a CV write would block or fail
|
||||
* return the appropriate value.
|
||||
* If this callback is not defined,
|
||||
* the library determines if a write to the EEPROM
|
||||
* would block.
|
||||
*
|
||||
* Inputs:
|
||||
* None
|
||||
*
|
||||
* Returns:
|
||||
* 1 - CV is ready to be written.
|
||||
* 0 - CV is not ready to be written.
|
||||
*/
|
||||
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 changed 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.
|
||||
*
|
||||
* Inputs:
|
||||
* CV - CV number.
|
||||
* Value - Value of the CV.
|
||||
*
|
||||
* Returns:
|
||||
* 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.
|
||||
* This is called when CVs must be reset
|
||||
* to their factory defaults. This callback
|
||||
* should write the factory default value of
|
||||
* relevent CVs using the setCV() method.
|
||||
* setCV() must not block whens this is called.
|
||||
* Test with isSetCVReady() prior to calling setCV()
|
||||
*
|
||||
* Inputs:
|
||||
* None
|
||||
* *
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyCVResetFactoryDefault(void) __attribute__ ((weak));
|
||||
|
||||
/*+
|
||||
* notifyCVAck() Called when a CV write must be acknowledged.
|
||||
* This callback must increase the current drawn by this
|
||||
* decoder by at least 60mA for 6ms +/- 1ms.
|
||||
*
|
||||
* Inputs:
|
||||
* None
|
||||
* *
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyCVAck(void) __attribute__ ((weak));
|
||||
/*+
|
||||
* notifyAdvancedCVAck() Called when a CV write must be acknowledged via Advanced Acknowledgement.
|
||||
* This callback must send the Advanced Acknowledgement via RailComm.
|
||||
*
|
||||
* Inputs:
|
||||
* None
|
||||
* *
|
||||
* Returns:
|
||||
* None
|
||||
*/
|
||||
extern void notifyAdvancedCVAck(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. These functions may be dropped in future versions
|
||||
extern void notifyDccAccState( uint16_t Addr, uint16_t BoardAddr, uint8_t OutputAddr, uint8_t State ) __attribute__ ((weak));
|
||||
extern void notifyDccSigState( uint16_t Addr, uint8_t OutputIndex, uint8_t State) __attribute__ ((weak));
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
# NmraDcc
|
||||
NMRA Digital Command Control (DCC) Library
|
||||
|
||||
This library allows you to interface to a NMRA DCC track signal and receive DCC commands.
|
||||
|
||||
The library currently supports the AVR ATTiny84/85 & ATMega88/168/328/32u4 and Teensy 3.x using the INT0/1 Hardware Interrupt and micros() ONLY and no longer uses Timer0 Compare Match B, which makes it much more portable to other platforms.
|
||||
|
||||
**Warning** as of version 1.4.4 support has been removed for the following two call-back functions, which will cause your sketch to silently stop working:
|
||||
|
||||
extern void notifyDccAccState( uint16_t Addr, uint16_t BoardAddr, uint8_t OutputAddr, uint8_t State )
|
||||
extern void notifyDccSigState( uint16_t Addr, uint8_t OutputIndex, uint8_t State)
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map Servo
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
DCC_MSG KEYWORD1
|
||||
NmraDcc KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
NmraDcc KEYWORD2
|
||||
pin KEYWORD2
|
||||
init KEYWORD2
|
||||
process KEYWORD2
|
||||
getCV KEYWORD2
|
||||
setCV KEYWORD2
|
||||
isSetCVReady KEYWORD2
|
||||
notifyDccReset KEYWORD2
|
||||
notifyDccIdle KEYWORD2
|
||||
notifyDccSpeed KEYWORD2
|
||||
notifyDccSpeedRaw KEYWORD2
|
||||
notifyDccFunc KEYWORD2
|
||||
notifyDccAccTurnoutBoard KEYWORD2
|
||||
notifyDccAccTurnoutOutput KEYWORD2
|
||||
notifyDccAccBoardAddrSet KEYWORD2
|
||||
notifyDccAccOutputAddrSet KEYWORD2
|
||||
notifyDccSigOutputState KEYWORD2
|
||||
notifyDccMsg KEYWORD2
|
||||
notifyCVValid KEYWORD2
|
||||
notifyCVRead KEYWORD2
|
||||
notifyCVWrite KEYWORD2
|
||||
notifyIsSetCVReady KEYWORD2
|
||||
notifyCVChange KEYWORD2
|
||||
notifyCVAck KEYWORD2
|
||||
notifyCVResetFactoryDefault KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
|
||||
MAN_ID_JMRI LITERAL1
|
||||
MAN_ID_DIY LITERAL1
|
||||
MAN_ID_SILICON_RAILWAY LITERAL1
|
||||
FLAGS_MY_ADDRESS_ONLY LITERAL1
|
||||
FLAGS_OUTPUT_ADDRESS_MODE LITERAL1
|
||||
FLAGS_DCC_ACCESSORY_DECODER LITERAL1
|
||||
|
||||
CV_ACCESSORY_DECODER_ADDRESS_LSB LITERAL1
|
||||
CV_ACCESSORY_DECODER_ADDRESS_MSB LITERAL1
|
||||
|
||||
CV_MULTIFUNCTION_PRIMARY_ADDRESS LITERAL1
|
||||
CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB LITERAL1
|
||||
CV_MULTIFUNCTION_EXTENDED_ADDRESS_LSB LITERAL1
|
||||
|
||||
CV_VERSION_ID LITERAL1
|
||||
CV_MANUFACTURER_ID LITERAL1
|
||||
CV_29_CONFIG LITERAL1
|
||||
CV_OPS_MODE_ADDRESS_LSB LITERAL1
|
||||
|
||||
#######################################
|
||||
@@ -0,0 +1,9 @@
|
||||
name=NmraDcc
|
||||
version=2.0.6
|
||||
author=Alex Shepherd, Wolfgang Kuffer, Geoff Bunza, Martin Pischky, Franz-Peter Müller, Sven (littleyoda), Hans Tanner
|
||||
maintainer=Alex Shepherd <kiwi64ajs@gmail.com>
|
||||
sentence=Enables NMRA DCC Communication
|
||||
paragraph=This library allows you to interface to a NMRA DCC track signal and receive DCC commands. The library has been tested on AVR ATTiny84/85 & ATMega88/168/328/32u4, ESP8266 and Teensy 3.x using the INT0/1 Hardware Interrupt and micros() ONLY and no longer uses Timer0 Compare Match B, which makes it much more portable to other platforms.
|
||||
category=Communication
|
||||
url=https://github.com/mrrwa/NmraDcc
|
||||
architectures=*
|
||||
Reference in New Issue
Block a user