mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-04-03 20:20:12 +02:00
Compare commits
167 Commits
v5.2.50-De
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
4125e73318 | ||
|
911bbd63be | ||
|
393b0bbd16 | ||
|
d9bd1e75f2 | ||
|
d1daf41f12 | ||
|
6bfa7028c4 | ||
|
a5d1d04882 | ||
|
bd6e426499 | ||
|
09bae44cc0 | ||
|
9f3354c687 | ||
|
fb495985f4 | ||
|
f868604ca9 | ||
|
41168a9dd8 | ||
|
0154e7fd78 | ||
|
9054d8d9f5 | ||
|
865f75dda4 | ||
|
b40fa779a6 | ||
|
2115ada2a1 | ||
|
830de850a9 | ||
|
c28965c58d | ||
|
0476b9c1d8 | ||
|
ba9ca1ccad | ||
|
c389fe9d3b | ||
|
79c30ec516 | ||
|
147fe15e04 | ||
|
b5491f9b52 | ||
|
6f1c7a9e98 | ||
|
42986c3b2d | ||
|
c1046ddcc0 | ||
|
818240b349 | ||
|
3c725afab4 | ||
|
13488e1e93 | ||
|
6cc3b4c6bf | ||
|
43fe772661 | ||
|
cafd53a0e5 | ||
|
d4a99b5db5 | ||
|
3ead534c81 | ||
|
84bc098157 | ||
|
8329fd83ce | ||
|
4f16091670 | ||
|
377f10e1c5 | ||
|
016a20259a | ||
|
14724aeb2a | ||
|
8f48e2ed94 | ||
|
6710c47f03 | ||
|
420d14567d | ||
|
953b8054f5 | ||
|
8081bfdf1e | ||
|
03bd1e897a | ||
|
d8f6d91408 | ||
|
dbb15c6aaa | ||
|
614802c756 | ||
|
5efe385f2e | ||
|
c50f3e016c | ||
|
535dcabcec | ||
|
1d18d5dea5 | ||
|
21c01ab69a | ||
|
fa00e9e11b | ||
|
ece2ac3ccf | ||
|
ea2e5ab8e9 | ||
|
480eb1bfde | ||
|
21dca05257 | ||
|
f5014f5595 | ||
|
33c8ed19a9 | ||
|
0e99ad143b | ||
|
01533e2cd2 | ||
|
07ab7286ba | ||
|
dc481a2f0c | ||
|
692f97e480 | ||
|
7fb7751f19 | ||
|
546ddd8139 | ||
|
4aa353edbc | ||
|
c1d6ee2804 | ||
|
14360b4198 | ||
|
dd898d3c16 | ||
|
277431e84c | ||
|
fe2f705fa9 | ||
|
2606d73d93 | ||
|
ec42c09e06 | ||
|
4ab77c21ed | ||
|
b53384ab51 | ||
|
b026417efb | ||
|
7ffbd9d0e8 | ||
|
6fa5511670 | ||
|
c07ac38ab1 | ||
|
4174c2a4ab | ||
|
30236f9b36 | ||
|
7395aa4af8 | ||
|
2397b773d7 | ||
|
9a08f2df63 | ||
|
8245208b2b | ||
|
4ed2ee9adc | ||
|
06a353cfa0 | ||
|
dfe9e6b69f | ||
|
4d84eccac3 | ||
|
edb02a00ce | ||
|
5db19a0fb8 | ||
|
b62661c337 | ||
|
048ba3fd1e | ||
|
c8c3697fa0 | ||
|
8c3c5dfe33 | ||
|
92288603bf | ||
|
80c8b3ef62 | ||
|
127f3acce5 | ||
|
690c629e6d | ||
|
e328ea5c5d | ||
|
ed853eef1d | ||
|
05e77c924e | ||
|
923b031d06 | ||
|
7e29011d63 | ||
|
c5c5609fc6 | ||
|
9c263062e4 | ||
|
f39fd89fbd | ||
|
4e57a80265 | ||
|
27dc8059d7 | ||
|
dc2eae499f | ||
|
c518dcdc0b | ||
|
e6047f6693 | ||
|
96c4757cc6 | ||
|
60e564df51 | ||
|
a8b4e39733 | ||
|
d705626f4a | ||
|
c97284c15f | ||
|
df1f365c1e | ||
|
023c004842 | ||
|
2481f1c5d6 | ||
|
7dadecb5df | ||
|
6ef312b510 | ||
|
97f9fb4813 | ||
|
3d6c935308 | ||
|
fba9a30813 | ||
|
5f65fd5944 | ||
|
a26610bc7f | ||
|
4e491a1e56 | ||
|
430161ef60 | ||
|
264a53dacf | ||
|
0c96d4ffc2 | ||
|
843fa42692 | ||
|
b17dc5a0dd | ||
|
449a5f1670 | ||
|
06b8995861 | ||
|
2172d2e175 | ||
|
86291cbec4 | ||
|
66791b19f5 | ||
|
6689a1d35f | ||
|
91818ed80c | ||
|
86310aea4f | ||
|
a610e83f6e | ||
|
1449dc7bac | ||
|
bd11cfbf8b | ||
|
16214fad66 | ||
|
76ad3ee48d | ||
|
742b100f65 | ||
|
83d4930124 | ||
|
b4e7982099 | ||
|
3af2f67792 | ||
|
c382bd33bc | ||
|
28d60d4984 | ||
|
3b162996ad | ||
|
fb414a7a50 | ||
|
818e05b425 | ||
|
c5168f030f | ||
|
387ea019bd | ||
|
a981f83bb9 | ||
|
749a859db5 | ||
|
659c58b307 | ||
|
0b9ec7460b |
95
CamParser.cpp
Normal file
95
CamParser.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
|
||||
//sensorCAM parser.cpp version 3.03 Sep 2024
|
||||
#include "CamParser.h"
|
||||
#include "FSH.h"
|
||||
#include "IO_EXSensorCAM.h"
|
||||
|
||||
#ifndef SENSORCAM_VPIN //define CAM vpin (700?) in config.h
|
||||
#define SENSORCAM_VPIN 0
|
||||
#endif
|
||||
#define CAM_VPIN SENSORCAM_VPIN
|
||||
#ifndef SENSORCAM2_VPIN
|
||||
#define SENSORCAM2_VPIN CAM_VPIN
|
||||
#endif
|
||||
#ifndef SENSORCAM3_VPIN
|
||||
#define SENSORCAM3_VPIN 0
|
||||
#endif
|
||||
const int CAMVPINS[] = {CAM_VPIN,SENSORCAM_VPIN,SENSORCAM2_VPIN,SENSORCAM3_VPIN};
|
||||
const int16_t ver=30177;
|
||||
const int16_t ve =2899;
|
||||
|
||||
VPIN EXSensorCAM::CAMBaseVpin = CAM_VPIN;
|
||||
|
||||
bool CamParser::parseN(Print * stream, byte paramCount, int16_t p[]) {
|
||||
(void)stream; // probably unused parameter
|
||||
VPIN vpin=EXSensorCAM::CAMBaseVpin; //use current CAM selection
|
||||
|
||||
if (paramCount==0) {
|
||||
DIAG(F("vpin:%d EXSensorCAMs defined at Vpins #1@ %d #2@ %d #3@ %d"),vpin,CAMVPINS[1],CAMVPINS[2],CAMVPINS[3]);
|
||||
return true;
|
||||
}
|
||||
uint8_t camop=p[0]; // cam oprerator
|
||||
int param1=0;
|
||||
int16_t param3=9999; // =0 could invoke parameter changes. & -1 gives later errors
|
||||
|
||||
if(camop=='C'){
|
||||
if(p[1]>=100) EXSensorCAM::CAMBaseVpin=p[1];
|
||||
if(p[1]<4) EXSensorCAM::CAMBaseVpin=CAMVPINS[p[1]];
|
||||
DIAG(F("CAM base Vpin: %c %d "),p[0],EXSensorCAM::CAMBaseVpin);
|
||||
return true;
|
||||
}
|
||||
if (camop<100) { //switch CAM# if p[1] dictates
|
||||
if(p[1]>=100 && p[1]<400) { //limits to CAM# 1 to 3 for now
|
||||
vpin=CAMVPINS[p[1]/100];
|
||||
EXSensorCAM::CAMBaseVpin=vpin;
|
||||
DIAG(F("switching to CAM %d baseVpin:%d"),p[1]/100,vpin);
|
||||
p[1]=p[1]%100; //strip off CAM #
|
||||
}
|
||||
}
|
||||
if (EXSensorCAM::CAMBaseVpin==0) return false; // no cam defined
|
||||
|
||||
|
||||
// send UPPER case to sensorCAM to flag binary data from a DCCEX-CS parser
|
||||
switch(paramCount) {
|
||||
case 1: //<N ver> produces '^'
|
||||
if((p[0] == ve) || (p[0] == ver) || (p[0] == 'V')) camop='^';
|
||||
if (STRCHR_P((const char *)F("EFGMQRVW^"),camop) == nullptr) return false;
|
||||
if (camop=='Q') param3=10; //<NQ> for activation state of all 10 banks of sensors
|
||||
if (camop=='F') camop=']'; //<NF> for Reset/Finish webCAM.
|
||||
break; // F Coded as ']' else conflicts with <Nf %%>
|
||||
|
||||
case 2: //<N camop p1>
|
||||
if (STRCHR_P((const char *)F("ABFILMNOPQRSTUV"),camop)==nullptr) return false;
|
||||
param1=p[1];
|
||||
break;
|
||||
|
||||
case 3: //<N vpin rowY colx > or <N cmd p1 p2>
|
||||
camop=p[0];
|
||||
if (p[0]>=100) { //vpin - i.e. NOT 'A' through 'Z'
|
||||
if (p[1]>236 || p[1]<0) return false; //row
|
||||
if (p[2]>316 || p[2]<0) return false; //column
|
||||
camop=0x80; // special 'a' case for IO_SensorCAM
|
||||
vpin = p[0];
|
||||
}else if (STRCHR_P((const char *)F("IJMNT"),camop) == nullptr) return false;
|
||||
param1 = p[1];
|
||||
param3 = p[2];
|
||||
break;
|
||||
|
||||
case 4: //<N a id row col>
|
||||
if (camop!='A') return false; //must start with 'a'
|
||||
if (p[3]>316 || p[3]<0) return false;
|
||||
if (p[2]>236 || p[2]<0) return false;
|
||||
if (p[1]>97 || p[1]<0) return false; //treat as bsNo.
|
||||
vpin = vpin + (p[1]/10)*8 + p[1]%10; //translate p[1]
|
||||
camop=0x80; // special 'a' case for IO_SensorCAM
|
||||
param1=p[2]; // row
|
||||
param3=p[3]; // col
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
DIAG(F("CamParser: %d %c %d %d"),vpin,camop,param1,param3);
|
||||
IODevice::writeAnalogue(vpin,param1,camop,param3);
|
||||
return true;
|
||||
}
|
12
CamParser.h
Normal file
12
CamParser.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef CamParser_H
|
||||
#define CamParser_H
|
||||
#include <Arduino.h>
|
||||
#include "IODevice.h"
|
||||
|
||||
class CamParser {
|
||||
public:
|
||||
static bool parseN(Print * stream, byte paramCount, int16_t p[]);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -37,7 +37,7 @@ int16_t lastclocktime;
|
||||
int8_t lastclockrate;
|
||||
|
||||
|
||||
#if WIFI_ON || ETHERNET_ON || defined(SERIAL1_COMMANDS) || defined(SERIAL2_COMMANDS) || defined(SERIAL3_COMMANDS)
|
||||
#if WIFI_ON || ETHERNET_ON || defined(SERIAL1_COMMANDS) || defined(SERIAL2_COMMANDS) || defined(SERIAL3_COMMANDS) || defined(SERIAL4_COMMANDS) || defined(SERIAL5_COMMANDS) || defined(SERIAL6_COMMANDS)
|
||||
// use a buffer to allow broadcast
|
||||
StringBuffer * CommandDistributor::broadcastBufferWriter=new StringBuffer();
|
||||
template<typename... Targs> void CommandDistributor::broadcastReply(clientType type, Targs... msg){
|
||||
@ -248,6 +248,10 @@ void CommandDistributor::broadcastLoco(byte slot) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void CommandDistributor::broadcastForgetLoco(int16_t loco) {
|
||||
broadcastReply(COMMAND_TYPE, F("<l %d 0 1 0>\n<- %d>\n"), loco,loco);
|
||||
}
|
||||
|
||||
void CommandDistributor::broadcastPower() {
|
||||
char pstr[] = "? x";
|
||||
for(byte t=0; t<TrackManager::MAX_TRACKS; t++)
|
||||
@ -276,6 +280,9 @@ void CommandDistributor::broadcastPower() {
|
||||
state = '1';
|
||||
}
|
||||
|
||||
if (state != '2')
|
||||
broadcastReply(COMMAND_TYPE, F("<p%c>\n"),state);
|
||||
|
||||
// additional info about MAIN, PROG and JOIN
|
||||
bool main=TrackManager::getMainPower()==POWERMODE::ON;
|
||||
bool prog=TrackManager::getProgPower()==POWERMODE::ON;
|
||||
@ -284,7 +291,7 @@ void CommandDistributor::broadcastPower() {
|
||||
const FSH * reason=F("");
|
||||
if (join) {
|
||||
reason = F(" JOIN"); // with space at start so we can append without space
|
||||
broadcastReply(COMMAND_TYPE, F("<p1 %S>\n"),reason);
|
||||
broadcastReply(COMMAND_TYPE, F("<p1%S>\n"),reason);
|
||||
} else {
|
||||
if (main) {
|
||||
//reason = F("MAIN");
|
||||
@ -295,9 +302,6 @@ void CommandDistributor::broadcastPower() {
|
||||
broadcastReply(COMMAND_TYPE, F("<p1 PROG>\n"));
|
||||
}
|
||||
}
|
||||
|
||||
if (state != '2')
|
||||
broadcastReply(COMMAND_TYPE, F("<p%c>\n"),state);
|
||||
#ifdef CD_HANDLE_RING
|
||||
// send '1' if all main are on, otherwise global state (which in that case is '0' or '2')
|
||||
broadcastReply(WITHROTTLE_TYPE, F("PPA%c\n"), main?'1': state);
|
||||
@ -373,4 +377,3 @@ void CommandDistributor::setVirtualLCDSerial(Print * stream) {
|
||||
Print* CommandDistributor::virtualLCDSerial=&USB_SERIAL;
|
||||
byte CommandDistributor::virtualLCDClient=0xFF;
|
||||
byte CommandDistributor::rememberVLCDClient=0;
|
||||
|
||||
|
@ -47,6 +47,7 @@ private:
|
||||
public :
|
||||
static void parse(byte clientId,byte* buffer, RingStream * ring);
|
||||
static void broadcastLoco(byte slot);
|
||||
static void broadcastForgetLoco(int16_t loco);
|
||||
static void broadcastSensor(int16_t id, bool value);
|
||||
static void broadcastTurnout(int16_t id, bool isClosed);
|
||||
static void broadcastTurntable(int16_t id, uint8_t position, bool moving);
|
||||
|
@ -141,6 +141,23 @@ void setup()
|
||||
CommandDistributor::broadcastPower();
|
||||
}
|
||||
|
||||
/**************** for future reference
|
||||
void looptimer(unsigned long timeout, const FSH* message)
|
||||
{
|
||||
static unsigned long lasttimestamp = 0;
|
||||
unsigned long now = micros();
|
||||
if (timeout != 0) {
|
||||
unsigned long diff = now - lasttimestamp;
|
||||
if (diff > timeout) {
|
||||
DIAG(message);
|
||||
DIAG(F("DeltaT=%L"), diff);
|
||||
lasttimestamp = micros();
|
||||
return;
|
||||
}
|
||||
}
|
||||
lasttimestamp = now;
|
||||
}
|
||||
*********************************************/
|
||||
void loop()
|
||||
{
|
||||
// The main sketch has responsibilities during loop()
|
||||
@ -148,14 +165,15 @@ void loop()
|
||||
// Responsibility 1: Handle DCC background processes
|
||||
// (loco reminders and power checks)
|
||||
DCC::loop();
|
||||
|
||||
|
||||
// Responsibility 2: handle any incoming commands on USB connection
|
||||
SerialManager::loop();
|
||||
|
||||
|
||||
// Responsibility 3: Optionally handle any incoming WiFi traffic
|
||||
#ifndef ARDUINO_ARCH_ESP32
|
||||
#if WIFI_ON
|
||||
WifiInterface::loop();
|
||||
|
||||
#endif //WIFI_ON
|
||||
#else //ARDUINO_ARCH_ESP32
|
||||
#ifndef WIFI_TASK_ON_CORE0
|
||||
|
32
DCC.cpp
32
DCC.cpp
@ -229,15 +229,9 @@ bool DCC::setFn( int cab, int16_t functionNumber, bool on) {
|
||||
|
||||
// Flip function state (used from withrottle protocol)
|
||||
void DCC::changeFn( int cab, int16_t functionNumber) {
|
||||
if (cab<=0 || functionNumber>31) return;
|
||||
int reg = lookupSpeedTable(cab);
|
||||
if (reg<0) return;
|
||||
unsigned long funcmask = (1UL<<functionNumber);
|
||||
speedTable[reg].functions ^= funcmask;
|
||||
if (functionNumber <= 28) {
|
||||
updateGroupflags(speedTable[reg].groupFlags, functionNumber);
|
||||
}
|
||||
CommandDistributor::broadcastLoco(reg);
|
||||
auto currentValue=getFn(cab,functionNumber);
|
||||
if (currentValue<0) return; // function not valid for change
|
||||
setFn(cab,functionNumber, currentValue?false:true);
|
||||
}
|
||||
|
||||
// Report function state (used from withrottle protocol)
|
||||
@ -271,6 +265,20 @@ uint32_t DCC::getFunctionMap(int cab) {
|
||||
return (reg<0)?0:speedTable[reg].functions;
|
||||
}
|
||||
|
||||
// saves DC frequency (0..3) in spare functions 29,30,31
|
||||
void DCC::setDCFreq(int cab,byte freq) {
|
||||
if (cab==0 || freq>3) return;
|
||||
auto reg=lookupSpeedTable(cab,true);
|
||||
// drop and replace F29,30,31 (top 3 bits)
|
||||
auto newFunctions=speedTable[reg].functions & 0x1FFFFFFFUL;
|
||||
if (freq==1) newFunctions |= (1UL<<29); // F29
|
||||
else if (freq==2) newFunctions |= (1UL<<30); // F30
|
||||
else if (freq==3) newFunctions |= (1UL<<31); // F31
|
||||
if (newFunctions==speedTable[reg].functions) return; // no change
|
||||
speedTable[reg].functions=newFunctions;
|
||||
CommandDistributor::broadcastLoco(reg);
|
||||
}
|
||||
|
||||
void DCC::setAccessory(int address, byte port, bool gate, byte onoff /*= 2*/) {
|
||||
// onoff is tristate:
|
||||
// 0 => send off packet
|
||||
@ -728,11 +736,15 @@ void DCC::forgetLoco(int cab) { // removes any speed reminders for this loco
|
||||
if (reg>=0) {
|
||||
speedTable[reg].loco=0;
|
||||
setThrottle2(cab,1); // ESTOP if this loco still on track
|
||||
CommandDistributor::broadcastForgetLoco(cab);
|
||||
}
|
||||
}
|
||||
void DCC::forgetAllLocos() { // removes all speed reminders
|
||||
setThrottle2(0,1); // ESTOP all locos still on track
|
||||
for (int i=0;i<MAX_LOCOS;i++) speedTable[i].loco=0;
|
||||
for (int i=0;i<MAX_LOCOS;i++) {
|
||||
if (speedTable[i].loco) CommandDistributor::broadcastForgetLoco(speedTable[i].loco);
|
||||
speedTable[i].loco=0;
|
||||
}
|
||||
}
|
||||
|
||||
byte DCC::loopStatus=0;
|
||||
|
1
DCC.h
1
DCC.h
@ -70,6 +70,7 @@ public:
|
||||
static void changeFn(int cab, int16_t functionNumber);
|
||||
static int8_t getFn(int cab, int16_t functionNumber);
|
||||
static uint32_t getFunctionMap(int cab);
|
||||
static void setDCFreq(int cab,byte freq);
|
||||
static void updateGroupflags(byte &flags, int16_t functionNumber);
|
||||
static void setAccessory(int address, byte port, bool gate, byte onoff = 2);
|
||||
static bool setExtendedAccessory(int16_t address, int16_t value, byte repeats=3);
|
||||
|
25
DCCACK.cpp
25
DCCACK.cpp
@ -27,8 +27,8 @@
|
||||
#include "DCCWaveform.h"
|
||||
#include "TrackManager.h"
|
||||
|
||||
unsigned int DCCACK::minAckPulseDuration = 2000; // micros
|
||||
unsigned int DCCACK::maxAckPulseDuration = 20000; // micros
|
||||
unsigned long DCCACK::minAckPulseDuration = 2000; // micros
|
||||
unsigned long DCCACK::maxAckPulseDuration = 20000; // micros
|
||||
|
||||
MotorDriver * DCCACK::progDriver=NULL;
|
||||
ackOp const * DCCACK::ackManagerProg;
|
||||
@ -50,8 +50,8 @@ volatile uint8_t DCCACK::numAckSamples=0;
|
||||
uint8_t DCCACK::trailingEdgeCounter=0;
|
||||
|
||||
|
||||
unsigned int DCCACK::ackPulseDuration; // micros
|
||||
unsigned long DCCACK::ackPulseStart; // micros
|
||||
unsigned long DCCACK::ackPulseDuration; // micros
|
||||
unsigned long DCCACK::ackPulseStart; // micros
|
||||
volatile bool DCCACK::ackDetected;
|
||||
unsigned long DCCACK::ackCheckStart; // millis
|
||||
volatile bool DCCACK::ackPending;
|
||||
@ -67,16 +67,24 @@ CALLBACK_STATE DCCACK::callbackState=READY;
|
||||
ACK_CALLBACK DCCACK::ackManagerCallback;
|
||||
|
||||
void DCCACK::Setup(int cv, byte byteValueOrBitnum, ackOp const program[], ACK_CALLBACK callback) {
|
||||
// On ESP32 the joined track is hidden from sight (it has type MAIN)
|
||||
// and because of that we need first check if track was joined and
|
||||
// then unjoin if necessary. This requires that the joined flag is
|
||||
// cleared when the prog track is removed.
|
||||
ackManagerRejoin=TrackManager::isJoined();
|
||||
//DIAG(F("Joined is %d"), ackManagerRejoin);
|
||||
if (ackManagerRejoin) {
|
||||
// Change from JOIN must zero resets packet.
|
||||
TrackManager::setJoin(false);
|
||||
DCCWaveform::progTrack.clearResets();
|
||||
}
|
||||
|
||||
progDriver=TrackManager::getProgDriver();
|
||||
//DIAG(F("Progdriver is %d"), progDriver);
|
||||
if (progDriver==NULL) {
|
||||
TrackManager::setJoin(ackManagerRejoin);
|
||||
if (ackManagerRejoin) {
|
||||
DIAG(F("Joined but no Prog track"));
|
||||
TrackManager::setJoin(false);
|
||||
}
|
||||
callback(-3); // we dont have a prog track!
|
||||
return;
|
||||
}
|
||||
@ -127,7 +135,7 @@ bool DCCACK::checkResets(uint8_t numResets) {
|
||||
void DCCACK::setAckBaseline() {
|
||||
int baseline=progDriver->getCurrentRaw();
|
||||
ackThreshold= baseline + progDriver->mA2raw(ackLimitmA);
|
||||
if (Diag::ACK) DIAG(F("ACK baseline=%d/%dmA Threshold=%d/%dmA Duration between %uus and %uus"),
|
||||
if (Diag::ACK) DIAG(F("ACK baseline=%d/%dmA Threshold=%d/%dmA Duration between %lus and %lus"),
|
||||
baseline,progDriver->raw2mA(baseline),
|
||||
ackThreshold,progDriver->raw2mA(ackThreshold),
|
||||
minAckPulseDuration, maxAckPulseDuration);
|
||||
@ -146,7 +154,7 @@ void DCCACK::setAckPending() {
|
||||
|
||||
byte DCCACK::getAck() {
|
||||
if (ackPending) return (2); // still waiting
|
||||
if (Diag::ACK) DIAG(F("%S after %dmS max=%d/%dmA pulse=%uuS samples=%d gaps=%d"),ackDetected?F("ACK"):F("NO-ACK"), ackCheckDuration,
|
||||
if (Diag::ACK) DIAG(F("%S after %dmS max=%d/%dmA pulse=%luS samples=%d gaps=%d"),ackDetected?F("ACK"):F("NO-ACK"), ackCheckDuration,
|
||||
ackMaxCurrent,progDriver->raw2mA(ackMaxCurrent), ackPulseDuration, numAckSamples, numAckGaps);
|
||||
if (ackDetected) return (1); // Yes we had an ack
|
||||
return(0); // pending set off but not detected means no ACK.
|
||||
@ -483,4 +491,3 @@ void DCCACK::checkAck(byte sentResetsSincePacket) {
|
||||
}
|
||||
ackPulseStart=0; // We have detected a too-short or too-long pulse so ignore and wait for next leading edge
|
||||
}
|
||||
|
||||
|
10
DCCACK.h
10
DCCACK.h
@ -79,10 +79,10 @@ class DCCACK {
|
||||
static inline void setAckLimit(int mA) {
|
||||
ackLimitmA = mA;
|
||||
}
|
||||
static inline void setMinAckPulseDuration(unsigned int i) {
|
||||
static inline void setMinAckPulseDuration(unsigned long i) {
|
||||
minAckPulseDuration = i;
|
||||
}
|
||||
static inline void setMaxAckPulseDuration(unsigned int i) {
|
||||
static inline void setMaxAckPulseDuration(unsigned long i) {
|
||||
maxAckPulseDuration = i;
|
||||
}
|
||||
|
||||
@ -126,11 +126,11 @@ class DCCACK {
|
||||
static unsigned long ackCheckStart; // millis
|
||||
static unsigned int ackCheckDuration; // millis
|
||||
|
||||
static unsigned int ackPulseDuration; // micros
|
||||
static unsigned long ackPulseDuration; // micros
|
||||
static unsigned long ackPulseStart; // micros
|
||||
|
||||
static unsigned int minAckPulseDuration ; // micros
|
||||
static unsigned int maxAckPulseDuration ; // micros
|
||||
static unsigned long minAckPulseDuration ; // micros
|
||||
static unsigned long maxAckPulseDuration ; // micros
|
||||
static MotorDriver* progDriver;
|
||||
static volatile uint8_t numAckGaps;
|
||||
static volatile uint8_t numAckSamples;
|
||||
|
162
DCCEXParser.cpp
162
DCCEXParser.cpp
@ -2,7 +2,7 @@
|
||||
* © 2022 Paul M Antoine
|
||||
* © 2021 Neil McKechnie
|
||||
* © 2021 Mike S
|
||||
* © 2021 Herb Morton
|
||||
* © 2021-2024 Herb Morton
|
||||
* © 2020-2023 Harald Barth
|
||||
* © 2020-2021 M Steve Todd
|
||||
* © 2020-2021 Fred Decker
|
||||
@ -70,9 +70,9 @@ Once a new OPCODE is decided upon, update this list.
|
||||
L, Reserved for LCC interface (implemented in EXRAIL)
|
||||
m, message to throttles broadcast
|
||||
M, Write DCC packet
|
||||
n,
|
||||
N,
|
||||
o,
|
||||
n, Reserved for SensorCam
|
||||
N, Reserved for Sensorcam
|
||||
o, Neopixel driver (see also IO_NeoPixel.h)
|
||||
O, Output broadcast
|
||||
p, Broadcast power state
|
||||
P, Write DCC packet
|
||||
@ -91,10 +91,10 @@ Once a new OPCODE is decided upon, update this list.
|
||||
w, Write CV on main
|
||||
W, Write CV
|
||||
x,
|
||||
X, Invalid command
|
||||
y,
|
||||
X, Invalid command response
|
||||
y,
|
||||
Y, Output broadcast
|
||||
z,
|
||||
z, Direct output
|
||||
Z, Output configuration/control
|
||||
*/
|
||||
|
||||
@ -117,6 +117,10 @@ Once a new OPCODE is decided upon, update this list.
|
||||
#include "Turntables.h"
|
||||
#include "version.h"
|
||||
#include "KeywordHasher.h"
|
||||
#include "CamParser.h"
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include "WifiESP32.h"
|
||||
#endif
|
||||
|
||||
// This macro can't be created easily as a portable function because the
|
||||
// flashlist requires a far pointer for high flash access.
|
||||
@ -140,12 +144,12 @@ byte DCCEXParser::stashTarget=0;
|
||||
// Non-DCC things like turnouts, pins and sensors are handled in additional JMRI interface classes.
|
||||
|
||||
|
||||
int16_t DCCEXParser::splitValues(int16_t result[MAX_COMMAND_PARAMS], const byte *cmd, bool usehex)
|
||||
int16_t DCCEXParser::splitValues(int16_t result[MAX_COMMAND_PARAMS], byte *cmd, bool usehex)
|
||||
{
|
||||
byte state = 1;
|
||||
byte parameterCount = 0;
|
||||
int16_t runningValue = 0;
|
||||
const byte *remainingCmd = cmd + 1; // skips the opcode
|
||||
byte *remainingCmd = cmd + 1; // skips the opcode
|
||||
bool signNegative = false;
|
||||
|
||||
// clear all parameters in case not enough found
|
||||
@ -155,7 +159,6 @@ int16_t DCCEXParser::splitValues(int16_t result[MAX_COMMAND_PARAMS], const byte
|
||||
while (parameterCount < MAX_COMMAND_PARAMS)
|
||||
{
|
||||
byte hot = *remainingCmd;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
|
||||
@ -164,12 +167,29 @@ int16_t DCCEXParser::splitValues(int16_t result[MAX_COMMAND_PARAMS], const byte
|
||||
break;
|
||||
if (hot == '\0')
|
||||
return -1;
|
||||
if (hot == '>')
|
||||
if (hot == '>') {
|
||||
*remainingCmd = '\0'; // terminate the cmd string with 0 instead of '>'
|
||||
return parameterCount;
|
||||
}
|
||||
state = 2;
|
||||
continue;
|
||||
|
||||
case 2: // checking sign
|
||||
case 2: // checking sign or quoted string
|
||||
#ifdef HAS_ENOUGH_MEMORY
|
||||
if (hot == '"') {
|
||||
// this inserts an extra parameter 0x7777 in front
|
||||
// of each string parameter as a marker that can
|
||||
// be checked that a string parameter follows
|
||||
// This clashes of course with the real value
|
||||
// 0x7777 which we hope is used seldom
|
||||
result[parameterCount] = (int16_t)0x7777;
|
||||
parameterCount++;
|
||||
result[parameterCount] = (int16_t)(remainingCmd - cmd + 1);
|
||||
parameterCount++;
|
||||
state = 4;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
signNegative = false;
|
||||
runningValue = 0;
|
||||
state = 3;
|
||||
@ -200,6 +220,16 @@ int16_t DCCEXParser::splitValues(int16_t result[MAX_COMMAND_PARAMS], const byte
|
||||
parameterCount++;
|
||||
state = 1;
|
||||
continue;
|
||||
#ifdef HAS_ENOUGH_MEMORY
|
||||
case 4: // skipover text
|
||||
if (hot == '\0') // We did run to end of buffer without finding the "
|
||||
return -1;
|
||||
if (hot == '"') {
|
||||
*remainingCmd = '\0'; // overwrite " in command buffer with the end-of-string
|
||||
state = 1;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
remainingCmd++;
|
||||
}
|
||||
@ -237,17 +267,22 @@ void DCCEXParser::parse(const FSH * cmd) {
|
||||
// See documentation on DCC class for info on this section
|
||||
|
||||
void DCCEXParser::parse(Print *stream, byte *com, RingStream *ringStream) {
|
||||
// This function can get stings of the form "<C OMM AND>" or "C OMM AND"
|
||||
// found is true first after the leading "<" has been passed
|
||||
// This function can get stings of the form "<C OMM AND>" or "C OMM AND>"
|
||||
// found is true first after the leading "<" has been passed which results
|
||||
// in parseOne() getting c="C OMM AND>"
|
||||
byte *cForLater = NULL;
|
||||
bool found = (com[0] != '<');
|
||||
for (byte *c=com; c[0] != '\0'; c++) {
|
||||
if (found) {
|
||||
parseOne(stream, c, ringStream);
|
||||
cForLater = c;
|
||||
found=false;
|
||||
}
|
||||
if (c[0] == '<')
|
||||
if (c[0] == '<') {
|
||||
if (cForLater) parseOne(stream, cForLater, ringStream);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (cForLater) parseOne(stream, cForLater, ringStream);
|
||||
}
|
||||
|
||||
void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||
@ -374,7 +409,8 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||
|| (p[activep] > 1) || (p[activep] < 0) // invalid activate 0|1
|
||||
) break;
|
||||
// Honour the configuration option (config.h) which allows the <a> command to be reversed
|
||||
#ifdef DCC_ACCESSORY_COMMAND_REVERSE
|
||||
// Because of earlier confusion we need to do the same thing under both defines
|
||||
#if defined(DCC_ACCESSORY_COMMAND_REVERSE)
|
||||
DCC::setAccessory(address, subaddress,p[activep]==0,onoff);
|
||||
#else
|
||||
DCC::setAccessory(address, subaddress,p[activep]==1,onoff);
|
||||
@ -394,14 +430,43 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||
return;
|
||||
break;
|
||||
|
||||
case 'z': // direct pin manipulation
|
||||
#ifndef IO_NO_HAL
|
||||
case 'o': // Neopixel pin manipulation
|
||||
if (p[0]==0) break;
|
||||
{
|
||||
VPIN vpin=p[0]>0 ? p[0]:-p[0];
|
||||
bool setON=p[0]>0;
|
||||
if (params==1) { // <o [-]vpin>
|
||||
IODevice::write(vpin,setON);
|
||||
return;
|
||||
}
|
||||
if (params==2) { // <o [-]vpin count>
|
||||
IODevice::writeRange(vpin,setON,p[1]);
|
||||
return;
|
||||
}
|
||||
if (params==4 || params==5) { // <z [-]vpin r g b [count]>
|
||||
auto count=p[4]?p[4]:1;
|
||||
if (p[1]<0 || p[1]>0xFF) break;
|
||||
if (p[2]<0 || p[2]>0xFF) break;
|
||||
if (p[3]<0 || p[3]>0xFF) break;
|
||||
// strange parameter mangling... see IO_NeoPixel.h NeoPixel::_writeAnalogue
|
||||
int colour_RG=(p[1]<<8) | p[2];
|
||||
uint16_t colour_B=p[3];
|
||||
IODevice::writeAnalogueRange(vpin,colour_RG,setON,colour_B,count);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
case 'z': // direct pin manipulation
|
||||
if (p[0]==0) break;
|
||||
if (params==1) { // <z vpin | -vpin>
|
||||
if (p[0]>0) IODevice::write(p[0],HIGH);
|
||||
else IODevice::write(-p[0],LOW);
|
||||
return;
|
||||
}
|
||||
if (params>=2 && params<=4) { // <z vpin ana;og profile duration>
|
||||
if (params>=2 && params<=4) { // <z vpin analog profile duration>
|
||||
// unused params default to 0
|
||||
IODevice::writeAnalogue(p[0],p[1],p[2],p[3]);
|
||||
return;
|
||||
@ -521,7 +586,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||
{
|
||||
if (params > 1) break;
|
||||
if (params==0) { // All
|
||||
TrackManager::setTrackPower(TRACK_MODE_ALL, POWERMODE::ON);
|
||||
TrackManager::setTrackPower(TRACK_ALL, POWERMODE::ON);
|
||||
}
|
||||
if (params==1) {
|
||||
if (p[0]=="MAIN"_hk) { // <1 MAIN>
|
||||
@ -554,7 +619,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||
if (params > 1) break;
|
||||
if (params==0) { // All
|
||||
TrackManager::setJoin(false);
|
||||
TrackManager::setTrackPower(TRACK_MODE_ALL, POWERMODE::OFF);
|
||||
TrackManager::setTrackPower(TRACK_ALL, POWERMODE::OFF);
|
||||
}
|
||||
if (params==1) {
|
||||
if (p[0]=="MAIN"_hk) { // <0 MAIN>
|
||||
@ -563,6 +628,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||
}
|
||||
#ifndef DISABLE_PROG
|
||||
else if (p[0]=="PROG"_hk) { // <0 PROG>
|
||||
TrackManager::setJoin(false);
|
||||
TrackManager::progTrackBoosted=false; // Prog track boost mode will not outlive prog track off
|
||||
TrackManager::setTrackPower(TRACK_MODE_PROG, POWERMODE::OFF);
|
||||
}
|
||||
@ -615,9 +681,22 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||
StringFormatter::send(stream, F("\n"));
|
||||
return;
|
||||
case 'C': // CONFIG <C [params]>
|
||||
if (parseC(stream, params, p))
|
||||
return;
|
||||
break;
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
// currently this only works on ESP32
|
||||
#if defined(HAS_ENOUGH_MEMORY)
|
||||
if (p[0] == "WIFI"_hk) { // <C WIFI SSID PASSWORD>
|
||||
if (params != 5) // the 5 params 0 to 4 are (kinda): WIFI_hk 0x7777 &SSID 0x7777 &PASSWORD
|
||||
break;
|
||||
if (p[1] == 0x7777 && p[3] == 0x7777) {
|
||||
WifiESP::setup((const char*)(com + p[2]), (const char*)(com + p[4]), WIFI_HOSTNAME, IP_PORT, WIFI_CHANNEL, WIFI_FORCE_AP);
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#endif //ESP32
|
||||
if (parseC(stream, params, p))
|
||||
return;
|
||||
break;
|
||||
#ifndef DISABLE_DIAG
|
||||
case 'D': // DIAG <D [params]>
|
||||
if (parseD(stream, params, p))
|
||||
@ -641,6 +720,13 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||
|
||||
case 'F': // New command to call the new Loco Function API <F cab func 1|0>
|
||||
if(params!=3) break;
|
||||
|
||||
if (p[1]=="DCFREQ"_hk) { // <F cab DCFREQ 0..3>
|
||||
if (p[2]<0 || p[2]>3) break;
|
||||
DCC::setDCFreq(p[0],p[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Diag::CMD)
|
||||
DIAG(F("Setting loco %d F%d %S"), p[0], p[1], p[2] ? F("ON") : F("OFF"));
|
||||
if (DCC::setFn(p[0], p[1], p[2] == 1)) return;
|
||||
@ -799,7 +885,11 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||
return;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifndef IO_NO_HAL
|
||||
case 'N': // <N commands for SensorCam
|
||||
if (CamParser::parseN(stream,params,p)) return;
|
||||
break;
|
||||
#endif
|
||||
case '/': // implemented in EXRAIL parser
|
||||
case 'L': // LCC interface implemented in EXRAIL parser
|
||||
break; // Will <X> if not intercepted by EXRAIL
|
||||
@ -1073,15 +1163,24 @@ bool DCCEXParser::parseC(Print *stream, int16_t params, int16_t p[]) {
|
||||
#ifndef DISABLE_PROG
|
||||
case "ACK"_hk: // <D ACK ON/OFF> <D ACK [LIMIT|MIN|MAX|RETRY] Value>
|
||||
if (params >= 3) {
|
||||
long duration;
|
||||
if (p[1] == "LIMIT"_hk) {
|
||||
DCCACK::setAckLimit(p[2]);
|
||||
LCD(1, F("Ack Limit=%dmA"), p[2]); // <D ACK LIMIT 42>
|
||||
LCD(1, F("Ack Limit=%dmA"), p[2]); // <D ACK LIMIT 42>
|
||||
} else if (p[1] == "MIN"_hk) {
|
||||
DCCACK::setMinAckPulseDuration(p[2]);
|
||||
LCD(0, F("Ack Min=%uus"), p[2]); // <D ACK MIN 1500>
|
||||
if (params == 4 && p[3] == "MS"_hk)
|
||||
duration = p[2] * 1000L;
|
||||
else
|
||||
duration = p[2];
|
||||
DCCACK::setMinAckPulseDuration(duration);
|
||||
LCD(0, F("Ack Min=%lus"), duration); // <D ACK MIN 1500>
|
||||
} else if (p[1] == "MAX"_hk) {
|
||||
DCCACK::setMaxAckPulseDuration(p[2]);
|
||||
LCD(0, F("Ack Max=%uus"), p[2]); // <D ACK MAX 9000>
|
||||
if (params == 4 && p[3] == "MS"_hk) // <D ACK MAX 80 MS>
|
||||
duration = p[2] * 1000L;
|
||||
else
|
||||
duration = p[2];
|
||||
DCCACK::setMaxAckPulseDuration(duration);
|
||||
LCD(0, F("Ack Max=%lus"), duration); // <D ACK MAX 9000>
|
||||
} else if (p[1] == "RETRY"_hk) {
|
||||
if (p[2] >255) p[2]=3;
|
||||
LCD(0, F("Ack Retry=%d Sum=%d"), p[2], DCCACK::setAckRetry(p[2])); // <D ACK RETRY 2>
|
||||
@ -1094,8 +1193,7 @@ bool DCCEXParser::parseC(Print *stream, int16_t params, int16_t p[]) {
|
||||
}
|
||||
return true;
|
||||
#endif
|
||||
|
||||
default: // invalid/unknown
|
||||
default: // invalid/unknown
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
|
@ -43,7 +43,7 @@ struct DCCEXParser
|
||||
private:
|
||||
|
||||
static const int16_t MAX_BUFFER=50; // longest command sent in
|
||||
static int16_t splitValues( int16_t result[MAX_COMMAND_PARAMS], const byte * command, bool usehex);
|
||||
static int16_t splitValues( int16_t result[MAX_COMMAND_PARAMS], byte * command, bool usehex);
|
||||
|
||||
static bool parseT(Print * stream, int16_t params, int16_t p[]);
|
||||
static bool parseZ(Print * stream, int16_t params, int16_t p[]);
|
||||
|
19
DCCRMT.cpp
19
DCCRMT.cpp
@ -17,6 +17,25 @@
|
||||
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* RMT has "channels" which us FIFO RAM where you place what you want to send
|
||||
* or receive. Channels can be merged to get more words per channel.
|
||||
*
|
||||
* WROOM: 8 channels total of 512 words, 64 words per channel. We use currently
|
||||
* channel 0+1 for 128 words for DCC MAIN and 2+3 for DCC PROG.
|
||||
*
|
||||
* S3: 8 channels total of 384 words. 4 channels dedicated for TX and 4 channels
|
||||
* dedicated for RX. 48 words per channel. So for TX there are 4 channels and we
|
||||
* could use them with 96 words for MAIN and PROG if DCC data does fit in there.
|
||||
*
|
||||
* C3: 4 channels total of 192 words. As we do not use RX we can use all for TX
|
||||
* so the situation is the same as for the -S3
|
||||
*
|
||||
* C6, H2: 4 channels total of 192 words. 2 channels dedictaed for TX and
|
||||
* 2 channels dedicated for RX. Half RMT capacity compared to the C3.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include "defines.h"
|
||||
#include "DIAG.h"
|
||||
|
6
DCCRMT.h
6
DCCRMT.h
@ -44,6 +44,12 @@ class RMTChannel {
|
||||
return true;
|
||||
return dataReady;
|
||||
};
|
||||
inline void waitForDataCopy() {
|
||||
while(1) { // do nothing and wait for interrupt clearing dataReady to happen
|
||||
if (dataReady == false)
|
||||
break;
|
||||
}
|
||||
};
|
||||
inline uint32_t packetCount() { return packetCounter; };
|
||||
|
||||
private:
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* © 2022-2023 Paul M. Antoine
|
||||
* © 2022-2024 Paul M. Antoine
|
||||
* © 2021 Mike S
|
||||
* © 2021-2023 Harald Barth
|
||||
* © 2021 Fred Decker
|
||||
@ -135,6 +135,8 @@ private:
|
||||
#if defined (ARDUINO_ARCH_STM32)
|
||||
// bit array of used pins (max 32)
|
||||
static uint32_t usedpins;
|
||||
static uint32_t * analogchans; // Array of channel numbers to be scanned
|
||||
static ADC_TypeDef * * adcchans; // Array to capture which ADC is each input channel on
|
||||
#else
|
||||
// bit array of used pins (max 16)
|
||||
static uint16_t usedpins;
|
||||
|
@ -185,8 +185,10 @@ int DCCTimer::freeMemory() {
|
||||
}
|
||||
|
||||
void DCCTimer::reset() {
|
||||
wdt_enable( WDTO_15MS); // set Arduino watchdog timer for 15ms
|
||||
delay(50); // wait for the prescaller time to expire
|
||||
// 250ms chosen to circumwent bootloader bug which
|
||||
// hangs at too short timepout (like 15ms)
|
||||
wdt_enable( WDTO_250MS); // set Arduino watchdog timer for 250ms
|
||||
delay(500); // wait for it to happen
|
||||
|
||||
}
|
||||
|
||||
@ -195,6 +197,8 @@ void DCCTimer::DCCEXanalogWriteFrequency(uint8_t pin, uint32_t f) {
|
||||
}
|
||||
void DCCTimer::DCCEXanalogWriteFrequencyInternal(uint8_t pin, uint32_t fbits) {
|
||||
#if defined(ARDUINO_AVR_UNO)
|
||||
(void)fbits;
|
||||
(void) pin;
|
||||
// Not worth doin something here as:
|
||||
// If we are on pin 9 or 10 we are on Timer1 and we can not touch Timer1 as that is our DCC source.
|
||||
// If we are on pin 5 or 6 we are on Timer 0 ad we can not touch Timer0 as that is millis() etc.
|
||||
|
@ -76,8 +76,19 @@ int DCCTimer::freeMemory() {
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
|
||||
#if __has_include("esp_idf_version.h")
|
||||
#include "esp_idf_version.h"
|
||||
#endif
|
||||
#if ESP_IDF_VERSION_MAJOR == 4
|
||||
// all well correct IDF version
|
||||
#else
|
||||
#error "DCC-EX does not support compiling with IDF version 5.0 or later. Downgrade your ESP32 library to a version that contains IDF version 4. Arduino ESP32 library 3.0.0 is too new. Downgrade to one of 2.0.9 to 2.0.17"
|
||||
#endif
|
||||
|
||||
// protect all the rest of the code from IDF version 5
|
||||
#if ESP_IDF_VERSION_MAJOR == 4
|
||||
#include "DIAG.h"
|
||||
#include <driver/adc.h>
|
||||
#include <soc/sens_reg.h>
|
||||
@ -292,7 +303,12 @@ void DCCTimer::DCCEXInrushControlOn(uint8_t pin, int duty, bool inverted) {
|
||||
int ADCee::init(uint8_t pin) {
|
||||
pinMode(pin, ANALOG);
|
||||
adc1_config_width(ADC_WIDTH_BIT_12);
|
||||
// Espressif deprecated ADC_ATTEN_DB_11 somewhere between 2.0.9 and 2.0.17
|
||||
#ifdef ADC_ATTEN_11db
|
||||
adc1_config_channel_atten(pinToADC1Channel(pin),ADC_ATTEN_11db);
|
||||
#else
|
||||
adc1_config_channel_atten(pinToADC1Channel(pin),ADC_ATTEN_DB_11);
|
||||
#endif
|
||||
return adc1_get_raw(pinToADC1Channel(pin));
|
||||
}
|
||||
int16_t ADCee::ADCmax() {
|
||||
@ -312,6 +328,5 @@ void ADCee::scan() {
|
||||
|
||||
void ADCee::begin() {
|
||||
}
|
||||
|
||||
#endif //IDF v4
|
||||
#endif //ESP32
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* © 2023 Neil McKechnie
|
||||
* © 2022-2023 Paul M. Antoine
|
||||
* © 2022-2024 Paul M. Antoine
|
||||
* © 2021 Mike S
|
||||
* © 2021, 2023 Harald Barth
|
||||
* © 2021 Fred Decker
|
||||
@ -34,8 +34,22 @@
|
||||
#include "TrackManager.h"
|
||||
#endif
|
||||
#include "DIAG.h"
|
||||
#include <wiring_private.h>
|
||||
|
||||
#if defined(ARDUINO_NUCLEO_F401RE) || defined(ARDUINO_NUCLEO_F411RE)
|
||||
#if defined(ARDUINO_NUCLEO_F401RE)
|
||||
// Nucleo-64 boards don't have additional serial ports defined by default
|
||||
// Serial1 is available on the F401RE, but not hugely convenient.
|
||||
// Rx pin on PB7 is useful, but all the Tx pins map to Arduino digital pins, specifically:
|
||||
// PA9 == D8
|
||||
// PB6 == D10
|
||||
// of which D8 is needed by the standard and EX8874 motor shields. D10 would be used if a second
|
||||
// EX8874 is stacked. So only disable this if using a second motor shield.
|
||||
HardwareSerial Serial1(PB7, PB6); // Rx=PB7, Tx=PB6 -- CN7 pin 17 and CN10 pin 17
|
||||
// Serial2 is defined to use USART2 by default, but is in fact used as the diag console
|
||||
// via the debugger on the Nucleo-64. It is therefore unavailable for other DCC-EX uses like WiFi, DFPlayer, etc.
|
||||
// Let's define Serial6 as an additional serial port (the only other option for the F401RE)
|
||||
HardwareSerial Serial6(PA12, PA11); // Rx=PA12, Tx=PA11 -- CN10 pins 12 and 14 - F401RE
|
||||
#elif defined(ARDUINO_NUCLEO_F411RE)
|
||||
// Nucleo-64 boards don't have additional serial ports defined by default
|
||||
HardwareSerial Serial1(PB7, PA15); // Rx=PB7, Tx=PA15 -- CN7 pins 17 and 21 - F411RE
|
||||
// Serial2 is defined to use USART2 by default, but is in fact used as the diag console
|
||||
@ -53,12 +67,12 @@ HardwareSerial Serial3(PC11, PC10); // Rx=PC11, Tx=PC10 -- USART3 - F446RE
|
||||
HardwareSerial Serial5(PD2, PC12); // Rx=PD2, Tx=PC12 -- UART5 - F446RE
|
||||
// On the F446RE, Serial4 and Serial6 also use pins we can't readily map while using the Arduino pins
|
||||
#elif defined(ARDUINO_NUCLEO_F412ZG) || defined(ARDUINO_NUCLEO_F413ZH) || defined(ARDUINO_NUCLEO_F446ZE) || \
|
||||
defined(ARDUINO_NUCLEO_F429ZI) || defined(ARDUINO_NUCLEO_F439ZI)
|
||||
defined(ARDUINO_NUCLEO_F429ZI) || defined(ARDUINO_NUCLEO_F439ZI) || defined(ARDUINO_NUCLEO_F4X9ZI)
|
||||
// Nucleo-144 boards don't have Serial1 defined by default
|
||||
HardwareSerial Serial6(PG9, PG14); // Rx=PG9, Tx=PG14 -- USART6
|
||||
HardwareSerial Serial5(PD2, PC12); // Rx=PD2, Tx=PC12 -- UART5
|
||||
#if !defined(ARDUINO_NUCLEO_F412ZG)
|
||||
HardwareSerial Serial2(PD6, PD5); // Rx=PD6, Tx=PD5 -- UART5
|
||||
HardwareSerial Serial2(PD6, PD5); // Rx=PD6, Tx=PD5 -- UART2
|
||||
#if !defined(ARDUINO_NUCLEO_F412ZG) // F412ZG does not have UART5
|
||||
HardwareSerial Serial5(PD2, PC12); // Rx=PD2, Tx=PC12 -- UART5
|
||||
#endif
|
||||
// Serial3 is defined to use USART3 by default, but is in fact used as the diag console
|
||||
// via the debugger on the Nucleo-144. It is therefore unavailable for other DCC-EX uses like WiFi, DFPlayer, etc.
|
||||
@ -314,7 +328,7 @@ void DCCTimer::DCCEXanalogWriteFrequencyInternal(uint8_t pin, uint32_t frequency
|
||||
if (pin_timer[pin] != NULL)
|
||||
{
|
||||
pin_timer[pin]->setPWM(pin_channel[pin], pin, frequency, 0); // set frequency in Hertz, 0% dutycycle
|
||||
DIAG(F("DCCEXanalogWriteFrequency::Pin %d on Timer %d, frequency %d"), pin, pin_channel[pin], frequency);
|
||||
DIAG(F("DCCEXanalogWriteFrequency::Pin %d on Timer Channel %d, frequency %d"), pin, pin_channel[pin], frequency);
|
||||
}
|
||||
else
|
||||
DIAG(F("DCCEXanalogWriteFrequency::failed to allocate HardwareTimer instance!"));
|
||||
@ -363,9 +377,9 @@ void DCCTimer::DCCEXanalogWrite(uint8_t pin, int value, bool invert) {
|
||||
uint32_t ADCee::usedpins = 0; // Max of 32 ADC input channels!
|
||||
uint8_t ADCee::highestPin = 0; // Highest pin to scan
|
||||
int * ADCee::analogvals = NULL; // Array of analog values last captured
|
||||
uint32_t * analogchans = NULL; // Array of channel numbers to be scanned
|
||||
uint32_t * ADCee::analogchans = NULL; // Array of channel numbers to be scanned
|
||||
// bool adc1configured = false;
|
||||
ADC_TypeDef * * adcchans = NULL; // Array to capture which ADC is each input channel on
|
||||
ADC_TypeDef * * ADCee::adcchans = NULL; // Array to capture which ADC is each input channel on
|
||||
|
||||
int16_t ADCee::ADCmax()
|
||||
{
|
||||
@ -383,9 +397,10 @@ int ADCee::init(uint8_t pin) {
|
||||
uint32_t adcchan = STM_PIN_CHANNEL(pinmap_function(stmpin, PinMap_ADC)); // find ADC input channel
|
||||
ADC_TypeDef *adc = (ADC_TypeDef *)pinmap_find_peripheral(stmpin, PinMap_ADC); // find which ADC this pin is on ADC1/2/3 etc.
|
||||
int adcnum = 1;
|
||||
// All variants have ADC1
|
||||
if (adc == ADC1)
|
||||
DIAG(F("ADCee::init(): found pin %d on ADC1"), pin);
|
||||
// Checking for ADC2 and ADC3 being defined helps cater for more variants later
|
||||
// Checking for ADC2 and ADC3 being defined helps cater for more variants
|
||||
#if defined(ADC2)
|
||||
else if (adc == ADC2)
|
||||
{
|
||||
@ -432,6 +447,18 @@ int ADCee::init(uint8_t pin) {
|
||||
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOFEN; //Power up PORTF
|
||||
gpioBase = GPIOF;
|
||||
break;
|
||||
#endif
|
||||
#if defined(GPIOG)
|
||||
case 0x06:
|
||||
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOGEN; //Power up PORTG
|
||||
gpioBase = GPIOG;
|
||||
break;
|
||||
#endif
|
||||
#if defined(GPIOH)
|
||||
case 0x07:
|
||||
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOHEN; //Power up PORTH
|
||||
gpioBase = GPIOH;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return -1023; // some silly value as error
|
||||
|
@ -278,7 +278,11 @@ void DCCWaveform::begin() {
|
||||
|
||||
void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repeats) {
|
||||
if (byteCount > MAX_PACKET_SIZE) return; // allow for chksum
|
||||
|
||||
RMTChannel *rmtchannel = (isMainTrack ? rmtMainChannel : rmtProgChannel);
|
||||
if (rmtchannel == NULL)
|
||||
return; // no idea to prepare packet if we can not send it anyway
|
||||
|
||||
rmtchannel->waitForDataCopy(); // blocking wait so we can write into buffer
|
||||
byte checksum = 0;
|
||||
for (byte b = 0; b < byteCount; b++) {
|
||||
checksum ^= buffer[b];
|
||||
@ -296,13 +300,7 @@ void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repea
|
||||
{
|
||||
int ret = 0;
|
||||
do {
|
||||
if(isMainTrack) {
|
||||
if (rmtMainChannel != NULL)
|
||||
ret = rmtMainChannel->RMTfillData(pendingPacket, pendingLength, pendingRepeats);
|
||||
} else {
|
||||
if (rmtProgChannel != NULL)
|
||||
ret = rmtProgChannel->RMTfillData(pendingPacket, pendingLength, pendingRepeats);
|
||||
}
|
||||
ret = rmtchannel->RMTfillData(pendingPacket, pendingLength, pendingRepeats);
|
||||
} while(ret > 0);
|
||||
}
|
||||
}
|
||||
|
20
EXRAIL.h
20
EXRAIL.h
@ -1,3 +1,23 @@
|
||||
/*
|
||||
* © 2021 Fred Decker
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef EXRAIL_H
|
||||
#define EXRAIL_H
|
||||
|
||||
|
286
EXRAIL2.cpp
286
EXRAIL2.cpp
@ -1,8 +1,10 @@
|
||||
/*
|
||||
* © 2024 Paul M. Antoine
|
||||
* © 2021 Neil McKechnie
|
||||
* © 2021-2023 Harald Barth
|
||||
* © 2020-2023 Chris Harlow
|
||||
* © 2022-2023 Colin Murdoch
|
||||
* © 2025 Morten Nielsen
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
@ -72,6 +74,7 @@ RMFT2 * RMFT2::pausingTask=NULL; // Task causing a PAUSE.
|
||||
byte RMFT2::flags[MAX_FLAGS];
|
||||
Print * RMFT2::LCCSerial=0;
|
||||
LookList * RMFT2::routeLookup=NULL;
|
||||
LookList * RMFT2::signalLookup=NULL;
|
||||
LookList * RMFT2::onThrowLookup=NULL;
|
||||
LookList * RMFT2::onCloseLookup=NULL;
|
||||
LookList * RMFT2::onActivateLookup=NULL;
|
||||
@ -205,16 +208,29 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) {
|
||||
|
||||
// Second pass startup, define any turnouts or servos, set signals red
|
||||
// add sequences onRoutines to the lookups
|
||||
if (compileFeatures & FEATURE_SIGNAL) {
|
||||
onRedLookup=LookListLoader(OPCODE_ONRED);
|
||||
onAmberLookup=LookListLoader(OPCODE_ONAMBER);
|
||||
onGreenLookup=LookListLoader(OPCODE_ONGREEN);
|
||||
for (int sigslot=0;;sigslot++) {
|
||||
VPIN sigid=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigslot*8);
|
||||
if (sigid==0) break; // end of signal list
|
||||
doSignal(sigid & SIGNAL_ID_MASK, SIGNAL_RED);
|
||||
}
|
||||
}
|
||||
if (compileFeatures & FEATURE_SIGNAL) {
|
||||
|
||||
onRedLookup=LookListLoader(OPCODE_ONRED);
|
||||
onAmberLookup=LookListLoader(OPCODE_ONAMBER);
|
||||
onGreenLookup=LookListLoader(OPCODE_ONGREEN);
|
||||
// Load the signal lookup with slot numbers in the signal table
|
||||
int signalCount=0;
|
||||
for (int16_t slot=0;;slot++) {
|
||||
SIGNAL_DEFINITION signal=getSignalSlot(slot);
|
||||
DIAG(F("Signal s=%d id=%d t=%d"),slot,signal.id,signal.type);
|
||||
if (signal.type==sigtypeNoMoreSignals) break;
|
||||
if (signal.type==sigtypeContinuation) continue;
|
||||
signalCount++;
|
||||
}
|
||||
signalLookup=new LookList(signalCount);
|
||||
for (int16_t slot=0;;slot++) {
|
||||
SIGNAL_DEFINITION signal=getSignalSlot(slot);
|
||||
if (signal.type==sigtypeNoMoreSignals) break;
|
||||
if (signal.type==sigtypeContinuation) continue;
|
||||
signalLookup->add(signal.id,slot);
|
||||
doSignal(signal.id, SIGNAL_RED);
|
||||
}
|
||||
}
|
||||
|
||||
int progCounter;
|
||||
for (progCounter=0;; SKIPOP){
|
||||
@ -226,7 +242,6 @@ if (compileFeatures & FEATURE_SIGNAL) {
|
||||
case OPCODE_AT:
|
||||
case OPCODE_ATTIMEOUT2:
|
||||
case OPCODE_AFTER:
|
||||
case OPCODE_AFTEROVERLOAD:
|
||||
case OPCODE_IF:
|
||||
case OPCODE_IFNOT: {
|
||||
int16_t pin = (int16_t)operand;
|
||||
@ -298,7 +313,7 @@ if (compileFeatures & FEATURE_SIGNAL) {
|
||||
case OPCODE_EXTTTURNTABLE: {
|
||||
VPIN id=operand;
|
||||
VPIN pin=getOperand(progCounter,1);
|
||||
int home=getOperand(progCounter,3);
|
||||
int home=getOperand(progCounter,2);
|
||||
setTurntableHiddenState(EXTTTurntable::create(id,pin));
|
||||
Turntable *tto=Turntable::get(id);
|
||||
tto->addPosition(0,0,home);
|
||||
@ -477,10 +492,15 @@ bool RMFT2::skipIfBlock() {
|
||||
|
||||
|
||||
/* static */ void RMFT2::readLocoCallback(int16_t cv) {
|
||||
if (cv <= 0) {
|
||||
DIAG(F("CV read error"));
|
||||
progtrackLocoId = -1;
|
||||
return;
|
||||
}
|
||||
if (cv & LONG_ADDR_MARKER) { // maker bit indicates long addr
|
||||
progtrackLocoId = cv ^ LONG_ADDR_MARKER; // remove marker bit to get real long addr
|
||||
if (progtrackLocoId <= HIGHEST_SHORT_ADDR ) { // out of range for long addr
|
||||
DIAG(F("Long addr %d <= %d unsupported\n"), progtrackLocoId, HIGHEST_SHORT_ADDR);
|
||||
DIAG(F("Long addr %d <= %d unsupported"), progtrackLocoId, HIGHEST_SHORT_ADDR);
|
||||
progtrackLocoId = -1;
|
||||
}
|
||||
} else {
|
||||
@ -627,14 +647,16 @@ void RMFT2::loop2() {
|
||||
skipIf=blinkState!=at_timeout;
|
||||
break;
|
||||
|
||||
case OPCODE_AFTER: // waits for sensor to hit and then remain off for 0.5 seconds. (must come after an AT operation)
|
||||
case OPCODE_AFTER: // waits for sensor to hit and then remain off for x mS.
|
||||
// Note, this must come after an AT operation, which is
|
||||
// automatically inserted by the AFTER macro.
|
||||
if (readSensor(operand)) {
|
||||
// reset timer to half a second and keep waiting
|
||||
// reset timer and keep waiting
|
||||
waitAfter=millis();
|
||||
delayMe(50);
|
||||
return;
|
||||
}
|
||||
if (millis()-waitAfter < 500 ) return;
|
||||
if (millis()-waitAfter < getOperand(1) ) return;
|
||||
break;
|
||||
|
||||
case OPCODE_AFTEROVERLOAD: // waits for the power to be turned back on - either by power routine or button
|
||||
@ -656,13 +678,14 @@ void RMFT2::loop2() {
|
||||
break;
|
||||
|
||||
case OPCODE_SET:
|
||||
killBlinkOnVpin(operand);
|
||||
IODevice::write(operand,true);
|
||||
break;
|
||||
|
||||
case OPCODE_RESET:
|
||||
killBlinkOnVpin(operand);
|
||||
IODevice::write(operand,false);
|
||||
{
|
||||
auto count=getOperand(1);
|
||||
for (uint16_t i=0;i<count;i++) {
|
||||
killBlinkOnVpin(operand+i);
|
||||
IODevice::write(operand+i,opcode==OPCODE_SET);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case OPCODE_BLINK:
|
||||
@ -715,41 +738,7 @@ void RMFT2::loop2() {
|
||||
|
||||
case OPCODE_SETFREQ:
|
||||
// Frequency is default 0, or 1, 2,3
|
||||
//if (loco) DCC::setFn(loco,operand,true);
|
||||
switch (operand) {
|
||||
case 0: // default - all F-s off
|
||||
if (loco) {
|
||||
DCC::setFn(loco,29,false);
|
||||
DCC::setFn(loco,30,false);
|
||||
DCC::setFn(loco,31,false);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (loco) {
|
||||
DCC::setFn(loco,29,true);
|
||||
DCC::setFn(loco,30,false);
|
||||
DCC::setFn(loco,31,false);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (loco) {
|
||||
DCC::setFn(loco,29,false);
|
||||
DCC::setFn(loco,30,true);
|
||||
DCC::setFn(loco,31,false);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (loco) {
|
||||
DCC::setFn(loco,29,false);
|
||||
DCC::setFn(loco,30,false);
|
||||
DCC::setFn(loco,31,true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
; // do nothing
|
||||
break;
|
||||
}
|
||||
|
||||
DCC::setDCFreq(loco,operand);
|
||||
break;
|
||||
|
||||
case OPCODE_RESUME:
|
||||
@ -883,6 +872,14 @@ void RMFT2::loop2() {
|
||||
DCC::changeFn(operand,getOperand(1));
|
||||
break;
|
||||
|
||||
case OPCODE_XFWD:
|
||||
DCC::setThrottle(operand,getOperand(1), true);
|
||||
break;
|
||||
|
||||
case OPCODE_XREV:
|
||||
DCC::setThrottle(operand,getOperand(1), false);
|
||||
break;
|
||||
|
||||
case OPCODE_DCCACTIVATE: {
|
||||
// operand is address<<3 | subaddr<<1 | active
|
||||
int16_t addr=operand>>3;
|
||||
@ -934,8 +931,9 @@ void RMFT2::loop2() {
|
||||
|
||||
#ifndef DISABLE_PROG
|
||||
case OPCODE_JOIN:
|
||||
TrackManager::setPower(POWERMODE::ON);
|
||||
TrackManager::setJoin(true);
|
||||
TrackManager::setMainPower(POWERMODE::ON);
|
||||
TrackManager::setProgPower(POWERMODE::ON);
|
||||
break;
|
||||
|
||||
case OPCODE_UNJOIN:
|
||||
@ -952,11 +950,10 @@ void RMFT2::loop2() {
|
||||
delayMe(100);
|
||||
return; // still waiting for callback
|
||||
}
|
||||
if (progtrackLocoId<0) {
|
||||
kill(F("No Loco Found"),progtrackLocoId);
|
||||
return; // still waiting for callback
|
||||
}
|
||||
|
||||
// At failed read will result in loco == -1
|
||||
// which is intended so it can be checked
|
||||
// from within EXRAIL
|
||||
loco=progtrackLocoId;
|
||||
speedo=0;
|
||||
forward=true;
|
||||
@ -999,6 +996,14 @@ void RMFT2::loop2() {
|
||||
if ((compileFeatures & FEATURE_LCC) && LCCSerial)
|
||||
StringFormatter::send(LCCSerial,F("<L x%h>"),(uint16_t)operand);
|
||||
break;
|
||||
|
||||
case OPCODE_ACON: // MERG adapter
|
||||
case OPCODE_ACOF:
|
||||
if ((compileFeatures & FEATURE_LCC) && LCCSerial)
|
||||
StringFormatter::send(LCCSerial,F("<L x%c%h%h>"),
|
||||
opcode==OPCODE_ACON?'0':'1',
|
||||
(uint16_t)operand,getOperand(progCounter,1));
|
||||
break;
|
||||
|
||||
case OPCODE_LCCX: // long form LCC
|
||||
if ((compileFeatures & FEATURE_LCC) && LCCSerial)
|
||||
@ -1020,8 +1025,18 @@ void RMFT2::loop2() {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
#ifndef IO_NO_HAL
|
||||
case OPCODE_NEOPIXEL:
|
||||
// OPCODE_NEOPIXEL,V([-]vpin),OPCODE_PAD,V(colour_RG),OPCODE_PAD,V(colour_B),OPCODE_PAD,V(count)
|
||||
{
|
||||
VPIN vpin=operand>0?operand:-operand;
|
||||
auto count=getOperand(3);
|
||||
killBlinkOnVpin(vpin,count);
|
||||
IODevice::writeAnalogueRange(vpin,getOperand(1),operand>0,getOperand(2),count);
|
||||
}
|
||||
break;
|
||||
|
||||
case OPCODE_WAITFORTT: // OPCODE_WAITFOR,V(turntable_id)
|
||||
if (Turntable::ttMoving(operand)) {
|
||||
delayMe(100);
|
||||
@ -1087,6 +1102,8 @@ void RMFT2::loop2() {
|
||||
case OPCODE_PINTURNOUT: // Turnout definition ignored at runtime
|
||||
case OPCODE_ONCLOSE: // Turnout event catchers ignored here
|
||||
case OPCODE_ONLCC: // LCC event catchers ignored here
|
||||
case OPCODE_ONACON: // MERG event catchers ignored here
|
||||
case OPCODE_ONACOF: // MERG event catchers ignored here
|
||||
case OPCODE_ONTHROW:
|
||||
case OPCODE_ONACTIVATE: // Activate event catchers ignored here
|
||||
case OPCODE_ONDEACTIVATE:
|
||||
@ -1141,20 +1158,11 @@ void RMFT2::kill(const FSH * reason, int operand) {
|
||||
delete this;
|
||||
}
|
||||
|
||||
int16_t RMFT2::getSignalSlot(int16_t id) {
|
||||
for (int sigslot=0;;sigslot++) {
|
||||
int16_t sigid=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigslot*8);
|
||||
if (sigid==0) { // end of signal list
|
||||
DIAG(F("EXRAIL Signal %d not defined"), id);
|
||||
return -1;
|
||||
}
|
||||
// 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 SERVO_SIGNAL_FLAG set.
|
||||
|
||||
if ((sigid & SIGNAL_ID_MASK)!= id) continue; // keep looking
|
||||
return sigslot; // relative slot in signals table
|
||||
}
|
||||
SIGNAL_DEFINITION RMFT2::getSignalSlot(int16_t slot) {
|
||||
SIGNAL_DEFINITION signal;
|
||||
COPYHIGHFLASH(&signal,SignalDefinitions,slot*sizeof(SIGNAL_DEFINITION),sizeof(SIGNAL_DEFINITION));
|
||||
return signal;
|
||||
}
|
||||
|
||||
/* static */ void RMFT2::doSignal(int16_t id,char rag) {
|
||||
@ -1167,80 +1175,97 @@ int16_t RMFT2::getSignalSlot(int16_t id) {
|
||||
else if (rag==SIGNAL_GREEN) onGreenLookup->handleEvent(F("GREEN"),id);
|
||||
else onAmberLookup->handleEvent(F("AMBER"),id);
|
||||
|
||||
int16_t sigslot=getSignalSlot(id);
|
||||
auto sigslot=signalLookup->find(id);
|
||||
if (sigslot<0) return;
|
||||
|
||||
// keep track of signal state
|
||||
setFlag(sigslot,rag,SIGNAL_MASK);
|
||||
|
||||
// Correct signal definition found, get the rag values
|
||||
int16_t sigpos=sigslot*8;
|
||||
VPIN sigid=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos);
|
||||
VPIN redpin=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+2);
|
||||
VPIN amberpin=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+4);
|
||||
VPIN greenpin=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+6);
|
||||
//if (diag) DIAG(F("signal %d %d %d %d %d"),sigid,id,redpin,amberpin,greenpin);
|
||||
|
||||
VPIN sigtype=sigid & ~SIGNAL_ID_MASK;
|
||||
|
||||
if (sigtype == 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= rag==SIGNAL_RED? redpin: (rag==SIGNAL_GREEN? greenpin : amberpin);
|
||||
auto signal=getSignalSlot(sigslot);
|
||||
|
||||
switch (signal.type) {
|
||||
case sigtypeSERVO:
|
||||
{
|
||||
auto servopos = rag==SIGNAL_RED? signal.redpin: (rag==SIGNAL_GREEN? signal.greenpin : signal.amberpin);
|
||||
//if (diag) DIAG(F("sigA %d %d"),id,servopos);
|
||||
if (servopos!=0) IODevice::writeAnalogue(id,servopos,PCA9685::Bounce);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (sigtype== DCC_SIGNAL_FLAG) {
|
||||
case sigtypeDCC:
|
||||
{
|
||||
// redpin,amberpin are the DCC addr,subaddr
|
||||
DCC::setAccessory(redpin,amberpin, rag!=SIGNAL_RED);
|
||||
DCC::setAccessory(signal.redpin,signal.amberpin, rag!=SIGNAL_RED);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sigtype== DCCX_SIGNAL_FLAG) {
|
||||
case sigtypeDCCX:
|
||||
{
|
||||
// redpin,amberpin,greenpin are the 3 aspects
|
||||
byte value=redpin;
|
||||
if (rag==SIGNAL_AMBER) value=amberpin;
|
||||
if (rag==SIGNAL_GREEN) value=greenpin;
|
||||
DCC::setExtendedAccessory(sigid & SIGNAL_ID_MASK,value);
|
||||
auto value=signal.redpin;
|
||||
if (rag==SIGNAL_AMBER) value=signal.amberpin;
|
||||
if (rag==SIGNAL_GREEN) value=signal.greenpin;
|
||||
DCC::setExtendedAccessory(id, value);
|
||||
return;
|
||||
}
|
||||
|
||||
case sigtypeNEOPIXEL:
|
||||
{
|
||||
// redpin,amberpin,greenpin are the 3 RG values but with no blue permitted. . (code limitation hack)
|
||||
auto colour_RG=signal.redpin;
|
||||
if (rag==SIGNAL_AMBER) colour_RG=signal.amberpin;
|
||||
if (rag==SIGNAL_GREEN) colour_RG=signal.greenpin;
|
||||
|
||||
// blue channel is in followng signal slot (a continuation)
|
||||
auto signal2=getSignalSlot(sigslot+1);
|
||||
auto colour_B=signal2.redpin;
|
||||
if (rag==SIGNAL_AMBER) colour_B=signal2.amberpin;
|
||||
if (rag==SIGNAL_GREEN) colour_B=signal2.greenpin;
|
||||
IODevice::writeAnalogue(id, colour_RG,true,colour_B);
|
||||
return;
|
||||
}
|
||||
|
||||
case sigtypeSIGNAL:
|
||||
case sigtypeSIGNALH:
|
||||
{
|
||||
// LED or similar 3 pin signal, (all pins zero would be a virtual signal)
|
||||
// If amberpin is zero, synthesise amber from red+green
|
||||
const byte SIMAMBER=0x00;
|
||||
if (rag==SIGNAL_AMBER && (amberpin==0)) rag=SIMAMBER; // special case this func only
|
||||
if (rag==SIGNAL_AMBER && (signal.amberpin==0)) rag=SIMAMBER; // special case this func only
|
||||
|
||||
// Manage invert (HIGH on) pins
|
||||
bool aHigh=sigid & ACTIVE_HIGH_SIGNAL_FLAG;
|
||||
bool aHigh=signal.type==sigtypeSIGNALH;
|
||||
|
||||
// set the three pins
|
||||
if (redpin) {
|
||||
if (signal.redpin) {
|
||||
bool redval=(rag==SIGNAL_RED || rag==SIMAMBER);
|
||||
if (!aHigh) redval=!redval;
|
||||
killBlinkOnVpin(redpin);
|
||||
IODevice::write(redpin,redval);
|
||||
killBlinkOnVpin(signal.redpin);
|
||||
IODevice::write(signal.redpin,redval);
|
||||
}
|
||||
if (amberpin) {
|
||||
if (signal.amberpin) {
|
||||
bool amberval=(rag==SIGNAL_AMBER);
|
||||
if (!aHigh) amberval=!amberval;
|
||||
killBlinkOnVpin(amberpin);
|
||||
IODevice::write(amberpin,amberval);
|
||||
killBlinkOnVpin(signal.amberpin);
|
||||
IODevice::write(signal.amberpin,amberval);
|
||||
}
|
||||
if (greenpin) {
|
||||
if (signal.greenpin) {
|
||||
bool greenval=(rag==SIGNAL_GREEN || rag==SIMAMBER);
|
||||
if (!aHigh) greenval=!greenval;
|
||||
killBlinkOnVpin(greenpin);
|
||||
IODevice::write(greenpin,greenval);
|
||||
killBlinkOnVpin(signal.greenpin);
|
||||
IODevice::write(signal.greenpin,greenval);
|
||||
}
|
||||
}
|
||||
case sigtypeVIRTUAL: break;
|
||||
case sigtypeContinuation: break;
|
||||
case sigtypeNoMoreSignals: break;
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ bool RMFT2::isSignal(int16_t id,char rag) {
|
||||
if (!(compileFeatures & FEATURE_SIGNAL)) return false;
|
||||
int16_t sigslot=getSignalSlot(id);
|
||||
int16_t sigslot=signalLookup->find(id);
|
||||
if (sigslot<0) return false;
|
||||
return (flags[sigslot] & SIGNAL_MASK) == rag;
|
||||
}
|
||||
@ -1252,25 +1277,23 @@ int16_t RMFT2::getSignalSlot(int16_t id) {
|
||||
// Otherwise false so the parser should send the command directly
|
||||
bool RMFT2::signalAspectEvent(int16_t address, byte aspect ) {
|
||||
if (!(compileFeatures & FEATURE_SIGNAL)) return false;
|
||||
int16_t sigslot=getSignalSlot(address);
|
||||
auto sigslot=signalLookup->find(address);
|
||||
if (sigslot<0) return false; // this is not a defined signal
|
||||
int16_t sigpos=sigslot*8;
|
||||
VPIN sigid=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos);
|
||||
VPIN sigtype=sigid & ~SIGNAL_ID_MASK;
|
||||
if (sigtype!=DCCX_SIGNAL_FLAG) return false; // not a DCCX signal
|
||||
auto signal=getSignalSlot(sigslot);
|
||||
if (signal.type!=sigtypeDCCX) return false; // not a DCCX signal
|
||||
// Turn an aspect change into a RED/AMBER/GREEN setting
|
||||
if (aspect==GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+2)) {
|
||||
doSignal(sigid,SIGNAL_RED);
|
||||
if (aspect==signal.redpin) {
|
||||
doSignal(address,SIGNAL_RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (aspect==GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+4)) {
|
||||
doSignal(sigid,SIGNAL_AMBER);
|
||||
if (aspect==signal.amberpin) {
|
||||
doSignal(address,SIGNAL_AMBER);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (aspect==GETHIGHFLASHW(RMFT2::SignalDefinitions,sigpos+6)) {
|
||||
doSignal(sigid,SIGNAL_GREEN);
|
||||
if (aspect==signal.greenpin) {
|
||||
doSignal(address,SIGNAL_GREEN);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1315,7 +1338,7 @@ void RMFT2::clockEvent(int16_t clocktime, bool change) {
|
||||
void RMFT2::powerEvent(int16_t track, bool overload) {
|
||||
// Hunt for an ONOVERLOAD for this item
|
||||
if (Diag::CMD)
|
||||
DIAG(F("powerEvent : %c"), track);
|
||||
DIAG(F("powerEvent : %c"), track + 'A');
|
||||
if (overload) {
|
||||
onOverloadLookup->handleEvent(F("POWER"),track);
|
||||
}
|
||||
@ -1324,19 +1347,24 @@ void RMFT2::powerEvent(int16_t track, bool overload) {
|
||||
// This function is used when setting pins so that a SET or RESET
|
||||
// will cause any blink task on that pin to terminate.
|
||||
// It will be compiled out of existence if no BLINK feature is used.
|
||||
void RMFT2::killBlinkOnVpin(VPIN pin) {
|
||||
void RMFT2::killBlinkOnVpin(VPIN pin, uint16_t count) {
|
||||
if (!(compileFeatures & FEATURE_BLINK)) return;
|
||||
|
||||
RMFT2 * stoptask=loopTask; // stop when we get back to here
|
||||
RMFT2 * task=loopTask;
|
||||
VPIN lastPin=pin+count-1;
|
||||
while(task) {
|
||||
auto nextTask=task->next;
|
||||
if (
|
||||
(task->blinkState==blink_high || task->blinkState==blink_low)
|
||||
&& task->blinkPin==pin) {
|
||||
&& task->blinkPin>=pin
|
||||
&& task->blinkPin<=lastPin
|
||||
) {
|
||||
if (diag) DIAG(F("kill blink %d"),task->blinkPin,lastPin);
|
||||
task->kill();
|
||||
return;
|
||||
}
|
||||
task=task->next;
|
||||
if (task==loopTask) return;
|
||||
}
|
||||
task=nextTask;
|
||||
if (task==stoptask) return;
|
||||
}
|
||||
}
|
||||
|
||||
|
41
EXRAIL2.h
41
EXRAIL2.h
@ -3,6 +3,7 @@
|
||||
* © 2020-2022 Chris Harlow
|
||||
* © 2022-2023 Colin Murdoch
|
||||
* © 2023 Harald Barth
|
||||
* © 2025 Morten Nielsen
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
@ -45,7 +46,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,OPCODE_TOGGLE_TURNOUT,
|
||||
OPCODE_ENDIF,OPCODE_ELSE,
|
||||
OPCODE_DELAY,OPCODE_DELAYMINS,OPCODE_DELAYMS,OPCODE_RANDWAIT,
|
||||
OPCODE_FON,OPCODE_FOFF,OPCODE_XFON,OPCODE_XFOFF,
|
||||
OPCODE_FTOGGLE,OPCODE_XFTOGGLE,
|
||||
OPCODE_FTOGGLE,OPCODE_XFTOGGLE,OPCODE_XFWD,OPCODE_XREV,
|
||||
OPCODE_RED,OPCODE_GREEN,OPCODE_AMBER,OPCODE_DRIVE,
|
||||
OPCODE_SERVO,OPCODE_SIGNAL,OPCODE_TURNOUT,OPCODE_WAITFOR,
|
||||
OPCODE_PAD,OPCODE_FOLLOW,OPCODE_CALL,OPCODE_RETURN,
|
||||
@ -69,11 +70,14 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,OPCODE_TOGGLE_TURNOUT,
|
||||
OPCODE_TTADDPOSITION,OPCODE_DCCTURNTABLE,OPCODE_EXTTTURNTABLE,
|
||||
OPCODE_ONROTATE,OPCODE_ROTATE,OPCODE_WAITFORTT,
|
||||
OPCODE_LCC,OPCODE_LCCX,OPCODE_ONLCC,
|
||||
OPCODE_ACON, OPCODE_ACOF,
|
||||
OPCODE_ONACON, OPCODE_ONACOF,
|
||||
OPCODE_ONOVERLOAD,
|
||||
OPCODE_ROUTE_ACTIVE,OPCODE_ROUTE_INACTIVE,OPCODE_ROUTE_HIDDEN,
|
||||
OPCODE_ROUTE_DISABLED,
|
||||
OPCODE_STASH,OPCODE_CLEAR_STASH,OPCODE_CLEAR_ALL_STASH,OPCODE_PICKUP_STASH,
|
||||
OPCODE_ONBUTTON,OPCODE_ONSENSOR,
|
||||
OPCODE_ONBUTTON,OPCODE_ONSENSOR,
|
||||
OPCODE_NEOPIXEL,
|
||||
// OPcodes below this point are skip-nesting IF operations
|
||||
// placed here so that they may be skipped as a group
|
||||
// see skipIfBlock()
|
||||
@ -107,6 +111,23 @@ enum BlinkState: byte {
|
||||
blink_high, // blink task running with pin high
|
||||
at_timeout // ATTIMEOUT timed out flag
|
||||
};
|
||||
enum SignalType {
|
||||
sigtypeVIRTUAL,
|
||||
sigtypeSIGNAL,
|
||||
sigtypeSIGNALH,
|
||||
sigtypeDCC,
|
||||
sigtypeDCCX,
|
||||
sigtypeSERVO,
|
||||
sigtypeNEOPIXEL,
|
||||
sigtypeContinuation, // neopixels require a second line
|
||||
sigtypeNoMoreSignals
|
||||
};
|
||||
|
||||
struct SIGNAL_DEFINITION {
|
||||
SignalType type;
|
||||
VPIN id;
|
||||
VPIN redpin,amberpin,greenpin;
|
||||
};
|
||||
|
||||
// Flag bits for compile time features.
|
||||
static const byte FEATURE_SIGNAL= 0x80;
|
||||
@ -168,12 +189,7 @@ class LookList {
|
||||
static void rotateEvent(int16_t id, bool change);
|
||||
static void powerEvent(int16_t track, bool overload);
|
||||
static bool signalAspectEvent(int16_t address, byte aspect );
|
||||
static const int16_t SERVO_SIGNAL_FLAG=0x4000;
|
||||
static const int16_t ACTIVE_HIGH_SIGNAL_FLAG=0x2000;
|
||||
static const int16_t DCC_SIGNAL_FLAG=0x1000;
|
||||
static const int16_t DCCX_SIGNAL_FLAG=0x3000;
|
||||
static const int16_t SIGNAL_ID_MASK=0x0FFF;
|
||||
// Throttle Info Access functions built by exrail macros
|
||||
// Throttle Info Access functions built by exrail macros
|
||||
static const byte rosterNameCount;
|
||||
static const int16_t HIGHFLASH routeIdList[];
|
||||
static const int16_t HIGHFLASH automationIdList[];
|
||||
@ -187,6 +203,8 @@ class LookList {
|
||||
static const FSH * getTurntablePositionDescription(int16_t turntableId, uint8_t positionId);
|
||||
static void startNonRecursiveTask(const FSH* reason, int16_t id,int pc);
|
||||
static bool readSensor(uint16_t sensorId);
|
||||
static bool isSignal(int16_t id,char rag);
|
||||
static SIGNAL_DEFINITION getSignalSlot(int16_t slotno);
|
||||
|
||||
private:
|
||||
static void ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16_t p[]);
|
||||
@ -196,8 +214,6 @@ private:
|
||||
static bool getFlag(VPIN id,byte mask);
|
||||
static int16_t progtrackLocoId;
|
||||
static void doSignal(int16_t id,char rag);
|
||||
static bool isSignal(int16_t id,char rag);
|
||||
static int16_t getSignalSlot(int16_t id);
|
||||
static void setTurnoutHiddenState(Turnout * t);
|
||||
#ifndef IO_NO_HAL
|
||||
static void setTurntableHiddenState(Turntable * tto);
|
||||
@ -205,7 +221,7 @@ private:
|
||||
static LookList* LookListLoader(OPCODE op1,
|
||||
OPCODE op2=OPCODE_ENDEXRAIL,OPCODE op3=OPCODE_ENDEXRAIL);
|
||||
static uint16_t getOperand(int progCounter,byte n);
|
||||
static void killBlinkOnVpin(VPIN pin);
|
||||
static void killBlinkOnVpin(VPIN pin,uint16_t count=1);
|
||||
static RMFT2 * loopTask;
|
||||
static RMFT2 * pausingTask;
|
||||
void delayMe(long millisecs);
|
||||
@ -221,10 +237,11 @@ private:
|
||||
|
||||
static bool diag;
|
||||
static const HIGHFLASH3 byte RouteCode[];
|
||||
static const HIGHFLASH int16_t SignalDefinitions[];
|
||||
static const HIGHFLASH SIGNAL_DEFINITION SignalDefinitions[];
|
||||
static byte flags[MAX_FLAGS];
|
||||
static Print * LCCSerial;
|
||||
static LookList * routeLookup;
|
||||
static LookList * signalLookup;
|
||||
static LookList * onThrowLookup;
|
||||
static LookList * onCloseLookup;
|
||||
static LookList * onActivateLookup;
|
||||
|
@ -2,6 +2,7 @@
|
||||
* © 2020-2022 Chris Harlow. All rights reserved.
|
||||
* © 2022-2023 Colin Murdoch
|
||||
* © 2023 Harald Barth
|
||||
* © 2025 Morten Nielsen
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
*
|
||||
@ -99,6 +100,13 @@
|
||||
#undef LCCX
|
||||
#undef LCN
|
||||
#undef MOVETT
|
||||
#undef NEOPIXEL
|
||||
#undef NEOPIXEL_OFF
|
||||
#undef NEOPIXEL_SIGNAL
|
||||
#undef ACON
|
||||
#undef ACOF
|
||||
#undef ONACON
|
||||
#undef ONACOF
|
||||
#undef MESSAGE
|
||||
#undef ONACTIVATE
|
||||
#undef ONACTIVATEL
|
||||
@ -187,11 +195,13 @@
|
||||
#undef XFOFF
|
||||
#undef XFON
|
||||
#undef XFTOGGLE
|
||||
#undef XREV
|
||||
#undef XFWD
|
||||
|
||||
#ifndef RMFT2_UNDEF_ONLY
|
||||
#define ACTIVATE(addr,subaddr)
|
||||
#define ACTIVATEL(addr)
|
||||
#define AFTER(sensor_id)
|
||||
#define AFTER(sensor_id,timer...)
|
||||
#define AFTEROVERLOAD(track_id)
|
||||
#define ALIAS(name,value...)
|
||||
#define AMBER(signal_id)
|
||||
@ -207,12 +217,12 @@
|
||||
#define BROADCAST(msg)
|
||||
#define CALL(route)
|
||||
#define CLEAR_STASH(id)
|
||||
#define CLEAR_ALL_STASH(id)
|
||||
#define CLEAR_ALL_STASH
|
||||
#define CLOSE(id)
|
||||
#define CONFIGURE_SERVO(vpin,pos1,pos2,profile)
|
||||
#define DCC_SIGNAL(id,add,subaddr)
|
||||
#define DCCX_SIGNAL(id,redAspect,amberAspect,greenAspect)
|
||||
#define DCC_TURNTABLE(id,home,description)
|
||||
#define DCC_TURNTABLE(id,home,description...)
|
||||
#define DEACTIVATE(addr,subaddr)
|
||||
#define DEACTIVATEL(addr)
|
||||
#define DELAY(mindelay)
|
||||
@ -226,7 +236,7 @@
|
||||
#define ENDTASK
|
||||
#define ESTOP
|
||||
#define EXRAIL
|
||||
#define EXTT_TURNTABLE(id,vpin,home,description)
|
||||
#define EXTT_TURNTABLE(id,vpin,home,description...)
|
||||
#define FADE(pin,value,ms)
|
||||
#define FOFF(func)
|
||||
#define FOLLOW(route)
|
||||
@ -265,6 +275,12 @@
|
||||
#define LCN(msg)
|
||||
#define MESSAGE(msg)
|
||||
#define MOVETT(id,steps,activity)
|
||||
#define NEOPIXEL(id,r,g,b,count...)
|
||||
#define NEOPIXEL_SIGNAL(sigid,redcolour,ambercolour,greencolour)
|
||||
#define ACON(eventid)
|
||||
#define ACOF(eventid)
|
||||
#define ONACON(eventid)
|
||||
#define ONACOF(eventid)
|
||||
#define ONACTIVATE(addr,subaddr)
|
||||
#define ONACTIVATEL(linear)
|
||||
#define ONAMBER(signal_id)
|
||||
@ -296,7 +312,7 @@
|
||||
#define READ_LOCO
|
||||
#define RED(signal_id)
|
||||
#define RESERVE(blockid)
|
||||
#define RESET(pin)
|
||||
#define RESET(pin,count...)
|
||||
#define RESUME
|
||||
#define RETURN
|
||||
#define REV(speed)
|
||||
@ -322,11 +338,11 @@
|
||||
#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 SET(pin,count...)
|
||||
#define SET_TRACK(track,mode)
|
||||
#define SET_POWER(track,onoff)
|
||||
#define SETLOCO(loco)
|
||||
#define SETFREQ(loco,freq)
|
||||
#define SETFREQ(freq)
|
||||
#define SIGNAL(redpin,amberpin,greenpin)
|
||||
#define SIGNALH(redpin,amberpin,greenpin)
|
||||
#define SPEED(speed)
|
||||
@ -352,5 +368,7 @@
|
||||
#define XFOFF(cab,func)
|
||||
#define XFON(cab,func)
|
||||
#define XFTOGGLE(cab,func)
|
||||
#define XFWD(cab,speed)
|
||||
#define XREV(cab,speed)
|
||||
|
||||
#endif
|
||||
|
@ -61,47 +61,85 @@ void RMFT2::ComandFilter(Print * stream, byte & opcode, byte & paramCount, int16
|
||||
case 'L':
|
||||
// This entire code block is compiled out if LLC macros not used
|
||||
if (!(compileFeatures & FEATURE_LCC)) return;
|
||||
|
||||
static int lccProgCounter=0;
|
||||
static int lccEventIndex=0;
|
||||
|
||||
if (paramCount==0) { //<L> LCC adapter introducing self
|
||||
LCCSerial=stream; // now we know where to send events we raise
|
||||
opcode=0; // flag command as intercepted
|
||||
|
||||
// loop through all possible sent events
|
||||
for (int progCounter=0;; SKIPOP) {
|
||||
byte opcode=GET_OPCODE;
|
||||
if (opcode==OPCODE_ENDEXRAIL) break;
|
||||
if (opcode==OPCODE_LCC) StringFormatter::send(stream,F("<LS x%h>\n"),getOperand(progCounter,0));
|
||||
if (opcode==OPCODE_LCCX) { // long form LCC
|
||||
StringFormatter::send(stream,F("<LS x%h%h%h%h>\n"),
|
||||
// loop through all possible sent/waited events
|
||||
for (int progCounter=lccProgCounter;; SKIPOP) {
|
||||
byte exrailOpcode=GET_OPCODE;
|
||||
switch (exrailOpcode) {
|
||||
case OPCODE_ENDEXRAIL:
|
||||
stream->print(F("<LR>\n")); // ready to roll
|
||||
lccProgCounter=0; // allow a second pass
|
||||
lccEventIndex=0;
|
||||
return;
|
||||
|
||||
case OPCODE_LCC:
|
||||
StringFormatter::send(stream,F("<LS x%h>\n"),getOperand(progCounter,0));
|
||||
SKIPOP;
|
||||
lccProgCounter=progCounter;
|
||||
return;
|
||||
|
||||
case OPCODE_LCCX: // long form LCC
|
||||
StringFormatter::send(stream,F("<LS x%h%h%h%h>\n"),
|
||||
getOperand(progCounter,1),
|
||||
getOperand(progCounter,2),
|
||||
getOperand(progCounter,3),
|
||||
getOperand(progCounter,0)
|
||||
);
|
||||
}}
|
||||
);
|
||||
SKIPOP;SKIPOP;SKIPOP;SKIPOP;
|
||||
lccProgCounter=progCounter;
|
||||
return;
|
||||
|
||||
case OPCODE_ACON: // CBUS ACON
|
||||
case OPCODE_ACOF: // CBUS ACOF
|
||||
StringFormatter::send(stream,F("<LS x%c%h%h>\n"),
|
||||
exrailOpcode==OPCODE_ACOF?'1':'0',
|
||||
getOperand(progCounter,0),getOperand(progCounter,1));
|
||||
SKIPOP;SKIPOP;
|
||||
lccProgCounter=progCounter;
|
||||
return;
|
||||
|
||||
// we stream the hex events we wish to listen to
|
||||
// and at the same time build the event index looku.
|
||||
|
||||
|
||||
int eventIndex=0;
|
||||
for (int progCounter=0;; SKIPOP) {
|
||||
byte opcode=GET_OPCODE;
|
||||
if (opcode==OPCODE_ENDEXRAIL) break;
|
||||
if (opcode==OPCODE_ONLCC) {
|
||||
onLCCLookup[eventIndex]=progCounter; // TODO skip...
|
||||
case OPCODE_ONLCC:
|
||||
StringFormatter::send(stream,F("<LL %d x%h%h%h:%h>\n"),
|
||||
eventIndex,
|
||||
lccEventIndex,
|
||||
getOperand(progCounter,1),
|
||||
getOperand(progCounter,2),
|
||||
getOperand(progCounter,3),
|
||||
getOperand(progCounter,0)
|
||||
);
|
||||
eventIndex++;
|
||||
}
|
||||
SKIPOP;SKIPOP;SKIPOP;SKIPOP;
|
||||
// start on handler at next
|
||||
onLCCLookup[lccEventIndex]=progCounter;
|
||||
lccEventIndex++;
|
||||
lccProgCounter=progCounter;
|
||||
return;
|
||||
|
||||
case OPCODE_ONACON:
|
||||
case OPCODE_ONACOF:
|
||||
StringFormatter::send(stream,F("<LL %d x%c%h%h>\n"),
|
||||
lccEventIndex,
|
||||
exrailOpcode==OPCODE_ONACOF?'1':'0',
|
||||
getOperand(progCounter,0),getOperand(progCounter,1)
|
||||
);
|
||||
SKIPOP;SKIPOP;
|
||||
// start on handler at next
|
||||
onLCCLookup[lccEventIndex]=progCounter;
|
||||
lccEventIndex++;
|
||||
lccProgCounter=progCounter;
|
||||
return;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
StringFormatter::send(stream,F("<LR>\n")); // Ready to rumble
|
||||
opcode=0;
|
||||
break;
|
||||
}
|
||||
if (paramCount==1) { // <L eventid> LCC event arrived from adapter
|
||||
int16_t eventid=p[0];
|
||||
@ -214,12 +252,13 @@ bool RMFT2::parseSlash(Print * stream, byte & paramCount, int16_t p[]) {
|
||||
// do the signals
|
||||
// flags[n] represents the state of the nth signal in the table
|
||||
for (int sigslot=0;;sigslot++) {
|
||||
VPIN sigid=GETHIGHFLASHW(RMFT2::SignalDefinitions,sigslot*8);
|
||||
if (sigid==0) break; // end of signal list
|
||||
byte flag=flags[sigslot] & SIGNAL_MASK; // obtain signal flags for this id
|
||||
SIGNAL_DEFINITION slot=getSignalSlot(sigslot);
|
||||
if (slot.type==sigtypeNoMoreSignals) break; // end of signal list
|
||||
if (slot.type==sigtypeContinuation) continue; // continueation of previous line
|
||||
byte flag=flags[sigslot] & SIGNAL_MASK; // obtain signal flags for this ids
|
||||
StringFormatter::send(stream,F("\n%S[%d]"),
|
||||
(flag == SIGNAL_RED)? F("RED") : (flag==SIGNAL_GREEN) ? F("GREEN") : F("AMBER"),
|
||||
sigid & SIGNAL_ID_MASK);
|
||||
(flag == SIGNAL_RED)? F("RED") : (flag==SIGNAL_GREEN) ? F("GREEN") : F("AMBER"),
|
||||
slot.id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -324,4 +363,3 @@ bool RMFT2::parseSlash(Print * stream, byte & paramCount, int16_t p[]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
* © 2020-2022 Chris Harlow
|
||||
* © 2022-2023 Colin Murdoch
|
||||
* © 2023 Harald Barth
|
||||
* © 2025 Morten Nielsen
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of CommandStation-EX
|
||||
@ -63,6 +64,10 @@
|
||||
// playing sounds with IO_I2CDFPlayer
|
||||
#define PLAYSOUND ANOUT
|
||||
|
||||
// SEG7 is a helper to create ANOUT from a 7-segment request
|
||||
#define SEG7(vpin,value,format) \
|
||||
ANOUT(vpin,(value & 0xFFFF),TM1638::DF_##format,((uint32_t)value)>>16)
|
||||
|
||||
// helper macro to strip leading zeros off time inputs
|
||||
// (10#mins)%100)
|
||||
#define STRIP_ZERO(value) 10##value%100
|
||||
@ -71,11 +76,13 @@
|
||||
//const byte TRACK_POWER_0=0, TRACK_POWER_OFF=0;
|
||||
//const byte TRACK_POWER_1=1, TRACK_POWER_ON=1;
|
||||
|
||||
// NEOPIXEL RG generator for NEOPIXEL_SIGNAL
|
||||
#define NeoRGB(red,green,blue) (((uint32_t)(red & 0xff)<<16) | ((uint32_t)(green & 0xff)<<8) | (uint32_t)(blue & 0xff))
|
||||
|
||||
// Pass 1 Implements aliases
|
||||
#include "EXRAIL2MacroReset.h"
|
||||
#undef ALIAS
|
||||
#define ALIAS(name,value...) const int name= 1##value##0 ==10 ? -__COUNTER__ : value##0/10;
|
||||
#define ALIAS(name,value...) const int name= #value[0] ? value+0: -__COUNTER__ ;
|
||||
#include "myAutomation.h"
|
||||
|
||||
// Pass 1d Detect sequence duplicates.
|
||||
@ -180,6 +187,8 @@ bool exrailHalSetup() {
|
||||
#define DCC_SIGNAL(id,addr,subaddr) | FEATURE_SIGNAL
|
||||
#undef DCCX_SIGNAL
|
||||
#define DCCX_SIGNAL(id,redAspect,amberAspect,greenAspect) | FEATURE_SIGNAL
|
||||
#undef NEOPIXEL_SIGNAL
|
||||
#define NEOPIXEL_SIGNAL(sigid,redcolour,ambercolour,greencolour) | FEATURE_SIGNAL
|
||||
#undef VIRTUAL_SIGNAL
|
||||
#define VIRTUAL_SIGNAL(id) | FEATURE_SIGNAL
|
||||
|
||||
@ -189,6 +198,14 @@ bool exrailHalSetup() {
|
||||
#define LCCX(senderid,eventid) | FEATURE_LCC
|
||||
#undef ONLCC
|
||||
#define ONLCC(senderid,eventid) | FEATURE_LCC
|
||||
#undef ACON
|
||||
#define ACON(eventid) | FEATURE_LCC
|
||||
#undef ACOF
|
||||
#define ACOF(eventid) | FEATURE_LCC
|
||||
#undef ONACON
|
||||
#define ONACON(eventid) | FEATURE_LCC
|
||||
#undef ONACOF
|
||||
#define ONACOF(eventid) | FEATURE_LCC
|
||||
#undef ROUTE_ACTIVE
|
||||
#define ROUTE_ACTIVE(id) | FEATURE_ROUTESTATE
|
||||
#undef ROUTE_INACTIVE
|
||||
@ -413,26 +430,35 @@ const FSH * RMFT2::getRosterFunctions(int16_t id) {
|
||||
// Pass 8 Signal definitions
|
||||
#include "EXRAIL2MacroReset.h"
|
||||
#undef SIGNAL
|
||||
#define SIGNAL(redpin,amberpin,greenpin) redpin,redpin,amberpin,greenpin,
|
||||
#define SIGNAL(redpin,amberpin,greenpin) {sigtypeSIGNAL,redpin,redpin,amberpin,greenpin},
|
||||
#undef SIGNALH
|
||||
#define SIGNALH(redpin,amberpin,greenpin) redpin | RMFT2::ACTIVE_HIGH_SIGNAL_FLAG,redpin,amberpin,greenpin,
|
||||
#define SIGNALH(redpin,amberpin,greenpin) {sigtypeSIGNALH,redpin,redpin,amberpin,greenpin},
|
||||
#undef SERVO_SIGNAL
|
||||
#define SERVO_SIGNAL(vpin,redval,amberval,greenval) vpin | RMFT2::SERVO_SIGNAL_FLAG,redval,amberval,greenval,
|
||||
#define SERVO_SIGNAL(vpin,redval,amberval,greenval) {sigtypeSERVO,vpin,redval,amberval,greenval},
|
||||
#undef DCC_SIGNAL
|
||||
#define DCC_SIGNAL(id,addr,subaddr) id | RMFT2::DCC_SIGNAL_FLAG,addr,subaddr,0,
|
||||
#define DCC_SIGNAL(id,addr,subaddr) {sigtypeDCC,id,addr,subaddr,0},
|
||||
#undef DCCX_SIGNAL
|
||||
#define DCCX_SIGNAL(id,redAspect,amberAspect,greenAspect) id | RMFT2::DCCX_SIGNAL_FLAG,redAspect,amberAspect,greenAspect,
|
||||
#define DCCX_SIGNAL(id,redAspect,amberAspect,greenAspect) {sigtypeDCCX,id,redAspect,amberAspect,greenAspect},
|
||||
#undef NEOPIXEL_SIGNAL
|
||||
#define NEOPIXEL_SIGNAL(id,redRGB,amberRGB,greenRGB) \
|
||||
{sigtypeNEOPIXEL,id,((VPIN)((redRGB)>>8)), ((VPIN)((amberRGB)>>8)), ((VPIN)((greenRGB)>>8))},\
|
||||
{sigtypeContinuation,id,((VPIN)((redRGB) & 0xff)), ((VPIN)((amberRGB) & 0xFF)), ((VPIN)((greenRGB) & 0xFF))},
|
||||
#undef VIRTUAL_SIGNAL
|
||||
#define VIRTUAL_SIGNAL(id) id,0,0,0,
|
||||
#define VIRTUAL_SIGNAL(id) {sigtypeVIRTUAL,id,0,0,0},
|
||||
|
||||
const HIGHFLASH int16_t RMFT2::SignalDefinitions[] = {
|
||||
const HIGHFLASH SIGNAL_DEFINITION RMFT2::SignalDefinitions[] = {
|
||||
#include "myAutomation.h"
|
||||
0,0,0,0 };
|
||||
{sigtypeNoMoreSignals,0,0,0,0}
|
||||
};
|
||||
|
||||
// Pass 9 ONLCC counter and lookup array
|
||||
// Pass 9 ONLCC/ ONMERG counter and lookup array
|
||||
#include "EXRAIL2MacroReset.h"
|
||||
#undef ONLCC
|
||||
#define ONLCC(sender,event) +1
|
||||
#undef ONACON
|
||||
#define ONACON(event) +1
|
||||
#undef ONACOF
|
||||
#define ONACOF(event) +1
|
||||
|
||||
const int RMFT2::countLCCLookup=0
|
||||
#include "myAutomation.h"
|
||||
@ -451,7 +477,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
|
||||
|
||||
#define ACTIVATE(addr,subaddr) OPCODE_DCCACTIVATE,V(addr<<3 | subaddr<<1 | 1),
|
||||
#define ACTIVATEL(addr) OPCODE_DCCACTIVATE,V((addr+3)<<1 | 1),
|
||||
#define AFTER(sensor_id) OPCODE_AT,V(sensor_id),OPCODE_AFTER,V(sensor_id),
|
||||
#define AFTER(sensor_id,timer...) OPCODE_AT,V(sensor_id),OPCODE_AFTER,V(sensor_id),OPCODE_PAD,V(#timer[0]?timer+0:500),
|
||||
#define AFTEROVERLOAD(track_id) OPCODE_AFTEROVERLOAD,V(TRACK_NUMBER_##track_id),
|
||||
#define ALIAS(name,value...)
|
||||
#define AMBER(signal_id) OPCODE_AMBER,V(signal_id),
|
||||
@ -491,7 +517,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
|
||||
#ifndef IO_NO_HAL
|
||||
#define EXTT_TURNTABLE(id,vpin,home,description...) OPCODE_EXTTTURNTABLE,V(id),OPCODE_PAD,V(vpin),OPCODE_PAD,V(home),
|
||||
#endif
|
||||
#define FADE(pin,value,ms) OPCODE_SERVO,V(pin),OPCODE_PAD,V(value),OPCODE_PAD,V(PCA9685::ProfileType::UseDuration|PCA9685::NoPowerOff),OPCODE_PAD,V(ms/100L),
|
||||
#define FADE(pin,value,ms) OPCODE_SERVO,V(pin),OPCODE_PAD,V(value),OPCODE_PAD,V((int16_t)PCA9685::ProfileType::UseDuration|(int16_t)PCA9685::ProfileType::NoPowerOff),OPCODE_PAD,V(ms/100L),
|
||||
#define FOFF(func) OPCODE_FOFF,V(func),
|
||||
#define FOLLOW(route) OPCODE_FOLLOW,V(route),
|
||||
#define FON(func) OPCODE_FON,V(func),
|
||||
@ -529,6 +555,10 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
|
||||
OPCODE_PAD,V((((uint64_t)sender)>>32)&0xFFFF),\
|
||||
OPCODE_PAD,V((((uint64_t)sender)>>16)&0xFFFF),\
|
||||
OPCODE_PAD,V((((uint64_t)sender)>>0)&0xFFFF),
|
||||
#define ACON(eventid) OPCODE_ACON,V(((uint32_t)eventid >>16) & 0xFFFF),OPCODE_PAD,V(eventid & 0xFFFF),
|
||||
#define ACOF(eventid) OPCODE_ACOF,V(((uint32_t)eventid >>16) & 0xFFFF),OPCODE_PAD,V(eventid & 0xFFFF),
|
||||
#define ONACON(eventid) OPCODE_ONACON,V((uint32_t)(eventid) >>16),OPCODE_PAD,V(eventid & 0xFFFF),
|
||||
#define ONACOF(eventid) OPCODE_ONACOF,V((uint32_t)(eventid) >>16),OPCODE_PAD,V(eventid & 0xFFFF),
|
||||
#define LCD(id,msg) PRINT(msg)
|
||||
#define SCREEN(display,id,msg) PRINT(msg)
|
||||
#define STEALTH(code...) PRINT(dummy)
|
||||
@ -536,6 +566,12 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
|
||||
#define LCN(msg) PRINT(msg)
|
||||
#define MESSAGE(msg) PRINT(msg)
|
||||
#define MOVETT(id,steps,activity) OPCODE_SERVO,V(id),OPCODE_PAD,V(steps),OPCODE_PAD,V(EXTurntable::activity),OPCODE_PAD,V(0),
|
||||
#define NEOPIXEL(id,r,g,b,count...) OPCODE_NEOPIXEL,V(id),\
|
||||
OPCODE_PAD,V(((r & 0xff)<<8) | (g & 0xff)),\
|
||||
OPCODE_PAD,V((b & 0xff)),\
|
||||
OPCODE_PAD,V(#count[0]?(count+0):1),
|
||||
|
||||
#define NEOPIXEL_SIGNAL(sigid,redcolour,ambercolour,greencolour)
|
||||
#define ONACTIVATE(addr,subaddr) OPCODE_ONACTIVATE,V(addr<<2|subaddr),
|
||||
#define ONACTIVATEL(linear) OPCODE_ONACTIVATE,V(linear+3),
|
||||
#define ONAMBER(signal_id) OPCODE_ONAMBER,V(signal_id),
|
||||
@ -572,7 +608,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
|
||||
#define READ_LOCO OPCODE_READ_LOCO1,0,0,OPCODE_READ_LOCO2,0,0,
|
||||
#define RED(signal_id) OPCODE_RED,V(signal_id),
|
||||
#define RESERVE(blockid) OPCODE_RESERVE,V(blockid),
|
||||
#define RESET(pin) OPCODE_RESET,V(pin),
|
||||
#define RESET(pin,count...) OPCODE_RESET,V(pin),OPCODE_PAD,V(#count[0] ? count+0: 1),
|
||||
#define RESUME OPCODE_RESUME,0,0,
|
||||
#define RETURN OPCODE_RETURN,0,0,
|
||||
#define REV(speed) OPCODE_REV,V(speed),
|
||||
@ -600,11 +636,11 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
|
||||
#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 SET(pin,count...) OPCODE_SET,V(pin),OPCODE_PAD,V(#count[0] ? count+0: 1),
|
||||
#define SET_TRACK(track,mode) OPCODE_SET_TRACK,V(TRACK_MODE_##mode <<8 | TRACK_NUMBER_##track),
|
||||
#define SET_POWER(track,onoff) OPCODE_SET_POWER,V(TRACK_POWER_##onoff),OPCODE_PAD, V(TRACK_NUMBER_##track),
|
||||
#define SETLOCO(loco) OPCODE_SETLOCO,V(loco),
|
||||
#define SETFREQ(loco,freq) OPCODE_SETLOCO,V(loco), OPCODE_SETFREQ,V(freq),
|
||||
#define SETFREQ(freq) OPCODE_SETFREQ,V(freq),
|
||||
#define SIGNAL(redpin,amberpin,greenpin)
|
||||
#define SIGNALH(redpin,amberpin,greenpin)
|
||||
#define SPEED(speed) OPCODE_SPEED,V(speed),
|
||||
@ -630,6 +666,8 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
|
||||
#define XFOFF(cab,func) OPCODE_XFOFF,V(cab),OPCODE_PAD,V(func),
|
||||
#define XFON(cab,func) OPCODE_XFON,V(cab),OPCODE_PAD,V(func),
|
||||
#define XFTOGGLE(cab,func) OPCODE_XFTOGGLE,V(cab),OPCODE_PAD,V(func),
|
||||
#define XFWD(cab,speed) OPCODE_XFWD,V(cab),OPCODE_PAD,V(speed),
|
||||
#define XREV(cab,speed) OPCODE_XREV,V(cab),OPCODE_PAD,V(speed),
|
||||
|
||||
// Build RouteCode
|
||||
const int StringMacroTracker2=__COUNTER__;
|
||||
|
@ -47,4 +47,4 @@ class EXRAILSensor {
|
||||
bool onChange;
|
||||
byte latchDelay;
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
@ -1,8 +1,10 @@
|
||||
/*
|
||||
* © 2024 Morten "Doc" Nielsen
|
||||
* © 2023-2024 Paul M. Antoine
|
||||
* © 2022 Bruno Sanches
|
||||
* © 2021 Fred Decker
|
||||
* © 2020-2022 Harald Barth
|
||||
* © 2020-2021 Chris Harlow
|
||||
* © 2020-2024 Chris Harlow
|
||||
* © 2020 Gregor Baues
|
||||
* All rights reserved.
|
||||
*
|
||||
@ -29,76 +31,139 @@
|
||||
#include "CommandDistributor.h"
|
||||
#include "WiThrottle.h"
|
||||
#include "DCCTimer.h"
|
||||
#if __has_include ( "MDNS_Generic.h")
|
||||
#include "MDNS_Generic.h"
|
||||
#define DO_MDNS
|
||||
EthernetUDP udp;
|
||||
MDNS mdns(udp);
|
||||
#endif
|
||||
|
||||
|
||||
//extern void looptimer(unsigned long timeout, const FSH* message);
|
||||
#define looptimer(a,b)
|
||||
|
||||
bool EthernetInterface::connected=false;
|
||||
EthernetServer * EthernetInterface::server= nullptr;
|
||||
EthernetClient EthernetInterface::clients[MAX_SOCK_NUM]; // accept up to MAX_SOCK_NUM client connections at the same time; This depends on the chipset used on the Shield
|
||||
bool EthernetInterface::inUse[MAX_SOCK_NUM]; // accept up to MAX_SOCK_NUM client connections at the same time; This depends on the chipset used on the Shield
|
||||
uint8_t EthernetInterface::buffer[MAX_ETH_BUFFER+1]; // buffer used by TCP for the recv
|
||||
RingStream * EthernetInterface::outboundRing = nullptr;
|
||||
|
||||
EthernetInterface * EthernetInterface::singleton=NULL;
|
||||
/**
|
||||
* @brief Setup Ethernet Connection
|
||||
*
|
||||
*/
|
||||
void EthernetInterface::setup()
|
||||
|
||||
void EthernetInterface::setup()
|
||||
{
|
||||
if (singleton!=NULL) {
|
||||
DIAG(F("Prog Error!"));
|
||||
return;
|
||||
}
|
||||
if ((singleton=new EthernetInterface()))
|
||||
return;
|
||||
DIAG(F("Ethernet not initialized"));
|
||||
};
|
||||
DIAG(F("Ethernet starting"
|
||||
#ifdef DO_MDNS
|
||||
" (with mDNS)"
|
||||
#endif
|
||||
" Please be patient, especially if no cable is connected!"
|
||||
));
|
||||
|
||||
#ifdef STM32_ETHERNET
|
||||
// Set a HOSTNAME for the DHCP request - a nice to have, but hard it seems on LWIP for STM32
|
||||
// The default is "lwip", which is **always** set in STM32Ethernet/src/utility/ethernetif.cpp
|
||||
// for some reason. One can edit it to instead read:
|
||||
// #if LWIP_NETIF_HOSTNAME
|
||||
// /* Initialize interface hostname */
|
||||
// if (netif->hostname == NULL)
|
||||
// netif->hostname = "lwip";
|
||||
// #endif /* LWIP_NETIF_HOSTNAME */
|
||||
// Which seems more useful! We should propose the patch... so the following line actually works!
|
||||
netif_set_hostname(&gnetif, WIFI_HOSTNAME); // Should probably be passed in the contructor...
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef IP_ADDRESS
|
||||
static IPAddress myIP(IP_ADDRESS);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Aquire IP Address from DHCP and start server
|
||||
*
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
EthernetInterface::EthernetInterface()
|
||||
{
|
||||
byte mac[6];
|
||||
DCCTimer::getSimulatedMacAddress(mac);
|
||||
connected=false;
|
||||
|
||||
#ifdef IP_ADDRESS
|
||||
Ethernet.begin(mac, myIP);
|
||||
#else
|
||||
if (Ethernet.begin(mac) == 0)
|
||||
{
|
||||
DIAG(F("Ethernet.begin FAILED"));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
|
||||
DIAG(F("Ethernet shield not found or W5100"));
|
||||
}
|
||||
|
||||
unsigned long startmilli = millis();
|
||||
while ((millis() - startmilli) < 5500) { // Loop to give time to check for cable connection
|
||||
if (Ethernet.linkStatus() == LinkON)
|
||||
break;
|
||||
DIAG(F("Ethernet waiting for link (1sec) "));
|
||||
delay(1000);
|
||||
}
|
||||
// now we either do have link of we have a W5100
|
||||
// where we do not know if we have link. That's
|
||||
// the reason to now run checkLink.
|
||||
// CheckLinks sets up outboundRing if it does
|
||||
// not exist yet as well.
|
||||
checkLink();
|
||||
#ifdef IP_ADDRESS
|
||||
static IPAddress myIP(IP_ADDRESS);
|
||||
Ethernet.begin(mac,myIP);
|
||||
#else
|
||||
if (Ethernet.begin(mac)==0)
|
||||
{
|
||||
LCD(4,F("IP: No DHCP"));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
auto ip = Ethernet.localIP(); // look what IP was obtained (dynamic or static)
|
||||
if (!ip) {
|
||||
LCD(4,F("IP: None"));
|
||||
return;
|
||||
}
|
||||
server = new EthernetServer(IP_PORT); // Ethernet Server listening on default port IP_PORT
|
||||
server->begin();
|
||||
|
||||
// Arrange display of IP address and port
|
||||
#ifdef LCD_DRIVER
|
||||
const byte lcdData[]={LCD_DRIVER};
|
||||
const bool wideDisplay=lcdData[1]>=24; // data[1] is cols.
|
||||
#else
|
||||
const bool wideDisplay=true;
|
||||
#endif
|
||||
if (wideDisplay) {
|
||||
// OLEDS or just usb diag is ok on one line.
|
||||
LCD(4,F("IP %d.%d.%d.%d:%d"), ip[0], ip[1], ip[2], ip[3], IP_PORT);
|
||||
}
|
||||
else { // LCDs generally too narrow, so take 2 lines
|
||||
LCD(4,F("IP %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
|
||||
LCD(5,F("Port %d"), IP_PORT);
|
||||
}
|
||||
|
||||
outboundRing=new RingStream(OUTBOUND_RING_SIZE);
|
||||
#ifdef DO_MDNS
|
||||
mdns.begin(Ethernet.localIP(), WIFI_HOSTNAME); // hostname
|
||||
mdns.addServiceRecord(WIFI_HOSTNAME "._withrottle", IP_PORT, MDNSServiceTCP);
|
||||
// Not sure if we need to run it once, but just in case!
|
||||
mdns.run();
|
||||
#endif
|
||||
connected=true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cleanup any resources
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
EthernetInterface::~EthernetInterface() {
|
||||
delete server;
|
||||
delete outboundRing;
|
||||
#if defined (STM32_ETHERNET)
|
||||
void EthernetInterface::acceptClient() { // STM32 version
|
||||
auto client=server->available();
|
||||
if (!client) return;
|
||||
// check for existing client
|
||||
for (byte socket = 0; socket < MAX_SOCK_NUM; socket++)
|
||||
if (inUse[socket] && client == clients[socket]) return;
|
||||
|
||||
// new client
|
||||
for (byte socket = 0; socket < MAX_SOCK_NUM; socket++)
|
||||
{
|
||||
if (!inUse[socket])
|
||||
{
|
||||
clients[socket] = client;
|
||||
inUse[socket]=true;
|
||||
if (Diag::ETHERNET)
|
||||
DIAG(F("Ethernet: New client socket %d"), socket);
|
||||
return;
|
||||
}
|
||||
}
|
||||
DIAG(F("Ethernet OVERFLOW"));
|
||||
}
|
||||
#else
|
||||
void EthernetInterface::acceptClient() { // non-STM32 version
|
||||
auto client=server->accept();
|
||||
if (!client) return;
|
||||
auto socket=client.getSocketNumber();
|
||||
clients[socket]=client;
|
||||
inUse[socket]=true;
|
||||
if (Diag::ETHERNET)
|
||||
DIAG(F("Ethernet: New client socket %d"), socket);
|
||||
}
|
||||
#endif
|
||||
|
||||
void EthernetInterface::dropClient(byte socket)
|
||||
{
|
||||
clients[socket].stop();
|
||||
inUse[socket]=false;
|
||||
CommandDistributor::forget(socket);
|
||||
if (Diag::ETHERNET) DIAG(F("Ethernet: Disconnect %d "), socket);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,134 +172,109 @@ EthernetInterface::~EthernetInterface() {
|
||||
*/
|
||||
void EthernetInterface::loop()
|
||||
{
|
||||
if (!singleton || (!singleton->checkLink()))
|
||||
return;
|
||||
if (!connected) return;
|
||||
looptimer(5000, F("E.loop"));
|
||||
|
||||
static bool warnedAboutLink=false;
|
||||
if (Ethernet.linkStatus() == LinkOFF){
|
||||
if (warnedAboutLink) return;
|
||||
DIAG(F("Ethernet link OFF"));
|
||||
warnedAboutLink=true;
|
||||
return;
|
||||
}
|
||||
looptimer(5000, F("E.loop warn"));
|
||||
|
||||
// link status must be ok here
|
||||
if (warnedAboutLink) {
|
||||
DIAG(F("Ethernet link RESTORED"));
|
||||
warnedAboutLink=false;
|
||||
}
|
||||
|
||||
#ifdef DO_MDNS
|
||||
// Always do this because we don't want traffic to intefere with being found!
|
||||
mdns.run();
|
||||
looptimer(5000, F("E.mdns"));
|
||||
|
||||
#endif
|
||||
|
||||
//
|
||||
switch (Ethernet.maintain()) {
|
||||
case 1:
|
||||
//renewed fail
|
||||
DIAG(F("Ethernet Error: renewed fail"));
|
||||
singleton=NULL;
|
||||
connected=false;
|
||||
return;
|
||||
case 3:
|
||||
//rebind fail
|
||||
DIAG(F("Ethernet Error: rebind fail"));
|
||||
singleton=NULL;
|
||||
connected=false;
|
||||
return;
|
||||
default:
|
||||
//nothing happened
|
||||
//DIAG(F("maintained"));
|
||||
break;
|
||||
}
|
||||
singleton->loop2();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks ethernet link cable status and detects when it connects / disconnects
|
||||
*
|
||||
* @return true when cable is connected, false otherwise
|
||||
*/
|
||||
bool EthernetInterface::checkLink() {
|
||||
if (Ethernet.linkStatus() != LinkOFF) { // check for not linkOFF instead of linkON as the W5100 does return LinkUnknown
|
||||
//if we are not connected yet, setup a new server
|
||||
if(!connected) {
|
||||
DIAG(F("Ethernet cable connected"));
|
||||
connected=true;
|
||||
#ifdef IP_ADDRESS
|
||||
Ethernet.setLocalIP(myIP); // for static IP, set it again
|
||||
#endif
|
||||
IPAddress ip = Ethernet.localIP(); // look what IP was obtained (dynamic or static)
|
||||
server = new EthernetServer(IP_PORT); // Ethernet Server listening on default port IP_PORT
|
||||
server->begin();
|
||||
LCD(4,F("IP: %d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
|
||||
LCD(5,F("Port:%d"), IP_PORT);
|
||||
// only create a outboundRing it none exists, this may happen if the cable
|
||||
// gets disconnected and connected again
|
||||
if(!outboundRing)
|
||||
outboundRing=new RingStream(OUTBOUND_RING_SIZE);
|
||||
}
|
||||
return true;
|
||||
} else { // connected
|
||||
DIAG(F("Ethernet cable disconnected"));
|
||||
connected=false;
|
||||
//clean up any client
|
||||
for (byte socket = 0; socket < MAX_SOCK_NUM; socket++) {
|
||||
if(clients[socket].connected())
|
||||
clients[socket].stop();
|
||||
}
|
||||
// tear down server
|
||||
delete server;
|
||||
server = nullptr;
|
||||
LCD(4,F("IP: None"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void EthernetInterface::loop2() {
|
||||
if (!outboundRing) { // no idea to call loop2() if we can't handle outgoing data in it
|
||||
if (Diag::ETHERNET) DIAG(F("No outboundRing"));
|
||||
return;
|
||||
}
|
||||
looptimer(5000, F("E.maintain"));
|
||||
|
||||
// get client from the server
|
||||
EthernetClient client = server->accept();
|
||||
|
||||
// check for new client
|
||||
if (client)
|
||||
acceptClient();
|
||||
|
||||
// handle disconnected sockets because STM32 library doesnt
|
||||
// do the read==0 response.
|
||||
for (byte socket = 0; socket < MAX_SOCK_NUM; socket++)
|
||||
{
|
||||
if (Diag::ETHERNET) DIAG(F("Ethernet: New client "));
|
||||
byte socket;
|
||||
for (socket = 0; socket < MAX_SOCK_NUM; socket++)
|
||||
{
|
||||
if (!clients[socket])
|
||||
{
|
||||
// On accept() the EthernetServer doesn't track the client anymore
|
||||
// so we store it in our client array
|
||||
if (Diag::ETHERNET) DIAG(F("Socket %d"),socket);
|
||||
clients[socket] = client;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (socket==MAX_SOCK_NUM) DIAG(F("new Ethernet OVERFLOW"));
|
||||
}
|
||||
if (inUse[socket] && !clients[socket].connected()) dropClient(socket);
|
||||
}
|
||||
|
||||
// check for incoming data from all possible clients
|
||||
for (byte socket = 0; socket < MAX_SOCK_NUM; socket++)
|
||||
{
|
||||
if (clients[socket]) {
|
||||
|
||||
int available=clients[socket].available();
|
||||
if (available > 0) {
|
||||
if (Diag::ETHERNET) DIAG(F("Ethernet: available socket=%d,avail=%d"), socket, available);
|
||||
// read bytes from a client
|
||||
int count = clients[socket].read(buffer, MAX_ETH_BUFFER);
|
||||
buffer[count] = '\0'; // terminate the string properly
|
||||
if (Diag::ETHERNET) DIAG(F(",count=%d:%e"), socket,buffer);
|
||||
// execute with data going directly back
|
||||
CommandDistributor::parse(socket,buffer,outboundRing);
|
||||
return; // limit the amount of processing that takes place within 1 loop() cycle.
|
||||
}
|
||||
}
|
||||
if (!inUse[socket]) continue; // socket is not in use
|
||||
|
||||
// read any bytes from this client
|
||||
auto count = clients[socket].read(buffer, MAX_ETH_BUFFER);
|
||||
|
||||
if (count<0) continue; // -1 indicates nothing to read
|
||||
|
||||
if (count > 0) { // we have incoming data
|
||||
buffer[count] = '\0'; // terminate the string properly
|
||||
if (Diag::ETHERNET) DIAG(F("Ethernet s=%d, c=%d b=:%e"), socket, count, buffer);
|
||||
// execute with data going directly back
|
||||
CommandDistributor::parse(socket,buffer,outboundRing);
|
||||
//looptimer(5000, F("Ethloop2 parse"));
|
||||
return; // limit the amount of processing that takes place within 1 loop() cycle.
|
||||
}
|
||||
|
||||
// count=0 The client has disconnected
|
||||
dropClient(socket);
|
||||
}
|
||||
|
||||
// stop any clients which disconnect
|
||||
for (int socket = 0; socket<MAX_SOCK_NUM; socket++) {
|
||||
if (clients[socket] && !clients[socket].connected()) {
|
||||
clients[socket].stop();
|
||||
CommandDistributor::forget(socket);
|
||||
if (Diag::ETHERNET) DIAG(F("Ethernet: disconnect %d "), socket);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WiThrottle::loop(outboundRing);
|
||||
|
||||
|
||||
// handle at most 1 outbound transmission
|
||||
int socketOut=outboundRing->read();
|
||||
auto socketOut=outboundRing->read();
|
||||
if (socketOut<0) return; // no outbound pending
|
||||
|
||||
if (socketOut >= MAX_SOCK_NUM) {
|
||||
DIAG(F("Ethernet outboundRing socket=%d error"), socketOut);
|
||||
} else if (socketOut >= 0) {
|
||||
int count=outboundRing->count();
|
||||
if (Diag::ETHERNET) DIAG(F("Ethernet reply socket=%d, count=:%d"), socketOut,count);
|
||||
for(;count>0;count--) clients[socketOut].write(outboundRing->read());
|
||||
clients[socketOut].flush(); //maybe
|
||||
// This is a catastrophic code failure and unrecoverable.
|
||||
DIAG(F("Ethernet outboundRing s=%d error"), socketOut);
|
||||
connected=false;
|
||||
return;
|
||||
}
|
||||
|
||||
auto count=outboundRing->count();
|
||||
{
|
||||
char tmpbuf[count+1]; // one extra for '\0'
|
||||
for(int i=0;i<count;i++) {
|
||||
tmpbuf[i] = outboundRing->read();
|
||||
}
|
||||
tmpbuf[count]=0;
|
||||
if (inUse[socketOut]) {
|
||||
if (Diag::ETHERNET) DIAG(F("Ethernet reply s=%d, c=%d, b:%e"),
|
||||
socketOut,count,tmpbuf);
|
||||
clients[socketOut].write(tmpbuf,count);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
@ -1,8 +1,10 @@
|
||||
/*
|
||||
* © 2023-2024 Paul M. Antoine
|
||||
* © 2021 Neil McKechnie
|
||||
* © 2021 Mike S
|
||||
* © 2021 Fred Decker
|
||||
* © 2020-2021 Chris Harlow
|
||||
* © 2020-2022 Harald Barth
|
||||
* © 2020-2024 Chris Harlow
|
||||
* © 2020 Gregor Baues
|
||||
* All rights reserved.
|
||||
*
|
||||
@ -35,6 +37,15 @@
|
||||
#if defined (ARDUINO_TEENSY41)
|
||||
#include <NativeEthernet.h> //TEENSY Ethernet Treiber
|
||||
#include <NativeEthernetUdp.h>
|
||||
#define MAX_SOCK_NUM 4
|
||||
#elif defined (ARDUINO_NUCLEO_F429ZI) || defined (ARDUINO_NUCLEO_F439ZI) || defined (ARDUINO_NUCLEO_F4X9ZI)
|
||||
#include <LwIP.h>
|
||||
// #include "STM32lwipopts.h"
|
||||
#include <STM32Ethernet.h>
|
||||
#include <lwip/netif.h>
|
||||
extern "C" struct netif gnetif;
|
||||
#define STM32_ETHERNET
|
||||
#define MAX_SOCK_NUM 8
|
||||
#else
|
||||
#include "Ethernet.h"
|
||||
#endif
|
||||
@ -45,7 +56,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define MAX_ETH_BUFFER 512
|
||||
#define MAX_ETH_BUFFER 128
|
||||
#define OUTBOUND_RING_SIZE 2048
|
||||
|
||||
class EthernetInterface {
|
||||
@ -56,16 +67,15 @@ class EthernetInterface {
|
||||
static void loop();
|
||||
|
||||
private:
|
||||
static EthernetInterface * singleton;
|
||||
bool connected;
|
||||
EthernetInterface();
|
||||
~EthernetInterface();
|
||||
void loop2();
|
||||
bool checkLink();
|
||||
EthernetServer * server = NULL;
|
||||
EthernetClient clients[MAX_SOCK_NUM]; // accept up to MAX_SOCK_NUM client connections at the same time; This depends on the chipset used on the Shield
|
||||
uint8_t buffer[MAX_ETH_BUFFER+1]; // buffer used by TCP for the recv
|
||||
RingStream * outboundRing = NULL;
|
||||
static bool connected;
|
||||
static EthernetServer * server;
|
||||
static EthernetClient clients[MAX_SOCK_NUM]; // accept up to MAX_SOCK_NUM client connections at the same time; This depends on the chipset used on the Shield
|
||||
static bool inUse[MAX_SOCK_NUM]; // accept up to MAX_SOCK_NUM client connections at the same time; This depends on the chipset used on the Shield
|
||||
static uint8_t buffer[MAX_ETH_BUFFER+1]; // buffer used by TCP for the recv
|
||||
static RingStream * outboundRing;
|
||||
static void acceptClient();
|
||||
static void dropClient(byte socketnum);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
8
FSH.h
8
FSH.h
@ -52,6 +52,7 @@ typedef __FlashStringHelper FSH;
|
||||
#define STRNCPY_P strncpy_P
|
||||
#define STRNCMP_P strncmp_P
|
||||
#define STRLEN_P strlen_P
|
||||
#define STRCHR_P strchr_P
|
||||
|
||||
#if defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560)
|
||||
// AVR_MEGA memory deliberately placed at end of link may need _far functions
|
||||
@ -60,6 +61,8 @@ typedef __FlashStringHelper FSH;
|
||||
#define GETFARPTR(data) pgm_get_far_address(data)
|
||||
#define GETHIGHFLASH(data,offset) pgm_read_byte_far(GETFARPTR(data)+offset)
|
||||
#define GETHIGHFLASHW(data,offset) pgm_read_word_far(GETFARPTR(data)+offset)
|
||||
#define COPYHIGHFLASH(target,base,offset,length) \
|
||||
memcpy_PF(target,GETFARPTR(base) + offset,length)
|
||||
#else
|
||||
// AVR_UNO/NANO runtime does not support _far functions so just use _near equivalent
|
||||
// as there is no progmem above 32kb anyway.
|
||||
@ -68,6 +71,8 @@ typedef __FlashStringHelper FSH;
|
||||
#define GETFARPTR(data) ((uint32_t)(data))
|
||||
#define GETHIGHFLASH(data,offset) pgm_read_byte_near(GETFARPTR(data)+(offset))
|
||||
#define GETHIGHFLASHW(data,offset) pgm_read_word_near(GETFARPTR(data)+(offset))
|
||||
#define COPYHIGHFLASH(target,base,offset,length) \
|
||||
memcpy_P(target,(byte *)base + offset,length)
|
||||
#endif
|
||||
|
||||
#else
|
||||
@ -87,10 +92,13 @@ typedef char FSH;
|
||||
#define GETFLASH(addr) (*(const byte *)(addr))
|
||||
#define GETHIGHFLASH(data,offset) (*(const byte *)(GETFARPTR(data)+offset))
|
||||
#define GETHIGHFLASHW(data,offset) (*(const uint16_t *)(GETFARPTR(data)+offset))
|
||||
#define COPYHIGHFLASH(target,base,offset,length) \
|
||||
memcpy(target,(byte *)&base + offset,length)
|
||||
#define STRCPY_P strcpy
|
||||
#define STRCMP_P strcmp
|
||||
#define STRNCPY_P strncpy
|
||||
#define STRNCMP_P strncmp
|
||||
#define STRLEN_P strlen
|
||||
#define STRCHR_P strchr
|
||||
#endif
|
||||
#endif
|
||||
|
@ -1 +1 @@
|
||||
#define GITHUB_SHA "devel-202404061747Z"
|
||||
#define GITHUB_SHA "c389fe9"
|
||||
|
@ -46,27 +46,37 @@
|
||||
|
||||
// Helper function for listing device types
|
||||
static const FSH * guessI2CDeviceType(uint8_t address) {
|
||||
if (address == 0x1A)
|
||||
// 0x09-0x18 selectable, but for now handle the default
|
||||
return F("Piicodev 865/915MHz Transceiver");
|
||||
if (address == 0x1C)
|
||||
return F("QMC6310 Magnetometer");
|
||||
if (address >= 0x20 && address <= 0x26)
|
||||
return F("GPIO Expander");
|
||||
else if (address == 0x27)
|
||||
if (address == 0x27)
|
||||
return F("GPIO Expander or LCD Display");
|
||||
else if (address == 0x29)
|
||||
if (address == 0x29)
|
||||
return F("Time-of-flight sensor");
|
||||
else if (address >= 0x3c && address <= 0x3d)
|
||||
return F("OLED Display");
|
||||
else if (address >= 0x48 && address <= 0x57) // SC16IS752x UART detection
|
||||
if (address == 0x34)
|
||||
return F("TCA8418 keypad scanner");
|
||||
if (address >= 0x3c && address <= 0x3d)
|
||||
// 0x3c can also be an HMC883L magnetometer
|
||||
return F("OLED Display or HMC583L Magnetometer");
|
||||
if (address >= 0x48 && address <= 0x57) // SC16IS752x UART detection
|
||||
return F("SC16IS75x UART");
|
||||
else if (address >= 0x48 && address <= 0x4f)
|
||||
if (address >= 0x48 && address <= 0x4f)
|
||||
return F("Analogue Inputs or PWM");
|
||||
else if (address >= 0x40 && address <= 0x4f)
|
||||
if (address >= 0x40 && address <= 0x4f)
|
||||
return F("PWM");
|
||||
else if (address >= 0x50 && address <= 0x5f)
|
||||
if (address >= 0x50 && address <= 0x5f)
|
||||
return F("EEPROM");
|
||||
else if (address == 0x68)
|
||||
if (address >= 0x60 && address <= 0x68)
|
||||
return F("Adafruit NeoPixel Driver");
|
||||
if (address == 0x68)
|
||||
return F("Real-time clock");
|
||||
else if (address >= 0x70 && address <= 0x77)
|
||||
if (address >= 0x70 && address <= 0x77)
|
||||
return F("I2C Mux");
|
||||
else
|
||||
// Unknown type
|
||||
return F("?");
|
||||
}
|
||||
|
||||
|
@ -384,4 +384,4 @@ void I2CManagerClass::handleInterrupt() {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* © 2022-23 Paul M Antoine
|
||||
* © 2022-24 Paul M Antoine
|
||||
* © 2023, Neil McKechnie
|
||||
* All rights reserved.
|
||||
*
|
||||
@ -38,8 +38,9 @@
|
||||
*****************************************************************************/
|
||||
#if defined(I2C_USE_INTERRUPTS) && defined(ARDUINO_ARCH_STM32)
|
||||
#if defined(ARDUINO_NUCLEO_F401RE) || defined(ARDUINO_NUCLEO_F411RE) || defined(ARDUINO_NUCLEO_F446RE) \
|
||||
|| defined(ARDUINO_NUCLEO_F412ZG) || defined(ARDUINO_NUCLEO_F413ZH) \
|
||||
|| defined(ARDUINO_NUCLEO_F429ZI) || defined(ARDUINO_NUCLEO_F446ZE)
|
||||
|| defined(ARDUINO_NUCLEO_F412ZG) || defined(ARDUINO_NUCLEO_F413ZH) || defined(ARDUINO_NUCLEO_F446ZE) \
|
||||
|| defined(ARDUINO_NUCLEO_F429ZI) || defined(ARDUINO_NUCLEO_F439ZI) || defined(ARDUINO_NUCLEO_F4X9ZI)
|
||||
|
||||
// Assume I2C1 for now - default I2C bus on Nucleo-F411RE and likely all Nucleo-64
|
||||
// and Nucleo-144 variants
|
||||
I2C_TypeDef *s = I2C1;
|
||||
@ -184,7 +185,7 @@ void I2CManagerClass::I2C_init()
|
||||
GPIOB->OTYPER |= (1<<8) | (1<<9); // PB8 and PB9 set to open drain output capability
|
||||
GPIOB->OSPEEDR |= (3<<(8*2)) | (3<<(9*2)); // PB8 and PB9 set to High Speed mode
|
||||
GPIOB->PUPDR &= ~((3<<(8*2)) | (3<<(9*2))); // Clear all PUPDR bits for PB8 and PB9
|
||||
GPIOB->PUPDR |= (1<<(8*2)) | (1<<(9*2)); // PB8 and PB9 set to pull-up capability
|
||||
// GPIOB->PUPDR |= (1<<(8*2)) | (1<<(9*2)); // PB8 and PB9 set to pull-up capability
|
||||
// Alt Function High register routing pins PB8 and PB9 for I2C1:
|
||||
// Bits (3:2:1:0) = 0:1:0:0 --> AF4 for pin PB8
|
||||
// Bits (7:6:5:4) = 0:1:0:0 --> AF4 for pin PB9
|
||||
|
@ -231,4 +231,4 @@ void I2CManagerClass::queueRequest(I2CRB *req) {
|
||||
***************************************************************************/
|
||||
void I2CManagerClass::loop() {}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
39
IODevice.cpp
39
IODevice.cpp
@ -251,6 +251,26 @@ void IODevice::write(VPIN vpin, int value) {
|
||||
#endif
|
||||
}
|
||||
|
||||
// Write value to count virtual pin(s).
|
||||
// these may be within one driver or separated over several drivers
|
||||
void IODevice::writeRange(VPIN vpin, int value, int count) {
|
||||
|
||||
while(count) {
|
||||
auto dev = findDevice(vpin);
|
||||
if (dev) {
|
||||
auto vpinBefore=vpin;
|
||||
// write to driver, driver will return next vpin it cant handle
|
||||
vpin=dev->_writeRange(vpin, value,count);
|
||||
count-= vpin-vpinBefore; // decrement by number of vpins changed
|
||||
}
|
||||
else {
|
||||
// skip a vpin if no device handler
|
||||
vpin++;
|
||||
count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write analogue value to virtual pin(s). If multiple devices are allocated
|
||||
// the same pin then only the first one found will be used.
|
||||
//
|
||||
@ -270,6 +290,24 @@ void IODevice::writeAnalogue(VPIN vpin, int value, uint8_t param1, uint16_t para
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
void IODevice::writeAnalogueRange(VPIN vpin, int value, uint8_t param1, uint16_t param2,int count) {
|
||||
while(count) {
|
||||
auto dev = findDevice(vpin);
|
||||
if (dev) {
|
||||
auto vpinBefore=vpin;
|
||||
// write to driver, driver will return next vpin it cant handle
|
||||
vpin=dev->_writeAnalogueRange(vpin, value, param1, param2,count);
|
||||
count-= vpin-vpinBefore; // decrement by number of vpins changed
|
||||
}
|
||||
else {
|
||||
// skip a vpin if no device handler
|
||||
vpin++;
|
||||
count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// isBusy, when called for a device pin is always a digital output or analogue output,
|
||||
// returns input feedback state of the pin, i.e. whether the pin is busy performing
|
||||
// an animation or fade over a period of time.
|
||||
@ -589,4 +627,3 @@ bool ArduinoPins::fastReadDigital(uint8_t pin) {
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
|
27
IODevice.h
27
IODevice.h
@ -38,6 +38,7 @@
|
||||
#include "FSH.h"
|
||||
#include "I2CManager.h"
|
||||
#include "inttypes.h"
|
||||
#include "TemplateForEnums.h"
|
||||
|
||||
typedef uint16_t VPIN;
|
||||
// Limit VPIN number to max 32767. Above this number, printing often gives negative values.
|
||||
@ -128,9 +129,11 @@ public:
|
||||
|
||||
// write invokes the IODevice instance's _write method.
|
||||
static void write(VPIN vpin, int value);
|
||||
static void writeRange(VPIN vpin, int value,int count);
|
||||
|
||||
// write invokes the IODevice instance's _writeAnalogue method (not applicable for digital outputs)
|
||||
static void writeAnalogue(VPIN vpin, int value, uint8_t profile=0, uint16_t duration=0);
|
||||
static void writeAnalogueRange(VPIN vpin, int value, uint8_t profile, uint16_t duration, int count);
|
||||
|
||||
// isBusy returns true if the device is currently in an animation of some sort, e.g. is changing
|
||||
// the output over a period of time.
|
||||
@ -177,11 +180,29 @@ public:
|
||||
virtual void _write(VPIN vpin, int value) {
|
||||
(void)vpin; (void)value;
|
||||
};
|
||||
|
||||
// Method to write new state (optionally implemented within device class)
|
||||
// This will, by default just write to one vpin and return whet to do next.
|
||||
// the real power comes where a single driver can update many vpins in one call.
|
||||
virtual VPIN _writeRange(VPIN vpin, int value, int count) {
|
||||
(void)count;
|
||||
_write(vpin,value);
|
||||
return vpin+1; // try next vpin
|
||||
};
|
||||
|
||||
// Method to write an 'analogue' value (optionally implemented within device class)
|
||||
virtual void _writeAnalogue(VPIN vpin, int value, uint8_t param1=0, uint16_t param2=0) {
|
||||
(void)vpin; (void)value; (void) param1; (void)param2;
|
||||
};
|
||||
|
||||
// Method to write an 'analogue' value to a VPIN range (optionally implemented within device class)
|
||||
// This will, by default just write to one vpin and return whet to do next.
|
||||
// the real power comes where a single driver can update many vpins in one call.
|
||||
virtual VPIN _writeAnalogueRange(VPIN vpin, int value, uint8_t param1, uint16_t param2, int count) {
|
||||
(void) count;
|
||||
_writeAnalogue(vpin, value, param1, param2);
|
||||
return vpin+1;
|
||||
};
|
||||
|
||||
// Method to read digital pin state (optionally implemented within device class)
|
||||
virtual int _read(VPIN vpin) {
|
||||
@ -547,6 +568,10 @@ protected:
|
||||
#include "IO_duinoNodes.h"
|
||||
#include "IO_EXIOExpander.h"
|
||||
#include "IO_trainbrains.h"
|
||||
|
||||
#include "IO_EncoderThrottle.h"
|
||||
#include "IO_TCA8418.h"
|
||||
#include "IO_NeoPixel.h"
|
||||
#include "IO_TM1638.h"
|
||||
#include "IO_EXSensorCAM.h"
|
||||
|
||||
#endif // iodevice_h
|
||||
|
@ -166,4 +166,4 @@ private:
|
||||
uint8_t _nextState;
|
||||
};
|
||||
|
||||
#endif // io_analogueinputs_h
|
||||
#endif // io_analogueinputs_h
|
||||
|
@ -65,4 +65,3 @@ void DCCAccessoryDecoder::_display() {
|
||||
DIAG(F("DCCAccessoryDecoder Configured on Vpins:%u-%u Addresses %d/%d-%d/%d)"), _firstVpin, _firstVpin+_nPins-1,
|
||||
ADDRESS(_packedAddress), SUBADDRESS(_packedAddress), ADDRESS(endAddress), SUBADDRESS(endAddress));
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,7 @@ static void create(I2CAddress i2cAddress) {
|
||||
// Start by assuming we will find the clock
|
||||
// Check if specified I2C address is responding (blocking operation)
|
||||
// Returns I2C_STATUS_OK (0) if OK, or error code.
|
||||
I2CManager.begin();
|
||||
uint8_t _checkforclock = I2CManager.checkAddress(i2cAddress);
|
||||
DIAG(F("Clock check result - %d"), _checkforclock);
|
||||
// XXXX change thistosave2 bytes
|
||||
|
425
IO_EXSensorCAM.h
Normal file
425
IO_EXSensorCAM.h
Normal file
@ -0,0 +1,425 @@
|
||||
/* 2024/08/14
|
||||
* © 2024, Barry Daniel ESP32-CAM revision
|
||||
*
|
||||
* This file is part of EX-CommandStation
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#define driverVer 305
|
||||
// v305 less debug & alpha ordered switch
|
||||
// v304 static oldb0; t(##[,%%];
|
||||
// v303 zipped with CS 5.2.76 and uploaded to repo (with debug)
|
||||
// v302 SEND=StringFormatter::send, remove Sp(), add 'q', memcpy( .8) -> .7);
|
||||
// v301 improved 'f','p'&'q' code and driver version calc. Correct bsNo calc. for 'a'
|
||||
// v300 stripped & revised without expander functionality. Needs sensorCAM.h v300 AND CamParser.cpp
|
||||
// v222 uses '@'for EXIORDD read. handles <NB $> and <NN $ ##>
|
||||
// v216 includes 'j' command and uses CamParser rather than myFilter.h Incompatible with v203 senorCAM
|
||||
// v203 added pvtThreshold to 'i' output
|
||||
// v201 deleted code for compatibility with CAM pre v171. Needs CAM ver201 with o06 only
|
||||
// v200 rewrite reduces need for double reads of ESP32 slave CAM. Deleted ESP32CAP.
|
||||
// Inompatible with pre-v170 sensorCAM, unless set S06 to 0 and S07 to 1 (o06 & l07 say)
|
||||
/*
|
||||
* The IO_EXSensorCAM.h device driver can integrate with the sensorCAM device.
|
||||
* It is modelled on the IO_EXIOExpander.h device driver to include specific needs of the ESP32 sensorCAM
|
||||
* This device driver will configure the device on startup, along with CamParser.cpp
|
||||
* interacting with the sensorCAM device for all input/output duties.
|
||||
*
|
||||
* #include "CamParser.h" in DCCEXParser.cpp
|
||||
* #include "IO_EXSensorCAM.h" in IODevice.h
|
||||
* To create EX-SensorCAM devices, define them in myHal.cpp: with
|
||||
* EXSensorCAM::create(baseVpin,num_vpins,i2c_address) or
|
||||
* alternatively use HAL(EXSensorCAM baseVpin numpins i2c_address) in myAutomation.h
|
||||
* also #define SENSORCAM_VPIN baseVpin in config.h
|
||||
*
|
||||
* void halSetup() {
|
||||
* // EXSensorCAM::create(vpin, num_vpins, i2c_address);
|
||||
* EXSensorCAM::create(700, 80, 0x11);
|
||||
* }
|
||||
*
|
||||
* I2C packet size of 32 bytes (in the Wire library).
|
||||
*/
|
||||
# define DIGITALREFRESH 20000UL // min uSec delay between digital reads of digitalInputStates
|
||||
#ifndef IO_EX_EXSENSORCAM_H
|
||||
#define IO_EX_EXSENSORCAM_H
|
||||
#define SEND StringFormatter::send
|
||||
#include "IODevice.h"
|
||||
#include "I2CManager.h"
|
||||
#include "DIAG.h"
|
||||
#include "FSH.h"
|
||||
#include "CamParser.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* IODevice subclass for EX-SensorCAM.
|
||||
*/
|
||||
class EXSensorCAM : public IODevice {
|
||||
public:
|
||||
static void create(VPIN vpin, int nPins, I2CAddress i2cAddress) {
|
||||
if (checkNoOverlap(vpin, nPins, i2cAddress))
|
||||
new EXSensorCAM(vpin, nPins, i2cAddress);
|
||||
}
|
||||
|
||||
static VPIN CAMBaseVpin;
|
||||
|
||||
private:
|
||||
// Constructor
|
||||
EXSensorCAM(VPIN firstVpin, int nPins, I2CAddress i2cAddress) {
|
||||
_firstVpin = firstVpin;
|
||||
// Number of pins cannot exceed 255 (1 byte) because of I2C message structure.
|
||||
if (nPins > 80) nPins = 80;
|
||||
_nPins = nPins;
|
||||
_I2CAddress = i2cAddress;
|
||||
addDevice(this);
|
||||
}
|
||||
//*************************
|
||||
void _begin() {
|
||||
uint8_t status;
|
||||
// Initialise EX-SensorCAM device
|
||||
I2CManager.begin();
|
||||
if (!I2CManager.exists(_I2CAddress)) {
|
||||
DIAG(F("EX-SensorCAM I2C:%s device not found"), _I2CAddress.toString());
|
||||
_deviceState = DEVSTATE_FAILED;
|
||||
return;
|
||||
}else {
|
||||
uint8_t commandBuffer[4]={EXIOINIT,(uint8_t)_nPins,(uint8_t)(_firstVpin & 0xFF),(uint8_t)(_firstVpin>>8)};
|
||||
status = I2CManager.read(_I2CAddress,_inputBuf,sizeof(_inputBuf),commandBuffer,sizeof(commandBuffer));
|
||||
//EXIOINIT needed to trigger and send firstVpin to CAM
|
||||
|
||||
if (status == I2C_STATUS_OK) {
|
||||
// Attempt to get version, non-blocking results in poor placement of response. Can be blocking here!
|
||||
commandBuffer[0] = '^'; //new version code
|
||||
|
||||
status = I2CManager.read(_I2CAddress, _inputBuf, sizeof(_inputBuf), commandBuffer, 1);
|
||||
// for ESP32 CAM, read again for good immediate response version data
|
||||
status = I2CManager.read(_I2CAddress, _inputBuf, sizeof(_inputBuf), commandBuffer, 1);
|
||||
|
||||
if (status == I2C_STATUS_OK) {
|
||||
_majorVer= _inputBuf[1]/10;
|
||||
_minorVer= _inputBuf[1]%10;
|
||||
_patchVer= _inputBuf[2];
|
||||
DIAG(F("EX-SensorCAM device found, I2C:%s, Version v%d.%d.%d"),
|
||||
_I2CAddress.toString(),_majorVer, _minorVer,_patchVer);
|
||||
}
|
||||
}
|
||||
if (status != I2C_STATUS_OK)
|
||||
reportError(status);
|
||||
}
|
||||
}
|
||||
//*************************
|
||||
// Digital input pin configuration, used to enable on EX-IOExpander device and set pullups if requested.
|
||||
// Configuration isn't done frequently so we can use blocking I2C calls here, and so buffers can
|
||||
// be allocated from the stack to reduce RAM allocation.
|
||||
bool _configure(VPIN vpin, ConfigTypeEnum configType, int paramCount, int params[]) override {
|
||||
(void)configType; (void)params; // unused
|
||||
if(_verPrint) DIAG(F("_configure() driver IO_EXSensorCAM v0.%d.%d vpin: %d "), driverVer/100,driverVer%100,vpin);
|
||||
_verPrint=false; //only give driver versions once
|
||||
if (paramCount != 1) return false;
|
||||
return true; //at least confirm that CAM is (always) configured (no vpin check!)
|
||||
}
|
||||
//*************************
|
||||
// Analogue input pin configuration, used to enable an EX-IOExpander device.
|
||||
int _configureAnalogIn(VPIN vpin) override {
|
||||
DIAG(F("_configureAnalogIn() IO_EXSensorCAM vpin %d"),vpin);
|
||||
return true; // NOTE: use of EXRAIL IFGTE() etc use "analog" reads.
|
||||
}
|
||||
//*************************
|
||||
// Main loop, collect both digital and "analog" pin states continuously (faster sensor/input reads)
|
||||
void _loop(unsigned long currentMicros) override {
|
||||
if (_deviceState == DEVSTATE_FAILED) return;
|
||||
// Request block is used for "analogue" (cmd. data) and digital reads from the sensorCAM, which
|
||||
// are performed on a cyclic basis. Writes are performed synchronously as and when requested.
|
||||
if (_readState != RDS_IDLE) { //expecting a return packet
|
||||
if (_i2crb.isBusy()) return; // If I2C operation still in progress, return
|
||||
uint8_t status = _i2crb.status;
|
||||
if (status == I2C_STATUS_OK) { // If device request ok, read input data
|
||||
//apparently the above checks do not guarantee a good packet! error rate about 1 pkt per 1000
|
||||
//there should be a packet in _CAMresponseBuff[32]
|
||||
if ((_CAMresponseBuff[0] & 0x60) >= 0x60) { //Buff[0] seems to have ascii cmd header (bit6 high) (o06)
|
||||
int error = processIncomingPkt( _CAMresponseBuff, _CAMresponseBuff[0]); // '~' 'i' 'm' 'n' 't' etc
|
||||
if (error>0) DIAG(F("CAM packet header(0x%x) not recognised"),_CAMresponseBuff[0]);
|
||||
}else{ // Header not valid - typically replaced by bank 0 data! To avoid any bad responses set S06 to 0
|
||||
// Versions of sensorCAM.h after v300 should return header for '@' of '`'(0x60) (not 0xE6)
|
||||
// followed by digitalInputStates sensor state array
|
||||
}
|
||||
}else reportError(status, false); // report i2c eror but don't go offline.
|
||||
_readState = RDS_IDLE;
|
||||
}
|
||||
|
||||
// If we're not doing anything now, check to see if a new state table transfer, or for 't' repeat, is due.
|
||||
if (_readState == RDS_IDLE) { //check if time for digitalRefresh
|
||||
if ( currentMicros - _lastDigitalRead > _digitalRefresh) {
|
||||
// Issue new read request for digital states.
|
||||
|
||||
_readCommandBuffer[0] = '@'; //start new read of digitalInputStates Table // non-blocking read
|
||||
I2CManager.read(_I2CAddress,_CAMresponseBuff, 32,_readCommandBuffer, 1, &_i2crb);
|
||||
_lastDigitalRead = currentMicros;
|
||||
_readState = RDS_DIGITAL;
|
||||
|
||||
}else{ //slip in a repeat <NT n> if pending
|
||||
if (currentMicros - _lasttStateRead > _tStateRefresh) // Delay for "analog" command repetitions
|
||||
if (_savedCmd[2]>1) { //repeat a 't' command
|
||||
for (int i=0;i<7;i++) _readCommandBuffer[i] =_savedCmd[i];
|
||||
int errors = ioESP32(_I2CAddress, _CAMresponseBuff, 32, _readCommandBuffer, 7);
|
||||
_lasttStateRead = currentMicros;
|
||||
_savedCmd[2] -= 1; //decrement repeats
|
||||
if (errors==0) return;
|
||||
DIAG(F("ioESP32 error %d header 0x%x"),errors,_CAMresponseBuff[0]);
|
||||
_readState = RDS_TSTATE; //this should stop further cmd requests until packet read (or timeout)
|
||||
}
|
||||
} //end repeat 't'
|
||||
}
|
||||
}
|
||||
//*************************
|
||||
// Obtain the bank of 8 sensors as an "analog" value
|
||||
// can be used to track the position through a sequential sensor bank
|
||||
int _readAnalogue(VPIN vpin) override {
|
||||
if (_deviceState == DEVSTATE_FAILED) return 0;
|
||||
return _digitalInputStates[(vpin - _firstVpin) / 8];
|
||||
}
|
||||
//*************************
|
||||
// Obtain the correct digital sensor input value
|
||||
int _read(VPIN vpin) override {
|
||||
if (_deviceState == DEVSTATE_FAILED) return 0;
|
||||
int pin = vpin - _firstVpin;
|
||||
return bitRead(_digitalInputStates[pin / 8], pin % 8);
|
||||
}
|
||||
//*************************
|
||||
// Write digital value.
|
||||
void _write(VPIN vpin, int value) override {
|
||||
DIAG(F("**_write() vpin %d = %d"),vpin,value);
|
||||
return ;
|
||||
}
|
||||
//*************************
|
||||
// i2cAddr of ESP32 CAM
|
||||
// rBuf buffer for return packet
|
||||
// inbytes number of bytes to request from CAM
|
||||
// outBuff holds outbytes to be sent to CAM
|
||||
int ioESP32(uint8_t i2cAddr,uint8_t *rBuf,int inbytes,uint8_t *outBuff,int outbytes) {
|
||||
uint8_t status = _i2crb.status;
|
||||
|
||||
while( _i2crb.status != I2C_STATUS_OK){status = _i2crb.status;} //wait until bus free
|
||||
|
||||
status = I2CManager.read(i2cAddr, rBuf, inbytes, outBuff, outbytes);
|
||||
|
||||
if (status != I2C_STATUS_OK){
|
||||
DIAG(F("EX-SensorCAM I2C:%s Error:%d %S"), _I2CAddress.toString(), status, I2CManager.getErrorMessage(status));
|
||||
reportError(status); return status;
|
||||
}
|
||||
return 0; // 0 for no error != 0 for error number.
|
||||
}
|
||||
//*************************
|
||||
//function to interpret packet from sensorCAM.ino
|
||||
//i2cAddr to identify CAM# (if # >1)
|
||||
//rBuf contains packet of up to 32 bytes usually with (ascii) cmd header in rBuf[0]
|
||||
//sensorCmd command header byte from CAM (in rBuf[0]?)
|
||||
int processIncomingPkt(uint8_t *rBuf,uint8_t sensorCmd) {
|
||||
//static uint8_t oldb0; //for debug only
|
||||
int k;
|
||||
int b;
|
||||
char str[] = "11111111";
|
||||
// if (sensorCmd <= '~') DIAG(F("processIncomingPkt %c %d %d %d"),rBuf[0],rBuf[1],rBuf[2],rBuf[3]);
|
||||
switch (sensorCmd){
|
||||
case '`': //response to request for digitalInputStates[] table '@'=>'`'
|
||||
memcpy(_digitalInputStates, rBuf+1, digitalBytesNeeded);
|
||||
// if ( _digitalInputStates[0]!=oldb0) { oldb0=_digitalInputStates[0]; //debug
|
||||
// for (k=0;k<5;k++) {Serial.print(" ");Serial.print(_digitalInputStates[k],HEX);}
|
||||
// }
|
||||
break;
|
||||
|
||||
case EXIORDY: //some commands give back acknowledgement only
|
||||
break;
|
||||
|
||||
case CAMERR: //cmd format error code from CAM
|
||||
DIAG(F("CAM cmd error 0xFE 0x%x"),rBuf[1]);
|
||||
break;
|
||||
|
||||
case '~': //information from '^' version request <N v[er]>
|
||||
DIAG(F("EX-SensorCAM device found, I2C:%s,CAM Version v%d.%d.%d vpins %u-%u"),
|
||||
_I2CAddress.toString(), rBuf[1]/10, rBuf[1]%10, rBuf[2],(int) _firstVpin, (int) _firstVpin +_nPins-1);
|
||||
DIAG(F("IO_EXSensorCAM driver v0.%d.%d vpin: %d "), driverVer/100,driverVer%100,_firstVpin);
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
DIAG(F("(f %%%%) frame header 'f' for bsNo %d/%d - showing Quarter sample (1 row) only"), rBuf[1]/8,rBuf[1]%8);
|
||||
SEND(&USB_SERIAL,F("<n row: %d Ref bytes: "),rBuf[2]);
|
||||
for(k=3;k<15;k++)
|
||||
SEND(&USB_SERIAL,F("%x%x%s"), rBuf[k]>>4, rBuf[k]&15, k%3==2 ? " " : " ");
|
||||
Serial.print(" latest grab: ");
|
||||
for(k=16;k<28;k++)
|
||||
SEND(&USB_SERIAL,F("%x%x%s"), rBuf[k]>>4, rBuf[k]&15, (k%3==0) ? " " : " ");
|
||||
Serial.print(" n>\n");
|
||||
break;
|
||||
|
||||
case 'i': //information from i%%
|
||||
k=256*rBuf[5]+rBuf[4];
|
||||
DIAG(F("(i%%%%[,$$]) Info: Sensor 0%o(%d) enabled:%d status:%d row=%d x=%d Twin=0%o pvtThreshold=%d A~%d")
|
||||
,rBuf[1],rBuf[1],rBuf[3],rBuf[2],rBuf[6],k,rBuf[7],rBuf[9],int(rBuf[8])*16);
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
DIAG(F("(m$[,##]) Min/max: $ frames min2flip (trip) %d, maxSensors 0%o, minSensors 0%o, nLED %d,"
|
||||
" threshold %d, TWOIMAGE_MAXBS 0%o"),rBuf[1],rBuf[3],rBuf[2],rBuf[4],rBuf[5],rBuf[6]);
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
DIAG(F("(n$[,##]) Nominate: $ nLED %d, ## minSensors 0%o (maxSensors 0%o threshold %d)")
|
||||
,rBuf[4],rBuf[2],rBuf[3],rBuf[5]);
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
b=rBuf[1]-2;
|
||||
if(b<4) { Serial.print("<n (p%%) Bank empty n>\n"); break; }
|
||||
SEND(&USB_SERIAL,F("<n (p%%) Bank: %d "),(0x7F&rBuf[2])/8);
|
||||
for (int j=2; j<b; j+=3)
|
||||
SEND(&USB_SERIAL,F(" S[%d%d]: r=%d x=%d"),0x7F&rBuf[j]/8,0x7F&rBuf[j]%8,rBuf[j+1],rBuf[j+2]+2*(rBuf[j]&0x80));
|
||||
Serial.print(" n>\n");
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
for (int i =0; i<8; i++) str[i] = ((rBuf[2] << i) & 0x80 ? '1' : '0');
|
||||
DIAG(F("(q $) Query bank %c ENABLED sensors(S%c7-%c0): %s "), rBuf[1], rBuf[1], rBuf[1], str);
|
||||
break;
|
||||
|
||||
case 't': //threshold etc. from t## //bad pkt if 't' FF's
|
||||
if(rBuf[1]==0xFF) {Serial.println("<n bad CAM 't' packet: 74 FF n>");_savedCmd[2] +=1; return 0;}
|
||||
SEND(&USB_SERIAL,F("<n (t[##[,%%%%]]) Threshold:%d sensor S00:-%d"),rBuf[1],min(rBuf[2]&0x7F,99));
|
||||
if(rBuf[2]>127) Serial.print("##* ");
|
||||
else{
|
||||
if(rBuf[2]>rBuf[1]) Serial.print("-?* ");
|
||||
else Serial.print("--* ");
|
||||
}
|
||||
for(int i=3;i<31;i+=2){
|
||||
uint8_t valu=rBuf[i]; //get bsn
|
||||
if(valu==80) break; //80 = end flag
|
||||
else{
|
||||
SEND(&USB_SERIAL,F("%d%d:"), (valu&0x7F)/8,(valu&0x7F)%8);
|
||||
if(valu>=128) Serial.print("?-");
|
||||
else {if(rBuf[i+1]>=128) Serial.print("oo");else Serial.print("--");}
|
||||
valu=rBuf[i+1];
|
||||
SEND(&USB_SERIAL,F("%d%s"),min(valu&0x7F,99),(valu<128) ? "--* ":"##* ");
|
||||
}
|
||||
}
|
||||
Serial.print(" >\n");
|
||||
break;
|
||||
|
||||
default: //header not a recognised cmd character
|
||||
DIAG(F("CAM packet header not valid (0x%x) (0x%x) (0x%x)"),rBuf[0],rBuf[1],rBuf[2]);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
//*************************
|
||||
// Write (analogue) 8bit (command) values. Write the parameters to the sensorCAM
|
||||
void _writeAnalogue(VPIN vpin, int param1, uint8_t camop, uint16_t param3) override {
|
||||
uint8_t outputBuffer[7];
|
||||
int errors=0;
|
||||
outputBuffer[0] = camop;
|
||||
int pin = vpin - _firstVpin;
|
||||
|
||||
if(camop >= 0x80) { //case "a" (4p) also (3p) e.g. <N 713 210 310>
|
||||
camop=param1; //put row (0-236) in expected place
|
||||
param1=param3; //put column in expected place
|
||||
outputBuffer[0] = 'A';
|
||||
pin = (pin/8)*10 + pin%8; //restore bsNo. as integer
|
||||
}
|
||||
if (_deviceState == DEVSTATE_FAILED) return;
|
||||
|
||||
outputBuffer[1] = pin; //vpin => bsn
|
||||
outputBuffer[2] = param1 & 0xFF;
|
||||
outputBuffer[3] = param1 >> 8;
|
||||
outputBuffer[4] = camop; //command code
|
||||
outputBuffer[5] = param3 & 0xFF;
|
||||
outputBuffer[6] = param3 >> 8;
|
||||
|
||||
int count=param1+1;
|
||||
if(camop=='Q'){
|
||||
if(param3<=10) {count=param3; camop='B';}
|
||||
//if(param1<10) outputBuffer[2] = param1*10;
|
||||
}
|
||||
if(camop=='B'){ //then 'b'(b%) cmd - can totally deal with that here. (but can't do b%,# (brightSF))
|
||||
if(param1>97) return;
|
||||
if(param1>9) param1 = param1/10; //accept a bsNo
|
||||
for(int bnk=param1;bnk<count;bnk++) {
|
||||
uint8_t b=_digitalInputStates[bnk];
|
||||
char str[] = "11111111";
|
||||
for (int i=0;i<8;i++) if(((b<<i)&0x80) == 0) str[i]='0';
|
||||
DIAG(F("(b $) Bank: %d activated byte: 0x%x%x (sensors S%d7->%d0) %s"), bnk,b>>4,b&15,bnk,bnk,str );
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (outputBuffer[4]=='T') { //then 't' cmd
|
||||
if(param1<31) { //repeated calls if param < 31
|
||||
//for (int i=0;i<7;i++) _savedCmd[i]=outputBuffer[i];
|
||||
memcpy( _savedCmd, outputBuffer, 7);
|
||||
}else _savedCmd[2] = 0; //no repeats if ##>30
|
||||
}else _savedCmd[2] = 0; //no repeats unless 't'
|
||||
|
||||
_lasttStateRead = micros(); //don't repeat until _tStateRefresh mSec
|
||||
|
||||
errors = ioESP32(_I2CAddress, _CAMresponseBuff, 32 , outputBuffer, 7); //send to esp32-CAM
|
||||
if (errors==0) return;
|
||||
else { // if (_CAMresponseBuff[0] != EXIORDY) //can't be sure what is inBuff[0] !
|
||||
DIAG(F("ioESP32 i2c error %d header 0x%x"),errors,_CAMresponseBuff[0]);
|
||||
}
|
||||
}
|
||||
//*************************
|
||||
// Display device information and status.
|
||||
void _display() override {
|
||||
DIAG(F("EX-SensorCAM I2C:%s v%d.%d.%d Vpins %u-%u %S"),
|
||||
_I2CAddress.toString(), _majorVer, _minorVer, _patchVer,
|
||||
(int)_firstVpin, (int)_firstVpin+_nPins-1,
|
||||
_deviceState == DEVSTATE_FAILED ? F("OFFLINE") : F(""));
|
||||
}
|
||||
//*************************
|
||||
// Helper function for error handling
|
||||
void reportError(uint8_t status, bool fail=true) {
|
||||
DIAG(F("EX-SensorCAM I2C:%s Error:%d (%S)"), _I2CAddress.toString(),
|
||||
status, I2CManager.getErrorMessage(status));
|
||||
if (fail) _deviceState = DEVSTATE_FAILED;
|
||||
}
|
||||
//*************************
|
||||
uint8_t _numDigitalPins = 80;
|
||||
size_t digitalBytesNeeded=10;
|
||||
uint8_t _CAMresponseBuff[34];
|
||||
|
||||
uint8_t _majorVer = 0;
|
||||
uint8_t _minorVer = 0;
|
||||
uint8_t _patchVer = 0;
|
||||
|
||||
uint8_t _digitalInputStates[10];
|
||||
I2CRB _i2crb;
|
||||
uint8_t _inputBuf[12];
|
||||
byte _outputBuffer[8];
|
||||
|
||||
bool _verPrint=true;
|
||||
|
||||
uint8_t _readCommandBuffer[8];
|
||||
uint8_t _savedCmd[8]; //for repeat 't' command
|
||||
//uint8_t _digitalPinBytes = 10; // Size of allocated memory buffer (may be longer than needed)
|
||||
|
||||
enum {RDS_IDLE, RDS_DIGITAL, RDS_TSTATE}; // Read operation states
|
||||
uint8_t _readState = RDS_IDLE;
|
||||
//uint8_t cmdBuffer[7]={0,0,0,0,0,0,0};
|
||||
unsigned long _lastDigitalRead = 0;
|
||||
unsigned long _lasttStateRead = 0;
|
||||
unsigned long _digitalRefresh = DIGITALREFRESH; // Delay refreshing digital inputs for 10ms
|
||||
const unsigned long _tStateRefresh = 120000UL; // Delay refreshing repeat "tState" inputs
|
||||
|
||||
enum {
|
||||
EXIOINIT = 0xE0, // Flag to initialise setup procedure
|
||||
EXIORDY = 0xE1, // Flag we have completed setup procedure, also for EX-IO to ACK setup
|
||||
CAMERR = 0xFE
|
||||
};
|
||||
};
|
||||
#endif
|
143
IO_EncoderThrottle.cpp
Normal file
143
IO_EncoderThrottle.cpp
Normal file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* © 2024, Chris Harlow. All rights reserved.
|
||||
*
|
||||
* This file is part of EX-CommandStation
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The IO_EncoderThrottle device driver uses a rotary encoder connected to vpins
|
||||
* to drive a loco.
|
||||
* Loco id is selected by writeAnalog.
|
||||
*/
|
||||
|
||||
#include "IODevice.h"
|
||||
#include "DIAG.h"
|
||||
#include "DCC.h"
|
||||
|
||||
const byte _DIR_CW = 0x10; // Clockwise step
|
||||
const byte _DIR_CCW = 0x20; // Counter-clockwise step
|
||||
|
||||
const byte transition_table[5][4]= {
|
||||
{0,1,3,0}, // 0: 00
|
||||
{1,1,1,2 | _DIR_CW}, // 1: 00->01
|
||||
{2,2,0,2}, // 2: 00->01->11
|
||||
{3,3,3,4 | _DIR_CCW}, // 3: 00->10
|
||||
{4,0,4,4} // 4: 00->10->11
|
||||
};
|
||||
|
||||
const byte _STATE_MASK = 0x07;
|
||||
const byte _DIR_MASK = 0x30;
|
||||
|
||||
|
||||
|
||||
void EncoderThrottle::create(VPIN firstVpin, int dtPin, int clkPin, int clickPin, byte notch) {
|
||||
if (checkNoOverlap(firstVpin)) new EncoderThrottle(firstVpin, dtPin,clkPin,clickPin,notch);
|
||||
}
|
||||
|
||||
|
||||
// Constructor
|
||||
EncoderThrottle::EncoderThrottle(VPIN firstVpin, int dtPin, int clkPin, int clickPin, byte notch){
|
||||
_firstVpin = firstVpin;
|
||||
_nPins = 1;
|
||||
_I2CAddress = 0;
|
||||
_dtPin=dtPin;
|
||||
_clkPin=clkPin;
|
||||
_clickPin=clickPin;
|
||||
_notch=notch;
|
||||
_locoid=0;
|
||||
_stopState=xrSTOP;
|
||||
_rocoState=0;
|
||||
_prevpinstate=4; // not 01..11
|
||||
IODevice::configureInput(dtPin,true);
|
||||
IODevice::configureInput(clkPin,true);
|
||||
IODevice::configureInput(clickPin,true);
|
||||
addDevice(this);
|
||||
_display();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void EncoderThrottle::_loop(unsigned long currentMicros) {
|
||||
if (_locoid==0) return; // not in use
|
||||
|
||||
// Clicking down on the roco, stops the loco and sets the direction as unknown.
|
||||
if (IODevice::read(_clickPin)) {
|
||||
if (_stopState==xrSTOP) return; // debounced multiple stops
|
||||
DCC::setThrottle(_locoid,1,DCC::getThrottleDirection(_locoid));
|
||||
_stopState=xrSTOP;
|
||||
DIAG(F("DRIVE %d STOP"),_locoid);
|
||||
return;
|
||||
}
|
||||
|
||||
// read roco pins and detect state change
|
||||
byte pinstate = (IODevice::read(_dtPin) << 1) | IODevice::read(_clkPin);
|
||||
if (pinstate==_prevpinstate) return;
|
||||
_prevpinstate=pinstate;
|
||||
|
||||
_rocoState = transition_table[_rocoState & _STATE_MASK][pinstate];
|
||||
if ((_rocoState & _DIR_MASK) == 0) return; // no value change
|
||||
|
||||
int change=(_rocoState & _DIR_CW)?+1:-1;
|
||||
// handle roco change -1 or +1 (clockwise)
|
||||
|
||||
if (_stopState==xrSTOP) {
|
||||
// first move after button press sets the direction. (clockwise=fwd)
|
||||
_stopState=change>0?xrFWD:xrREV;
|
||||
}
|
||||
|
||||
// when going fwd, clockwise increases speed.
|
||||
// but when reversing, anticlockwise increases speed.
|
||||
// This is similar to a center-zero pot control but with
|
||||
// the added safety that you cant panic-spin into the other
|
||||
// direction.
|
||||
if (_stopState==xrREV) change=-change;
|
||||
// manage limits
|
||||
int oldspeed=DCC::getThrottleSpeed(_locoid);
|
||||
if (oldspeed==1)oldspeed=0; // break out of estop
|
||||
int newspeed=change>0 ? (min((oldspeed+_notch),126)) : (max(0,(oldspeed-_notch)));
|
||||
if (newspeed==1) newspeed=0; // normal decelereated stop.
|
||||
if (oldspeed!=newspeed) {
|
||||
DIAG(F("DRIVE %d notch %S %d %S"),_locoid,
|
||||
change>0?F("UP"):F("DOWN"),_notch,
|
||||
_stopState==xrFWD?F("FWD"):F("REV"));
|
||||
DCC::setThrottle(_locoid,newspeed,_stopState==xrFWD);
|
||||
}
|
||||
}
|
||||
|
||||
// Selocoid as analog value to start drive
|
||||
// use <z vpin locoid [notch]>
|
||||
void EncoderThrottle::_writeAnalogue(VPIN vpin, int value, uint8_t param1, uint16_t param2) {
|
||||
(void) param2;
|
||||
_locoid=value;
|
||||
if (param1>0) _notch=param1;
|
||||
_rocoState=0;
|
||||
|
||||
// If loco is moving, we inherit direction from it.
|
||||
_stopState=xrSTOP;
|
||||
if (_locoid>0) {
|
||||
auto speedbyte=DCC::getThrottleSpeedByte(_locoid);
|
||||
if ((speedbyte & 0x7f) >1) {
|
||||
// loco is moving
|
||||
_stopState= (speedbyte & 0x80)?xrFWD:xrREV;
|
||||
}
|
||||
}
|
||||
_display();
|
||||
}
|
||||
|
||||
|
||||
void EncoderThrottle::_display() {
|
||||
DIAG(F("DRIVE vpin %d loco %d notch %d"),_firstVpin,_locoid,_notch);
|
||||
}
|
53
IO_EncoderThrottle.h
Normal file
53
IO_EncoderThrottle.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* © 2024, Chris Harlow. All rights reserved.
|
||||
*
|
||||
* This file is part of EX-CommandStation
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The IO_EncoderThrottle device driver uses a rotary encoder connected to vpins
|
||||
* to drive a loco.
|
||||
* Loco id is selected by writeAnalog.
|
||||
*/
|
||||
|
||||
#ifndef IO_EncoderThrottle_H
|
||||
#define IO_EncoderThrottle_H
|
||||
#include "IODevice.h"
|
||||
|
||||
class EncoderThrottle : public IODevice {
|
||||
public:
|
||||
|
||||
static void create(VPIN firstVpin, int dtPin, int clkPin, int clickPin, byte notch=10);
|
||||
|
||||
private:
|
||||
int _dtPin,_clkPin,_clickPin, _locoid, _notch,_prevpinstate;
|
||||
enum {xrSTOP,xrFWD,xrREV} _stopState;
|
||||
byte _rocoState;
|
||||
|
||||
// Constructor
|
||||
EncoderThrottle(VPIN firstVpin, int dtPin, int clkPin, int clickPin, byte notch);
|
||||
|
||||
void _loop(unsigned long currentMicros) override ;
|
||||
|
||||
// Selocoid as analog value to start drive
|
||||
// use <z vpin locoid [notch]>
|
||||
void _writeAnalogue(VPIN vpin, int value, uint8_t param1, uint16_t param2) override;
|
||||
|
||||
void _display() override ;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -162,4 +162,4 @@ protected:
|
||||
|
||||
};
|
||||
|
||||
#endif // IO_EXAMPLESERIAL_H
|
||||
#endif // IO_EXAMPLESERIAL_H
|
||||
|
@ -262,4 +262,4 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#endif // IO_HALDisplay_H
|
||||
#endif // IO_HALDisplay_H
|
||||
|
@ -98,4 +98,4 @@ private:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -108,4 +108,4 @@ private:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
334
IO_NeoPixel.h
Normal file
334
IO_NeoPixel.h
Normal file
@ -0,0 +1,334 @@
|
||||
/*
|
||||
* © 2024, Chris Harlow. All rights reserved.
|
||||
*
|
||||
* This file is part of EX-CommandStation
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The IO_NEOPIXEL.h device driver integrates with one or more Adafruit neopixel drivers.
|
||||
* This device driver will configure the device on startup, along with
|
||||
* interacting with the device for all input/output duties.
|
||||
*
|
||||
* To create NEOPIXEL devices, these are defined in myAutomation.h:
|
||||
* (Note the device driver is included by default)
|
||||
*
|
||||
* HAL(NEOPIXEL,first vpin, number of pixels,mode, i2c address)
|
||||
* e.g. HAL(NEOPIXEL,1000,64,NEO_RGB,0x60)
|
||||
* This gives each pixel in the chain an individual vpin
|
||||
* The number of pixels must match the physical pixels in the chain.
|
||||
*
|
||||
* This driver maintains a colour (rgb value in 5,5,5 bits only) plus an ON bit.
|
||||
* This can be written/read with an analog write/read call.
|
||||
* The ON bit can be set on and off with a digital write. This allows for
|
||||
* a pixel to be preset a colour and then turned on and off like any other light.
|
||||
*/
|
||||
|
||||
#ifndef IO_EX_NeoPixel_H
|
||||
#define IO_EX_NeoPixel_H
|
||||
|
||||
#include "IODevice.h"
|
||||
#include "I2CManager.h"
|
||||
#include "DIAG.h"
|
||||
#include "FSH.h"
|
||||
|
||||
|
||||
// The following macros to define the Neopixel String type
|
||||
// have been copied from the Adafruit Seesaw Library under the
|
||||
// terms of the GPL.
|
||||
// Credit to: https://github.com/adafruit/Adafruit_Seesaw
|
||||
|
||||
// The order of primary colors in the NeoPixel data stream can vary
|
||||
// among device types, manufacturers and even different revisions of
|
||||
// the same item. The third parameter to the seesaw_NeoPixel
|
||||
// constructor encodes the per-pixel byte offsets of the red, green
|
||||
// and blue primaries (plus white, if present) in the data stream --
|
||||
// the following #defines provide an easier-to-use named version for
|
||||
// each permutation. e.g. NEO_GRB indicates a NeoPixel-compatible
|
||||
// device expecting three bytes per pixel, with the first byte
|
||||
// containing the green value, second containing red and third
|
||||
// containing blue. The in-memory representation of a chain of
|
||||
// NeoPixels is the same as the data-stream order; no re-ordering of
|
||||
// bytes is required when issuing data to the chain.
|
||||
|
||||
// Bits 5,4 of this value are the offset (0-3) from the first byte of
|
||||
// a pixel to the location of the red color byte. Bits 3,2 are the
|
||||
// green offset and 1,0 are the blue offset. If it is an RGBW-type
|
||||
// device (supporting a white primary in addition to R,G,B), bits 7,6
|
||||
// are the offset to the white byte...otherwise, bits 7,6 are set to
|
||||
// the same value as 5,4 (red) to indicate an RGB (not RGBW) device.
|
||||
// i.e. binary representation:
|
||||
// 0bWWRRGGBB for RGBW devices
|
||||
// 0bRRRRGGBB for RGB
|
||||
|
||||
// RGB NeoPixel permutations; white and red offsets are always same
|
||||
// Offset: W R G B
|
||||
#define NEO_RGB ((0 << 6) | (0 << 4) | (1 << 2) | (2))
|
||||
#define NEO_RBG ((0 << 6) | (0 << 4) | (2 << 2) | (1))
|
||||
#define NEO_GRB ((1 << 6) | (1 << 4) | (0 << 2) | (2))
|
||||
#define NEO_GBR ((2 << 6) | (2 << 4) | (0 << 2) | (1))
|
||||
#define NEO_BRG ((1 << 6) | (1 << 4) | (2 << 2) | (0))
|
||||
#define NEO_BGR ((2 << 6) | (2 << 4) | (1 << 2) | (0))
|
||||
|
||||
// RGBW NeoPixel permutations; all 4 offsets are distinct
|
||||
// Offset: W R G B
|
||||
#define NEO_WRGB ((0 << 6) | (1 << 4) | (2 << 2) | (3))
|
||||
#define NEO_WRBG ((0 << 6) | (1 << 4) | (3 << 2) | (2))
|
||||
#define NEO_WGRB ((0 << 6) | (2 << 4) | (1 << 2) | (3))
|
||||
#define NEO_WGBR ((0 << 6) | (3 << 4) | (1 << 2) | (2))
|
||||
#define NEO_WBRG ((0 << 6) | (2 << 4) | (3 << 2) | (1))
|
||||
#define NEO_WBGR ((0 << 6) | (3 << 4) | (2 << 2) | (1))
|
||||
|
||||
#define NEO_RWGB ((1 << 6) | (0 << 4) | (2 << 2) | (3))
|
||||
#define NEO_RWBG ((1 << 6) | (0 << 4) | (3 << 2) | (2))
|
||||
#define NEO_RGWB ((2 << 6) | (0 << 4) | (1 << 2) | (3))
|
||||
#define NEO_RGBW ((3 << 6) | (0 << 4) | (1 << 2) | (2))
|
||||
#define NEO_RBWG ((2 << 6) | (0 << 4) | (3 << 2) | (1))
|
||||
#define NEO_RBGW ((3 << 6) | (0 << 4) | (2 << 2) | (1))
|
||||
|
||||
#define NEO_GWRB ((1 << 6) | (2 << 4) | (0 << 2) | (3))
|
||||
#define NEO_GWBR ((1 << 6) | (3 << 4) | (0 << 2) | (2))
|
||||
#define NEO_GRWB ((2 << 6) | (1 << 4) | (0 << 2) | (3))
|
||||
#define NEO_GRBW ((3 << 6) | (1 << 4) | (0 << 2) | (2))
|
||||
#define NEO_GBWR ((2 << 6) | (3 << 4) | (0 << 2) | (1))
|
||||
#define NEO_GBRW ((3 << 6) | (2 << 4) | (0 << 2) | (1))
|
||||
|
||||
#define NEO_BWRG ((1 << 6) | (2 << 4) | (3 << 2) | (0))
|
||||
#define NEO_BWGR ((1 << 6) | (3 << 4) | (2 << 2) | (0))
|
||||
#define NEO_BRWG ((2 << 6) | (1 << 4) | (3 << 2) | (0))
|
||||
#define NEO_BRGW ((3 << 6) | (1 << 4) | (2 << 2) | (0))
|
||||
#define NEO_BGWR ((2 << 6) | (3 << 4) | (1 << 2) | (0))
|
||||
#define NEO_BGRW ((3 << 6) | (2 << 4) | (1 << 2) | (0))
|
||||
|
||||
// If 400 KHz support is enabled, the third parameter to the constructor
|
||||
// requires a 16-bit value (in order to select 400 vs 800 KHz speed).
|
||||
// If only 800 KHz is enabled (as is default on ATtiny), an 8-bit value
|
||||
// is sufficient to encode pixel color order, saving some space.
|
||||
|
||||
#define NEO_KHZ800 0x0000 // 800 KHz datastream
|
||||
#define NEO_KHZ400 0x0100 // 400 KHz datastream
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* IODevice subclass for NeoPixel.
|
||||
*/
|
||||
|
||||
class NeoPixel : public IODevice {
|
||||
public:
|
||||
|
||||
static void create(VPIN vpin, int nPins, uint16_t mode=(NEO_GRB | NEO_KHZ800), I2CAddress i2cAddress=0x60) {
|
||||
if (checkNoOverlap(vpin, nPins, i2cAddress)) new NeoPixel(vpin, nPins, mode, i2cAddress);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static const byte SEESAW_NEOPIXEL_BASE=0x0E;
|
||||
static const byte SEESAW_NEOPIXEL_STATUS = 0x00;
|
||||
static const byte SEESAW_NEOPIXEL_PIN = 0x01;
|
||||
static const byte SEESAW_NEOPIXEL_SPEED = 0x02;
|
||||
static const byte SEESAW_NEOPIXEL_BUF_LENGTH = 0x03;
|
||||
static const byte SEESAW_NEOPIXEL_BUF=0x04;
|
||||
static const byte SEESAW_NEOPIXEL_SHOW=0x05;
|
||||
|
||||
// all adafruit examples say this pin. Presumably its hard wired
|
||||
// in the adapter anyway.
|
||||
static const byte SEESAW_PIN15 = 15;
|
||||
|
||||
// Constructor
|
||||
NeoPixel(VPIN firstVpin, int nPins, uint16_t mode, I2CAddress i2cAddress) {
|
||||
_firstVpin = firstVpin;
|
||||
_nPins=nPins;
|
||||
_I2CAddress = i2cAddress;
|
||||
|
||||
// calculate the offsets into the seesaw buffer for each colour depending
|
||||
// on the pixel strip type passed in mode.
|
||||
|
||||
_redOffset=4+(mode >> 4 & 0x03);
|
||||
_greenOffset=4+(mode >> 2 & 0x03);
|
||||
_blueOffset=4+(mode & 0x03);
|
||||
if (4+(mode >>6 & 0x03) == _redOffset) _bytesPerPixel=3;
|
||||
else _bytesPerPixel=4; // string has a white byte.
|
||||
|
||||
_kHz800=(mode & NEO_KHZ400)==0;
|
||||
_showPendimg=false;
|
||||
|
||||
// Each pixel requires 3 bytes RGB memory.
|
||||
// Although the driver device can remember this, it cant do off/on without
|
||||
// forgetting what the on colour was!
|
||||
pixelBuffer=(RGB *) malloc(_nPins*sizeof(RGB));
|
||||
stateBuffer=(byte *) calloc((_nPins+7)/8,sizeof(byte)); // all pixels off
|
||||
if (pixelBuffer==nullptr || stateBuffer==nullptr) {
|
||||
DIAG(F("NeoPixel I2C:%s not enough RAM"), _I2CAddress.toString());
|
||||
return;
|
||||
}
|
||||
// preset all pins to white so a digital on/off will do something even if no colour set.
|
||||
memset(pixelBuffer,0xFF,_nPins*sizeof(RGB));
|
||||
addDevice(this);
|
||||
}
|
||||
|
||||
void _begin() {
|
||||
|
||||
// Initialise Neopixel device
|
||||
I2CManager.begin();
|
||||
if (!I2CManager.exists(_I2CAddress)) {
|
||||
DIAG(F("NeoPixel I2C:%s device not found"), _I2CAddress.toString());
|
||||
_deviceState = DEVSTATE_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
byte speedBuffer[]={SEESAW_NEOPIXEL_BASE, SEESAW_NEOPIXEL_SPEED,_kHz800};
|
||||
I2CManager.write(_I2CAddress, speedBuffer, sizeof(speedBuffer));
|
||||
|
||||
// In the driver there are 3 of 4 byts per pixel
|
||||
auto numBytes=_bytesPerPixel * _nPins;
|
||||
byte setbuffer[] = {SEESAW_NEOPIXEL_BASE, SEESAW_NEOPIXEL_BUF_LENGTH,
|
||||
(byte)(numBytes >> 8), (byte)(numBytes & 0xFF)};
|
||||
I2CManager.write(_I2CAddress, setbuffer, sizeof(setbuffer));
|
||||
|
||||
const byte pinbuffer[] = {SEESAW_NEOPIXEL_BASE, SEESAW_NEOPIXEL_PIN,SEESAW_PIN15};
|
||||
I2CManager.write(_I2CAddress, pinbuffer, sizeof(pinbuffer));
|
||||
|
||||
for (auto pin=0;pin<_nPins;pin++) transmit(pin);
|
||||
_display();
|
||||
}
|
||||
|
||||
// loop called by HAL supervisor
|
||||
void _loop(unsigned long currentMicros) override {
|
||||
(void)currentMicros;
|
||||
if (!_showPendimg) return;
|
||||
byte showBuffer[]={SEESAW_NEOPIXEL_BASE,SEESAW_NEOPIXEL_SHOW};
|
||||
I2CManager.write(_I2CAddress,showBuffer,sizeof(showBuffer));
|
||||
_showPendimg=false;
|
||||
}
|
||||
|
||||
|
||||
// read back pixel on/off
|
||||
int _read(VPIN vpin) override {
|
||||
if (_deviceState == DEVSTATE_FAILED) return 0;
|
||||
return isPixelOn(vpin-_firstVpin);
|
||||
}
|
||||
|
||||
// Write digital value. Sets pixel on or off
|
||||
void _write(VPIN vpin, int value) override {
|
||||
if (_deviceState == DEVSTATE_FAILED) return;
|
||||
auto pixel=vpin-_firstVpin;
|
||||
if (value) {
|
||||
if (isPixelOn(pixel)) return;
|
||||
setPixelOn(pixel);
|
||||
}
|
||||
else { // set off
|
||||
if (!isPixelOn(pixel)) return;
|
||||
setPixelOff(pixel);
|
||||
}
|
||||
transmit(pixel);
|
||||
}
|
||||
|
||||
VPIN _writeRange(VPIN vpin,int value, int count) {
|
||||
// using write range cuts out the constant vpin to driver lookup so
|
||||
// we can update multiple pixels much faster.
|
||||
VPIN nextVpin=vpin + (count>_nPins ? _nPins : count);
|
||||
if (_deviceState != DEVSTATE_FAILED) while(vpin<nextVpin) {
|
||||
_write(vpin,value);
|
||||
vpin++;
|
||||
}
|
||||
return nextVpin; // next pin we cant
|
||||
}
|
||||
// Write analogue value.
|
||||
// The convoluted parameter mashing here is to allow passing the RGB and on/off
|
||||
// information through the generic HAL _writeAnalog interface which was originally
|
||||
// designed for servos and short integers
|
||||
void _writeAnalogue(VPIN vpin, int colour_RG, uint8_t onoff, uint16_t colour_B) override {
|
||||
if (_deviceState == DEVSTATE_FAILED) return;
|
||||
RGB newColour={(byte)((colour_RG>>8) & 0xFF), (byte)(colour_RG & 0xFF), (byte)(colour_B & 0xFF)};
|
||||
auto pixel=vpin-_firstVpin;
|
||||
if (pixelBuffer[pixel]==newColour && isPixelOn(pixel)==(bool)onoff) return; // no change
|
||||
|
||||
if (onoff) setPixelOn(pixel); else setPixelOff(pixel);
|
||||
pixelBuffer[pixel]=newColour;
|
||||
transmit(pixel);
|
||||
}
|
||||
VPIN _writeAnalogueRange(VPIN vpin, int colour_RG, uint8_t onoff, uint16_t colour_B, int count) override {
|
||||
// using write range cuts out the constant vpin to driver lookup so
|
||||
VPIN nextVpin=vpin + (count>_nPins ? _nPins : count);
|
||||
if (_deviceState != DEVSTATE_FAILED) while(vpin<nextVpin) {
|
||||
_writeAnalogue(vpin,colour_RG, onoff,colour_B);
|
||||
vpin++;
|
||||
}
|
||||
return nextVpin; // next pin we cant
|
||||
}
|
||||
|
||||
// Display device information and status.
|
||||
void _display() override {
|
||||
DIAG(F("NeoPixel I2C:%s Vpins %u-%u %S"),
|
||||
_I2CAddress.toString(),
|
||||
(int)_firstVpin, (int)_firstVpin+_nPins-1,
|
||||
_deviceState == DEVSTATE_FAILED ? F("OFFLINE") : F(""));
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool isPixelOn(int16_t pixel) {return stateBuffer[pixel/8] & (0x80>>(pixel%8));}
|
||||
void setPixelOn(int16_t pixel) {stateBuffer[pixel/8] |= (0x80>>(pixel%8));}
|
||||
void setPixelOff(int16_t pixel) {stateBuffer[pixel/8] &= ~(0x80>>(pixel%8));}
|
||||
|
||||
// Helper function for error handling
|
||||
void reportError(uint8_t status, bool fail=true) {
|
||||
DIAG(F("NeoPixel I2C:%s Error:%d (%S)"), _I2CAddress.toString(),
|
||||
status, I2CManager.getErrorMessage(status));
|
||||
if (fail)
|
||||
_deviceState = DEVSTATE_FAILED;
|
||||
}
|
||||
|
||||
|
||||
void transmit(uint16_t pixel) {
|
||||
byte buffer[]={SEESAW_NEOPIXEL_BASE,SEESAW_NEOPIXEL_BUF,0x00,0x00,0x00,0x00,0x00};
|
||||
uint16_t offset= pixel * _bytesPerPixel;
|
||||
buffer[2]=(byte)(offset>>8);
|
||||
buffer[3]=(byte)(offset & 0xFF);
|
||||
|
||||
if (isPixelOn(pixel)) {
|
||||
auto colour=pixelBuffer[pixel];
|
||||
buffer[_redOffset]=colour.red;
|
||||
buffer[_greenOffset]=colour.green;
|
||||
buffer[_blueOffset]=colour.blue;
|
||||
} // else leave buffer black (in buffer preset to zeros above)
|
||||
|
||||
// Transmit pixel to driver
|
||||
I2CManager.write(_I2CAddress,buffer,4 +_bytesPerPixel);
|
||||
_showPendimg=true;
|
||||
|
||||
}
|
||||
struct RGB {
|
||||
byte red;
|
||||
byte green;
|
||||
byte blue;
|
||||
bool operator==(const RGB& other) const {
|
||||
return red == other.red && green == other.green && blue == other.blue;
|
||||
}
|
||||
};
|
||||
|
||||
RGB* pixelBuffer = nullptr;
|
||||
byte* stateBuffer = nullptr; // 1 bit per pixel
|
||||
bool _showPendimg;
|
||||
|
||||
// mapping of RGB onto pixel buffer for seesaw.
|
||||
byte _bytesPerPixel;
|
||||
byte _redOffset;
|
||||
byte _greenOffset;
|
||||
byte _blueOffset;
|
||||
bool _kHz800;
|
||||
};
|
||||
|
||||
#endif
|
@ -167,4 +167,4 @@ private:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -101,4 +101,4 @@ private:
|
||||
uint8_t inputBuffer[1];
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -106,4 +106,4 @@ private:
|
||||
uint8_t inputBuffer[2];
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -30,4 +30,3 @@
|
||||
//
|
||||
const uint8_t FLASH Servo::_bounceProfile[30] =
|
||||
{0,2,3,7,13,33,50,83,100,83,75,70,65,60,60,65,74,84,100,83,75,70,70,72,75,80,87,92,97,100};
|
||||
|
||||
|
@ -295,4 +295,4 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
371
IO_TCA8418.h
Normal file
371
IO_TCA8418.h
Normal file
@ -0,0 +1,371 @@
|
||||
/*
|
||||
* © 2023-2024, Paul M. Antoine
|
||||
* © 2021, Neil McKechnie. All rights reserved.
|
||||
*
|
||||
* This file is part of DCC-EX API
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef io_tca8418_h
|
||||
#define io_tca8418_h
|
||||
|
||||
#include "IODevice.h"
|
||||
#include "I2CManager.h"
|
||||
#include "DIAG.h"
|
||||
#include "FSH.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
* IODevice subclass for TCA8418 80-key keypad encoder, which we'll treat as 80 available VPINs where
|
||||
* key down == 1 and key up == 0 by configuring just as an 8x10 keyboard matrix. Users can opt to use
|
||||
* up to all 80 of the available VPINs for now, allowing memory to be saved if not all events are required.
|
||||
*
|
||||
* The datasheet says:
|
||||
*
|
||||
* The TCA8418 can be configured to support many different configurations of keypad setups.
|
||||
* All 18 GPIOs for the rows and columns can be used to support up to 80 keys in an 8x10 key pad
|
||||
* array. Another option is that all 18 GPIOs be used for GPIs to read 18 buttons which are
|
||||
* not connected in an array. Any combination in between is also acceptable (for example, a
|
||||
* 3x4 keypad matrix and using the remaining 11 GPIOs as a combination of inputs and outputs).
|
||||
*
|
||||
* With an 8x10 key event matrix, the events are numbered as such:
|
||||
*
|
||||
* C0 C1 C2 C3 C4 C5 C6 C7 C8 C9
|
||||
* ========================================
|
||||
* R0| 0 1 2 3 4 5 6 7 8 9
|
||||
* R1| 10 11 12 13 14 15 16 17 18 19
|
||||
* R2| 20 21 22 23 24 25 26 27 28 29
|
||||
* R3| 30 31 32 33 34 35 36 37 38 39
|
||||
* R4| 40 41 42 43 44 45 46 47 48 49
|
||||
* R5| 50 51 52 53 54 55 56 57 58 59
|
||||
* R6| 60 61 62 63 64 65 66 67 68 69
|
||||
* R7| 70 71 72 73 74 75 76 77 78 79
|
||||
*
|
||||
* So if you start with VPIN 300, R0/C0 will be 300, and R7/C9 will be 379.
|
||||
*
|
||||
* HAL declaration for myAutomation.h is:
|
||||
* HAL(TCA8418, firstVpin, numPins, I2CAddress, interruptPin)
|
||||
*
|
||||
* Where numPins can be 1-80, and interruptPin can be any spare Arduino pin.
|
||||
*
|
||||
* Configure using the following on the main I2C bus:
|
||||
* HAL(TCA8418, 300, 80, 0x34)
|
||||
*
|
||||
* Use something like this on a multiplexor, and with up to 8 of the 8-way multiplexors you could have 64 different TCA8418 boards:
|
||||
* HAL(TCA8418, 400, 80, {SubBus_1, 0x34})
|
||||
*
|
||||
* And if needing an Interrupt pin to speed up operations:
|
||||
* HAL(TCA8418, 300, 80, 0x34, D21)
|
||||
*
|
||||
* Note that using an interrupt pin speeds up button press acquisition considerably (less than a millisecond vs 10-100),
|
||||
* but even with interrupts enabled the code presently checks every 100ms in case the interrupt pin becomes disconnected.
|
||||
* Use any available Arduino pin for interrupt monitoring.
|
||||
*/
|
||||
|
||||
class TCA8418 : public IODevice {
|
||||
public:
|
||||
|
||||
static void create(VPIN firstVpin, uint8_t nPins, I2CAddress i2cAddress, int interruptPin=-1) {
|
||||
if (checkNoOverlap(firstVpin, nPins, i2cAddress))
|
||||
new TCA8418(firstVpin, (nPins = (nPins > 80) ? 80 : nPins), i2cAddress, interruptPin);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
uint8_t* _digitalInputStates = NULL; // Array of pin states
|
||||
uint8_t _digitalPinBytes = 0; // Number of bytes in pin state array
|
||||
|
||||
uint8_t _numKeyEvents = 0; // Number of outsanding key events waiting for us
|
||||
|
||||
unsigned long _lastEventRead = 0;
|
||||
unsigned long _eventRefresh = 10000UL; // Delay refreshing events for 10ms
|
||||
const unsigned long _eventRefreshSlow = 100000UL; // Delay refreshing events for 100ms
|
||||
bool _gpioInterruptsEnabled = false;
|
||||
|
||||
uint8_t _inputBuffer[1];
|
||||
uint8_t _commandBuffer[1];
|
||||
I2CRB _i2crb;
|
||||
|
||||
enum {RDS_IDLE, RDS_EVENT, RDS_KEYCODE}; // Read operation states
|
||||
uint8_t _readState = RDS_IDLE;
|
||||
|
||||
// Constructor
|
||||
TCA8418(VPIN firstVpin, uint8_t nPins, I2CAddress i2cAddress, int interruptPin=-1) {
|
||||
if (nPins > 0)
|
||||
{
|
||||
_firstVpin = firstVpin;
|
||||
_nPins = nPins;
|
||||
_I2CAddress = i2cAddress;
|
||||
_gpioInterruptPin = interruptPin;
|
||||
addDevice(this);
|
||||
}
|
||||
}
|
||||
|
||||
void _begin() {
|
||||
|
||||
I2CManager.begin();
|
||||
|
||||
if (I2CManager.exists(_I2CAddress)) {
|
||||
// Default all GPIO pins to INPUT
|
||||
I2CManager.write(_I2CAddress, 2, REG_GPIO_DIR_1, 0x00);
|
||||
I2CManager.write(_I2CAddress, 2, REG_GPIO_DIR_2, 0x00);
|
||||
I2CManager.write(_I2CAddress, 2, REG_GPIO_DIR_3, 0x00);
|
||||
|
||||
// Remove all GPIO pins from events
|
||||
I2CManager.write(_I2CAddress, 2, REG_GPI_EM_1, 0x00);
|
||||
I2CManager.write(_I2CAddress, 2, REG_GPI_EM_2, 0x00);
|
||||
I2CManager.write(_I2CAddress, 2, REG_GPI_EM_3, 0x00);
|
||||
|
||||
// Set all pins to FALLING interrupts
|
||||
I2CManager.write(_I2CAddress, 2, REG_GPIO_INT_LVL_1, 0x00);
|
||||
I2CManager.write(_I2CAddress, 2, REG_GPIO_INT_LVL_2, 0x00);
|
||||
I2CManager.write(_I2CAddress, 2, REG_GPIO_INT_LVL_3, 0x00);
|
||||
|
||||
// Remove all GPIO pins from interrupts
|
||||
I2CManager.write(_I2CAddress, 2, REG_GPIO_INT_EN_1, 0x00);
|
||||
I2CManager.write(_I2CAddress, 2, REG_GPIO_INT_EN_2, 0x00);
|
||||
I2CManager.write(_I2CAddress, 2, REG_GPIO_INT_EN_3, 0x00);
|
||||
|
||||
// Set up an 8 x 10 matrix by writing 0xFF to all the row and column configs
|
||||
// Row config is maximum of 8, and in REG_KP_GPIO_1
|
||||
I2CManager.write(_I2CAddress, 2, REG_KP_GPIO_1, 0xFF);
|
||||
// Column config is maximum of 10, lower 8 bits in REG_KP_GPIO_2, upper in REG_KP_GPIO_3
|
||||
// Set first 8 columns
|
||||
I2CManager.write(_I2CAddress, 2, REG_KP_GPIO_2, 0xFF);
|
||||
// Turn on cols 9/10
|
||||
I2CManager.write(_I2CAddress, 2, REG_KP_GPIO_3, 0x03);
|
||||
|
||||
// // Set all pins to Enable Debounce
|
||||
I2CManager.write(_I2CAddress, 2, REG_DEBOUNCE_DIS_1, 0x00);
|
||||
I2CManager.write(_I2CAddress, 2, REG_DEBOUNCE_DIS_2, 0x00);
|
||||
I2CManager.write(_I2CAddress, 2, REG_DEBOUNCE_DIS_3, 0x00);
|
||||
|
||||
// Let's assume an 8x10 matrix for now, and configure
|
||||
_digitalPinBytes = (_nPins + 7) / 8;
|
||||
if ((_digitalInputStates = (byte *)calloc(_digitalPinBytes, 1)) == NULL) {
|
||||
DIAG(F("TCA8418 I2C: Unable to alloc %d bytes"), _digitalPinBytes);
|
||||
return;
|
||||
}
|
||||
|
||||
// Configure pin used for GPIO extender notification of change (if allocated)
|
||||
// and configure TCA8418 to produce key event interrupts
|
||||
if (_gpioInterruptPin >= 0) {
|
||||
DIAG(F("TCA8418 I2C: interrupt pin configured on %d"), _gpioInterruptPin);
|
||||
_gpioInterruptsEnabled = true;
|
||||
_eventRefresh = _eventRefreshSlow; // Switch to slower manual refreshes in case the INT pin isn't connected!
|
||||
pinMode(_gpioInterruptPin, INPUT_PULLUP);
|
||||
I2CManager.write(_I2CAddress, 2, REG_CFG, REG_CFG_KE_IEN);
|
||||
// Clear any pending interrupts
|
||||
I2CManager.write(_I2CAddress, 2, REG_INT_STAT, REG_STAT_K_INT);
|
||||
}
|
||||
|
||||
#ifdef DIAG_IO
|
||||
_display();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int _read(VPIN vpin) override {
|
||||
if (_deviceState == DEVSTATE_FAILED)
|
||||
return 0;
|
||||
int pin = vpin - _firstVpin;
|
||||
bool result = _digitalInputStates[pin / 8] & (1 << (pin % 8));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Main loop, collect both digital and analogue pin states continuously (faster sensor/input reads)
|
||||
void _loop(unsigned long currentMicros) override {
|
||||
if (_deviceState == DEVSTATE_FAILED) return; // If device failed, return
|
||||
|
||||
// Request block is used for key event reads from the TCA8418, which are performed
|
||||
// on a cyclic basis.
|
||||
|
||||
if (_readState != RDS_IDLE) {
|
||||
if (_i2crb.isBusy()) return; // If I2C operation still in progress, return
|
||||
|
||||
uint8_t status = _i2crb.status;
|
||||
if (status == I2C_STATUS_OK) { // If device request ok, read input data
|
||||
|
||||
// First check if we have any key events waiting
|
||||
if (_readState == RDS_EVENT) {
|
||||
if ((_numKeyEvents = (_inputBuffer[0] & 0x0F)) != 0) {
|
||||
// We could read each key event waiting in a synchronous loop, which may prove preferable
|
||||
// but for now, schedule an async read of the first key event in the queue
|
||||
_commandBuffer[0] = REG_KEY_EVENT_A;
|
||||
I2CManager.read(_I2CAddress, _inputBuffer, 1, _commandBuffer, 1, &_i2crb); // non-blocking read
|
||||
_readState = RDS_KEYCODE; // Shift to reading key events!
|
||||
}
|
||||
else // We found no key events waiting, return to IDLE
|
||||
_readState = RDS_IDLE;
|
||||
}
|
||||
else {
|
||||
// RDS_KEYCODE
|
||||
uint8_t key = _inputBuffer[0] & 0x7F;
|
||||
bool keyDown = _inputBuffer[0] & 0x80;
|
||||
// Check for just keypad events
|
||||
key--; // R0/C0 is key #1, so subtract 1 to create an array offset
|
||||
// We only want to record key events we're configured for, as we have calloc'd an
|
||||
// appropriately sized _digitalInputStates array!
|
||||
if (key < _nPins) {
|
||||
if (keyDown)
|
||||
_digitalInputStates[key / 8] |= (1 << (key % 8));
|
||||
else
|
||||
_digitalInputStates[key / 8] &= ~(1 << (key % 8));
|
||||
}
|
||||
else
|
||||
DIAG(F("TCA8418 I2C: key event %d discarded, outside Vpin range"), key);
|
||||
_numKeyEvents--; // One less key event to get
|
||||
if (_numKeyEvents != 0)
|
||||
{
|
||||
// DIAG(F("TCA8418 I2C: more keys in read event queue, # waiting is: %x"), _numKeyEvents);
|
||||
// We could read each key event waiting in a synchronous loop, which may prove preferable
|
||||
// but for now, schedule an async read of the first key event in the queue
|
||||
_commandBuffer[0] = REG_KEY_EVENT_A;
|
||||
I2CManager.read(_I2CAddress, _inputBuffer, 1, _commandBuffer, 1, &_i2crb); // non-blocking read
|
||||
}
|
||||
else {
|
||||
// DIAG(F("TCA8418 I2C: no more keys in read event queue"));
|
||||
// Clear any pending interrupts
|
||||
I2CManager.write(_I2CAddress, 2, REG_INT_STAT, REG_STAT_K_INT);
|
||||
_readState = RDS_IDLE; // Shift to IDLE
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else
|
||||
reportError(status, false); // report eror but don't go offline.
|
||||
}
|
||||
|
||||
// If we're not doing anything now, check to see if we have an interrupt pin configured and it is low,
|
||||
// or if our timer has elapsed and we should check anyway in case the interrupt pin is disconnected.
|
||||
if (_readState == RDS_IDLE) {
|
||||
if ((_gpioInterruptsEnabled && !digitalRead(_gpioInterruptPin)) ||
|
||||
((currentMicros - _lastEventRead) > _eventRefresh))
|
||||
{
|
||||
_commandBuffer[0] = REG_KEY_LCK_EC;
|
||||
I2CManager.read(_I2CAddress, _inputBuffer, 1, _commandBuffer, 1, &_i2crb); // non-blocking read
|
||||
_lastEventRead = currentMicros;
|
||||
_readState = RDS_EVENT; // Shift to looking for key events!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Display device information and status
|
||||
void _display() override {
|
||||
DIAG(F("TCA8418 I2C:%s Vpins %u-%u%S"),
|
||||
_I2CAddress.toString(),
|
||||
_firstVpin, (_firstVpin+_nPins-1),
|
||||
_deviceState == DEVSTATE_FAILED ? F(" OFFLINE") : F(""));
|
||||
if (_gpioInterruptsEnabled)
|
||||
DIAG(F("TCA8418 I2C:Interrupt on pin %d"), _gpioInterruptPin);
|
||||
}
|
||||
|
||||
// Helper function for error handling
|
||||
void reportError(uint8_t status, bool fail=true) {
|
||||
DIAG(F("TCA8418 I2C:%s Error:%d (%S)"), _I2CAddress.toString(),
|
||||
status, I2CManager.getErrorMessage(status));
|
||||
if (fail)
|
||||
_deviceState = DEVSTATE_FAILED;
|
||||
}
|
||||
|
||||
enum tca8418_registers
|
||||
{
|
||||
// REG_RESERVED = 0x00
|
||||
REG_CFG = 0x01, // Configuration register
|
||||
REG_INT_STAT = 0x02, // Interrupt status
|
||||
REG_KEY_LCK_EC = 0x03, // Key lock and event counter
|
||||
REG_KEY_EVENT_A = 0x04, // Key event register A
|
||||
REG_KEY_EVENT_B = 0x05, // Key event register B
|
||||
REG_KEY_EVENT_C = 0x06, // Key event register C
|
||||
REG_KEY_EVENT_D = 0x07, // Key event register D
|
||||
REG_KEY_EVENT_E = 0x08, // Key event register E
|
||||
REG_KEY_EVENT_F = 0x09, // Key event register F
|
||||
REG_KEY_EVENT_G = 0x0A, // Key event register G
|
||||
REG_KEY_EVENT_H = 0x0B, // Key event register H
|
||||
REG_KEY_EVENT_I = 0x0C, // Key event register I
|
||||
REG_KEY_EVENT_J = 0x0D, // Key event register J
|
||||
REG_KP_LCK_TIMER = 0x0E, // Keypad lock1 to lock2 timer
|
||||
REG_UNLOCK_1 = 0x0F, // Unlock register 1
|
||||
REG_UNLOCK_2 = 0x10, // Unlock register 2
|
||||
REG_GPIO_INT_STAT_1 = 0x11, // GPIO interrupt status 1
|
||||
REG_GPIO_INT_STAT_2 = 0x12, // GPIO interrupt status 2
|
||||
REG_GPIO_INT_STAT_3 = 0x13, // GPIO interrupt status 3
|
||||
REG_GPIO_DAT_STAT_1 = 0x14, // GPIO data status 1
|
||||
REG_GPIO_DAT_STAT_2 = 0x15, // GPIO data status 2
|
||||
REG_GPIO_DAT_STAT_3 = 0x16, // GPIO data status 3
|
||||
REG_GPIO_DAT_OUT_1 = 0x17, // GPIO data out 1
|
||||
REG_GPIO_DAT_OUT_2 = 0x18, // GPIO data out 2
|
||||
REG_GPIO_DAT_OUT_3 = 0x19, // GPIO data out 3
|
||||
REG_GPIO_INT_EN_1 = 0x1A, // GPIO interrupt enable 1
|
||||
REG_GPIO_INT_EN_2 = 0x1B, // GPIO interrupt enable 2
|
||||
REG_GPIO_INT_EN_3 = 0x1C, // GPIO interrupt enable 3
|
||||
REG_KP_GPIO_1 = 0x1D, // Keypad/GPIO select 1
|
||||
REG_KP_GPIO_2 = 0x1E, // Keypad/GPIO select 2
|
||||
REG_KP_GPIO_3 = 0x1F, // Keypad/GPIO select 3
|
||||
REG_GPI_EM_1 = 0x20, // GPI event mode 1
|
||||
REG_GPI_EM_2 = 0x21, // GPI event mode 2
|
||||
REG_GPI_EM_3 = 0x22, // GPI event mode 3
|
||||
REG_GPIO_DIR_1 = 0x23, // GPIO data direction 1
|
||||
REG_GPIO_DIR_2 = 0x24, // GPIO data direction 2
|
||||
REG_GPIO_DIR_3 = 0x25, // GPIO data direction 3
|
||||
REG_GPIO_INT_LVL_1 = 0x26, // GPIO edge/level detect 1
|
||||
REG_GPIO_INT_LVL_2 = 0x27, // GPIO edge/level detect 2
|
||||
REG_GPIO_INT_LVL_3 = 0x28, // GPIO edge/level detect 3
|
||||
REG_DEBOUNCE_DIS_1 = 0x29, // Debounce disable 1
|
||||
REG_DEBOUNCE_DIS_2 = 0x2A, // Debounce disable 2
|
||||
REG_DEBOUNCE_DIS_3 = 0x2B, // Debounce disable 3
|
||||
REG_GPIO_PULL_1 = 0x2C, // GPIO pull-up disable 1
|
||||
REG_GPIO_PULL_2 = 0x2D, // GPIO pull-up disable 2
|
||||
REG_GPIO_PULL_3 = 0x2E, // GPIO pull-up disable 3
|
||||
// REG_RESERVED = 0x2F
|
||||
};
|
||||
|
||||
enum tca8418_config_reg_fields
|
||||
{
|
||||
// Config Register #1 fields
|
||||
REG_CFG_AI = 0x80, // Auto-increment for read/write
|
||||
REG_CFG_GPI_E_CGF = 0x40, // Event mode config
|
||||
REG_CFG_OVR_FLOW_M = 0x20, // Overflow mode enable
|
||||
REG_CFG_INT_CFG = 0x10, // Interrupt config
|
||||
REG_CFG_OVR_FLOW_IEN = 0x08, // Overflow interrupt enable
|
||||
REG_CFG_K_LCK_IEN = 0x04, // Keypad lock interrupt enable
|
||||
REG_CFG_GPI_IEN = 0x02, // GPI interrupt enable
|
||||
REG_CFG_KE_IEN = 0x01, // Key events interrupt enable
|
||||
};
|
||||
|
||||
enum tca8418_int_status_fields
|
||||
{
|
||||
// Interrupt Status Register #2 fields
|
||||
REG_STAT_CAD_INT = 0x10, // Ctrl-alt-del seq status
|
||||
REG_STAT_OVR_FLOW_INT = 0x08, // Overflow interrupt status
|
||||
REG_STAT_K_LCK_INT = 0x04, // Key lock interrupt status
|
||||
REG_STAT_GPI_INT = 0x02, // GPI interrupt status
|
||||
REG_STAT_K_INT = 0x01, // Key events interrupt status
|
||||
};
|
||||
|
||||
enum tca8418_lock_ec_fields
|
||||
{
|
||||
// Key Lock Event Count Register #3
|
||||
REG_LCK_EC_K_LCK_EN = 0x40, // Key lock enable
|
||||
REG_LCK_EC_LCK_2 = 0x20, // Keypad lock status 2
|
||||
REG_LCK_EC_LCK_1 = 0x10, // Keypad lock status 1
|
||||
REG_LCK_EC_KLEC_3 = 0x08, // Key event count bit 3
|
||||
REG_LCK_EC_KLEC_2 = 0x04, // Key event count bit 2
|
||||
REG_LCK_EC_KLEC_1 = 0x02, // Key event count bit 1
|
||||
REG_LCK_EC_KLEC_0 = 0x01, // Key event count bit 0
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
215
IO_TM1638.cpp
Normal file
215
IO_TM1638.cpp
Normal file
@ -0,0 +1,215 @@
|
||||
/*
|
||||
* © 2024, Chris Harlow. All rights reserved.
|
||||
*
|
||||
* This file is part of DCC++EX API
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Credit to https://github.com/dvarrel/TM1638 for the basic formulae.*/
|
||||
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "IODevice.h"
|
||||
#include "DIAG.h"
|
||||
|
||||
|
||||
const uint8_t HIGHFLASH _digits[16]={
|
||||
0b00111111,0b00000110,0b01011011,0b01001111,
|
||||
0b01100110,0b01101101,0b01111101,0b00000111,
|
||||
0b01111111,0b01101111,0b01110111,0b01111100,
|
||||
0b00111001,0b01011110,0b01111001,0b01110001
|
||||
};
|
||||
|
||||
// Constructor
|
||||
TM1638::TM1638(VPIN firstVpin, byte clk_pin,byte dio_pin,byte stb_pin){
|
||||
_firstVpin = firstVpin;
|
||||
_nPins = 8;
|
||||
_clk_pin = clk_pin;
|
||||
_stb_pin = stb_pin;
|
||||
_dio_pin = dio_pin;
|
||||
pinMode(clk_pin,OUTPUT);
|
||||
pinMode(stb_pin,OUTPUT);
|
||||
pinMode(dio_pin,OUTPUT);
|
||||
_pulse = PULSE1_16;
|
||||
|
||||
_buttons=0;
|
||||
_leds=0;
|
||||
_lastLoop=micros();
|
||||
addDevice(this);
|
||||
}
|
||||
|
||||
|
||||
void TM1638::create(VPIN firstVpin, byte clk_pin,byte dio_pin,byte stb_pin) {
|
||||
if (checkNoOverlap(firstVpin,8))
|
||||
new TM1638(firstVpin, clk_pin,dio_pin,stb_pin);
|
||||
}
|
||||
|
||||
void TM1638::_begin() {
|
||||
displayClear();
|
||||
test();
|
||||
_display();
|
||||
}
|
||||
|
||||
|
||||
void TM1638::_loop(unsigned long currentMicros) {
|
||||
if (currentMicros - _lastLoop > (1000000UL/LoopHz)) {
|
||||
_buttons=getButtons();// Read the buttons
|
||||
_lastLoop=currentMicros;
|
||||
}
|
||||
}
|
||||
|
||||
void TM1638::_display() {
|
||||
DIAG(F("TM1638 Configured on Vpins:%u-%u"), _firstVpin, _firstVpin+_nPins-1);
|
||||
}
|
||||
|
||||
// digital read gets button state
|
||||
int TM1638::_read(VPIN vpin) {
|
||||
byte pin=vpin - _firstVpin;
|
||||
bool result=bitRead(_buttons,pin);
|
||||
// DIAG(F("TM1638 read (%d) buttons %x = %d"),pin,_buttons,result);
|
||||
return result;
|
||||
}
|
||||
|
||||
// digital write sets led state
|
||||
void TM1638::_write(VPIN vpin, int value) {
|
||||
// TODO.. skip if no state change
|
||||
writeLed(vpin - _firstVpin + 1,value!=0);
|
||||
}
|
||||
|
||||
// Analog write sets digit displays
|
||||
|
||||
void TM1638::_writeAnalogue(VPIN vpin, int lowBytes, uint8_t mode, uint16_t highBytes) {
|
||||
// mode is in DataFormat defined above.
|
||||
byte formatLength=mode & 0x0F; // last 4 bits
|
||||
byte formatType=mode & 0xF0; //
|
||||
int8_t leftDigit=vpin-_firstVpin; // 0..7 from left
|
||||
int8_t rightDigit=leftDigit+formatLength-1; // 0..7 from left
|
||||
|
||||
// loading is done right to left startDigit first
|
||||
int8_t startDigit=7-rightDigit; // reverse as 7 on left
|
||||
int8_t lastDigit=7-leftDigit; // reverse as 7 on left
|
||||
uint32_t value=highBytes;
|
||||
value<<=16;
|
||||
value |= (uint16_t)lowBytes;
|
||||
|
||||
//DIAG(F("TM1638 fl=%d ft=%x sd=%d ld=%d v=%l vx=%X"),
|
||||
// formatLength,formatType,startDigit,lastDigit,value,value);
|
||||
while(startDigit<=lastDigit) {
|
||||
switch (formatType) {
|
||||
case _DF_DECIMAL:// decimal (leading zeros)
|
||||
displayDig(startDigit,GETHIGHFLASH(_digits,(value%10)));
|
||||
value=value/10;
|
||||
break;
|
||||
case _DF_HEX:// HEX (leading zeros)
|
||||
displayDig(startDigit,GETHIGHFLASH(_digits,(value & 0x0F)));
|
||||
value>>=4;
|
||||
break;
|
||||
case _DF_RAW:// Raw 7-segment pattern
|
||||
displayDig(startDigit,value & 0xFF);
|
||||
value>>=8;
|
||||
break;
|
||||
default:
|
||||
DIAG(F("TM1368 invalid mode 0x%x"),mode);
|
||||
return;
|
||||
}
|
||||
startDigit++;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t TM1638::getButtons(){
|
||||
ArduinoPins::fastWriteDigital(_stb_pin, LOW);
|
||||
writeData(INSTRUCTION_READ_KEY);
|
||||
pinMode(_dio_pin, INPUT);
|
||||
ArduinoPins::fastWriteDigital(_clk_pin, LOW);
|
||||
uint8_t buttons=0;
|
||||
for (uint8_t eachByte=0; eachByte<4;eachByte++) {
|
||||
uint8_t value = 0;
|
||||
for (uint8_t eachBit = 0; eachBit < 8; eachBit++) {
|
||||
ArduinoPins::fastWriteDigital(_clk_pin, HIGH);
|
||||
value |= ArduinoPins::fastReadDigital(_dio_pin) << eachBit;
|
||||
ArduinoPins::fastWriteDigital(_clk_pin, LOW);
|
||||
}
|
||||
buttons |= value << eachByte;
|
||||
delayMicroseconds(1);
|
||||
}
|
||||
pinMode(_dio_pin, OUTPUT);
|
||||
ArduinoPins::fastWriteDigital(_stb_pin, HIGH);
|
||||
return buttons;
|
||||
}
|
||||
|
||||
|
||||
void TM1638::displayDig(uint8_t digitId, uint8_t pgfedcba){
|
||||
if (digitId>7) return;
|
||||
setDataInstruction(DISPLAY_TURN_ON | _pulse);
|
||||
setDataInstruction(INSTRUCTION_WRITE_DATA| INSTRUCTION_ADDRESS_FIXED);
|
||||
writeDataAt(FIRST_DISPLAY_ADDRESS+14-(digitId*2), pgfedcba);
|
||||
}
|
||||
|
||||
void TM1638::displayClear(){
|
||||
setDataInstruction(DISPLAY_TURN_ON | _pulse);
|
||||
setDataInstruction(INSTRUCTION_WRITE_DATA | INSTRUCTION_ADDRESS_FIXED);
|
||||
for (uint8_t i=0;i<15;i+=2){
|
||||
writeDataAt(FIRST_DISPLAY_ADDRESS+i,0x00);
|
||||
}
|
||||
}
|
||||
|
||||
void TM1638::writeLed(uint8_t num,bool state){
|
||||
if ((num<1) | (num>8)) return;
|
||||
setDataInstruction(DISPLAY_TURN_ON | _pulse);
|
||||
setDataInstruction(INSTRUCTION_WRITE_DATA | INSTRUCTION_ADDRESS_FIXED);
|
||||
writeDataAt(FIRST_DISPLAY_ADDRESS + (num*2-1), state);
|
||||
}
|
||||
|
||||
|
||||
void TM1638::writeData(uint8_t data){
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
ArduinoPins::fastWriteDigital(_dio_pin, data & 1);
|
||||
data >>= 1;
|
||||
ArduinoPins::fastWriteDigital(_clk_pin, HIGH);
|
||||
ArduinoPins::fastWriteDigital(_clk_pin, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
void TM1638::writeDataAt(uint8_t displayAddress, uint8_t data){
|
||||
ArduinoPins::fastWriteDigital(_stb_pin, LOW);
|
||||
writeData(displayAddress);
|
||||
writeData(data);
|
||||
ArduinoPins::fastWriteDigital(_stb_pin, HIGH);
|
||||
delayMicroseconds(1);
|
||||
}
|
||||
|
||||
void TM1638::setDataInstruction(uint8_t dataInstruction){
|
||||
ArduinoPins::fastWriteDigital(_stb_pin, LOW);
|
||||
writeData(dataInstruction);
|
||||
ArduinoPins::fastWriteDigital(_stb_pin, HIGH);
|
||||
delayMicroseconds(1);
|
||||
}
|
||||
|
||||
void TM1638::test(){
|
||||
DIAG(F("TM1638 test"));
|
||||
uint8_t val=0;
|
||||
for(uint8_t i=0;i<5;i++){
|
||||
setDataInstruction(DISPLAY_TURN_ON | _pulse);
|
||||
setDataInstruction(INSTRUCTION_WRITE_DATA| INSTRUCTION_ADDRESS_AUTO);
|
||||
ArduinoPins::fastWriteDigital(_stb_pin, LOW);
|
||||
writeData(FIRST_DISPLAY_ADDRESS);
|
||||
for(uint8_t i=0;i<16;i++)
|
||||
writeData(val);
|
||||
ArduinoPins::fastWriteDigital(_stb_pin, HIGH);
|
||||
delay(1000);
|
||||
val = ~val;
|
||||
}
|
||||
|
||||
}
|
134
IO_TM1638.h
Normal file
134
IO_TM1638.h
Normal file
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* © 2024, Chris Harlow. All rights reserved.
|
||||
*
|
||||
* This file is part of DCC++EX API
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef IO_TM1638_h
|
||||
#define IO_TM1638_h
|
||||
#include <Arduino.h>
|
||||
#include "IODevice.h"
|
||||
#include "DIAG.h"
|
||||
|
||||
class TM1638 : public IODevice {
|
||||
private:
|
||||
|
||||
uint8_t _buttons;
|
||||
uint8_t _leds;
|
||||
unsigned long _lastLoop;
|
||||
static const int LoopHz=20;
|
||||
|
||||
static const byte
|
||||
INSTRUCTION_WRITE_DATA=0x40,
|
||||
INSTRUCTION_READ_KEY=0x42,
|
||||
INSTRUCTION_ADDRESS_AUTO=0x40,
|
||||
INSTRUCTION_ADDRESS_FIXED=0x44,
|
||||
INSTRUCTION_NORMAL_MODE=0x40,
|
||||
INSTRUCTION_TEST_MODE=0x48,
|
||||
|
||||
FIRST_DISPLAY_ADDRESS=0xC0,
|
||||
|
||||
DISPLAY_TURN_OFF=0x80,
|
||||
DISPLAY_TURN_ON=0x88;
|
||||
|
||||
|
||||
uint8_t _clk_pin;
|
||||
uint8_t _stb_pin;
|
||||
uint8_t _dio_pin;
|
||||
uint8_t _pulse;
|
||||
bool _isOn;
|
||||
|
||||
|
||||
// Constructor
|
||||
TM1638(VPIN firstVpin, byte clk_pin,byte dio_pin,byte stb_pin);
|
||||
|
||||
public:
|
||||
enum DigitFormat : byte {
|
||||
// last 4 bits are length.
|
||||
// DF_1.. DF_8 decimal
|
||||
DF_1=0x01,DF_2=0x02,DF_3=0x03,DF_4=0x04,
|
||||
DF_5=0x05,DF_6=0x06,DF_7=0x07,DF_8=0x08,
|
||||
// DF_1X.. DF_8X HEX
|
||||
DF_1X=0x11,DF_2X=0x12,DF_3X=0x13,DF_4X=0x14,
|
||||
DF_5X=0x15,DF_6X=0x16,DF_7X=0x17,DF_8X=0x18,
|
||||
// DF_1R .. DF_4R raw 7 segmnent data
|
||||
// only 4 because HAL analogWrite only passes 4 bytes
|
||||
DF_1R=0x21,DF_2R=0x22,DF_3R=0x23,DF_4R=0x24,
|
||||
|
||||
// bits of data conversion type (ored with length)
|
||||
_DF_DECIMAL=0x00,// right adjusted decimal unsigned leading zeros
|
||||
_DF_HEX=0x10, // right adjusted hex leading zeros
|
||||
_DF_RAW=0x20 // bytes are raw 7-segment pattern (max length 4)
|
||||
};
|
||||
|
||||
static void create(VPIN firstVpin, byte clk_pin,byte dio_pin,byte stb_pin);
|
||||
|
||||
// Functions overridden in IODevice
|
||||
void _begin();
|
||||
void _loop(unsigned long currentMicros) override ;
|
||||
void _writeAnalogue(VPIN vpin, int value, uint8_t param1, uint16_t param2) override;
|
||||
void _display() override ;
|
||||
int _read(VPIN pin) override;
|
||||
void _write(VPIN pin,int value) override;
|
||||
|
||||
// Device driving functions
|
||||
private:
|
||||
enum pulse_t {
|
||||
PULSE1_16,
|
||||
PULSE2_16,
|
||||
PULSE4_16,
|
||||
PULSE10_16,
|
||||
PULSE11_16,
|
||||
PULSE12_16,
|
||||
PULSE13_16,
|
||||
PULSE14_16
|
||||
};
|
||||
|
||||
/**
|
||||
* @fn getButtons
|
||||
* @return state of 8 buttons
|
||||
*/
|
||||
uint8_t getButtons();
|
||||
|
||||
/**
|
||||
* @fn writeLed
|
||||
* @brief put led ON or OFF
|
||||
* @param num num of led(1-8)
|
||||
* @param state (true or false)
|
||||
*/
|
||||
void writeLed(uint8_t num, bool state);
|
||||
|
||||
|
||||
/**
|
||||
* @fn displayDig
|
||||
* @brief set 7 segment display + dot
|
||||
* @param digitId num of digit(0-7)
|
||||
* @param val value 8 bits
|
||||
*/
|
||||
void displayDig(uint8_t digitId, uint8_t pgfedcba);
|
||||
|
||||
/**
|
||||
* @fn displayClear
|
||||
* @brief switch off all leds and segment display
|
||||
*/
|
||||
void displayClear();
|
||||
void test();
|
||||
void writeData(uint8_t data);
|
||||
void writeDataAt(uint8_t displayAddress, uint8_t data);
|
||||
void setDisplayMode(uint8_t displayMode);
|
||||
void setDataInstruction(uint8_t dataInstruction);
|
||||
};
|
||||
#endif
|
@ -131,4 +131,4 @@ protected:
|
||||
|
||||
};
|
||||
|
||||
#endif // IO_TOUCHKEYPAD_H
|
||||
#endif // IO_TOUCHKEYPAD_H
|
||||
|
@ -170,4 +170,4 @@ public:
|
||||
}
|
||||
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
@ -95,4 +95,4 @@ private:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -26,7 +26,7 @@
|
||||
Thus "MAIN"_hk generates exactly the same run time vakue
|
||||
as const int16_t HASH_KEYWORD_MAIN=11339
|
||||
*/
|
||||
#ifndef KeywordHAsher_h
|
||||
#ifndef KeywordHasher_h
|
||||
#define KeywordHasher_h
|
||||
|
||||
#include <Arduino.h>
|
||||
@ -54,4 +54,43 @@ static_assert("MAIN"_hk == 11339,"Keyword hasher error");
|
||||
static_assert("SLOW"_hk == -17209,"Keyword hasher error");
|
||||
static_assert("SPEED28"_hk == -17064,"Keyword hasher error");
|
||||
static_assert("SPEED128"_hk == 25816,"Keyword hasher error");
|
||||
#endif
|
||||
|
||||
// Compile time converter from "abcd"_s7 to the 7 segment nearest equivalent
|
||||
|
||||
constexpr uint8_t seg7Digits[]={
|
||||
0b00111111,0b00000110,0b01011011,0b01001111, // 0..3
|
||||
0b01100110,0b01101101,0b01111101,0b00000111, // 4..7
|
||||
0b01111111,0b01101111 // 8..9
|
||||
};
|
||||
|
||||
constexpr uint8_t seg7Letters[]={
|
||||
0b01110111,0b01111100,0b00111001,0b01011110, // ABCD
|
||||
0b01111001,0b01110001,0b00111101,0b01110110, // EFGH
|
||||
0b00000100,0b00011110,0b01110010,0b00111000, //IJKL
|
||||
0b01010101,0b01010100,0b01011100,0b01110011, // MNOP
|
||||
0b10111111,0b01010000,0b01101101,0b01111000, // QRST
|
||||
0b00111110,0b00011100,0b01101010,0b01001001, //UVWX
|
||||
0b01100110,0b01011011 //YZ
|
||||
};
|
||||
constexpr uint8_t seg7Space=0b00000000;
|
||||
constexpr uint8_t seg7Minus=0b01000000;
|
||||
constexpr uint8_t seg7Equals=0b01001000;
|
||||
|
||||
|
||||
constexpr uint32_t CompiletimeSeg7(const char * sv, uint32_t running, size_t rlen) {
|
||||
return (*sv==0 || rlen==0) ? running << (8*rlen) : CompiletimeSeg7(sv+1,
|
||||
(*sv >= '0' && *sv <= '9') ? (running<<8) | seg7Digits[*sv-'0'] :
|
||||
(*sv >= 'A' && *sv <= 'Z') ? (running<<8) | seg7Letters[*sv-'A'] :
|
||||
(*sv >= 'a' && *sv <= 'z') ? (running<<8) | seg7Letters[*sv-'a'] :
|
||||
(*sv == '-') ? (running<<8) | seg7Minus :
|
||||
(*sv == '=') ? (running<<8) | seg7Equals :
|
||||
(running<<8) | seg7Space,
|
||||
rlen-1
|
||||
); //
|
||||
}
|
||||
|
||||
constexpr uint32_t operator""_s7(const char * keyword, size_t len)
|
||||
{
|
||||
return CompiletimeSeg7(keyword,0*len,4);
|
||||
}
|
||||
#endif
|
||||
|
@ -221,4 +221,4 @@ void LiquidCrystal_I2C::expanderWrite(uint8_t value) {
|
||||
rb.wait();
|
||||
outputBuffer[0] = value | _backlightval;
|
||||
I2CManager.write(_Addr, outputBuffer, 1, &rb); // Write command asynchronously
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* © 2022-2023 Paul M Antoine
|
||||
* © 2022-2024 Paul M Antoine
|
||||
* © 2024 Herb Morton
|
||||
* © 2021 Mike S
|
||||
* © 2021 Fred Decker
|
||||
* © 2020-2023 Harald Barth
|
||||
@ -38,6 +39,8 @@ volatile portreg_t shadowPORTC;
|
||||
volatile portreg_t shadowPORTD;
|
||||
volatile portreg_t shadowPORTE;
|
||||
volatile portreg_t shadowPORTF;
|
||||
volatile portreg_t shadowPORTG;
|
||||
volatile portreg_t shadowPORTH;
|
||||
#endif
|
||||
|
||||
MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, int16_t brake_pin,
|
||||
@ -88,6 +91,16 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
|
||||
fastSignalPin.shadowinout = fastSignalPin.inout;
|
||||
fastSignalPin.inout = &shadowPORTF;
|
||||
}
|
||||
if (HAVE_PORTG(fastSignalPin.inout == &PORTG)) {
|
||||
DIAG(F("Found PORTG pin %d"),signalPin);
|
||||
fastSignalPin.shadowinout = fastSignalPin.inout;
|
||||
fastSignalPin.inout = &shadowPORTG;
|
||||
}
|
||||
if (HAVE_PORTH(fastSignalPin.inout == &PORTH)) {
|
||||
DIAG(F("Found PORTH pin %d"),signalPin);
|
||||
fastSignalPin.shadowinout = fastSignalPin.inout;
|
||||
fastSignalPin.inout = &shadowPORTH;
|
||||
}
|
||||
|
||||
signalPin2=signal_pin2;
|
||||
if (signalPin2!=UNUSED_PIN) {
|
||||
@ -126,6 +139,16 @@ MotorDriver::MotorDriver(int16_t power_pin, byte signal_pin, byte signal_pin2, i
|
||||
fastSignalPin2.shadowinout = fastSignalPin2.inout;
|
||||
fastSignalPin2.inout = &shadowPORTF;
|
||||
}
|
||||
if (HAVE_PORTG(fastSignalPin2.inout == &PORTG)) {
|
||||
DIAG(F("Found PORTG pin %d"),signalPin2);
|
||||
fastSignalPin2.shadowinout = fastSignalPin2.inout;
|
||||
fastSignalPin2.inout = &shadowPORTG;
|
||||
}
|
||||
if (HAVE_PORTH(fastSignalPin2.inout == &PORTH)) {
|
||||
DIAG(F("Found PORTH pin %d"),signalPin2);
|
||||
fastSignalPin2.shadowinout = fastSignalPin2.inout;
|
||||
fastSignalPin2.inout = &shadowPORTH;
|
||||
}
|
||||
}
|
||||
else dualSignal=false;
|
||||
|
||||
@ -393,6 +416,18 @@ void MotorDriver::setDCSignal(byte speedcode, uint8_t frequency /*default =0*/)
|
||||
setSignal(tDir);
|
||||
HAVE_PORTF(PORTF=shadowPORTF);
|
||||
interrupts();
|
||||
} else if (HAVE_PORTG(fastSignalPin.shadowinout == &PORTG)) {
|
||||
noInterrupts();
|
||||
HAVE_PORTG(shadowPORTG=PORTG);
|
||||
setSignal(tDir);
|
||||
HAVE_PORTG(PORTG=shadowPORTG);
|
||||
interrupts();
|
||||
} else if (HAVE_PORTH(fastSignalPin.shadowinout == &PORTH)) {
|
||||
noInterrupts();
|
||||
HAVE_PORTH(shadowPORTH=PORTH);
|
||||
setSignal(tDir);
|
||||
HAVE_PORTH(PORTH=shadowPORTH);
|
||||
interrupts();
|
||||
} else {
|
||||
noInterrupts();
|
||||
setSignal(tDir);
|
||||
@ -541,7 +576,7 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
|
||||
DIAG(F("TRACK %c ALERT FAULT"), trackno + 'A');
|
||||
}
|
||||
setPower(POWERMODE::ALERT);
|
||||
if ((trackMode & TRACK_MODE_AUTOINV) && (trackMode & (TRACK_MODE_MAIN|TRACK_MODE_EXT|TRACK_MODE_BOOST))){
|
||||
if ((trackMode & TRACK_MODIFIER_AUTO) && (trackMode & (TRACK_MODE_MAIN|TRACK_MODE_EXT|TRACK_MODE_BOOST))){
|
||||
DIAG(F("TRACK %c INVERT"), trackno + 'A');
|
||||
invertOutput();
|
||||
}
|
||||
@ -604,6 +639,10 @@ void MotorDriver::checkPowerOverload(bool useProgLimit, byte trackno) {
|
||||
}
|
||||
throttleInrush(false);
|
||||
setPower(POWERMODE::ON);
|
||||
break;
|
||||
}
|
||||
if (goodtime > POWER_SAMPLE_ALERT_GOOD/2) {
|
||||
throttleInrush(false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* © 2022-2023 Paul M. Antoine
|
||||
* © 2022-2024 Paul M. Antoine
|
||||
* © 2021 Mike S
|
||||
* © 2021 Fred Decker
|
||||
* © 2020 Chris Harlow
|
||||
@ -26,23 +26,33 @@
|
||||
#include "FSH.h"
|
||||
#include "IODevice.h"
|
||||
#include "DCCTimer.h"
|
||||
#include <wiring_private.h>
|
||||
|
||||
#include "TemplateForEnums.h"
|
||||
// use powers of two so we can do logical and/or on the track modes in if clauses.
|
||||
// RACK_MODE_DCX is (TRACK_MODE_DC|TRACK_MODE_INV)
|
||||
template<class T> inline T operator~ (T a) { return (T)~(int)a; }
|
||||
template<class T> inline T operator| (T a, T b) { return (T)((int)a | (int)b); }
|
||||
template<class T> inline T operator& (T a, T b) { return (T)((int)a & (int)b); }
|
||||
template<class T> inline T operator^ (T a, T b) { return (T)((int)a ^ (int)b); }
|
||||
enum TRACK_MODE : byte {TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PROG = 4,
|
||||
TRACK_MODE_DC = 8, TRACK_MODE_EXT = 16,
|
||||
// For example TRACK_MODE_DC_INV is (TRACK_MODE_DC|TRACK_MODIFIER_INV)
|
||||
enum TRACK_MODE : byte {
|
||||
// main modes
|
||||
TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PROG = 4,
|
||||
TRACK_MODE_DC = 8, TRACK_MODE_EXT = 16,
|
||||
// modifiers
|
||||
TRACK_MODIFIER_INV = 64, TRACK_MODIFIER_AUTO = 128,
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
TRACK_MODE_BOOST = 32,
|
||||
TRACK_MODE_BOOST = 32,
|
||||
TRACK_MODE_BOOST_INV = TRACK_MODE_BOOST|TRACK_MODIFIER_INV,
|
||||
TRACK_MODE_BOOST_AUTO = TRACK_MODE_BOOST|TRACK_MODIFIER_AUTO,
|
||||
#else
|
||||
TRACK_MODE_BOOST = 0,
|
||||
TRACK_MODE_BOOST = 0,
|
||||
TRACK_MODE_BOOST_INV = 0,
|
||||
TRACK_MODE_BOOST_AUTO = 0,
|
||||
#endif
|
||||
TRACK_MODE_ALL = TRACK_MODE_MAIN|TRACK_MODE_PROG|TRACK_MODE_DC|TRACK_MODE_EXT|TRACK_MODE_BOOST,
|
||||
TRACK_MODE_INV = 64,
|
||||
TRACK_MODE_DCX = TRACK_MODE_DC|TRACK_MODE_INV, TRACK_MODE_AUTOINV = 128};
|
||||
// derived modes; TRACK_ALL is calles that so it does not match TRACK_MODE_*
|
||||
TRACK_ALL = TRACK_MODE_MAIN|TRACK_MODE_PROG|TRACK_MODE_DC|TRACK_MODE_EXT|TRACK_MODE_BOOST,
|
||||
TRACK_MODE_MAIN_INV = TRACK_MODE_MAIN|TRACK_MODIFIER_INV,
|
||||
TRACK_MODE_MAIN_AUTO = TRACK_MODE_MAIN|TRACK_MODIFIER_AUTO,
|
||||
TRACK_MODE_DC_INV = TRACK_MODE_DC|TRACK_MODIFIER_INV,
|
||||
TRACK_MODE_DCX = TRACK_MODE_DC_INV // DCX is other name for historical reasons
|
||||
};
|
||||
|
||||
#define setHIGH(fastpin) *fastpin.inout |= fastpin.maskHIGH
|
||||
#define setLOW(fastpin) *fastpin.inout &= fastpin.maskLOW
|
||||
@ -83,6 +93,14 @@ enum TRACK_MODE : byte {TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PRO
|
||||
#define PORTF GPIOF->ODR
|
||||
#define HAVE_PORTF(X) X
|
||||
#endif
|
||||
#if defined(GPIOG)
|
||||
#define PORTG GPIOG->ODR
|
||||
#define HAVE_PORTG(X) X
|
||||
#endif
|
||||
#if defined(GPIOH)
|
||||
#define PORTH GPIOH->ODR
|
||||
#define HAVE_PORTH(X) X
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// if macros not defined as pass-through we define
|
||||
@ -106,6 +124,12 @@ enum TRACK_MODE : byte {TRACK_MODE_NONE = 1, TRACK_MODE_MAIN = 2, TRACK_MODE_PRO
|
||||
#ifndef HAVE_PORTF
|
||||
#define HAVE_PORTF(X) byte TOKENPASTE2(Unique_, __LINE__) __attribute__((unused)) =0
|
||||
#endif
|
||||
#ifndef HAVE_PORTG
|
||||
#define HAVE_PORTG(X) byte TOKENPASTE2(Unique_, __LINE__) __attribute__((unused)) =0
|
||||
#endif
|
||||
#ifndef HAVE_PORTH
|
||||
#define HAVE_PORTH(X) byte TOKENPASTE2(Unique_, __LINE__) __attribute__((unused)) =0
|
||||
#endif
|
||||
|
||||
// Virtualised Motor shield 1-track hardware Interface
|
||||
|
||||
@ -145,6 +169,8 @@ extern volatile portreg_t shadowPORTC;
|
||||
extern volatile portreg_t shadowPORTD;
|
||||
extern volatile portreg_t shadowPORTE;
|
||||
extern volatile portreg_t shadowPORTF;
|
||||
extern volatile portreg_t shadowPORTG;
|
||||
extern volatile portreg_t shadowPORTH;
|
||||
|
||||
enum class POWERMODE : byte { OFF, ON, OVERLOAD, ALERT };
|
||||
|
||||
@ -256,7 +282,7 @@ class MotorDriver {
|
||||
#endif
|
||||
inline void setMode(TRACK_MODE m) {
|
||||
trackMode = m;
|
||||
invertOutput(trackMode & TRACK_MODE_INV);
|
||||
invertOutput(trackMode & TRACK_MODIFIER_INV);
|
||||
};
|
||||
inline void invertOutput() { // toggles output inversion
|
||||
invertPhase = !invertPhase;
|
||||
|
@ -75,11 +75,19 @@
|
||||
#define SAMD_STANDARD_MOTOR_SHIELD STANDARD_MOTOR_SHIELD
|
||||
#define STM32_STANDARD_MOTOR_SHIELD STANDARD_MOTOR_SHIELD
|
||||
|
||||
#if defined(ARDUINO_NUCLEO_F429ZI) || defined(ARDUINO_NUCLEO_F439ZI) || defined(ARDUINO_NUCLEO_F4X9ZI)
|
||||
// EX 8874 based shield connected to a 3V3 system with 12-bit (4096) ADC
|
||||
// The Ethernet capable STM32 models cannot use Channel B BRAKE on D8, and must use the ALT pin of D6,
|
||||
// AND cannot use Channel B PWN on D11, but must use the ALT pin of D5
|
||||
#define EX8874_SHIELD F("EX8874"), \
|
||||
new MotorDriver( 3, 12, UNUSED_PIN, 9, A0, 1.27, 5000, A4), \
|
||||
new MotorDriver( 5, 13, UNUSED_PIN, 6, A1, 1.27, 5000, A5)
|
||||
#else
|
||||
// EX 8874 based shield connected to a 3V3 system with 12-bit (4096) ADC
|
||||
#define EX8874_SHIELD F("EX8874"), \
|
||||
new MotorDriver( 3, 12, UNUSED_PIN, 9, A0, 1.27, 5000, A4), \
|
||||
new MotorDriver(11, 13, UNUSED_PIN, 8, A1, 1.27, 5000, A5)
|
||||
|
||||
#endif
|
||||
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
// STANDARD shield on an ESPDUINO-32 (ESP32 in Uno form factor). The shield must be eiter the
|
||||
@ -97,6 +105,18 @@
|
||||
new MotorDriver(25/* 3*/, 19/*12*/, UNUSED_PIN, 13/*9*/, 35/*A2*/, 1.27, 5000, 36 /*A4*/), \
|
||||
new MotorDriver(23/*11*/, 18/*13*/, UNUSED_PIN, 12/*8*/, 34/*A3*/, 1.27, 5000, 39 /*A5*/)
|
||||
|
||||
// EX-CSB1 with integrated motor driver definition
|
||||
#define EXCSB1 F("EXCSB1"),\
|
||||
new MotorDriver(25, 0, UNUSED_PIN, -14, 34, 2.23, 5000, 19), \
|
||||
new MotorDriver(27, 15, UNUSED_PIN, -2, 35, 2.23, 5000, 23)
|
||||
|
||||
// EX-CSB1 with EX-8874 stacked on top for 4 outputs
|
||||
#define EXCSB1_WITH_EX8874 F("EXCSB1_WITH_EX8874"),\
|
||||
new MotorDriver(25, 0, UNUSED_PIN, -14, 34, 2.23, 5000, 19), \
|
||||
new MotorDriver(27, 15, UNUSED_PIN, -2, 35, 2.23, 5000, 23), \
|
||||
new MotorDriver(26, 5, UNUSED_PIN, 13, 36, 1.52, 5000, 18), \
|
||||
new MotorDriver(16, 4, UNUSED_PIN, 12, 39, 1.52, 5000, 17)
|
||||
|
||||
#else
|
||||
// STANDARD shield on any Arduino Uno or Mega compatible with the original specification.
|
||||
#define STANDARD_MOTOR_SHIELD F("STANDARD_MOTOR_SHIELD"), \
|
||||
|
82
README.md
82
README.md
@ -1,77 +1,39 @@
|
||||
# What is DCC++ EX?
|
||||
DCC++ EX is the organization maintaining several codebases that together represent a fully open source DCC system. Currently, this includes the following:
|
||||
# What is DCC-EX?
|
||||
DCC-EX is a team of dedicated enthusiasts producing open source DCC & DC solutions for you to run your complete model railroad layout. Our easy to use, do-it-yourself, and free open source products run on off-the-shelf Arduino technology and are supported by numerous third party hardware and apps like JMRI, Engine Driver, wiThrottle, Rocrail and more.
|
||||
|
||||
* [CommandStation-EX](https://github.com/DCC-EX/CommandStation-EX/releases) - the latest take on the DCC++ command station for controlling your trains. Runs on an Arduino board, and includes advanced features such as a WiThrottle server implementation, turnout operation, general purpose inputs and outputs (I/O), and JMRI integration.
|
||||
* [exWebThrottle](https://github.com/DCC-EX/exWebThrottle) - a simple web based controller for your DCC++ command station.
|
||||
* [BaseStation-installer](https://github.com/DCC-EX/BaseStation-Installer) - an installer executable that takes care of downloading and installing DCC++ firmware onto your hardware setup.
|
||||
* [BaseStation-Classic](https://github.com/DCC-EX/BaseStation-Classic) - the original DCC++ software, packaged in a stable release. No active development, bug fixes only.
|
||||
Currently, our products include the following:
|
||||
|
||||
A basic DCC++ EX hardware setup can use easy to find, widely avalable Arduino boards that you can assemble yourself.
|
||||
|
||||
Both CommandStation-EX and BaseStation-Classic support much of the NMRA Digital Command Control (DCC) [standards](http://www.nmra.org/dcc-working-group "NMRA DCC Working Group"), including:
|
||||
|
||||
* simultaneous control of multiple locomotives
|
||||
* 2-byte and 4-byte locomotive addressing
|
||||
* 28 or 128-step speed throttling
|
||||
* Activate/de-activate all accessory function addresses 0-2048
|
||||
* Control of all cab functions F0-F28 and F29-F68
|
||||
* Main Track: Write configuration variable bytes and set/clear specific configuration variable (CV) bits (aka Programming on Main or POM)
|
||||
* Programming Track: Same as the main track with the addition of reading configuration variable bytes
|
||||
* And many more custom features. see [What's new in CommandStation-EX?](#whats-new-in-commandstation-ex)
|
||||
* [EX-CommandStation](https://github.com/DCC-EX/CommandStation-EX/releases)
|
||||
* [EX-WebThrottle](https://github.com/DCC-EX/exWebThrottle)
|
||||
* [EX-Installer](https://github.com/DCC-EX/EX-Installer)
|
||||
* [EX-MotoShield8874](https://dcc-ex.com/reference/hardware/motorboards/ex-motor-shield-8874.html#gsc.tab=0)
|
||||
* [EX-DCCInspector](https://github.com/DCC-EX/DCCInspector-EX)
|
||||
* [EX-Toolbox](https://github.com/DCC-EX/EX-Toolbox)
|
||||
* [EX-Turntable](https://github.com/DCC-EX/EX-Turntable)
|
||||
* [EX-IOExpander](https://github.com/DCC-EX/EX-IOExpander)
|
||||
* [EX-FastClock](https://github.com/DCC-EX/EX-FastClock)
|
||||
* [DCCEXProtocol](https://github.com/DCC-EX/DCCEXProtocol)
|
||||
|
||||
Details of these projects can be found on [our web site](https://dcc-ex.com/).
|
||||
|
||||
# What’s in this Repository?
|
||||
|
||||
This repository, CommandStation-EX, contains a complete DCC++ EX Commmand Station sketch designed for compiling and uploading into an Arduino Uno, Mega, or Nano.
|
||||
This repository, CommandStation-EX, contains a complete DCC-EX *EX-CommmandStation* sketch designed for compiling and uploading into an Arduino Uno, Mega, or Nano.
|
||||
|
||||
To utilize this sketch, you can use the following:
|
||||
|
||||
1. (beginner) our [automated installer](https://github.com/DCC-EX/BaseStation-Installer)
|
||||
1. (recommended for all levels of user) our [automated installer](https://github.com/DCC-EX/EX-Installer)
|
||||
2. (intermediate) download the latest version from the [releases page](https://github.com/DCC-EX/CommandStation-EX/releases)
|
||||
3. (advanced) use git clone on this repository
|
||||
|
||||
Not using the installer? Open the file "CommandStation-EX.ino" in the
|
||||
Arduino IDE. Please do not rename the folder containing the sketch
|
||||
code, nor add any files in that folder. The Arduino IDE relies on the
|
||||
structure and name of the folder to properly display and compile the
|
||||
code. Rename or copy config.example.h to config.h. If you do not have
|
||||
the standard setup, you must edit config.h according to the help texts
|
||||
in config.h.
|
||||
Refer to [our web site](https://https://dcc-ex.com/ex-commandstation/get-started/index.html#/) for the hardware required for this project.
|
||||
|
||||
## What's new in CommandStation-EX?
|
||||
**We seriously recommend using the EX-Installer**, however if you choose not to use the installer...
|
||||
|
||||
* WiThrottle server built in. Connect Engine Driver or WiThrottle clients directly to your Command Station (or through JMRI as before)
|
||||
* WiFi and Ethernet shield support
|
||||
* No more jumpers or soldering!
|
||||
* Direct support for all the most popular motor control boards including single pin (Arduino) or dual pin (IBT_2) type PWM inputs without the need for an adapter circuit
|
||||
* I2C Display support (LCD and OLED)
|
||||
* Improved short circuit detection and automatic reset from an overload
|
||||
* Current reading, sensing and ACK detection settings in milliAmps instead of just pin readings
|
||||
* Improved adherence to the NMRA DCC specification
|
||||
* Complete support for all the old commands and front ends like JMRI
|
||||
* Railcom cutout (beta)
|
||||
* Simpler, modular, faster code with an API Library for developers for easy expansion
|
||||
* New features and functions in JMRI
|
||||
* Ability to join MAIN and PROG tracks into one MAIN track to run your locos
|
||||
* "Drive-Away" feature - Throttles with support, like Engine Driver, can allow a loco to be programmed on a usable, electrically isolated programming track and then drive off onto the main track
|
||||
* Diagnostic commands to test decoders that aren't reading or writing correctly
|
||||
* Support for Uno, Nano, Mega, Nano Every and Teensy microcontrollers
|
||||
* User Functions: Filter regular commands (like a turnout or output command) and pass it to your own function or accessory
|
||||
* Support for LCN (layout control nodes)
|
||||
* mySetup.h file that acts like an Autoexec.Bat command to send startup commands to the CS
|
||||
* High Accuracty Waveform option for rock steady DCC signals
|
||||
* New current response outputs current in mA, overlimit current, and maximum board capable current. Support for new current meter in JMRI
|
||||
* USB Browser based EX-WebThrottle
|
||||
* New, simpler, function control command
|
||||
* Number of locos discovery command `<#>`
|
||||
* Emergency stop command <!>
|
||||
* Release cabs from memory command <-> all cabs, <- CAB> for just one loco address
|
||||
* Automatic slot (register) management
|
||||
* Automation (coming soon)
|
||||
|
||||
NOTE: DCC-EX is a major rewrite to the code. We started over and rebuilt it from the ground up! For what that means, you can read [HERE](https://dcc-ex.com/about/rewrite.html).
|
||||
* Open the file ``CommandStation-EX.ino`` in the Arduino IDE or Visual Studio Code (VSC). Please do not rename the folder containing the sketch code, nor add any files in that folder. The Arduino IDE relies on the structure and name of the folder to properly display and compile the code.
|
||||
* Rename or copy ``config.example.h`` to ``config.h``.
|
||||
* You must edit ``config.h`` according to the help texts in ``config.h``.
|
||||
|
||||
# More information
|
||||
You can learn more at the [DCC++ EX website](https://dcc-ex.com/)
|
||||
You can learn more at the [DCC-EX website](https://dcc-ex.com/)
|
||||
|
||||
- November 14, 2020
|
||||
|
BIN
Release_Notes/DCC-EX v5.4 Release Notes.xlsx
Normal file
BIN
Release_Notes/DCC-EX v5.4 Release Notes.xlsx
Normal file
Binary file not shown.
77
Release_Notes/NeoPixel.md
Normal file
77
Release_Notes/NeoPixel.md
Normal file
@ -0,0 +1,77 @@
|
||||
NeoPixel support
|
||||
|
||||
The IO_NeoPixel.h driver supports the adafruit neopixel seesaw board. It turns each pixel into an individual VPIN which can be given a colour and turned on or off using the new <o> command or the NEOPIXEL Exrail macro. Exrail SIGNALS can also drive a single pixel signal or multiple separate pixels.
|
||||
|
||||
|
||||
1. Defining the hardware driver:
|
||||
Add a driver definition in myAutomation.h for each adafruit I2C driver.
|
||||
|
||||
HAL(neoPixel, firstVpin, numberOfPixels [, mode [, i2caddress])
|
||||
Where mode is selected from the various pixel string types which have varying
|
||||
colour order or refresh frequency. For MOST strings this mode will be NEO_GRB but for others refer to the comments in IO_NeoPixel.h
|
||||
If omitted the node and i2caddress default to NEO_GRB, 0x60.
|
||||
|
||||
HAL(NeoPixel,1000,20)
|
||||
This is a NeoPixel driver defaulting to I2C aqddress 0x60 for a GRB pixel string. Pixels are given vpin numbers from 1000 to 1019.
|
||||
HAL(NeoPixel,1020,20,NEO_GRB,0x61)
|
||||
This is a NeoPixel driver on i2c address 0x61
|
||||
|
||||
2. Setting pixels from the < > commands.
|
||||
By default, each pixel in the string is created as white but switched off.
|
||||
Each pixel has a vpin starting from the first vpin in the HAL definitions.
|
||||
|
||||
<o vpin> switches pixel on (same as <z vpin>) e.g. <o 1005>
|
||||
<o -vpin> switches pixel off (same as <z -vpin>) e.g. <o -1003>
|
||||
(the z commands work on pixels the same as other gpio pins.)
|
||||
|
||||
<o [-]vpin count> switches on/off count pixels starting at vpin. e.g <o 1000 5>
|
||||
Note: it IS acceptable to switch across 2 strings of pixels if they are contiguous vpin ranges. It is also interesting that this command doesnt care if the vpins are NeoPixel or any other type, so it can be used to switch a range of other pin types.
|
||||
|
||||
<o [-]vpin red green blue [count]> sets the colour and on/off status of a pin or pins. Each colour is 0..255 e.g. <o 1005 255 255 0> sets pin 1005 to bright yellow and ON, <0 -1006 0 0 255 10> sets pins 1006 to 1015 (10 pins) to bright blue but OFF.
|
||||
Note: If you set a pin to a colour, you can turn it on and off without having to reset the colour every time. This is something the adafruit seesaw library can't do and is just one of several reasons why we dont use it.
|
||||
|
||||
3. Setting pixels from EXRAIL
|
||||
The new NEOPIXEL macro provides the same functionality as the <o [-]vpin red green blue [count]> command above.
|
||||
NEOPIXEL([-]vpin, red, green, blue [,count])
|
||||
|
||||
Setting pixels on or off (without colour change) can be done with SET/RESET [currently there is no set range facility but that may be added as a general exrail thing... watch this space]
|
||||
|
||||
Because the pixels obey set/reset, the BLINK command can also be used to control blinking a pixel.
|
||||
|
||||
4. EXRAIL pixel signals.
|
||||
There are two types possible, a mast with separate fixed colour pixels for each aspect, or a mast with one multiple colour pixel for all aspects.
|
||||
|
||||
For separate pixels, the colours should be established at startup and a normal SIGNALH macro used.
|
||||
|
||||
AUTOSTART
|
||||
SIGNALH(1010,1011,1012)
|
||||
NEOPIXEL(1010,255,0,0)
|
||||
NEOPIXEL(1011,128,128,0)
|
||||
NEOPIXEL(1012,0,255,0)
|
||||
RED(1010) // force signal state otherwise all 3 lights will be on
|
||||
DONE
|
||||
|
||||
For signals with 1 pixel, the NEOPIXEL_SIGNAL macro will create a signal
|
||||
NEOPIXEL_SIGNAL(vpin,redfx,amberfx,greenfx)
|
||||
|
||||
** Changed... ****
|
||||
The fx values above can be created by the NeoRGB macro so a bright red would be NeoRGB(255,0,0) bright green NeoRGB(0,255,0) and amber something like NeoRGB(255,100,0)
|
||||
NeoRGB creates a single int32_t value so it can be used in several ways as convenient.
|
||||
|
||||
// create 1-lamp signal with NeoRGB colours
|
||||
NEOPIXEL_SIGNAL(1000,NeoRGB(255,0,0),NeoRGB(255,100,0),NeoRGB(0,255,0))
|
||||
|
||||
// Create 1-lamp signal with named colours.
|
||||
// This is better if you have multiple signals.
|
||||
// (Note: ALIAS is not suitable due to word length defaults)
|
||||
#define REDLAMP NeoRGB(255,0,0)
|
||||
#define AMBERLAMP NeoRGB(255,100,0)
|
||||
#define GREENLAMP NeoRGB(0,255,0)
|
||||
NEOPIXEL_SIGNAL(1001,REDLAMP,AMBERLAMP,GREENLAMP)
|
||||
|
||||
// Create 1-lamp signal with web type RGB colours
|
||||
// (Using blue for the amber signal , just testing)
|
||||
NEOPIXEL_SIGNAL(1002,0xFF0000,0x0000FF,0x00FF00)
|
||||
|
||||
|
||||
|
44
Release_Notes/TCA8418.md
Normal file
44
Release_Notes/TCA8418.md
Normal file
@ -0,0 +1,44 @@
|
||||
## TCA8418 ##
|
||||
|
||||
The TCA8418 IC from Texas Instruments is a low cost and very capable GPIO and keyboard scanner. Used as a keyboard scanner, it has 8 rows of 10 columns of IO pins which allow encoding of up to 80 buttons. The IC is available on an Adafruit board with Qwiic I2C interconnect called the "Adafruit TCA8418 Keypad Matrix and GPIO Expander Breakout" and available here for the modest sum of $US6 or so: https://www.adafruit.com/product/4918
|
||||
|
||||
The great advantage of this IC is that the keyboard scanning is done continuously, and it has a 10-element event queue, so even if you don't get to the interrupt immediately, keypress and release events will be held for you. Since it's I2C its very easy to use with any DCC-EX command station.
|
||||
|
||||
The TCA8418 driver presently configures the IC in the full 8x10 keyboard scanning mode, and then maps each key down/key up event to the state of a single vpin for extremely easy use from within EX-RAIL and JMRI as each key looks like an individual sensor.
|
||||
|
||||
This is ideal for mimic panels where you may need a lot of buttons, but with this board you can use just 18 wires to handle as many as 80 buttons.
|
||||
|
||||
By adding a simple HAL statement to myAutomation.h it creates between 1 and 80 buttons it will report back.
|
||||
|
||||
`HAL(TCA8418, firstVpin, numPins, I2CAddress, interruptPin)`
|
||||
|
||||
For example:
|
||||
|
||||
`HAL(TCA8418, 300, 80, 0x34)`
|
||||
|
||||
Creates VPINs 300-379 which you can monitor with EX-RAIL, JMRI sensors etc.
|
||||
|
||||
With an 8x10 key event matrix, the events are numbered using the Rn row pins and Cn column pins as such:
|
||||
|
||||
C0 C1 C2 C3 C4 C5 C6 C7 C8 C9
|
||||
========================================
|
||||
R0| 0 1 2 3 4 5 6 7 8 9
|
||||
R1| 10 11 12 13 14 15 16 17 18 19
|
||||
R2| 20 21 22 23 24 25 26 27 28 29
|
||||
R3| 30 31 32 33 34 35 36 37 38 39
|
||||
R4| 40 41 42 43 44 45 46 47 48 49
|
||||
R5| 50 51 52 53 54 55 56 57 58 59
|
||||
R6| 60 61 62 63 64 65 66 67 68 69
|
||||
R7| 70 71 72 73 74 75 76 77 78 79
|
||||
|
||||
So if you start with the first pin definition being VPIN 300, R0/C0 will be 300 + 0, and R7/C9 will be 300+79 or 379.
|
||||
|
||||
Use something like this on a multiplexor, and with up to 8 of the 8-way multiplexors you could have 64 different TCA8418 boards:
|
||||
|
||||
`HAL(TCA8418, 400, 80, {SubBus_1, 0x34})`
|
||||
|
||||
And if needing an Interrupt pin to speed up operations:
|
||||
`HAL(TCA8418, 300, 80, 0x34, 21)`
|
||||
|
||||
Note that using an interrupt pin speeds up button press acquisition considerably (less than a millisecond vs 10-100), but even with interrupts enabled the code presently checks every 100ms in case the interrupt pin becomes disconnected. Use any available Arduino pin for interrupt monitoring.
|
||||
|
84
Release_Notes/TM1638.md
Normal file
84
Release_Notes/TM1638.md
Normal file
@ -0,0 +1,84 @@
|
||||
## TM1638 ##
|
||||
|
||||
The TM1638 board provides a very cheap way of implementing 8 buttons, 8 leds and an 8 digit 7segment display in a package requiring just 5 Dupont wires (vcc, gnd + 3 GPIO pins) from the command station without soldering.
|
||||
|
||||
|
||||
This is ideal for prototyping and testing, simulating sensors and signals, displaying states etc. For a built layout, this could provide a control for things that are not particularly suited to throttle 'route' buttons, perhaps lineside automations or fiddle yard lane selection.
|
||||
|
||||
By adding a simple HAL statement to myAutomation.h it creates 8 buttons/sensors and 8 leds.
|
||||
|
||||
`HAL(TM1638,500,29,31,33)`
|
||||
Creates VPINs 500-507 And desscribes the GPIO pins used to connect the clk,dio,stb pins on the TM1638 board.
|
||||
|
||||
Setting each of the VPINs will control the associated LED (using for example SET, RESET or BLINK in Exrail or `<z 500> <z -501> from a command).
|
||||
|
||||
Unlike most pins, you can also read the same pin number and get the button state, using Exrail IF/AT/ONBUTTON etc.
|
||||
|
||||
For example:
|
||||
`
|
||||
HAL(TM1638,500,29,31,33)
|
||||
`
|
||||
All the folowing examples assume you are using VPIN 500 as the first, leftmost, led/button on the TM1638 board.
|
||||
|
||||
|
||||
`ONBUTTON(500)
|
||||
SET(500) // light the first led
|
||||
BLINK(501,500,500) // blink the second led
|
||||
SETLOCO(3) FWD(50) // set a loco going
|
||||
AT(501) STOP // press second button to stop
|
||||
RESET(500) RESET(501) // turn leds off
|
||||
DONE
|
||||
`
|
||||
|
||||
Buttons behave like any other sensor, so using `<S 500 500 1>` will cause the command station to issue `<Q 500>` and `<q 500>` messages when the first button is pressed or released.
|
||||
|
||||
Exrail `JMRI_SENSOR(500,8)` will create `<S` commands for all 8 buttons.
|
||||
|
||||
## Using the 7 Segment display ##
|
||||
|
||||
The 8 digit display can be treated as 8 separate digits (left most being the same VPIN as the leftmost button and led) or be written to in sections of any length. Writing uses the existing analogue interface to the common HAL but is awkward to use directly. To make this easier from Exrail, a SEG7 macro provides a remapping to the ANOUT facility that makes more sense.
|
||||
|
||||
SEG7(vpin,value,format)
|
||||
|
||||
The vpin determins which digit to start writing at.
|
||||
The value can be a 32bit unsigned integer but is interpreted differentlky according to the format.
|
||||
|
||||
Format values:
|
||||
1..8 give the length (number of display digits) to fill, and defaults to decimal number with leading zeros.
|
||||
|
||||
1X..8X give the length but display in hex.
|
||||
|
||||
1R..4R treats each byte of the value as raw 7-segment patterns so that it can write letters and symbols using any compination of the 7segments and deciml point.
|
||||
|
||||
There is a useful description here:
|
||||
https://jetpackacademy.com/wp-content/uploads/2018/06/TM1638_cheat_sheet_download.pdf
|
||||
|
||||
|
||||
e.g. SEG7(500,3,4)
|
||||
writes 0003 to first 4 digits of the display
|
||||
SEG7(504,0xcafe,4X)
|
||||
writes CAFE to the last 4 digits
|
||||
SEG7(500,0xdeadbeef,8X)
|
||||
writes dEAdbEEF to all 8 digits.
|
||||
|
||||
Writing raw segment patters requires knowledge of the bit pattern to segment relationship:
|
||||
` 0
|
||||
== 0 ==
|
||||
5| | 1
|
||||
== 6 ==
|
||||
4 | | 2
|
||||
== 3 ==
|
||||
7=decimal point
|
||||
|
||||
Thus Letter A is segments 6 5 4 2 1 0, in bits that is (0 bit on right)
|
||||
0b01110111 or 0x77
|
||||
This is not easy to do my hand and thus a new string type suffix has been introduced to make simple text messages. Note that the HAL interface only has width for 32 bits which is only 4 symbols so writing 8 digits requires two calls.
|
||||
|
||||
e.g. SEG7(500,"Hell"_s7,4R) SEG7(504,"o"_s7,4R)
|
||||
DELAY(1000)
|
||||
SEG7(500,"Worl"_s7,4R) SEG7(504,"d"_s7,4R)
|
||||
|
||||
Note that some letters like k,m,v,x do not have particularly readable 7-segment representations.
|
||||
|
||||
Credit to https://github.com/dvarrel/TM1638 for the basic formulae.
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* © 2022 Paul M. Antoine
|
||||
* © 2021 Chris Harlow
|
||||
* © 2022 Harald Barth
|
||||
* © 2022 2024 Harald Barth
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of DCC++EX
|
||||
@ -23,6 +23,7 @@
|
||||
#include "SerialManager.h"
|
||||
#include "DCCEXParser.h"
|
||||
#include "StringFormatter.h"
|
||||
#include "DIAG.h"
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#ifdef SERIAL_BT_COMMANDS
|
||||
@ -36,6 +37,10 @@ BluetoothSerial SerialBT;
|
||||
#endif //COMMANDS
|
||||
#endif //ESP32
|
||||
|
||||
static const byte PAYLOAD_FALSE = 0;
|
||||
static const byte PAYLOAD_NORMAL = 1;
|
||||
static const byte PAYLOAD_STRING = 2;
|
||||
|
||||
SerialManager * SerialManager::first=NULL;
|
||||
|
||||
SerialManager::SerialManager(Stream * myserial) {
|
||||
@ -43,7 +48,7 @@ SerialManager::SerialManager(Stream * myserial) {
|
||||
next=first;
|
||||
first=this;
|
||||
bufferLength=0;
|
||||
inCommandPayload=false;
|
||||
inCommandPayload=PAYLOAD_FALSE;
|
||||
}
|
||||
|
||||
void SerialManager::init() {
|
||||
@ -68,7 +73,11 @@ void SerialManager::init() {
|
||||
new SerialManager(&Serial3);
|
||||
#endif
|
||||
#ifdef SERIAL2_COMMANDS
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
Serial2.begin(115200, SERIAL_8N1, 16, 17); // GPIO 16 RXD2; GPIO 17 TXD2 on ESP32
|
||||
#else // not ESP32
|
||||
Serial2.begin(115200);
|
||||
#endif // ESP32
|
||||
new SerialManager(&Serial2);
|
||||
#endif
|
||||
#ifdef SERIAL1_COMMANDS
|
||||
@ -88,7 +97,11 @@ void SerialManager::init() {
|
||||
}
|
||||
#endif
|
||||
#ifdef SABERTOOTH
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
Serial2.begin(9600, SERIAL_8N1, 16, 17); // GPIO 16 RXD2; GPIO 17 TXD2 on ESP32
|
||||
#else
|
||||
Serial2.begin(9600);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -104,23 +117,43 @@ void SerialManager::loop() {
|
||||
}
|
||||
|
||||
void SerialManager::loop2() {
|
||||
while (serial->available()) {
|
||||
char ch = serial->read();
|
||||
if (ch == '<') {
|
||||
inCommandPayload = true;
|
||||
bufferLength = 0;
|
||||
buffer[0] = '\0';
|
||||
}
|
||||
else if (inCommandPayload) {
|
||||
if (bufferLength < (COMMAND_BUFFER_SIZE-1))
|
||||
buffer[bufferLength++] = ch;
|
||||
while (serial->available()) {
|
||||
char ch = serial->read();
|
||||
if (!inCommandPayload) {
|
||||
if (ch == '<') {
|
||||
inCommandPayload = PAYLOAD_NORMAL;
|
||||
bufferLength = 0;
|
||||
buffer[0] = '\0';
|
||||
}
|
||||
} else { // if (inCommandPayload)
|
||||
if (bufferLength < (COMMAND_BUFFER_SIZE-1)) {
|
||||
buffer[bufferLength++] = ch; // advance bufferLength
|
||||
if (inCommandPayload > PAYLOAD_NORMAL) {
|
||||
if (inCommandPayload > 32 + 2) { // String way too long
|
||||
ch = '>'; // we end this nonsense
|
||||
inCommandPayload = PAYLOAD_NORMAL;
|
||||
DIAG(F("Parse error: Unbalanced string"));
|
||||
// fall through to ending parsing below
|
||||
} else if (ch == '"') { // String end
|
||||
inCommandPayload = PAYLOAD_NORMAL;
|
||||
continue; // do not fall through
|
||||
} else
|
||||
inCommandPayload++;
|
||||
}
|
||||
if (inCommandPayload == PAYLOAD_NORMAL) {
|
||||
if (ch == '>') {
|
||||
buffer[bufferLength] = '\0';
|
||||
DCCEXParser::parse(serial, buffer, NULL);
|
||||
inCommandPayload = false;
|
||||
buffer[bufferLength] = '\0'; // This \0 is after the '>'
|
||||
DCCEXParser::parse(serial, buffer, NULL); // buffer parsed with trailing '>'
|
||||
inCommandPayload = PAYLOAD_FALSE;
|
||||
break;
|
||||
} else if (ch == '"') {
|
||||
inCommandPayload = PAYLOAD_STRING;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
DIAG(F("Parse error: input buffer overflow"));
|
||||
inCommandPayload = PAYLOAD_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,6 @@ private:
|
||||
SerialManager * next;
|
||||
byte bufferLength;
|
||||
byte buffer[COMMAND_BUFFER_SIZE];
|
||||
bool inCommandPayload;
|
||||
byte inCommandPayload;
|
||||
};
|
||||
#endif
|
||||
|
@ -41,5 +41,3 @@ size_t StringBuffer::write(uint8_t b) {
|
||||
_buffer[_pos_write]='\0';
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,4 +35,4 @@ class StringBuffer : public Print {
|
||||
char _buffer[buffer_max+2];
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -139,6 +139,7 @@ void StringFormatter::send2(Print * stream,const FSH* format, va_list args) {
|
||||
case 'd': printPadded(stream,va_arg(args, int), formatWidth, formatLeft); break;
|
||||
case 'u': printPadded(stream,va_arg(args, unsigned int), formatWidth, formatLeft); break;
|
||||
case 'l': printPadded(stream,va_arg(args, long), formatWidth, formatLeft); break;
|
||||
case 'L': stream->print(va_arg(args, unsigned long), DEC); break;
|
||||
case 'b': stream->print(va_arg(args, int), BIN); break;
|
||||
case 'o': stream->print(va_arg(args, int), OCT); break;
|
||||
case 'x': stream->print((unsigned int)va_arg(args, unsigned int), HEX); break;
|
||||
|
26
TemplateForEnums.h
Normal file
26
TemplateForEnums.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* © 2024, Harald Barth. All rights reserved.
|
||||
*
|
||||
* This file is part of DCC-EX
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TemplateForEnums
|
||||
#define TemplateForEnums
|
||||
template<class T> inline T operator~ (T a) { return (T)~(int)a; }
|
||||
template<class T> inline T operator| (T a, T b) { return (T)((int)a | (int)b); }
|
||||
template<class T> inline T operator& (T a, T b) { return (T)((int)a & (int)b); }
|
||||
template<class T> inline T operator^ (T a, T b) { return (T)((int)a ^ (int)b); }
|
||||
#endif
|
||||
|
@ -1,6 +1,8 @@
|
||||
/*
|
||||
* © 2022 Chris Harlow
|
||||
* © 2022-2024 Harald Barth
|
||||
* © 2023-2024 Paul M. Antoine
|
||||
* © 2024 Herb Morton
|
||||
* © 2023 Colin Murdoch
|
||||
* All rights reserved.
|
||||
*
|
||||
@ -35,7 +37,7 @@
|
||||
|
||||
#define APPLY_BY_MODE(findmode,function) \
|
||||
FOR_EACH_TRACK(t) \
|
||||
if (track[t]->getMode()==findmode) \
|
||||
if (track[t]->getMode() & findmode) \
|
||||
track[t]->function;
|
||||
|
||||
MotorDriver * TrackManager::track[MAX_TRACKS] = { NULL };
|
||||
@ -149,6 +151,8 @@ void TrackManager::setDCCSignal( bool on) {
|
||||
HAVE_PORTD(shadowPORTD=PORTD);
|
||||
HAVE_PORTE(shadowPORTE=PORTE);
|
||||
HAVE_PORTF(shadowPORTF=PORTF);
|
||||
HAVE_PORTG(shadowPORTG=PORTG);
|
||||
HAVE_PORTH(shadowPORTH=PORTH);
|
||||
APPLY_BY_MODE(TRACK_MODE_MAIN,setSignal(on));
|
||||
HAVE_PORTA(PORTA=shadowPORTA);
|
||||
HAVE_PORTB(PORTB=shadowPORTB);
|
||||
@ -156,6 +160,8 @@ void TrackManager::setDCCSignal( bool on) {
|
||||
HAVE_PORTD(PORTD=shadowPORTD);
|
||||
HAVE_PORTE(PORTE=shadowPORTE);
|
||||
HAVE_PORTF(PORTF=shadowPORTF);
|
||||
HAVE_PORTG(PORTG=shadowPORTG);
|
||||
HAVE_PORTH(PORTH=shadowPORTH);
|
||||
}
|
||||
|
||||
// setPROGSignal(), called from interrupt context
|
||||
@ -167,6 +173,8 @@ void TrackManager::setPROGSignal( bool on) {
|
||||
HAVE_PORTD(shadowPORTD=PORTD);
|
||||
HAVE_PORTE(shadowPORTE=PORTE);
|
||||
HAVE_PORTF(shadowPORTF=PORTF);
|
||||
HAVE_PORTG(shadowPORTG=PORTG);
|
||||
HAVE_PORTH(shadowPORTH=PORTH);
|
||||
APPLY_BY_MODE(TRACK_MODE_PROG,setSignal(on));
|
||||
HAVE_PORTA(PORTA=shadowPORTA);
|
||||
HAVE_PORTB(PORTB=shadowPORTB);
|
||||
@ -174,6 +182,8 @@ void TrackManager::setPROGSignal( bool on) {
|
||||
HAVE_PORTD(PORTD=shadowPORTD);
|
||||
HAVE_PORTE(PORTE=shadowPORTE);
|
||||
HAVE_PORTF(PORTF=shadowPORTF);
|
||||
HAVE_PORTG(PORTG=shadowPORTG);
|
||||
HAVE_PORTH(PORTH=shadowPORTH);
|
||||
}
|
||||
|
||||
// setDCSignal(), called from normal context
|
||||
@ -236,9 +246,6 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
||||
#endif
|
||||
#ifndef DISABLE_PROG
|
||||
if (mode & TRACK_MODE_PROG) {
|
||||
#else
|
||||
if (false) {
|
||||
#endif
|
||||
// only allow 1 track to be prog
|
||||
FOR_EACH_TRACK(t)
|
||||
if ( (track[t]->getMode() & TRACK_MODE_PROG) && t != trackToSet) {
|
||||
@ -251,6 +258,7 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
||||
} else {
|
||||
track[trackToSet]->makeProgTrack(false); // only the prog track knows it's type
|
||||
}
|
||||
#endif
|
||||
|
||||
// When a track is switched, we must clear any side effects of its previous
|
||||
// state, otherwise trains run away or just dont move.
|
||||
@ -348,11 +356,24 @@ bool TrackManager::setTrackMode(byte trackToSet, TRACK_MODE mode, int16_t dcAddr
|
||||
applyDCSpeed(trackToSet);
|
||||
}
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#ifndef DISABLE_PROG
|
||||
if (tempProgTrack == trackToSet && oldmode & TRACK_MODE_MAIN && !(mode & TRACK_MODE_PROG)) {
|
||||
// If we just take away the prog track, the join should not
|
||||
// be active either. So do in effect an unjoin
|
||||
//DIAG(F("Unsync"));
|
||||
tempProgTrack = MAX_TRACKS+1;
|
||||
progTrackSyncMain=false;
|
||||
if (joinRelay!=UNUSED_PIN) digitalWrite(joinRelay,LOW);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
// Turn off power if we changed the mode of this track
|
||||
if (mode != oldmode)
|
||||
if (mode != oldmode) {
|
||||
track[trackToSet]->setPower(POWERMODE::OFF);
|
||||
streamTrackState(NULL,trackToSet);
|
||||
}
|
||||
|
||||
streamTrackState(NULL,trackToSet);
|
||||
//DIAG(F("TrackMode=%d"),mode);
|
||||
return true;
|
||||
}
|
||||
@ -377,11 +398,15 @@ bool TrackManager::parseEqualSign(Print *stream, int16_t params, int16_t p[])
|
||||
if (params>1 && (p[0]<0 || p[0]>=MAX_TRACKS))
|
||||
return false;
|
||||
|
||||
if (params==2 && p[1]=="MAIN"_hk) // <= id MAIN>
|
||||
if (params==2 && p[1]=="MAIN"_hk) // <= id MAIN>
|
||||
return setTrackMode(p[0],TRACK_MODE_MAIN);
|
||||
if (params==2 && p[1]=="MAIN_INV"_hk) // <= id MAIN_INV>
|
||||
return setTrackMode(p[0],TRACK_MODE_MAIN_INV);
|
||||
if (params==2 && p[1]=="MAIN_AUTO"_hk) // <= id MAIN_AUTO>
|
||||
return setTrackMode(p[0],TRACK_MODE_MAIN_AUTO);
|
||||
|
||||
#ifndef DISABLE_PROG
|
||||
if (params==2 && p[1]=="PROG"_hk) // <= id PROG>
|
||||
if (params==2 && p[1]=="PROG"_hk) // <= id PROG>
|
||||
return setTrackMode(p[0],TRACK_MODE_PROG);
|
||||
#endif
|
||||
|
||||
@ -392,20 +417,27 @@ bool TrackManager::parseEqualSign(Print *stream, int16_t params, int16_t p[])
|
||||
return setTrackMode(p[0],TRACK_MODE_EXT);
|
||||
#ifdef BOOSTER_INPUT
|
||||
if (TRACK_MODE_BOOST != 0 && // compile time optimization
|
||||
params==2 && p[1]=="BOOST"_hk) // <= id BOOST>
|
||||
params==2 && p[1]=="BOOST"_hk) // <= id BOOST>
|
||||
return setTrackMode(p[0],TRACK_MODE_BOOST);
|
||||
if (TRACK_MODE_BOOST_INV != 0 && // compile time optimization
|
||||
params==2 && p[1]=="BOOST_INV"_hk) // <= id BOOST_INV>
|
||||
return setTrackMode(p[0],TRACK_MODE_BOOST_INV);
|
||||
if (TRACK_MODE_BOOST_AUTO != 0 && // compile time optimization
|
||||
params==2 && p[1]=="BOOST_AUTO"_hk) // <= id BOOST_AUTO>
|
||||
return setTrackMode(p[0],TRACK_MODE_BOOST_AUTO);
|
||||
#endif
|
||||
if (params==2 && p[1]=="AUTO"_hk) // <= id AUTO>
|
||||
return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODE_AUTOINV);
|
||||
if (params==2 && p[1]=="AUTO"_hk) // <= id AUTO>
|
||||
return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODIFIER_AUTO);
|
||||
|
||||
if (params==2 && p[1]=="INV"_hk) // <= id AUTO>
|
||||
return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODE_INV);
|
||||
if (params==2 && p[1]=="INV"_hk) // <= id INV>
|
||||
return setTrackMode(p[0], track[p[0]]->getMode() | TRACK_MODIFIER_INV);
|
||||
|
||||
if (params==3 && p[1]=="DC"_hk && p[2]>0) // <= id DC cab>
|
||||
if (params==3 && p[1]=="DC"_hk && p[2]>0) // <= id DC cab>
|
||||
return setTrackMode(p[0],TRACK_MODE_DC,p[2]);
|
||||
|
||||
if (params==3 && p[1]=="DCX"_hk && p[2]>0) // <= id DCX cab>
|
||||
return setTrackMode(p[0],TRACK_MODE_DC|TRACK_MODE_INV,p[2]);
|
||||
if (params==3 && (p[1]=="DC_INV"_hk || // <= id DC_INV cab>
|
||||
p[1]=="DCX"_hk) && p[2]>0) // <= id DCX cab>
|
||||
return setTrackMode(p[0],TRACK_MODE_DC_INV,p[2]);
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -414,9 +446,9 @@ const FSH* TrackManager::getModeName(TRACK_MODE tm) {
|
||||
const FSH *modename=F("---");
|
||||
|
||||
if (tm & TRACK_MODE_MAIN) {
|
||||
if(tm & TRACK_MODE_AUTOINV)
|
||||
if(tm & TRACK_MODIFIER_AUTO)
|
||||
modename=F("MAIN A");
|
||||
else if (tm & TRACK_MODE_INV)
|
||||
else if (tm & TRACK_MODIFIER_INV)
|
||||
modename=F("MAIN I>\n");
|
||||
else
|
||||
modename=F("MAIN");
|
||||
@ -430,15 +462,15 @@ const FSH* TrackManager::getModeName(TRACK_MODE tm) {
|
||||
else if(tm & TRACK_MODE_EXT)
|
||||
modename=F("EXT");
|
||||
else if(tm & TRACK_MODE_BOOST) {
|
||||
if(tm & TRACK_MODE_AUTOINV)
|
||||
if(tm & TRACK_MODIFIER_AUTO)
|
||||
modename=F("BOOST A");
|
||||
else if (tm & TRACK_MODE_INV)
|
||||
else if (tm & TRACK_MODIFIER_INV)
|
||||
modename=F("BOOST I");
|
||||
else
|
||||
modename=F("BOOST");
|
||||
}
|
||||
else if (tm & TRACK_MODE_DC) {
|
||||
if (tm & TRACK_MODE_INV)
|
||||
if (tm & TRACK_MODIFIER_INV)
|
||||
modename=F("DCX");
|
||||
else
|
||||
modename=F("DC");
|
||||
@ -631,22 +663,23 @@ void TrackManager::setJoinRelayPin(byte joinRelayPin) {
|
||||
|
||||
void TrackManager::setJoin(bool joined) {
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
if (joined) {
|
||||
if (joined) { // if we go into joined mode (PROG acts as MAIN)
|
||||
FOR_EACH_TRACK(t) {
|
||||
if (track[t]->getMode() & TRACK_MODE_PROG) {
|
||||
tempProgTrack = t;
|
||||
if (track[t]->getMode() & TRACK_MODE_PROG) { // find PROG track
|
||||
tempProgTrack = t; // remember PROG track
|
||||
setTrackMode(t, TRACK_MODE_MAIN);
|
||||
break;
|
||||
// setPower() of the track called after
|
||||
// seperately after setJoin() instead
|
||||
break; // there is only one prog track, done
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (tempProgTrack != MAX_TRACKS+1) {
|
||||
// as setTrackMode with TRACK_MODE_PROG defaults to
|
||||
// power off, we will take the current power state
|
||||
// of our track and then preserve that state.
|
||||
POWERMODE tPTmode = track[tempProgTrack]->getPower(); //get current power status of this track
|
||||
setTrackMode(tempProgTrack, TRACK_MODE_PROG);
|
||||
track[tempProgTrack]->setPower(tPTmode); //set track status as it was before
|
||||
// setTrackMode defaults to power off, so we
|
||||
// need to preserve that state.
|
||||
POWERMODE tPTmode = track[tempProgTrack]->getPower(); // get current power status of this track
|
||||
setTrackMode(tempProgTrack, TRACK_MODE_PROG); // set track mode back to prog
|
||||
track[tempProgTrack]->setPower(tPTmode); // set power status as it was before
|
||||
tempProgTrack = MAX_TRACKS+1;
|
||||
}
|
||||
}
|
||||
@ -674,4 +707,3 @@ TRACK_MODE TrackManager::getMode(byte t) {
|
||||
int16_t TrackManager::returnDCAddr(byte t) {
|
||||
return (trackDCAddr[t]);
|
||||
}
|
||||
|
||||
|
13
Turnouts.cpp
13
Turnouts.cpp
@ -123,7 +123,6 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
#define DIAG_IO
|
||||
// Static setClosed function is invoked from close(), throw() etc. to perform the
|
||||
// common parts of the turnout operation. Code which is specific to a turnout
|
||||
// type should be placed in the virtual function setClosedInternal(bool) which is
|
||||
@ -313,12 +312,6 @@
|
||||
*
|
||||
*************************************************************************************/
|
||||
|
||||
#if defined(DCC_TURNOUTS_RCN_213)
|
||||
const bool DCCTurnout::rcn213Compliant = true;
|
||||
#else
|
||||
const bool DCCTurnout::rcn213Compliant = false;
|
||||
#endif
|
||||
|
||||
// DCCTurnoutData contains data specific to this subclass that is
|
||||
// written to EEPROM when the turnout is saved.
|
||||
struct DCCTurnoutData {
|
||||
@ -386,7 +379,10 @@
|
||||
// DCC++ Classic behaviour is that Throw writes a 1 in the packet,
|
||||
// and Close writes a 0.
|
||||
// RCN-213 specifies that Throw is 0 and Close is 1.
|
||||
DCC::setAccessory(_dccTurnoutData.address, _dccTurnoutData.subAddress, close ^ !rcn213Compliant);
|
||||
#ifndef DCC_TURNOUTS_RCN_213
|
||||
close = !close;
|
||||
#endif
|
||||
DCC::setAccessory(_dccTurnoutData.address, _dccTurnoutData.subAddress, close);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -528,4 +524,3 @@
|
||||
StringFormatter::send(stream, F("<H %d LCN %d>\n"), _turnoutData.id,
|
||||
!_turnoutData.closed);
|
||||
}
|
||||
|
||||
|
@ -245,8 +245,6 @@ public:
|
||||
// Load a VPIN turnout definition from EEPROM. The common Turnout data has already been read at this point.
|
||||
static Turnout *load(struct TurnoutData *turnoutData);
|
||||
void print(Print *stream) override;
|
||||
// Flag whether DCC Accessory packets are to contain 1=close/0=throw(RCN-213) or 1=throw/0-close (DCC++ Classic)
|
||||
static const bool rcn213Compliant;
|
||||
|
||||
protected:
|
||||
bool setClosedInternal(bool close) override;
|
||||
|
@ -322,6 +322,15 @@ void WiThrottle::locoAction(RingStream * stream, byte* aval, char throttleChar,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'f': // Function key set, force function variant
|
||||
{
|
||||
bool pressed=aval[1]=='1';
|
||||
int fKey = getInt(aval+2);
|
||||
LOOPLOCOS(throttleChar, cab) {
|
||||
DCC::setFn(myLocos[loco].cab,fKey, pressed);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'q':
|
||||
if (aval[1]=='V' || aval[1]=='R' ) { //qV or qR
|
||||
// just flag the loco for broadcast and it will happen.
|
||||
@ -491,9 +500,9 @@ void WiThrottle::getLocoCallback(int16_t locoid) {
|
||||
char addcmd[20]={'M',stashThrottleChar,'+', addrchar};
|
||||
itoa(locoid,addcmd+4,10);
|
||||
stashInstance->multithrottle(stashStream, (byte *)addcmd);
|
||||
TrackManager::setJoin(true); // <1 JOIN> so we can drive loco away
|
||||
TrackManager::setMainPower(POWERMODE::ON);
|
||||
TrackManager::setProgPower(POWERMODE::ON);
|
||||
TrackManager::setJoin(true); // <1 JOIN> so we can drive loco away
|
||||
DIAG(F("LocoCallback commit success"));
|
||||
stashStream->commit();
|
||||
}
|
||||
|
@ -23,13 +23,13 @@
|
||||
#include <vector>
|
||||
#include "defines.h"
|
||||
#include "ESPmDNS.h"
|
||||
#include <WiFi.h>
|
||||
#include "esp_wifi.h"
|
||||
#include "WifiESP32.h"
|
||||
#include "DIAG.h"
|
||||
#include "RingStream.h"
|
||||
#include "CommandDistributor.h"
|
||||
#include "WiThrottle.h"
|
||||
#include "DCC.h"
|
||||
/*
|
||||
#include "soc/rtc_wdt.h"
|
||||
#include "esp_task_wdt.h"
|
||||
@ -109,10 +109,13 @@ private:
|
||||
bool inUse;
|
||||
};
|
||||
|
||||
// file scope variables
|
||||
static std::vector<NetworkClient> clients; // a list to hold all clients
|
||||
static WiFiServer *server = NULL;
|
||||
static RingStream *outboundRing = new RingStream(10240);
|
||||
static bool APmode = false;
|
||||
// init of static class scope variables
|
||||
bool WifiESP::wifiUp = false;
|
||||
WiFiServer *WifiESP::server = NULL;
|
||||
|
||||
#ifdef WIFI_TASK_ON_CORE0
|
||||
void wifiLoop(void *){
|
||||
@ -128,6 +131,30 @@ char asciitolower(char in) {
|
||||
return in;
|
||||
}
|
||||
|
||||
void WifiESP::teardown() {
|
||||
// stop all locos
|
||||
DCC::setThrottle(0,1,1); // this broadcasts speed 1(estop) and sets all reminders to speed 1.
|
||||
// terminate all clients connections
|
||||
while (!clients.empty()) {
|
||||
// pop_back() should invoke destructor which does stop()
|
||||
// on the underlying TCP connction
|
||||
clients.pop_back();
|
||||
}
|
||||
// stop server
|
||||
if (server != NULL) {
|
||||
server->stop();
|
||||
server->close();
|
||||
server->end();
|
||||
DIAG(F("server stop, close, end"));
|
||||
}
|
||||
// terminate MDNS anouncement
|
||||
mdns_service_remove_all();
|
||||
mdns_free();
|
||||
// stop WiFi
|
||||
WiFi.disconnect(true);
|
||||
wifiUp = false;
|
||||
}
|
||||
|
||||
bool WifiESP::setup(const char *SSid,
|
||||
const char *password,
|
||||
const char *hostname,
|
||||
@ -136,8 +163,10 @@ bool WifiESP::setup(const char *SSid,
|
||||
const bool forceAP) {
|
||||
bool havePassword = true;
|
||||
bool haveSSID = true;
|
||||
bool wifiUp = false;
|
||||
// bool wifiUp = false;
|
||||
uint8_t tries = 40;
|
||||
if (wifiUp)
|
||||
teardown();
|
||||
|
||||
//#ifdef SERIAL_BT_COMMANDS
|
||||
//return false;
|
||||
@ -147,6 +176,12 @@ bool WifiESP::setup(const char *SSid,
|
||||
// enableCoreWDT(1);
|
||||
// disableCoreWDT(0);
|
||||
|
||||
#ifdef WIFI_LED
|
||||
// Turn off Wifi LED
|
||||
pinMode(WIFI_LED, OUTPUT);
|
||||
digitalWrite(WIFI_LED, 0);
|
||||
#endif
|
||||
|
||||
// clean start
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect(true);
|
||||
@ -247,12 +282,19 @@ bool WifiESP::setup(const char *SSid,
|
||||
// no idea to go on
|
||||
return false;
|
||||
}
|
||||
#ifdef WIFI_LED
|
||||
else{
|
||||
// Turn on Wifi connected LED
|
||||
digitalWrite(WIFI_LED, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Now Wifi is up, register the mDNS service
|
||||
if(!MDNS.begin(hostname)) {
|
||||
DIAG(F("Wifi setup failed to start mDNS"));
|
||||
}
|
||||
if(!MDNS.addService("withrottle", "tcp", 2560)) {
|
||||
if(!MDNS.addService("withrottle", "tcp", port)) {
|
||||
DIAG(F("Wifi setup failed to add withrottle service to mDNS"));
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#ifndef WifiESP32_h
|
||||
#define WifiESP32_h
|
||||
|
||||
#include <WiFi.h>
|
||||
#include "FSH.h"
|
||||
|
||||
class WifiESP
|
||||
@ -36,6 +37,9 @@ public:
|
||||
const bool forceAP);
|
||||
static void loop();
|
||||
private:
|
||||
static void teardown();
|
||||
static bool wifiUp;
|
||||
static WiFiServer *server;
|
||||
};
|
||||
#endif //WifiESP8266_h
|
||||
#endif //ESP8266
|
||||
|
@ -1,4 +1,5 @@
|
||||
/*
|
||||
* © 2022-2024 Paul M. Antoine
|
||||
* © 2021 Fred Decker
|
||||
* © 2020-2022 Harald Barth
|
||||
* © 2020-2022 Chris Harlow
|
||||
@ -70,9 +71,10 @@ Stream * WifiInterface::wifiStream;
|
||||
#define SERIAL3 Serial5
|
||||
#elif defined(ARDUINO_NUCLEO_F413ZH) || defined(ARDUINO_NUCLEO_F429ZI) \
|
||||
|| defined(ARDUINO_NUCLEO_F446ZE) || defined(ARDUINO_NUCLEO_F412ZG) \
|
||||
|| defined(ARDUINO_NUCLEO_F439ZI)
|
||||
#define NUM_SERIAL 2
|
||||
|| defined(ARDUINO_NUCLEO_F439ZI) || defined(ARDUINO_NUCLEO_F4X9ZI)
|
||||
#define NUM_SERIAL 3
|
||||
#define SERIAL1 Serial6
|
||||
#define SERIAL3 Serial2
|
||||
#else
|
||||
#warning This variant of Nucleo not yet explicitly supported
|
||||
#endif
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* © 2022 Paul M. Antoine
|
||||
* © 2021 Neil McKechnie
|
||||
* © 2020-2023 Harald Barth
|
||||
* © 2020-2025 Harald Barth
|
||||
* © 2020-2021 Fred Decker
|
||||
* © 2020-2021 Chris Harlow
|
||||
* © 2023 Nathan Kellenicki
|
||||
@ -45,15 +45,14 @@ The configuration file for DCC-EX Command Station
|
||||
// the correct resistor could damage the sense pin on your Arduino or destroy
|
||||
// the device.
|
||||
//
|
||||
// DEFINE MOTOR_SHIELD_TYPE BELOW. THESE ARE EXAMPLES. FULL LIST IN MotorDrivers.h
|
||||
// DEFINE MOTOR_SHIELD_TYPE BELOW. THESE ARE EXAMPLES. Full list in MotorDrivers.h
|
||||
//
|
||||
// STANDARD_MOTOR_SHIELD : Arduino Motor shield Rev3 based on the L298 with 18V 2A per channel
|
||||
// POLOLU_MOTOR_SHIELD : Pololu MC33926 Motor Driver (not recommended for prog track)
|
||||
// FUNDUMOTO_SHIELD : Fundumoto Shield, no current sensing (not recommended, no short protection)
|
||||
// FIREBOX_MK1 : The Firebox MK1
|
||||
// FIREBOX_MK1S : The Firebox MK1S
|
||||
// IBT_2_WITH_ARDUINO : Arduino Motor Shield for PROG and IBT-2 for MAIN
|
||||
// EX8874_SHIELD : DCC-EX TI DRV8874 based motor shield
|
||||
// EXCSB1 : DCC-EX CSB-1 hardware
|
||||
// EXCSB1_WITH_EX8874 : DCC-EX CSB-1 hardware with DCC-EX TI DRV8874 shield
|
||||
// NO_SHIELD : CS without any motor shield (as an accessory only CS)
|
||||
// |
|
||||
// +-----------------------v
|
||||
//
|
||||
@ -81,7 +80,7 @@ The configuration file for DCC-EX Command Station
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// NOTE: Only supported on Arduino Mega
|
||||
// NOTE: Not supported on Arduino Uno or Nano
|
||||
// Set to false if you not even want it on the Arduino Mega
|
||||
//
|
||||
#define ENABLE_WIFI true
|
||||
@ -116,13 +115,13 @@ The configuration file for DCC-EX Command Station
|
||||
// Your password may not contain ``"'' (double quote, ASCII 0x22).
|
||||
#define WIFI_PASSWORD "Your network passwd"
|
||||
//
|
||||
// WIFI_HOSTNAME: You probably don't need to change this
|
||||
// WIFI_HOSTNAME: You can change this if you have more than one
|
||||
// CS to make them show up with different names on the network.
|
||||
// Otherwise do not touch.
|
||||
#define WIFI_HOSTNAME "dccex"
|
||||
//
|
||||
// WIFI_CHANNEL: If the line "#define ENABLE_WIFI true" is uncommented,
|
||||
// WiFi will be enabled (Mega only). The default channel is set to "1" whether
|
||||
// this line exists or not. If you need to use an alternate channel (we recommend
|
||||
// using only 1,6, or 11) you may change it here.
|
||||
// WIFI_CHANNEL: The default channel is set to "1". If you need to use an
|
||||
// alternate channel (we recommend using only 1,6, or 11) you may change it here.
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// WIFI_FORCE_AP: If you'd like to specify your own WIFI_SSID in AP mode, set this
|
||||
@ -132,8 +131,9 @@ The configuration file for DCC-EX Command Station
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ENABLE_ETHERNET: Set to true if you have an Arduino Ethernet card (wired). This
|
||||
// is not for Wifi. You will then need the Arduino Ethernet library as well
|
||||
// ENABLE_ETHERNET: Set to true if you have an Arduino Ethernet card (wired) based
|
||||
// on the W5100/W5500 ethernet chip or an STM32 CS with builin ethernet like the F429ZI.
|
||||
// This is not for Wifi. You will then need the Arduino Ethernet library as well.
|
||||
//
|
||||
//#define ENABLE_ETHERNET true
|
||||
|
||||
@ -270,8 +270,9 @@ The configuration file for DCC-EX Command Station
|
||||
// for triggering DCC Accessory Decoders, so that <a addr subaddr 0> generates a
|
||||
// DCC packet with D=1 (close turnout) and <a addr subaddr 1> generates D=0
|
||||
// (throw turnout).
|
||||
//#define DCC_ACCESSORY_RCN_213
|
||||
//
|
||||
//#define DCC_ACCESSORY_COMMAND_REVERSE
|
||||
|
||||
|
||||
// HANDLING MULTIPLE SERIAL THROTTLES
|
||||
// The command station always operates with the default Serial port.
|
||||
// Diagnostics are only emitted on the default serial port and not broadcast.
|
||||
@ -307,11 +308,21 @@ The configuration file for DCC-EX Command Station
|
||||
//
|
||||
//#define SERIAL_BT_COMMANDS
|
||||
|
||||
// BOOSTER PIN INPUT ON ESP32
|
||||
// BOOSTER PIN INPUT ON ESP32 CS
|
||||
// On ESP32 you have the possibility to define a pin as booster input
|
||||
// Arduio pin D2 is GPIO 26 on ESPDuino32
|
||||
//
|
||||
// Arduino pin D2 is GPIO 26 is Booster Input on ESPDuino32
|
||||
//#define BOOSTER_INPUT 26
|
||||
//
|
||||
// GPIO 32 is Booster Input on EX-CSB1
|
||||
//#define BOOSTER_INPUT 32
|
||||
|
||||
// ESP32 LED Wifi Indicator
|
||||
// GPIO 2 on ESPduino32
|
||||
//#define WIFI_LED 2
|
||||
//
|
||||
// GPIO 33 on EX-CSB1
|
||||
//#define WIFI_LED 33
|
||||
|
||||
// SABERTOOTH
|
||||
//
|
||||
@ -325,3 +336,17 @@ The configuration file for DCC-EX Command Station
|
||||
//#define SABERTOOTH 1
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SENSORCAM
|
||||
// ESP32-CAM based video sensors require #define to use appropriate base vpin number.
|
||||
//#define SENSORCAM_VPIN 700
|
||||
// To bypass vPin number, define CAM for ex-rail use e.g. AT(CAM 012) for S12 etc.
|
||||
//#define CAM SENSORCAM_VPIN+
|
||||
//
|
||||
//#define SENSORCAM2_VPIN 600 //define other CAM's if installed.
|
||||
//#define CAM2 SENSORCAM2_VPIN+ //for EX-RAIL commands e.g. IFLT(CAM2 020,1)
|
||||
//
|
||||
// For smoother power-up, when using the CAM, you may need a STARTUP_DELAY.
|
||||
// That is described further above.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
120
platformio.ini
120
platformio.ini
@ -12,18 +12,10 @@
|
||||
default_envs =
|
||||
mega2560
|
||||
uno
|
||||
unowifiR2
|
||||
nano
|
||||
samd21-dev-usb
|
||||
samd21-zero-usb
|
||||
ESP32
|
||||
Nucleo-F411RE
|
||||
Nucleo-F446RE
|
||||
Teensy3_2
|
||||
Teensy3_5
|
||||
Teensy3_6
|
||||
Teensy4_0
|
||||
Teensy4_1
|
||||
src_dir = .
|
||||
include_dir = .
|
||||
|
||||
@ -104,10 +96,35 @@ lib_deps =
|
||||
${env.lib_deps}
|
||||
arduino-libraries/Ethernet
|
||||
SPI
|
||||
MDNS_Generic
|
||||
|
||||
lib_ignore = WiFi101
|
||||
WiFi101_Generic
|
||||
WiFiEspAT
|
||||
WiFiMulti_Generic
|
||||
WiFiNINA_Generic
|
||||
|
||||
monitor_speed = 115200
|
||||
monitor_echo = yes
|
||||
build_flags =
|
||||
|
||||
[env:mega2560-eth]
|
||||
platform = atmelavr
|
||||
board = megaatmega2560
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
arduino-libraries/Ethernet
|
||||
MDNS_Generic
|
||||
SPI
|
||||
lib_ignore = WiFi101
|
||||
WiFi101_Generic
|
||||
WiFiEspAT
|
||||
WiFiMulti_Generic
|
||||
WiFiNINA_Generic
|
||||
monitor_speed = 115200
|
||||
monitor_echo = yes
|
||||
|
||||
[env:mega328]
|
||||
platform = atmelavr
|
||||
board = uno
|
||||
@ -164,7 +181,11 @@ monitor_echo = yes
|
||||
build_flags = -mcall-prologues
|
||||
|
||||
[env:ESP32]
|
||||
platform = espressif32
|
||||
; Lock version to 6.7.0 as that is
|
||||
; Arduino v2.0.16 (based on IDF v4.4.7)
|
||||
; which is the latest version based
|
||||
; on IDF v4. We can not use IDF v5.
|
||||
platform = espressif32 @ 6.7.0
|
||||
board = esp32dev
|
||||
framework = arduino
|
||||
lib_deps = ${env.lib_deps}
|
||||
@ -173,7 +194,7 @@ monitor_speed = 115200
|
||||
monitor_echo = yes
|
||||
|
||||
[env:Nucleo-F411RE]
|
||||
platform = ststm32
|
||||
platform = ststm32 @ 17.6.0
|
||||
board = nucleo_f411re
|
||||
framework = arduino
|
||||
lib_deps = ${env.lib_deps}
|
||||
@ -182,7 +203,7 @@ monitor_speed = 115200
|
||||
monitor_echo = yes
|
||||
|
||||
[env:Nucleo-F446RE]
|
||||
platform = ststm32
|
||||
platform = ststm32 @ 17.6.0
|
||||
board = nucleo_f446re
|
||||
framework = arduino
|
||||
lib_deps = ${env.lib_deps}
|
||||
@ -194,7 +215,7 @@ monitor_echo = yes
|
||||
; tested as yet
|
||||
;
|
||||
[env:Nucleo-F401RE]
|
||||
platform = ststm32
|
||||
platform = ststm32 @ 17.6.0
|
||||
board = nucleo_f401re
|
||||
framework = arduino
|
||||
lib_deps = ${env.lib_deps}
|
||||
@ -207,7 +228,7 @@ monitor_echo = yes
|
||||
; installed before you can let PlatformIO see this
|
||||
;
|
||||
; [env:Nucleo-F413ZH]
|
||||
; platform = ststm32
|
||||
; platform = ststm32 @ 17.6.0
|
||||
; board = nucleo_f413zh
|
||||
; framework = arduino
|
||||
; lib_deps = ${env.lib_deps}
|
||||
@ -218,21 +239,21 @@ monitor_echo = yes
|
||||
; Commented out by default as the F446ZE needs variant files
|
||||
; installed before you can let PlatformIO see this
|
||||
;
|
||||
; [env:Nucleo-F446ZE]
|
||||
; platform = ststm32
|
||||
; board = nucleo_f446ze
|
||||
; framework = arduino
|
||||
; lib_deps = ${env.lib_deps}
|
||||
; build_flags = -std=c++17 -Os -g2 -Wunused-variable
|
||||
; monitor_speed = 115200
|
||||
; monitor_echo = yes
|
||||
[env:Nucleo-F446ZE]
|
||||
platform = ststm32 @ 17.6.0
|
||||
board = nucleo_f446ze
|
||||
framework = arduino
|
||||
lib_deps = ${env.lib_deps}
|
||||
build_flags = -std=c++17 -Os -g2 -Wunused-variable
|
||||
monitor_speed = 115200
|
||||
monitor_echo = yes
|
||||
|
||||
; Commented out by default as the F412ZG needs variant files
|
||||
; installed before you can let PlatformIO see this
|
||||
;
|
||||
; [env:Nucleo-F412ZG]
|
||||
; platform = ststm32
|
||||
; board = blah_f412zg
|
||||
; platform = ststm32 @ 17.6.0
|
||||
; board = nucleo_f412zg
|
||||
; framework = arduino
|
||||
; lib_deps = ${env.lib_deps}
|
||||
; build_flags = -std=c++17 -Os -g2 -Wunused-variable
|
||||
@ -242,18 +263,47 @@ monitor_echo = yes
|
||||
|
||||
; Experimental - Ethernet work still in progress
|
||||
;
|
||||
; [env:Nucleo-F429ZI]
|
||||
; platform = ststm32
|
||||
; board = nucleo_f429zi
|
||||
; framework = arduino
|
||||
; lib_deps = ${env.lib_deps}
|
||||
; arduino-libraries/Ethernet @ ^2.0.1
|
||||
; stm32duino/STM32Ethernet @ ^1.3.0
|
||||
; stm32duino/STM32duino LwIP @ ^2.1.2
|
||||
; build_flags = -std=c++17 -Os -g2 -Wunused-variable
|
||||
; monitor_speed = 115200
|
||||
; monitor_echo = yes
|
||||
; upload_protocol = stlink
|
||||
[env:Nucleo-F429ZI]
|
||||
platform = ststm32 @ 17.6.0
|
||||
board = nucleo_f429zi
|
||||
framework = arduino
|
||||
lib_deps = ${env.lib_deps}
|
||||
stm32duino/STM32Ethernet @ ^1.4.0
|
||||
stm32duino/STM32duino LwIP @ ^2.1.3
|
||||
MDNS_Generic
|
||||
lib_ignore = WiFi101
|
||||
WiFi101_Generic
|
||||
WiFiEspAT
|
||||
WiFiMulti_Generic
|
||||
WiFiNINA_Generic
|
||||
build_flags = -std=c++17 -Os -g2 -Wunused-variable
|
||||
monitor_speed = 115200
|
||||
monitor_echo = yes
|
||||
upload_protocol = stlink
|
||||
|
||||
; Experimental - Ethernet work still in progress
|
||||
;
|
||||
[env:Nucleo-F439ZI]
|
||||
platform = ststm32 @ 17.6.0
|
||||
; board = nucleo_f439zi
|
||||
; Temporarily treat it as an F429ZI (they are code compatible) until
|
||||
; the PR to PlatformIO to update the F439ZI JSON file is available
|
||||
; PMA - 28-Sep-2024
|
||||
board = nucleo_f429zi
|
||||
framework = arduino
|
||||
lib_deps = ${env.lib_deps}
|
||||
stm32duino/STM32Ethernet @ ^1.4.0
|
||||
stm32duino/STM32duino LwIP @ ^2.1.3
|
||||
MDNS_Generic
|
||||
lib_ignore = WiFi101
|
||||
WiFi101_Generic
|
||||
WiFiEspAT
|
||||
WiFiMulti_Generic
|
||||
WiFiNINA_Generic
|
||||
build_flags = -std=c++17 -Os -g2 -Wunused-variable
|
||||
monitor_speed = 115200
|
||||
monitor_echo = yes
|
||||
upload_protocol = stlink
|
||||
|
||||
[env:Teensy3_2]
|
||||
platform = teensy
|
||||
|
73
version.h
73
version.h
@ -3,7 +3,78 @@
|
||||
|
||||
#include "StringFormatter.h"
|
||||
|
||||
#define VERSION "5.2.50"
|
||||
#define VERSION "5.4.7"
|
||||
// 5.4.7 - Bugfix: EXRAIL fix CLEAR_ALL_STASH
|
||||
// 5.4.6 - Bugfix: Do not drop further commands in same packet
|
||||
// 5.4.5 - ESP32: Better detection of correct IDF version
|
||||
// - track power is always turned on after setJoin() not by setJoin()
|
||||
// 5.4.4 - bugfix in parser, input buffer overrun and trailing > that did break <+>
|
||||
// 5.4.3 - bugfix changeFn for functions 29..31
|
||||
// 5.4.2 - Reversed turnout bugfix
|
||||
// 5.4.1 - ESP32 bugfix packet buffer race
|
||||
// 5.4.0 - New version on master
|
||||
// 5.2.96 - EXRAIL additions XFWD() and XREV()
|
||||
// 5.2.95 - Release candidate for 5.4
|
||||
// 5.2.94 - Bugfix: Less confusion and simpler code around the RCN213 defines
|
||||
// 5.2.93 - Bugfix ESP32: clear progTrackSyncMain (join flag) when prog track is removed
|
||||
// 5.2.92 - Bugfix: FADE power off fix, EXRAIL power diagnostic fix.
|
||||
// 5.2.91 - Bugfix: Neopixel I2C overlap check
|
||||
// 5.2.90 - Bugfix: EXRAIL EXTT_TURNTABLE() now has description as optional in line with ocumentation (also fixed DCC_TURNTABLE)
|
||||
// 5.2.89 - EXRAIL SET(vpin[,npins]) RESET(vpin,[,npins]) pin range manipulation
|
||||
// 5.2.88 - Fix bug where EX-Turntable objects return incorrect angle for home with <JP x>
|
||||
// 5.2.87 - CamParser and IO_EXSensorCam driver
|
||||
// 5.2.86 - IO_TCA8418 driver for keypad matrix input now fully functioning, including being able to use an interrupt pin
|
||||
// 5.2.85 - IO_TM1638 driver, SEG7 Exrail macro and _s7 segment pattern generator.
|
||||
// 5.2.84 - Fix TrackManager setDCCSignal and setPROGSignal for STM32 shadowing of PORTG/PORTH - this time it really is correct!
|
||||
// 5.2.83 - Various STM32 related fixes for serial ports, I2C pullups now turned off, and shadowing of PORTG/PORTH for TrackManager now correct
|
||||
// 5.2.82 - TrackManager and EXRAIL: Introduce more consistent names for <= ...> and SET_TRACK
|
||||
// 5.2.81 - STM32 Ethernet boards support, also now have specific EX8874 motor driver definition
|
||||
// 5.2.80 - EthernetInterface upgrade, including STM32 Ethernet support
|
||||
// 5.2.79 - serial manager loop that handles quoted strings
|
||||
// - WiFiESP32 reconfig
|
||||
// 5.2.78 - NeoPixel support.
|
||||
// - <o command
|
||||
// - HAL driver
|
||||
// - EXRAIL NEOPIXEL and NEOPIXEL_SIGNAL
|
||||
// 5.2.77 - Withrottle: Implement "force function" subcommand "f"
|
||||
// 5.2.76 - Bugfix: EXRAIL: Catch CV read errors in the callback
|
||||
// 5.2.75 - Bugfix: Serial lines 4 to 6 OK
|
||||
// 5.2.74 - Bugfix: ESP32 turn on the joined prog (as main) again after a prog operation
|
||||
// 5.2.73 - Bugfix: STM32 further fixes to shadowPORT entries in TrackManager.cpp for PORTG and PORTH
|
||||
// 5.2.72 - Bugfix: added shadowPORT entries in TrackManager.cpp for PORTG and PORTH on STM32, fixed typo in MotorDriver.cpp
|
||||
// 5.2.71 - Broadcasts of loco forgets.
|
||||
// 5.2.70 - IO_RocoDriver renamed to IO_EncoderThrottle.
|
||||
// - and included in IODEvice.h (circular dependency removed)
|
||||
// 5.2.69 - IO_RocoDriver. Direct drive train with rotary encoder hw.
|
||||
// 5.2.68 - Revert function map to signed (from 5.2.66) to avoid
|
||||
// incompatibilities with ED etc for F31 frequency flag.
|
||||
// 5.2.67 - EXRAIL AFTER optional debounce time variable (default 500mS)
|
||||
// - AFTER(42) == AFTER(42,500) sets time sensor must
|
||||
// - be continuously off.
|
||||
// 5.2.66 - <F cab DCFREQ 0..3>
|
||||
// - EXRAIL SETFREQ drop loco param (breaking since 5.2.28)
|
||||
// 5.2.65 - Speedup Exrail SETFREQ
|
||||
// 5.2.64 - Bugfix: <0 PROG> updated to undo JOIN
|
||||
// 5.2.63 - Implement WIFI_LED for ESP32, ESPduino32 and EX-CSB1, that is turned on when STA mode connects or AP mode is up
|
||||
// - Add BOOSTER_INPUT definitions for ESPduino32 and EX-CSB1 to config.example.h
|
||||
// - Add WIFI_LED definitions for ESPduino32 and EX-CSB1 to config.example.h
|
||||
// 5.2.62 - Allow acks way longer than standard
|
||||
// 5.2.61 - Merg CBUS ACON/ACOF/ONACON/ONACOF Adapter interface.
|
||||
// - LCC Adapter interface throttled startup,
|
||||
// (Breaking change with Adapter base code)
|
||||
// 5.2.60 - Bugfix: Opcode AFTEROVERLOAD does not have an argument that is a pin and needs to be initialized
|
||||
// - Remove inrush throttle after half good time so that we go to mode overload if problem persists
|
||||
// 5.2.59 - STM32 bugfix correct Serial1 definition for Nucleo-F401RE
|
||||
// - STM32 add support for ARDUINO_NUCLEO_F4X9ZI type to span F429/F439 in upcoming STM32duino release v2.8 as a result of our PR
|
||||
// 5.2.58 - EXRAIL ALIAS allows named pins
|
||||
// 5.2.57 - Bugfix autoreverse: Apply mode by binart bit match and not by equality
|
||||
// 5.2.56 - Bugfix and refactor for EXRAIL getSignalSlot
|
||||
// 5.2.55 - Move EXRAIL isSignal() to public to allow use in STEALTH call
|
||||
// 5.2.54 - Bugfix for EXRAIL signal handling for active high
|
||||
// 5.2.53 - Bugfix for EX-Fastclock, call I2CManager.begin() before checking I2C address
|
||||
// 5.2.52 - Bugfix for ADCee() to handle ADC2 and ADC3 channel inputs on F446ZE and others
|
||||
// - Add support for ports G and H on STM32 for ADCee() and MotorDriver pins/shadow regs
|
||||
// 5.2.51 - Bugfix for SIGNAL: Distinguish between sighandle and sigid
|
||||
// 5.2.50 - EXRAIL ONBUTTON/ONSENSOR observe LATCH
|
||||
// 5.2.49 - EXRAIL additions:
|
||||
// ONBUTTON, ONSENSOR
|
||||
|
Loading…
Reference in New Issue
Block a user