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

UNTESTED SERVO_SIGNAL

SERVO_SIGNAL definition in EXRAIL
SERVO_SIGNAL(vpin, redpos, amberpos, greenpos)

use RED/AMBER/GREEN as for led signals.
This commit is contained in:
Asbelos 2022-02-06 13:56:51 +00:00
parent 22bf2b69f1
commit 4300a3fdac
5 changed files with 45 additions and 16 deletions

View File

@ -913,23 +913,45 @@ void RMFT2::kill(const FSH * reason, int operand) {
/* static */ void RMFT2::doSignal(VPIN id,bool red, bool amber, bool green) {
//if (diag) DIAG(F(" dosignal %d"),id);
for (int sigpos=0;;sigpos+=3) {
VPIN redpin=GETFLASHW(RMFT2::SignalDefinitions+sigpos);
for (int sigpos=0;;sigpos+=4) {
//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);
return; // signal not found
}
if (redpin==id) {
VPIN amberpin=GETFLASHW(RMFT2::SignalDefinitions+sigpos+1);
VPIN greenpin=GETFLASHW(RMFT2::SignalDefinitions+sigpos+2);
// sigid is the signal id used in RED/AMBER/GREEN macro
// for a LED signal it will be same as redpin
// but for a servo signal it will also have SERVER_SIGNAL_FLAG set.
if ((sigid & ~SERVO_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 amberpin is zero, synthesise amber from red+green
IODevice::write(redpin,red || (amber && (amberpin==0)));
if (amberpin) IODevice::write(amberpin,amber);
if (greenpin) IODevice::write(greenpin,green || (amber && (amberpin==0)));
if (sigid & SERVO_SIGNAL_FLAG) {
// A servo signal, the pin numbers are actually servo positions
// 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;
}
// LED or similar 3 pin signal
// If amberpin is zero, synthesise amber from red+green
if (amber && (amberpin==0)) {
red=true;
green=true;
}
// set the three pins
if (redpin) IODevice::write(redpin,red);
if (amberpin) IODevice::write(amberpin,amber);
if (greenpin) IODevice::write(greenpin,green);
return;
}
}

View File

@ -94,6 +94,8 @@ class LookList {
static const byte rosterNameCount;
static void emitWithrottleRoster(Print * stream);
static const FSH * getRosterFunctions(int16_t cabid);
static const int16_t SERVO_SIGNAL_FLAG=0x4000;
private:
static void ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16_t p[]);
static bool parseSlash(Print * stream, byte & paramCount, int16_t p[]) ;

View File

@ -97,6 +97,7 @@
#undef SERVO
#undef SERVO2
#undef SERVO_TURNOUT
#undef SERVO_SIGNAL
#undef SET
#undef SETLOCO
#undef SIGNAL
@ -185,6 +186,7 @@
#define SERIAL3(msg)
#define SERVO(id,position,profile)
#define SERVO2(id,position,duration)
#define SERVO_SIGNAL(vpin,redpos,amberpos,greenpos)
#define SERVO_TURNOUT(id,pin,activeAngle,inactiveAngle,profile,description...)
#define SET(pin)
#define SETLOCO(loco)

View File

@ -146,10 +146,12 @@ const FSH * RMFT2::getRosterFunctions(int16_t cabid) {
// Pass 8 Signal definitions
#include "EXRAIL2MacroReset.h"
#undef SIGNAL
#define SIGNAL(redpin,amberpin,greenpin) redpin,amberpin,greenpin,
#define SIGNAL(redpin,amberpin,greenpin) redpin,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[] = {
#include "myAutomation.h"
0,0,0 };
0,0,0,0 };
// Last Pass : create main routes table
// Only undef the macros, not dummy them.
@ -234,6 +236,7 @@ const FLASH int16_t RMFT2::SignalDefinitions[] = {
#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 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 SET(pin) OPCODE_SET,V(pin),
#define SETLOCO(loco) OPCODE_SETLOCO,V(loco),

View File

@ -3,7 +3,7 @@
#include "StringFormatter.h"
#define VERSION "3.2.0 rc13"
#define VERSION "4.0.1 ServoSignalTest"
// 3.2.0 Major functional and non-functional changes.
// New HAL added for I/O (digital and analogue inputs and outputs, servos etc).
// Support for MCP23008, MCP23017 and PCF9584 I2C GPIO Extender modules.