mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-26 17:46:14 +01:00
Merge branch 'turnouteeprom' into mergetest, conflicts in DCC.cpp resolved
Conflicts: DCC.cpp
This commit is contained in:
commit
abd83bf7d6
|
@ -12,7 +12,6 @@
|
|||
#include "config.h"
|
||||
#include "DCCEX.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Enables an I2C 2x24 or 4x24 LCD Screen
|
||||
|
@ -32,7 +31,6 @@ DCCEXParser serialParser;
|
|||
|
||||
void setup()
|
||||
{
|
||||
|
||||
////////////////////////////////////////////
|
||||
//
|
||||
// More display stuff. Need to put this in a .h file and make
|
||||
|
|
7
DCC.cpp
7
DCC.cpp
|
@ -20,10 +20,10 @@
|
|||
#include "DCC.h"
|
||||
#include "DCCWaveform.h"
|
||||
#include "DIAG.h"
|
||||
#include "EEStore.h"
|
||||
#include "GITHUB_SHA.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
// This module is responsible for converting API calls into
|
||||
// messages to be sent to the waveform generator.
|
||||
// It has no visibility of the hardware, timers, interrupts
|
||||
|
@ -48,6 +48,11 @@ __FlashStringHelper* DCC::shieldName=NULL;
|
|||
void DCC::begin(const __FlashStringHelper* motorShieldName, MotorDriver * mainDriver, MotorDriver* progDriver, byte timerNumber) {
|
||||
shieldName=(__FlashStringHelper*)motorShieldName;
|
||||
DIAG(F("<iDCC-EX V-%S / %S / %S G-%S>\n"), F(VERSION), F(ARDUINO_TYPE), shieldName, F(GITHUB_SHA));
|
||||
|
||||
// Load stuff from EEprom
|
||||
(void)EEPROM; // tell compiler not to warn this is unused
|
||||
EEStore::init();
|
||||
|
||||
DCCWaveform::begin(mainDriver,progDriver, timerNumber);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ const int HASH_KEYWORD_ON = 2657;
|
|||
const int HASH_KEYWORD_DCC = 6436;
|
||||
const int HASH_KEYWORD_SLOW = -17209;
|
||||
const int HASH_KEYWORD_PROGBOOST = -6353;
|
||||
const int HASH_KEYWORD_EEPROM = -7168;
|
||||
|
||||
int DCCEXParser::stashP[MAX_PARAMS];
|
||||
bool DCCEXParser::stashBusy;
|
||||
|
@ -168,9 +169,9 @@ void DCCEXParser::setAtCommandCallback(AT_COMMAND_CALLBACK callback)
|
|||
// See documentation on DCC class for info on this section
|
||||
void DCCEXParser::parse(Print *stream, byte *com, bool blocking)
|
||||
{
|
||||
(void)EEPROM; // tell compiler not to warn this is unused
|
||||
if (Diag::CMD)
|
||||
DIAG(F("\nPARSING:%s\n"), com);
|
||||
(void)EEPROM; // tell compiler not to warn thi is unused
|
||||
int p[MAX_PARAMS];
|
||||
while (com[0] == '<' || com[0] == ' ')
|
||||
com++; // strip off any number of < or spaces
|
||||
|
@ -608,6 +609,11 @@ bool DCCEXParser::parseD(Print *stream, int params, int p[])
|
|||
DCC::setProgTrackBoost(true);
|
||||
return true;
|
||||
|
||||
case HASH_KEYWORD_EEPROM:
|
||||
if (params >= 1)
|
||||
EEStore::dump(p[1]);
|
||||
return true;
|
||||
|
||||
default: // invalid/unknown
|
||||
break;
|
||||
}
|
||||
|
|
12
EEStore.cpp
12
EEStore.cpp
|
@ -2,7 +2,7 @@
|
|||
#include "Turnouts.h"
|
||||
#include "Sensors.h"
|
||||
#include "Outputs.h"
|
||||
|
||||
#include "DIAG.h"
|
||||
|
||||
#if defined(ARDUINO_ARCH_SAMD)
|
||||
ExternalEEPROM EEPROM;
|
||||
|
@ -72,5 +72,15 @@ int EEStore::pointer(){
|
|||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void EEStore::dump(int num) {
|
||||
byte b;
|
||||
DIAG(F("\nAddr 0x char\n"));
|
||||
for (int n=0 ; n<num; n++) {
|
||||
EEPROM.get(n, b);
|
||||
DIAG(F("%d %x %c\n"),n,b,isascii(b) ? b : ' ');
|
||||
}
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
EEStore *EEStore::eeStore=NULL;
|
||||
int EEStore::eeAddress=0;
|
||||
|
|
|
@ -29,6 +29,7 @@ struct EEStore{
|
|||
static void advance(int);
|
||||
static void store();
|
||||
static void clear();
|
||||
static void dump(int);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
53
Turnouts.cpp
53
Turnouts.cpp
|
@ -1,5 +1,7 @@
|
|||
/*
|
||||
* © 2013-2016 Gregg E. Berman
|
||||
* © 2020, Chris Harlow. All rights reserved.
|
||||
* © 2020, Harald Barth.
|
||||
*
|
||||
* This file is part of Asbelos DCC API
|
||||
*
|
||||
|
@ -19,29 +21,42 @@
|
|||
#include "Turnouts.h"
|
||||
#include "EEStore.h"
|
||||
#include "PWMServoDriver.h"
|
||||
#ifdef EESTOREDEBUG
|
||||
#include "DIAG.h"
|
||||
#endif
|
||||
|
||||
bool Turnout::activate(int n,bool state){
|
||||
//DIAG(F("\nTurnout::activate(%d,%d)\n"),n,state);
|
||||
bool Turnout::activate(int n,bool state){
|
||||
#ifdef EESTOREDEBUG
|
||||
DIAG(F("\nTurnout::activate(%d,%d)\n"),n,state);
|
||||
#endif
|
||||
Turnout * tt=get(n);
|
||||
if (tt==NULL) return false;
|
||||
tt->activate(state);
|
||||
if(n>0) EEPROM.put(n,tt->data.tStatus);
|
||||
EEStore::store();
|
||||
turnoutlistHash++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Turnout::isActive(int n){
|
||||
bool Turnout::isActive(int n){
|
||||
Turnout * tt=get(n);
|
||||
if (tt==NULL) return false;
|
||||
return tt->data.tStatus & STATUS_ACTIVE;
|
||||
}
|
||||
|
||||
// activate is virtual here so that it can be overridden by a non-DCC turnout mechanism
|
||||
void Turnout::activate(bool state) {
|
||||
if (state) data.tStatus|=STATUS_ACTIVE;
|
||||
else data.tStatus &= ~STATUS_ACTIVE;
|
||||
if (data.tStatus & STATUS_PWM) PWMServoDriver::setServo(data.tStatus & STATUS_PWMPIN, (data.inactiveAngle+(state?data.moveAngle:0)));
|
||||
else DCC::setAccessory(data.address,data.subAddress, state);
|
||||
void Turnout::activate(bool state) {
|
||||
#ifdef EESTOREDEBUG
|
||||
DIAG(F("\nTurnout::activate(%d)\n"),state);
|
||||
#endif
|
||||
if (state)
|
||||
data.tStatus|=STATUS_ACTIVE;
|
||||
else
|
||||
data.tStatus &= ~STATUS_ACTIVE;
|
||||
if (data.tStatus & STATUS_PWM)
|
||||
PWMServoDriver::setServo(data.tStatus & STATUS_PWMPIN, (data.inactiveAngle+(state?data.moveAngle:0)));
|
||||
else
|
||||
DCC::setAccessory(data.address,data.subAddress, state);
|
||||
EEStore::store();
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -81,6 +96,9 @@ void Turnout::load(){
|
|||
else tt=create(data.id,data.address,data.subAddress);
|
||||
tt->data.tStatus=data.tStatus;
|
||||
EEStore::advance(sizeof(tt->data));
|
||||
#ifdef EESTOREDEBUG
|
||||
tt->print(tt);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,6 +111,9 @@ void Turnout::store(){
|
|||
EEStore::eeStore->data.nTurnouts=0;
|
||||
|
||||
while(tt!=NULL){
|
||||
#ifdef EESTOREDEBUG
|
||||
tt->print(tt);
|
||||
#endif
|
||||
EEPROM.put(EEStore::pointer(),tt->data);
|
||||
EEStore::advance(sizeof(tt->data));
|
||||
tt=tt->nextTurnout;
|
||||
|
@ -129,7 +150,19 @@ Turnout *Turnout::create(int id){
|
|||
turnoutlistHash++;
|
||||
return tt;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// print debug info about the state of a turnout
|
||||
//
|
||||
#ifdef EESTOREDEBUG
|
||||
void Turnout::print(Turnout *tt) {
|
||||
if (tt->data.tStatus & STATUS_PWM )
|
||||
DIAG(F("Turnout %d ZeroAngle %d MoveAngle %d Status %d\n"),tt->data.id, tt->data.inactiveAngle, tt->data.moveAngle,tt->data.tStatus & STATUS_ACTIVE);
|
||||
else
|
||||
DIAG(F("Turnout %d Addr %d Subaddr %d Status %d\n"),tt->data.id, tt->data.address, tt->data.subAddress,tt->data.tStatus & STATUS_ACTIVE);
|
||||
}
|
||||
#endif
|
||||
|
||||
Turnout *Turnout::firstTurnout=NULL;
|
||||
int Turnout::turnoutlistHash=0; //bump on every change so clients know when to refresh their lists
|
||||
|
|
|
@ -49,6 +49,9 @@ class Turnout {
|
|||
static Turnout *create(int id , byte pin , int activeAngle, int inactiveAngle);
|
||||
static Turnout *create(int id);
|
||||
void activate(bool state);
|
||||
#ifdef EESTOREDEBUG
|
||||
void print(Turnout *tt);
|
||||
#endif
|
||||
}; // Turnout
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user