mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 08:06:13 +01:00
Merge branch 'feature/config' of https://github.com/DCC-EX/CommandStation-EX into feature/config
This commit is contained in:
commit
f76fb8d6c5
|
@ -29,16 +29,23 @@
|
||||||
int ramLowWatermark = 32767; // This figure gets overwritten dynamically in loop()
|
int ramLowWatermark = 32767; // This figure gets overwritten dynamically in loop()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_MEGAAVR)
|
||||||
|
#include <Arduino.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// Enables an I2C 2x24 or 4x24 LCD Screen
|
// Enables an I2C 2x24 or 4x24 LCD Screen
|
||||||
#ifdef ENABLE_LCD
|
#if ENABLE_LCD
|
||||||
bool lcdEnabled = false;
|
bool lcdEnabled = false;
|
||||||
#if defined(LIB_TYPE_PCF8574)
|
#if defined(LIB_TYPE_PCF8574)
|
||||||
LiquidCrystal_PCF8574 lcdDisplay(LCD_ADDRESS);
|
LiquidCrystal_PCF8574 lcdDisplay(LCD_ADDRESS);
|
||||||
#elif defined(LIB_TYPE_I2C)
|
#elif defined(LIB_TYPE_I2C)
|
||||||
LiquidCrystal_I2C lcdDisplay = LiquidCrystal_I2C(LCD_ADDRESS, LCD_COLUMNS, LCD_LINES);
|
LiquidCrystal_I2C lcdDisplay = LiquidCrystal_I2C(LCD_ADDRESS, LCD_COLUMNS, LCD_LINES);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// this code is here to demonstrate use of the DCC API and other techniques
|
// this code is here to demonstrate use of the DCC API and other techniques
|
||||||
|
@ -109,15 +116,16 @@ DCCEXParser serialParser;
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// More display stuff. Need to put this in a .h file and make
|
// More display stuff. Need to put this in a .h file and make
|
||||||
// it a class
|
// it a class
|
||||||
#ifdef ENABLE_LCD
|
#if ENABLE_LCD
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
// Check that we can find the LCD by its address before attempting to use it.
|
// Check that we can find the LCD by its address before attempting to use it.
|
||||||
Wire.beginTransmission(LCD_ADDRESS);
|
Wire.beginTransmission(LCD_ADDRESS);
|
||||||
if(Wire.endTransmission() == 0) {
|
if (Wire.endTransmission() == 0)
|
||||||
|
{
|
||||||
lcdEnabled = true;
|
lcdEnabled = true;
|
||||||
lcdDisplay.begin(LCD_COLUMNS, LCD_LINES);
|
lcdDisplay.begin(LCD_COLUMNS, LCD_LINES);
|
||||||
lcdDisplay.setBacklight(255);
|
lcdDisplay.setBacklight(255);
|
||||||
|
@ -126,15 +134,15 @@ void setup()
|
||||||
lcdDisplay.print("DCC++ EX v");
|
lcdDisplay.print("DCC++ EX v");
|
||||||
lcdDisplay.print(VERSION);
|
lcdDisplay.print(VERSION);
|
||||||
lcdDisplay.setCursor(0, 1);
|
lcdDisplay.setCursor(0, 1);
|
||||||
#if COMM_INTERFACE >= 1
|
#if COMM_INTERFACE >= 1
|
||||||
lcdDisplay.print("IP: PENDING");
|
lcdDisplay.print("IP: PENDING");
|
||||||
#else
|
#else
|
||||||
lcdDisplay.print("SERIAL: READY");
|
lcdDisplay.print("SERIAL: READY");
|
||||||
#endif
|
#endif
|
||||||
#if LCD_LINES > 2
|
#if LCD_LINES > 2
|
||||||
lcdDisplay.setCursor(0, 3);
|
lcdDisplay.setCursor(0, 3);
|
||||||
lcdDisplay.print("TRACK POWER: OFF");
|
lcdDisplay.print("TRACK POWER: OFF");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
179
DCC.h
179
DCC.h
|
@ -24,89 +24,91 @@
|
||||||
|
|
||||||
typedef void (*ACK_CALLBACK)(int result);
|
typedef void (*ACK_CALLBACK)(int result);
|
||||||
|
|
||||||
enum ackOp { // Program opcodes for the ack Manager
|
enum ackOp
|
||||||
BASELINE, // ensure enough resets sent before starting and obtain baseline current
|
{ // Program opcodes for the ack Manager
|
||||||
W0,W1, // issue write bit (0..1) packet
|
BASELINE, // ensure enough resets sent before starting and obtain baseline current
|
||||||
WB, // issue write byte packet
|
W0,
|
||||||
VB, // Issue validate Byte packet
|
W1, // issue write bit (0..1) packet
|
||||||
V0, // Issue validate bit=0 packet
|
WB, // issue write byte packet
|
||||||
V1, // issue validate bit=1 packlet
|
VB, // Issue validate Byte packet
|
||||||
WACK, // wait for ack (or absence of ack)
|
V0, // Issue validate bit=0 packet
|
||||||
ITC1, // If True Callback(1) (if prevous WACK got an ACK)
|
V1, // issue validate bit=1 packlet
|
||||||
ITC0, // If True callback(0);
|
WACK, // wait for ack (or absence of ack)
|
||||||
ITCB, // If True callback(byte)
|
ITC1, // If True Callback(1) (if prevous WACK got an ACK)
|
||||||
NAKFAIL, // if false callback(-1)
|
ITC0, // If True callback(0);
|
||||||
FAIL, // callback(-1)
|
ITCB, // If True callback(byte)
|
||||||
STARTMERGE, // Clear bit and byte settings ready for merge pass
|
NAKFAIL, // if false callback(-1)
|
||||||
MERGE, // Merge previous wack response with byte value and decrement bit number (use for readimng CV bytes)
|
FAIL, // callback(-1)
|
||||||
SETBIT, // sets bit number to next prog byte
|
STARTMERGE, // Clear bit and byte settings ready for merge pass
|
||||||
SETCV, // sets cv number to next prog byte
|
MERGE, // Merge previous wack response with byte value and decrement bit number (use for readimng CV bytes)
|
||||||
STASHLOCOID, // keeps current byte value for later
|
SETBIT, // sets bit number to next prog byte
|
||||||
COMBINELOCOID, // combines current value with stashed value and returns it
|
SETCV, // sets cv number to next prog byte
|
||||||
ITSKIP, // skip to SKIPTARGET if ack true
|
STASHLOCOID, // keeps current byte value for later
|
||||||
SKIPTARGET=0xFF // jump to target
|
COMBINELOCOID, // combines current value with stashed value and returns it
|
||||||
|
ITSKIP, // skip to SKIPTARGET if ack true
|
||||||
|
SKIPTARGET = 0xFF // jump to target
|
||||||
};
|
};
|
||||||
|
|
||||||
// Allocations with memory implications..!
|
// Allocations with memory implications..!
|
||||||
// Base system takes approx 900 bytes + 8 per loco. Turnouts, Sensors etc are dynamically created
|
// Base system takes approx 900 bytes + 8 per loco. Turnouts, Sensors etc are dynamically created
|
||||||
#ifdef ARDUINO_AVR_UNO
|
#ifdef ARDUINO_AVR_UNO
|
||||||
const byte MAX_LOCOS=20;
|
const byte MAX_LOCOS = 20;
|
||||||
#else
|
#else
|
||||||
const byte MAX_LOCOS=50;
|
const byte MAX_LOCOS = 50;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
class DCC
|
||||||
class DCC {
|
{
|
||||||
public:
|
public:
|
||||||
|
static void begin(const __FlashStringHelper *motorShieldName, MotorDriver *mainDriver, MotorDriver *progDriver, byte timerNumber = 1);
|
||||||
static void begin(const __FlashStringHelper* motorShieldName, MotorDriver * mainDriver, MotorDriver * progDriver, byte timerNumber=1);
|
|
||||||
static void loop();
|
static void loop();
|
||||||
|
|
||||||
// Public DCC API functions
|
// Public DCC API functions
|
||||||
static void setThrottle( uint16_t cab, uint8_t tSpeed, bool tDirection);
|
static void setThrottle(uint16_t cab, uint8_t tSpeed, bool tDirection);
|
||||||
static uint8_t getThrottleSpeed(int cab);
|
static uint8_t getThrottleSpeed(int cab);
|
||||||
static bool getThrottleDirection(int cab);
|
static bool getThrottleDirection(int cab);
|
||||||
static void writeCVByteMain(int cab, int cv, byte bValue);
|
static void writeCVByteMain(int cab, int cv, byte bValue);
|
||||||
static void writeCVBitMain(int cab, int cv, byte bNum, bool 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, byte eByte);
|
||||||
static void setFn( int cab, byte functionNumber, bool on);
|
static void setFn(int cab, byte functionNumber, bool on);
|
||||||
static int changeFn( int cab, byte functionNumber, bool pressed);
|
static int changeFn(int cab, byte functionNumber, bool pressed);
|
||||||
static void updateGroupflags(byte & flags, int functionNumber);
|
static void updateGroupflags(byte &flags, int functionNumber);
|
||||||
static void setAccessory(int aAdd, byte aNum, bool activate) ;
|
static void setAccessory(int aAdd, byte aNum, bool activate);
|
||||||
static bool writeTextPacket( byte *b, int nBytes);
|
static bool writeTextPacket(byte *b, int nBytes);
|
||||||
static void setProgTrackSyncMain(bool on); // when true, prog track becomes driveable
|
static void setProgTrackSyncMain(bool on); // when true, prog track becomes driveable
|
||||||
|
|
||||||
// ACKable progtrack calls bitresults callback 0,0 or -1, cv returns value or -1
|
// ACKable progtrack calls bitresults callback 0,0 or -1, cv returns value or -1
|
||||||
static void readCV(int cv, ACK_CALLBACK callback, bool blocking=false);
|
static void readCV(int cv, ACK_CALLBACK callback, bool blocking = false);
|
||||||
static void readCVBit(int cv, byte bitNum, ACK_CALLBACK callback, bool blocking=false); // -1 for error
|
static void readCVBit(int cv, byte bitNum, ACK_CALLBACK callback, bool blocking = false); // -1 for error
|
||||||
static void writeCVByte(int cv, byte byteValue, ACK_CALLBACK callback, bool blocking=false) ;
|
static void writeCVByte(int cv, byte byteValue, ACK_CALLBACK callback, bool blocking = false);
|
||||||
static void writeCVBit(int cv, byte bitNum, bool bitValue, ACK_CALLBACK callback, bool blocking=false);
|
static void writeCVBit(int cv, byte bitNum, bool bitValue, ACK_CALLBACK callback, bool blocking = false);
|
||||||
static void verifyCVByte(int cv, byte byteValue, ACK_CALLBACK callback, bool blocking=false) ;
|
static void verifyCVByte(int cv, byte byteValue, ACK_CALLBACK callback, bool blocking = false);
|
||||||
static void verifyCVBit(int cv, byte bitNum, bool bitValue, ACK_CALLBACK callback, bool blocking=false);
|
static void verifyCVBit(int cv, byte bitNum, bool bitValue, ACK_CALLBACK callback, bool blocking = false);
|
||||||
|
|
||||||
static void getLocoId(ACK_CALLBACK callback, bool blocking=false);
|
static void getLocoId(ACK_CALLBACK callback, bool blocking = false);
|
||||||
|
|
||||||
// Enhanced API functions
|
// Enhanced API functions
|
||||||
static void forgetLoco(int cab); // removes any speed reminders for this loco
|
static void forgetLoco(int cab); // removes any speed reminders for this loco
|
||||||
static void forgetAllLocos(); // removes all speed reminders
|
static void forgetAllLocos(); // removes all speed reminders
|
||||||
static void displayCabList(Print * stream);
|
static void displayCabList(Print *stream);
|
||||||
|
|
||||||
static __FlashStringHelper* getMotorShieldName();
|
static __FlashStringHelper *getMotorShieldName();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct LOCO {
|
struct LOCO
|
||||||
int loco;
|
{
|
||||||
byte speedCode;
|
int loco;
|
||||||
byte groupFlags;
|
byte speedCode;
|
||||||
unsigned long functions;
|
byte groupFlags;
|
||||||
|
unsigned long functions;
|
||||||
};
|
};
|
||||||
static byte loopStatus;
|
static byte loopStatus;
|
||||||
static void setThrottle2( uint16_t cab, uint8_t speedCode);
|
static void setThrottle2(uint16_t cab, uint8_t speedCode);
|
||||||
static void updateLocoReminder(int loco, byte speedCode);
|
static void updateLocoReminder(int loco, byte speedCode);
|
||||||
static void setFunctionInternal( int cab, byte fByte, byte eByte);
|
static void setFunctionInternal(int cab, byte fByte, byte eByte);
|
||||||
static bool issueReminder(int reg);
|
static bool issueReminder(int reg);
|
||||||
static int nextLoco;
|
static int nextLoco;
|
||||||
static __FlashStringHelper* shieldName;
|
static __FlashStringHelper *shieldName;
|
||||||
|
|
||||||
static LOCO speedTable[MAX_LOCOS];
|
static LOCO speedTable[MAX_LOCOS];
|
||||||
static byte cv1(byte opcode, int cv);
|
static byte cv1(byte opcode, int cv);
|
||||||
|
@ -115,58 +117,57 @@ private:
|
||||||
static void issueReminders();
|
static void issueReminders();
|
||||||
static void callback(int value);
|
static void callback(int value);
|
||||||
|
|
||||||
// ACK MANAGER
|
// ACK MANAGER
|
||||||
static ackOp const * ackManagerProg;
|
static ackOp const *ackManagerProg;
|
||||||
static byte ackManagerByte;
|
static byte ackManagerByte;
|
||||||
static byte ackManagerBitNum;
|
static byte ackManagerBitNum;
|
||||||
static int ackManagerCv;
|
static int ackManagerCv;
|
||||||
static byte ackManagerStash;
|
static byte ackManagerStash;
|
||||||
static bool ackReceived;
|
static bool ackReceived;
|
||||||
static ACK_CALLBACK ackManagerCallback;
|
static ACK_CALLBACK ackManagerCallback;
|
||||||
static void ackManagerSetup(int cv, byte bitNumOrbyteValue, ackOp const program[], ACK_CALLBACK callback, bool blocking);
|
static void ackManagerSetup(int cv, byte bitNumOrbyteValue, ackOp const program[], ACK_CALLBACK callback, bool blocking);
|
||||||
static void ackManagerLoop(bool blocking);
|
static void ackManagerLoop(bool blocking);
|
||||||
static bool checkResets(bool blocking, uint8_t numResets);
|
static bool checkResets(bool blocking, uint8_t numResets);
|
||||||
static const int PROG_REPEATS=8; // repeats of programming commands (some decoders need at least 8 to be reliable)
|
static const int PROG_REPEATS = 8; // repeats of programming commands (some decoders need at least 8 to be reliable)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// NMRA codes #
|
// NMRA codes #
|
||||||
static const byte SET_SPEED=0x3f;
|
static const byte SET_SPEED = 0x3f;
|
||||||
static const byte WRITE_BYTE_MAIN = 0xEC;
|
static const byte WRITE_BYTE_MAIN = 0xEC;
|
||||||
static const byte WRITE_BIT_MAIN = 0xE8;
|
static const byte WRITE_BIT_MAIN = 0xE8;
|
||||||
static const byte WRITE_BYTE = 0x7C;
|
static const byte WRITE_BYTE = 0x7C;
|
||||||
static const byte VERIFY_BYTE= 0x74;
|
static const byte VERIFY_BYTE = 0x74;
|
||||||
static const byte BIT_MANIPULATE=0x78;
|
static const byte BIT_MANIPULATE = 0x78;
|
||||||
static const byte WRITE_BIT=0xF0;
|
static const byte WRITE_BIT = 0xF0;
|
||||||
static const byte VERIFY_BIT=0xE0;
|
static const byte VERIFY_BIT = 0xE0;
|
||||||
static const byte BIT_ON=0x08;
|
static const byte BIT_ON = 0x08;
|
||||||
static const byte BIT_OFF=0x00;
|
static const byte BIT_OFF = 0x00;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef ARDUINO_AVR_MEGA // is using Mega 1280, define as Mega 2560 (pinouts and functionality are identical)
|
#ifdef ARDUINO_AVR_MEGA // is using Mega 1280, define as Mega 2560 (pinouts and functionality are identical)
|
||||||
#define ARDUINO_AVR_MEGA2560
|
#define ARDUINO_AVR_MEGA2560
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ARDUINO_AVR_UNO)
|
#if defined(ARDUINO_AVR_UNO)
|
||||||
#define ARDUINO_TYPE "UNO"
|
#define ARDUINO_TYPE "UNO"
|
||||||
#elif defined(ARDUINO_AVR_NANO)
|
#elif defined(ARDUINO_AVR_NANO)
|
||||||
#define ARDUINO_TYPE "NANO"
|
#define ARDUINO_TYPE "NANO"
|
||||||
#elif defined(ARDUINO_AVR_MEGA2560)
|
#elif defined(ARDUINO_AVR_MEGA2560)
|
||||||
#define ARDUINO_TYPE "MEGA"
|
#define ARDUINO_TYPE "MEGA"
|
||||||
|
#elif defined(ARDUINO_ARCH_MEGAAVR)
|
||||||
|
#define ARDUINO_TYPE "UNOWIFIR2"
|
||||||
#else
|
#else
|
||||||
#error CANNOT COMPILE - DCC++ EX ONLY WORKS WITH AN ARDUINO UNO, NANO 328, OR ARDUINO MEGA 1280/2560
|
#error CANNOT COMPILE - DCC++ EX ONLY WORKS WITH AN ARDUINO UNO, NANO 328, OR ARDUINO MEGA 1280/2560
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ENABLE_LCD
|
||||||
#ifdef ENABLE_LCD
|
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#if defined(LIB_TYPE_PCF8574)
|
#if defined(LIB_TYPE_PCF8574)
|
||||||
#include <LiquidCrystal_PCF8574.h>
|
#include <LiquidCrystal_PCF8574.h>
|
||||||
extern LiquidCrystal_PCF8574 lcdDisplay;
|
extern LiquidCrystal_PCF8574 lcdDisplay;
|
||||||
#elif defined(LIB_TYPE_I2C)
|
#elif defined(LIB_TYPE_I2C)
|
||||||
#include <LiquidCrystal_I2C.h>
|
#include <LiquidCrystal_I2C.h>
|
||||||
extern LiquidCrystal_I2C lcdDisplay;
|
extern LiquidCrystal_I2C lcdDisplay;
|
||||||
#endif
|
#endif
|
||||||
extern bool lcdEnabled;
|
extern bool lcdEnabled;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
911
DCCEXParser.cpp
911
DCCEXParser.cpp
File diff suppressed because it is too large
Load Diff
29
MemStream.h
29
MemStream.h
|
@ -24,34 +24,43 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
#define MemStream_h
|
#define MemStream_h
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#if defined(ARDUINO_ARCH_MEGAAVR)
|
||||||
|
#include <Arduino.h>
|
||||||
|
#else
|
||||||
#include <Stream.h>
|
#include <Stream.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
class MemStream : public Stream
|
class MemStream : public Stream
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
uint8_t * _buffer;
|
uint8_t *_buffer;
|
||||||
const uint16_t _len;
|
const uint16_t _len;
|
||||||
bool _buffer_overflow;
|
bool _buffer_overflow;
|
||||||
uint16_t _pos_read;
|
uint16_t _pos_read;
|
||||||
uint16_t _pos_write;
|
uint16_t _pos_write;
|
||||||
bool _allowWrite;
|
bool _allowWrite;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// public methods
|
// public methods
|
||||||
MemStream(uint8_t *buffer, const uint16_t len, uint16_t content_len = 0, bool allowWrite=true);
|
MemStream(uint8_t *buffer, const uint16_t len, uint16_t content_len = 0, bool allowWrite = true);
|
||||||
~MemStream() {}
|
~MemStream() {}
|
||||||
|
|
||||||
operator const uint8_t *() const { return _buffer; }
|
operator const uint8_t *() const { return _buffer; }
|
||||||
operator const char *() const { return (const char*)_buffer; }
|
operator const char *() const { return (const char *)_buffer; }
|
||||||
|
|
||||||
uint16_t current_length() const { return _pos_write; }
|
uint16_t current_length() const { return _pos_write; }
|
||||||
|
|
||||||
bool listen() { return true; }
|
bool listen() { return true; }
|
||||||
void end() {}
|
void end() {}
|
||||||
bool isListening() { return true; }
|
bool isListening() { return true; }
|
||||||
bool overflow() { bool ret = _buffer_overflow; _buffer_overflow = false; return ret; }
|
bool overflow()
|
||||||
|
{
|
||||||
|
bool ret = _buffer_overflow;
|
||||||
|
_buffer_overflow = false;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
int peek();
|
int peek();
|
||||||
|
|
||||||
virtual size_t write(uint8_t byte);
|
virtual size_t write(uint8_t byte);
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
#ifndef MotorDrivers_h
|
#ifndef MotorDrivers_h
|
||||||
#define MotorDrivers_h
|
#define MotorDrivers_h
|
||||||
|
#if defined(ARDUINO_ARCH_MEGAAVR)
|
||||||
|
#include <Arduino.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// *** PLEASE NOTE *** THIS FILE IS **NOT** INTENDED TO BE EDITED WHEN CONFIGURING A SYSTEM.
|
// *** PLEASE NOTE *** THIS FILE IS **NOT** INTENDED TO BE EDITED WHEN CONFIGURING A SYSTEM.
|
||||||
// It will be overwritten if the library is updated.
|
// It will be overwritten if the library is updated.
|
||||||
|
@ -9,35 +12,34 @@
|
||||||
// A custom hardware setup will require your sketch to create MotorDriver instances
|
// A custom hardware setup will require your sketch to create MotorDriver instances
|
||||||
// similar to those defined here, WITHOUT editing this file.
|
// similar to those defined here, WITHOUT editing this file.
|
||||||
|
|
||||||
|
|
||||||
const byte UNUSED_PIN = 255;
|
const byte UNUSED_PIN = 255;
|
||||||
|
|
||||||
// MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, byte brake_pin, byte current_pin,
|
// MotorDriver(byte power_pin, byte signal_pin, byte signal_pin2, byte brake_pin, byte current_pin,
|
||||||
// float senseFactor, unsigned int tripMilliamps, byte faultPin);
|
// float senseFactor, unsigned int tripMilliamps, byte faultPin);
|
||||||
|
|
||||||
// Arduino standard Motor Shield
|
// Arduino standard Motor Shield
|
||||||
#define STANDARD_MOTOR_SHIELD F("STANDARD_MOTOR_SHIELD"), \
|
#define STANDARD_MOTOR_SHIELD F("STANDARD_MOTOR_SHIELD"), \
|
||||||
new MotorDriver(3 , 12, UNUSED_PIN, UNUSED_PIN, A0, 2.99, 2000, UNUSED_PIN), \
|
new MotorDriver(3, 12, UNUSED_PIN, UNUSED_PIN, A0, 2.99, 2000, UNUSED_PIN), \
|
||||||
new MotorDriver(11, 13, UNUSED_PIN, UNUSED_PIN, A1, 2.99, 250 , UNUSED_PIN)
|
new MotorDriver(11, 13, UNUSED_PIN, UNUSED_PIN, A1, 2.99, TRIP_CURRENT_PROG, UNUSED_PIN)
|
||||||
|
|
||||||
// Pololu Motor Shield
|
// Pololu Motor Shield
|
||||||
#define POLOLU_MOTOR_SHIELD F("POLOLU_MOTOR_SHIELD"), \
|
#define POLOLU_MOTOR_SHIELD F("POLOLU_MOTOR_SHIELD"), \
|
||||||
new MotorDriver(4, 7, UNUSED_PIN, 9 , A0, 18, 2000, 12), \
|
new MotorDriver(4, 7, UNUSED_PIN, 9, A0, 18, 2000, 12), \
|
||||||
new MotorDriver(2, 8, UNUSED_PIN, 10, A1, 18, 250 , UNUSED_PIN)
|
new MotorDriver(2, 8, UNUSED_PIN, 10, A1, 18, TRIP_CURRENT_PROG, UNUSED_PIN)
|
||||||
|
|
||||||
// Firebox Mk1
|
// Firebox Mk1
|
||||||
#define FIREBOX_MK1 F("FIREBOX_MK1"), \
|
#define FIREBOX_MK1 F("FIREBOX_MK1"), \
|
||||||
new MotorDriver(3, 6, 7, UNUSED_PIN, A5, 9.766, 5500, UNUSED_PIN), \
|
new MotorDriver(3, 6, 7, UNUSED_PIN, A5, 9.766, 5500, UNUSED_PIN), \
|
||||||
new MotorDriver(4, 8, 9, UNUSED_PIN, A1, 5.00, 250 , UNUSED_PIN)
|
new MotorDriver(4, 8, 9, UNUSED_PIN, A1, 5.00, TRIP_CURRENT_PROG, UNUSED_PIN)
|
||||||
|
|
||||||
// Firebox Mk1S
|
// Firebox Mk1S
|
||||||
#define FIREBOX_MK1S F("FIREBOX_MK1A"), \
|
#define FIREBOX_MK1S F("FIREBOX_MK1A"), \
|
||||||
new MotorDriver(24, 21, 22, 25, 23, 9.766, 5500, UNUSED_PIN), \
|
new MotorDriver(24, 21, 22, 25, 23, 9.766, 5500, UNUSED_PIN), \
|
||||||
new MotorDriver(30, 27, 28, 31, 29, 5.00, 250 , UNUSED_PIN)
|
new MotorDriver(30, 27, 28, 31, 29, 5.00, TRIP_CURRENT_PROG, UNUSED_PIN)
|
||||||
|
|
||||||
// FunduMoto Motor Shield
|
// FunduMoto Motor Shield
|
||||||
#define FUNDUMOTO_SHIELD F("FUNDUMOTO_SHIELD"), \
|
#define FUNDUMOTO_SHIELD F("FUNDUMOTO_SHIELD"), \
|
||||||
new MotorDriver(10 , 12, UNUSED_PIN, 9, A0, 2.99, 2000, UNUSED_PIN), \
|
new MotorDriver(10, 12, UNUSED_PIN, 9, A0, 2.99, 2000, UNUSED_PIN), \
|
||||||
new MotorDriver(11, 13, UNUSED_PIN, UNUSED_PIN, A1, 2.99, 250 , UNUSED_PIN)
|
new MotorDriver(11, 13, UNUSED_PIN, UNUSED_PIN, A1, 2.99, TRIP_CURRENT_PROG, UNUSED_PIN)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -85,10 +85,15 @@ ISR(TIMER2_OVF_vect)
|
||||||
|
|
||||||
#include "ATMEGA4809/Timer.h"
|
#include "ATMEGA4809/Timer.h"
|
||||||
|
|
||||||
Timer TimerA(0);
|
Timer TimerA(1);
|
||||||
|
Timer TimerB(2);
|
||||||
|
|
||||||
ISR(TCA0_OVF_vect) {
|
ISR(TIMER1_OVF_vect) {
|
||||||
TimerA.isrCallback();
|
TimerA.isrCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ISR(TIMER2_OVF_vect) {
|
||||||
|
TimerB.isrCallback();
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#include "DIAG.h"
|
#include "DIAG.h"
|
||||||
#include "StringFormatter.h"
|
#include "StringFormatter.h"
|
||||||
#include "WiThrottle.h"
|
#include "WiThrottle.h"
|
||||||
|
|
||||||
|
|
||||||
const char PROGMEM READY_SEARCH[] = "\r\nready\r\n";
|
const char PROGMEM READY_SEARCH[] = "\r\nready\r\n";
|
||||||
const char PROGMEM OK_SEARCH[] = "\r\nOK\r\n";
|
const char PROGMEM OK_SEARCH[] = "\r\nOK\r\n";
|
||||||
const char PROGMEM END_DETAIL_SEARCH[] = "@ 1000";
|
const char PROGMEM END_DETAIL_SEARCH[] = "@ 1000";
|
||||||
|
|
|
@ -21,37 +21,39 @@
|
||||||
#define WifiInterface_h
|
#define WifiInterface_h
|
||||||
#include "DCCEXParser.h"
|
#include "DCCEXParser.h"
|
||||||
#include "MemStream.h"
|
#include "MemStream.h"
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
typedef void (*HTTP_CALLBACK)(Print * stream, byte * cmd);
|
typedef void (*HTTP_CALLBACK)(Print *stream, byte *cmd);
|
||||||
|
|
||||||
class WifiInterface {
|
class WifiInterface
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static bool setup(Stream & setupStream, const __FlashStringHelper* SSSid, const __FlashStringHelper* password,
|
static bool setup(Stream &setupStream, const __FlashStringHelper *SSSid, const __FlashStringHelper *password,
|
||||||
const __FlashStringHelper* hostname, int port);
|
const __FlashStringHelper *hostname, int port);
|
||||||
static void loop();
|
static void loop();
|
||||||
static void ATCommand(const byte * command);
|
static void ATCommand(const byte *command);
|
||||||
static void setHTTPCallback(HTTP_CALLBACK callback);
|
static void setHTTPCallback(HTTP_CALLBACK callback);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Stream * wifiStream;
|
static Stream *wifiStream;
|
||||||
static DCCEXParser parser;
|
static DCCEXParser parser;
|
||||||
static bool setup2( const __FlashStringHelper* SSSid, const __FlashStringHelper* password,
|
static bool setup2(const __FlashStringHelper *SSSid, const __FlashStringHelper *password,
|
||||||
const __FlashStringHelper* hostname, int port);
|
const __FlashStringHelper *hostname, int port);
|
||||||
static bool checkForOK(const unsigned int timeout, const char* waitfor, bool echo, bool escapeEcho=true);
|
static bool checkForOK(const unsigned int timeout, const char *waitfor, bool echo, bool escapeEcho = true);
|
||||||
static bool isHTTP();
|
static bool isHTTP();
|
||||||
static HTTP_CALLBACK httpCallback;
|
static HTTP_CALLBACK httpCallback;
|
||||||
static bool connected;
|
static bool connected;
|
||||||
static bool closeAfter;
|
static bool closeAfter;
|
||||||
static byte loopstate;
|
static byte loopstate;
|
||||||
static int datalength;
|
static int datalength;
|
||||||
static int connectionId;
|
static int connectionId;
|
||||||
static unsigned long loopTimeoutStart;
|
static unsigned long loopTimeoutStart;
|
||||||
static const byte MAX_WIFI_BUFFER=250;
|
static const byte MAX_WIFI_BUFFER = 250;
|
||||||
static byte buffer[MAX_WIFI_BUFFER+1];
|
static byte buffer[MAX_WIFI_BUFFER + 1];
|
||||||
static MemStream streamer;
|
static MemStream streamer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user