mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-27 06:11:25 +01:00
Move call to mySetup into IODevice::begin().
Ensure that HAL devices are created before use by moving the call to mySetup into IODevice::begin(). The need for this became evident when it was noted that RMFT (EX-RAIL) interacts with HAL devices during its initialisation, by enabling pull-ups on digital inputs. Any
This commit is contained in:
parent
58fe81bf06
commit
b384d6c14d
@ -88,16 +88,9 @@ void setup()
|
||||
// Start RMFT (ignored if no automnation)
|
||||
RMFT::begin();
|
||||
|
||||
// Link to and call mySetup() function (if defined in the build in mySetup.cpp).
|
||||
// The contents will depend on the user's system hardware configuration.
|
||||
// The mySetup.cpp file is a standard C++ module so has access to all of the DCC++EX APIs.
|
||||
extern __attribute__((weak)) void mySetup();
|
||||
if (mySetup) {
|
||||
mySetup();
|
||||
}
|
||||
|
||||
// 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. throught the normal text commands.
|
||||
// This can be used to create turnouts, outputs, sensors etc. through the normal text commands.
|
||||
#if __has_include ( "mySetup.h")
|
||||
#define SETUP(cmd) serialParser.parse(F(cmd))
|
||||
#include "mySetup.h"
|
||||
|
61
IODevice.cpp
61
IODevice.cpp
@ -28,6 +28,9 @@
|
||||
#define USE_FAST_IO
|
||||
#endif
|
||||
|
||||
// Link to mySetup function. If not defined, the function reference will be NULL.
|
||||
extern __attribute__((weak)) void mySetup();
|
||||
|
||||
//==================================================================================================================
|
||||
// Static methods
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
@ -57,6 +60,13 @@ void IODevice::begin() {
|
||||
dev->_begin();
|
||||
}
|
||||
_initPhase = false;
|
||||
|
||||
// Call user's mySetup() function (if defined in the build in mySetup.cpp).
|
||||
// The contents will depend on the user's system hardware configuration.
|
||||
// The mySetup.cpp file is a standard C++ module so has access to all of the DCC++EX APIs.
|
||||
if (mySetup) {
|
||||
mySetup();
|
||||
}
|
||||
}
|
||||
|
||||
// Overarching static loop() method for the IODevice subsystem. Works through the
|
||||
@ -148,6 +158,33 @@ void IODevice::_display() {
|
||||
bool IODevice::configure(VPIN vpin, ConfigTypeEnum configType, int paramCount, int params[]) {
|
||||
IODevice *dev = findDevice(vpin);
|
||||
if (dev) return dev->_configure(vpin, configType, paramCount, params);
|
||||
#ifdef DIAG_IO
|
||||
DIAG(F("IODevice::configure(): Vpin ID %d not found!"), (int)vpin);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read value from virtual pin.
|
||||
int IODevice::read(VPIN vpin) {
|
||||
for (IODevice *dev = _firstDevice; dev != 0; dev = dev->_nextDevice) {
|
||||
if (dev->owns(vpin))
|
||||
return dev->_read(vpin);
|
||||
}
|
||||
#ifdef DIAG_IO
|
||||
DIAG(F("IODevice::read(): Vpin %d not found!"), (int)vpin);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read analogue value from virtual pin.
|
||||
int IODevice::readAnalogue(VPIN vpin) {
|
||||
for (IODevice *dev = _firstDevice; dev != 0; dev = dev->_nextDevice) {
|
||||
if (dev->owns(vpin))
|
||||
return dev->_readAnalogue(vpin);
|
||||
}
|
||||
#ifdef DIAG_IO
|
||||
DIAG(F("IODevice::readAnalogue(): Vpin %d not found!"), (int)vpin);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -258,30 +295,6 @@ bool IODevice::owns(VPIN id) {
|
||||
return (id >= _firstVpin && id < _firstVpin + _nPins);
|
||||
}
|
||||
|
||||
// Read value from virtual pin.
|
||||
int IODevice::read(VPIN vpin) {
|
||||
for (IODevice *dev = _firstDevice; dev != 0; dev = dev->_nextDevice) {
|
||||
if (dev->owns(vpin))
|
||||
return dev->_read(vpin);
|
||||
}
|
||||
#ifdef DIAG_IO
|
||||
DIAG(F("IODevice::read(): Vpin %d not found!"), (int)vpin);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read analogue value from virtual pin.
|
||||
int IODevice::readAnalogue(VPIN vpin) {
|
||||
for (IODevice *dev = _firstDevice; dev != 0; dev = dev->_nextDevice) {
|
||||
if (dev->owns(vpin))
|
||||
return dev->_readAnalogue(vpin);
|
||||
}
|
||||
#ifdef DIAG_IO
|
||||
DIAG(F("IODevice::readAnalogue(): Vpin %d not found!"), (int)vpin);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#else // !defined(IO_NO_HAL)
|
||||
|
||||
|
@ -10,8 +10,6 @@
|
||||
//
|
||||
|
||||
#include "IODevice.h"
|
||||
#include "Turnouts.h"
|
||||
#include "Sensors.h"
|
||||
#include "IO_HCSR04.h"
|
||||
#include "IO_VL53L0X.h"
|
||||
|
||||
@ -139,46 +137,6 @@ void mySetup() {
|
||||
//MCP23017::create(196, 16, 0x22);
|
||||
|
||||
|
||||
//=======================================================================
|
||||
// Creating a Turnout
|
||||
//=======================================================================
|
||||
// Parameters: same as <T> command for Servo turnouts
|
||||
// ID and VPIN are 100, sonar moves between positions 102 and 490 with slow profile.
|
||||
// Profile may be Instant, Fast, Medium, Slow or Bounce.
|
||||
|
||||
//ServoTurnout::create(100, 100, 490, 102, PCA9685::Slow);
|
||||
|
||||
|
||||
//=======================================================================
|
||||
// DCC Accessory turnout
|
||||
//=======================================================================
|
||||
// Parameters: same as <T> command for DCC Accessory turnouts
|
||||
// ID=3000
|
||||
// Decoder address=23
|
||||
// Decoder subaddress = 1
|
||||
|
||||
//DCCTurnout::create(3000, 23, 1);
|
||||
|
||||
|
||||
//=======================================================================
|
||||
// Creating a Sensor
|
||||
//=======================================================================
|
||||
// Parameters: As for the <S> command,
|
||||
// id = 164,
|
||||
// Vpin = 164 (configured above as pin 0 of an MCP23017)
|
||||
// Pullup enable = 1 (enabled)
|
||||
|
||||
//Sensor::create(164, 164, 1);
|
||||
|
||||
|
||||
//=======================================================================
|
||||
// Way of creating lots of identical sensors in a range
|
||||
//=======================================================================
|
||||
|
||||
//for (int i=165; i<180; i++)
|
||||
// Sensor::create(i, i, 1);
|
||||
|
||||
|
||||
//=======================================================================
|
||||
// Play mp3 files from a Micro-SD card, using a DFPlayer MP3 Module.
|
||||
//=======================================================================
|
||||
|
Loading…
Reference in New Issue
Block a user