mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2025-06-29 10:35:24 +02:00
make methods of DCCDecoder static; #ifdef all ESP32 only parts
This commit is contained in:
parent
f48f755608
commit
795d0edad9
@ -51,10 +51,12 @@
|
||||
|
||||
#include "DCCEX.h"
|
||||
#include "Display_Implementation.h"
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include "Sniffer.h"
|
||||
#include "DCCDecoder.h"
|
||||
Sniffer *dccSniffer = NULL;
|
||||
DCCDecoder *dccDecoder = NULL;
|
||||
bool DCCDecoder::active = false;
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
|
||||
#ifdef CPU_TYPE_ERROR
|
||||
#error CANNOT COMPILE - DCC++ EX ONLY WORKS WITH THE ARCHITECTURES LISTED IN defines.h
|
||||
@ -128,8 +130,9 @@ void setup()
|
||||
// Start RMFT aka EX-RAIL (ignored if no automnation)
|
||||
RMFT::begin();
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
dccSniffer = new Sniffer(BOOSTER_INPUT);
|
||||
dccDecoder = new DCCDecoder();
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
|
||||
// Invoke any DCC++EX commands in the form "SETUP("xxxx");"" found in optional file mySetup.h.
|
||||
// This can be used to create turnouts, outputs, sensors etc. through the normal text commands.
|
||||
@ -149,14 +152,16 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (dccSniffer && dccDecoder) {
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
if (dccSniffer) {
|
||||
DCCPacket p = dccSniffer->fetchPacket();
|
||||
if (p.len() != 0) {
|
||||
if (dccDecoder->parse(p)) {
|
||||
if (DCCDecoder::parse(p)) {
|
||||
p.print(Serial);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
|
||||
// The main sketch has responsibilities during loop()
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include "DCCDecoder.h"
|
||||
#include "LocoTable.h"
|
||||
#include "DCCEXParser.h"
|
||||
@ -23,6 +24,8 @@
|
||||
#include "DCC.h"
|
||||
|
||||
bool DCCDecoder::parse(DCCPacket &p) {
|
||||
if (!active)
|
||||
return false;
|
||||
const byte DECODER_MOBILE = 1;
|
||||
const byte DECODER_ACCESSORY = 2;
|
||||
byte decoderType = 0; // use 0 as none
|
||||
@ -170,3 +173,4 @@ bool DCCDecoder::parse(DCCPacket &p) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
|
@ -16,13 +16,15 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <Arduino.h>
|
||||
#include "DCCPacket.h"
|
||||
|
||||
class DCCDecoder {
|
||||
public:
|
||||
DCCDecoder() {};
|
||||
bool parse(DCCPacket &p);
|
||||
static bool parse(DCCPacket &p);
|
||||
static inline void onoff(bool on) {active = on;};
|
||||
private:
|
||||
static bool active;
|
||||
};
|
||||
|
||||
#endif // ARDUINO_ARCH_ESP32
|
||||
|
@ -3,7 +3,7 @@
|
||||
* © 2021 Neil McKechnie
|
||||
* © 2021 Mike S
|
||||
* © 2021-2024 Herb Morton
|
||||
* © 2020-2023 Harald Barth
|
||||
* © 2020-2025 Harald Barth
|
||||
* © 2020-2021 M Steve Todd
|
||||
* © 2020-2021 Fred Decker
|
||||
* © 2020-2021 Chris Harlow
|
||||
@ -120,6 +120,7 @@ Once a new OPCODE is decided upon, update this list.
|
||||
#include "CamParser.h"
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include "WifiESP32.h"
|
||||
#include "DCCDecoder.h"
|
||||
#endif
|
||||
|
||||
// This macro can't be created easily as a portable function because the
|
||||
@ -683,6 +684,14 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
||||
case 'C': // CONFIG <C [params]>
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
// currently this only works on ESP32
|
||||
if (p[0] == "SNIFFER"_hk) { // <C SNIFFER ON|OFF>
|
||||
bool on = false;
|
||||
if (params>1 && p[1] == "ON"_hk) {
|
||||
on = true;
|
||||
}
|
||||
DCCDecoder::onoff(on);
|
||||
return;
|
||||
}
|
||||
#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
|
||||
|
Loading…
x
Reference in New Issue
Block a user