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

Merge branch 'ServoSignal' into TrackManager

This commit is contained in:
Asbelos 2022-03-18 13:47:07 +00:00
commit cd952c6ede
5 changed files with 78 additions and 16 deletions

View File

@ -598,6 +598,18 @@ void RMFT2::loop2() {
delayMe(50); delayMe(50);
return; return;
case OPCODE_ATGTE: // wait for analog sensor>= value
timeoutFlag=false;
if (IODevice::readAnalogue(operand) >= (int)(GET_OPERAND(1))) break;
delayMe(50);
return;
case OPCODE_ATLT: // wait for analog sensor < value
timeoutFlag=false;
if (IODevice::readAnalogue(operand) < (int)(GET_OPERAND(1))) break;
delayMe(50);
return;
case OPCODE_ATTIMEOUT1: // ATTIMEOUT(vpin,timeout) part 1 case OPCODE_ATTIMEOUT1: // ATTIMEOUT(vpin,timeout) part 1
timeoutStart=millis(); timeoutStart=millis();
timeoutFlag=false; timeoutFlag=false;
@ -927,23 +939,48 @@ void RMFT2::kill(const FSH * reason, int operand) {
/* static */ void RMFT2::doSignal(VPIN id,bool red, bool amber, bool green) { /* static */ void RMFT2::doSignal(VPIN id,bool red, bool amber, bool green) {
//if (diag) DIAG(F(" dosignal %d"),id); //if (diag) DIAG(F(" dosignal %d"),id);
for (int sigpos=0;;sigpos+=3) { for (int sigpos=0;;sigpos+=4) {
VPIN redpin=GETFLASHW(RMFT2::SignalDefinitions+sigpos);
//if (diag) DIAG(F("red=%d"),redpin); //if (diag) DIAG(F("red=%d"),redpin);
if (redpin==0) { VPIN sigid=GETFLASHW(RMFT2::SignalDefinitions+sigpos);
if (sigid==0) { // end of signal list
DIAG(F("EXRAIL Signal %d not defined"), id); DIAG(F("EXRAIL Signal %d not defined"), id);
return; // signal not found return; // signal not found
} }
if (redpin==id) { // sigid is the signal id used in RED/AMBER/GREEN macro
VPIN amberpin=GETFLASHW(RMFT2::SignalDefinitions+sigpos+1); // for a LED signal it will be same as redpin
VPIN greenpin=GETFLASHW(RMFT2::SignalDefinitions+sigpos+2); // but for a servo signal it will also have SERVO_SIGNAL_FLAG set.
if ((sigid & ~SERVO_SIGNAL_FLAG & ~ACTIVE_HIGH_SIGNAL_FLAG)!= id) continue; // keep looking
// Correct signal definition found, get the rag values
VPIN redpin=GETFLASHW(RMFT2::SignalDefinitions+sigpos+1);
VPIN amberpin=GETFLASHW(RMFT2::SignalDefinitions+sigpos+2);
VPIN greenpin=GETFLASHW(RMFT2::SignalDefinitions+sigpos+3);
//if (diag) DIAG(F("signal %d %d %d"),redpin,amberpin,greenpin); //if (diag) DIAG(F("signal %d %d %d"),redpin,amberpin,greenpin);
// If amberpin is zero, synthesise amber from red+green
IODevice::write(redpin,red || (amber && (amberpin==0))); if (sigid & SERVO_SIGNAL_FLAG) {
if (amberpin) IODevice::write(amberpin,amber); // A servo signal, the pin numbers are actually servo positions
if (greenpin) IODevice::write(greenpin,green || (amber && (amberpin==0))); // Note, setting a signal to a zero position has no effect.
int16_t servopos= red? redpin: (green? greenpin : amberpin);
if (servopos!=0) IODevice::writeAnalogue(id,servopos,PCA9685::Bounce);
return; return;
} }
// LED or similar 3 pin signal
// If amberpin is zero, synthesise amber from red+green
if (amber && (amberpin==0)) {
red=true;
green=true;
}
// Manage invert (HIGH on) pins
bool aHigh=sigid & ACTIVE_HIGH_SIGNAL_FLAG;
// set the three pins
if (redpin) IODevice::write(redpin,red^aHigh);
if (amberpin) IODevice::write(amberpin,amber^aHigh);
if (greenpin) IODevice::write(greenpin,green^aHigh);
return;
} }
} }

View File

@ -33,6 +33,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,
OPCODE_FWD,OPCODE_REV,OPCODE_SPEED,OPCODE_INVERT_DIRECTION, OPCODE_FWD,OPCODE_REV,OPCODE_SPEED,OPCODE_INVERT_DIRECTION,
OPCODE_RESERVE,OPCODE_FREE, OPCODE_RESERVE,OPCODE_FREE,
OPCODE_AT,OPCODE_AFTER,OPCODE_AUTOSTART, OPCODE_AT,OPCODE_AFTER,OPCODE_AUTOSTART,
OPCODE_ATGTE,OPCODE_ATLT,
OPCODE_ATTIMEOUT1,OPCODE_ATTIMEOUT2,OPCODE_IFTIMEOUT, OPCODE_ATTIMEOUT1,OPCODE_ATTIMEOUT2,OPCODE_IFTIMEOUT,
OPCODE_LATCH,OPCODE_UNLATCH,OPCODE_SET,OPCODE_RESET, OPCODE_LATCH,OPCODE_UNLATCH,OPCODE_SET,OPCODE_RESET,
OPCODE_IF,OPCODE_IFNOT,OPCODE_ENDIF,OPCODE_IFRANDOM,OPCODE_IFRESERVE, OPCODE_IF,OPCODE_IFNOT,OPCODE_ENDIF,OPCODE_IFRANDOM,OPCODE_IFRESERVE,
@ -94,6 +95,9 @@ class LookList {
static const byte rosterNameCount; static const byte rosterNameCount;
static void emitWithrottleRoster(Print * stream); static void emitWithrottleRoster(Print * stream);
static const FSH * getRosterFunctions(int16_t cabid); static const FSH * getRosterFunctions(int16_t cabid);
static const int16_t SERVO_SIGNAL_FLAG=0x4000;
static const int16_t ACTIVE_HIGH_SIGNAL_FLAG=0x2000;
private: private:
static void ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16_t p[]); static void ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16_t p[]);
static bool parseSlash(Print * stream, byte & paramCount, int16_t p[]) ; static bool parseSlash(Print * stream, byte & paramCount, int16_t p[]) ;

View File

@ -29,6 +29,8 @@
#undef ALIAS #undef ALIAS
#undef AMBER #undef AMBER
#undef AT #undef AT
#undef ATGTE
#undef ATLT
#undef ATTIMEOUT #undef ATTIMEOUT
#undef AUTOMATION #undef AUTOMATION
#undef AUTOSTART #undef AUTOSTART
@ -99,11 +101,13 @@
#undef SERVO #undef SERVO
#undef SERVO2 #undef SERVO2
#undef SERVO_TURNOUT #undef SERVO_TURNOUT
#undef SERVO_SIGNAL
#undef SET #undef SET
#undef SET_TRACK_DC #undef SET_TRACK_DC
#undef SET_TRACK_DCC #undef SET_TRACK_DCC
#undef SETLOCO #undef SETLOCO
#undef SIGNAL #undef SIGNAL
#undef SIGNALH
#undef SPEED #undef SPEED
#undef START #undef START
#undef STOP #undef STOP
@ -122,6 +126,8 @@
#define ALIAS(name,value) #define ALIAS(name,value)
#define AMBER(signal_id) #define AMBER(signal_id)
#define AT(sensor_id) #define AT(sensor_id)
#define ATGTE(sensor_id,value)
#define ATLT(sensor_id,value)
#define ATTIMEOUT(sensor_id,timeout_ms) #define ATTIMEOUT(sensor_id,timeout_ms)
#define AUTOMATION(id, description) #define AUTOMATION(id, description)
#define AUTOSTART #define AUTOSTART
@ -191,12 +197,14 @@
#define SERIAL3(msg) #define SERIAL3(msg)
#define SERVO(id,position,profile) #define SERVO(id,position,profile)
#define SERVO2(id,position,duration) #define SERVO2(id,position,duration)
#define SERVO_SIGNAL(vpin,redpos,amberpos,greenpos)
#define SERVO_TURNOUT(id,pin,activeAngle,inactiveAngle,profile,description...) #define SERVO_TURNOUT(id,pin,activeAngle,inactiveAngle,profile,description...)
#define SET(pin) #define SET(pin)
#define SET_TRACK_DC(trackid) #define SET_TRACK_DC(trackid)
#define SET_TRACK_DCC(trackid) #define SET_TRACK_DCC(trackid)
#define SETLOCO(loco) #define SETLOCO(loco)
#define SIGNAL(redpin,amberpin,greenpin) #define SIGNAL(redpin,amberpin,greenpin)
#define SIGNALH(redpin,amberpin,greenpin)
#define SPEED(speed) #define SPEED(speed)
#define START(route) #define START(route)
#define STOP #define STOP

View File

@ -148,10 +148,14 @@ const FSH * RMFT2::getRosterFunctions(int16_t cabid) {
// Pass 8 Signal definitions // Pass 8 Signal definitions
#include "EXRAIL2MacroReset.h" #include "EXRAIL2MacroReset.h"
#undef SIGNAL #undef SIGNAL
#define SIGNAL(redpin,amberpin,greenpin) redpin,amberpin,greenpin, #define SIGNAL(redpin,amberpin,greenpin) redpin,redpin,amberpin,greenpin,
#undef SIGNALH
#define SIGNALH(redpin,amberpin,greenpin) redpin | RMFT2::ACTIVE_HIGH_SIGNAL_FLAG,redpin,amberpin,greenpin,
#undef SERVO_SIGNAL
#define SERVO_SIGNAL(vpin,redval,amberval,greenval) vpin | RMFT2::SERVO_SIGNAL_FLAG,redval,amberval,greenval,
const FLASH int16_t RMFT2::SignalDefinitions[] = { const FLASH int16_t RMFT2::SignalDefinitions[] = {
#include "myAutomation.h" #include "myAutomation.h"
0,0,0 }; 0,0,0,0 };
// Last Pass : create main routes table // Last Pass : create main routes table
// Only undef the macros, not dummy them. // Only undef the macros, not dummy them.
@ -169,6 +173,8 @@ const FLASH int16_t RMFT2::SignalDefinitions[] = {
#define ALIAS(name,value) #define ALIAS(name,value)
#define AMBER(signal_id) OPCODE_AMBER,V(signal_id), #define AMBER(signal_id) OPCODE_AMBER,V(signal_id),
#define AT(sensor_id) OPCODE_AT,V(sensor_id), #define AT(sensor_id) OPCODE_AT,V(sensor_id),
#define ATGTE(sensor_id,value) OPCODE_ATGTE,V(sensor_id),OPCODE_PAD,V(value),
#define ATLT(sensor_id,value) OPCODE_ATLT,V(sensor_id),OPCODE_PAD,V(value),
#define ATTIMEOUT(sensor_id,timeout) OPCODE_ATTIMEOUT1,0,0,OPCODE_ATTIMEOUT2,V(sensor_id),OPCODE_PAD,V(timeout/100L), #define ATTIMEOUT(sensor_id,timeout) OPCODE_ATTIMEOUT1,0,0,OPCODE_ATTIMEOUT2,V(sensor_id),OPCODE_PAD,V(timeout/100L),
#define AUTOMATION(id, description) OPCODE_AUTOMATION, V(id), #define AUTOMATION(id, description) OPCODE_AUTOMATION, V(id),
#define AUTOSTART OPCODE_AUTOSTART,0,0, #define AUTOSTART OPCODE_AUTOSTART,0,0,
@ -238,12 +244,14 @@ const FLASH int16_t RMFT2::SignalDefinitions[] = {
#define SERIAL3(msg) PRINT(msg) #define SERIAL3(msg) PRINT(msg)
#define SERVO(id,position,profile) OPCODE_SERVO,V(id),OPCODE_PAD,V(position),OPCODE_PAD,V(PCA9685::profile),OPCODE_PAD,V(0), #define SERVO(id,position,profile) OPCODE_SERVO,V(id),OPCODE_PAD,V(position),OPCODE_PAD,V(PCA9685::profile),OPCODE_PAD,V(0),
#define SERVO2(id,position,ms) OPCODE_SERVO,V(id),OPCODE_PAD,V(position),OPCODE_PAD,V(PCA9685::Instant),OPCODE_PAD,V(ms/100L), #define SERVO2(id,position,ms) OPCODE_SERVO,V(id),OPCODE_PAD,V(position),OPCODE_PAD,V(PCA9685::Instant),OPCODE_PAD,V(ms/100L),
#define SERVO_SIGNAL(vpin,redpos,amberpos,greenpos)
#define SERVO_TURNOUT(id,pin,activeAngle,inactiveAngle,profile,description...) OPCODE_SERVOTURNOUT,V(id),OPCODE_PAD,V(pin),OPCODE_PAD,V(activeAngle),OPCODE_PAD,V(inactiveAngle),OPCODE_PAD,V(PCA9685::ProfileType::profile), #define SERVO_TURNOUT(id,pin,activeAngle,inactiveAngle,profile,description...) OPCODE_SERVOTURNOUT,V(id),OPCODE_PAD,V(pin),OPCODE_PAD,V(activeAngle),OPCODE_PAD,V(inactiveAngle),OPCODE_PAD,V(PCA9685::ProfileType::profile),
#define SET(pin) OPCODE_SET,V(pin), #define SET(pin) OPCODE_SET,V(pin),
#define SET_TRACK_DC(track) OPCODE_SET_TRACK,V(128+track), #define SET_TRACK_DC(track) OPCODE_SET_TRACK,V(128+track),
#define SET_TRACK_DCC(track) OPCODE_SET_TRACK,V(track), #define SET_TRACK_DCC(track) OPCODE_SET_TRACK,V(track),
#define SETLOCO(loco) OPCODE_SETLOCO,V(loco), #define SETLOCO(loco) OPCODE_SETLOCO,V(loco),
#define SIGNAL(redpin,amberpin,greenpin) #define SIGNAL(redpin,amberpin,greenpin)
#define SIGNALH(redpin,amberpin,greenpin)
#define SPEED(speed) OPCODE_SPEED,V(speed), #define SPEED(speed) OPCODE_SPEED,V(speed),
#define START(route) OPCODE_START,V(route), #define START(route) OPCODE_START,V(route),
#define STOP OPCODE_SPEED,V(0), #define STOP OPCODE_SPEED,V(0),

View File

@ -3,7 +3,12 @@
#include "StringFormatter.h" #include "StringFormatter.h"
#define VERSION "4.0.1"
#define VERSION "4.0.2"
// 4.0.2 EXRAIL additions:
// Servo signals (SERVO_SIGNAL)
// High-On signal pins (SIGNALH)
// Wait for analog value (ATGTE, ATLT)
// 4.0.1 EXRAIL BROADCAST("msg") // 4.0.1 EXRAIL BROADCAST("msg")
// EXRAIL POWERON // EXRAIL POWERON
// 4.0.0 Major functional and non-functional changes. // 4.0.0 Major functional and non-functional changes.