1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 08:06:13 +01:00
CommandStation-EX/DCC.h

55 lines
1.7 KiB
C
Raw Normal View History

2020-05-27 10:40:12 +02:00
#ifndef DCC_h
#define DCC_h
2020-05-24 17:07:16 +02:00
#include <Arduino.h>
2020-05-27 10:40:12 +02:00
#include "Config.h"
2020-05-24 17:07:16 +02:00
class DCC {
public:
static void begin();
static void loop();
// Public DCC API functions
static void setThrottle( uint16_t cab, uint8_t tSpeed, bool tDirection);
static int readCV(int cv);
static int readCVBit(int cv, byte bNum); // -1 for error
2020-05-24 17:07:16 +02:00
static bool writeCVByte(int cv, byte bValue) ;
static bool verifyCVByte(int cv,byte bValue);
2020-05-24 17:07:16 +02:00
static bool writeCVBit(int cv, byte bNum, bool bValue);
static bool verifyCVBit(int cv, byte bNum, bool bValue);
2020-05-24 17:07:16 +02:00
static void writeCVByteMain(int cab, int cv, byte bValue);
static void writeCVBitMain(int cab, int cv, byte bNum, bool bValue);
static void setFunction( int cab, byte fByte, byte eByte);
static void setFunction( int cab, byte fByte);
static void setAccessory(int aAdd, byte aNum, bool activate) ;
static bool writeTextPacket( byte *b, int nBytes);
static int getLocoId();
2020-05-24 17:07:16 +02:00
private:
struct LOCO {
int loco;
byte speed;
bool forward;
};
static void setThrottle2( uint16_t cab, uint8_t tSpeed, bool tDirection);
static void updateLocoReminder(int loco, byte tSpeed, bool forward);
static int nextLoco;
static LOCO speedTable[MAX_LOCOS];
static byte cv1(byte opcode, int cv);
static byte cv2(int cv);
// NMRA codes #
static const byte SET_SPEED=0x3f;
static const byte WRITE_BYTE_MAIN = 0xEC;
static const byte WRITE_BIT_MAIN = 0xE8;
static const byte WRITE_BYTE = 0x7C;
static const byte VERIFY_BYTE= 0x74;
static const byte BIT_MANIPULATE=0x78;
static const byte WRITE_BIT=0xF0;
static const byte VERIFY_BIT=0xE0;
static const byte BIT_ON=0x08;
static const byte BIT_OFF=0x00;
2020-05-24 17:07:16 +02:00
};
2020-05-27 10:40:12 +02:00
#endif