mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-24 21:21:24 +01:00
Remove virtual _isBusy() function in favor of _read().
When writing to analogue outputs pins, the digital _read() function now returns the 'busy' status of the analogue pin. Consequently, the _isBusy() function becomes superfluous and has been removed. The static IODevice::isBusy() function now calls the object's _read() function instead. Also, limit in DFPlayer of 3 pins has been removed.
This commit is contained in:
parent
07cc45d861
commit
ad7cd5f401
19
IODevice.cpp
19
IODevice.cpp
@ -53,7 +53,9 @@ void IODevice::begin() {
|
|||||||
MCP23017::create(180, 16, 0x21);
|
MCP23017::create(180, 16, 0x21);
|
||||||
|
|
||||||
// Call the begin() methods of each configured device in turn
|
// Call the begin() methods of each configured device in turn
|
||||||
|
unsigned long currentMicros = micros();
|
||||||
for (IODevice *dev=_firstDevice; dev!=NULL; dev = dev->_nextDevice) {
|
for (IODevice *dev=_firstDevice; dev!=NULL; dev = dev->_nextDevice) {
|
||||||
|
dev->_nextEntryTime = currentMicros;
|
||||||
dev->_begin();
|
dev->_begin();
|
||||||
}
|
}
|
||||||
_initPhase = false;
|
_initPhase = false;
|
||||||
@ -69,8 +71,14 @@ void IODevice::loop() {
|
|||||||
unsigned long currentMicros = micros();
|
unsigned long currentMicros = micros();
|
||||||
// Call every device's loop function in turn, one per entry.
|
// Call every device's loop function in turn, one per entry.
|
||||||
if (!_nextLoopDevice) _nextLoopDevice = _firstDevice;
|
if (!_nextLoopDevice) _nextLoopDevice = _firstDevice;
|
||||||
if (_nextLoopDevice) {
|
// Check if device exists, and is due to run
|
||||||
|
if (_nextLoopDevice /* && ((long)(currentMicros-_nextLoopDevice->_nextEntryTime) >= 0) */ ) {
|
||||||
|
// Move _nextEntryTime on, so that we can guarantee that the device will continue to
|
||||||
|
// be serviced if it doesn't update _nextEntryTime.
|
||||||
|
_nextLoopDevice->_nextEntryTime = currentMicros;
|
||||||
|
// Invoke device's _loop function
|
||||||
_nextLoopDevice->_loop(currentMicros);
|
_nextLoopDevice->_loop(currentMicros);
|
||||||
|
// Move to next device.
|
||||||
_nextLoopDevice = _nextLoopDevice->_nextDevice;
|
_nextLoopDevice = _nextLoopDevice->_nextDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,12 +165,13 @@ void IODevice::writeAnalogue(VPIN vpin, int value, uint8_t profile, uint16_t dur
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// isBusy returns true if the device is currently in an animation of some sort, e.g. is changing
|
// isBusy, when called for a device pin is always a digital output or analogue output,
|
||||||
// the output over a period of time.
|
// returns input feedback state of the pin, i.e. whether the pin is busy performing
|
||||||
|
// an animation or fade over a period of time.
|
||||||
bool IODevice::isBusy(VPIN vpin) {
|
bool IODevice::isBusy(VPIN vpin) {
|
||||||
IODevice *dev = findDevice(vpin);
|
IODevice *dev = findDevice(vpin);
|
||||||
if (dev)
|
if (dev)
|
||||||
return dev->_isBusy(vpin);
|
return dev->_read(vpin);
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -248,7 +257,7 @@ int IODevice::readAnalogue(VPIN vpin) {
|
|||||||
return dev->_readAnalogue(vpin);
|
return dev->_readAnalogue(vpin);
|
||||||
}
|
}
|
||||||
#ifdef DIAG_IO
|
#ifdef DIAG_IO
|
||||||
//DIAG(F("IODevice::readAnalogue(): Vpin %d not found!"), (int)vpin);
|
DIAG(F("IODevice::readAnalogue(): Vpin %d not found!"), (int)vpin);
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
17
IODevice.h
17
IODevice.h
@ -129,7 +129,7 @@ public:
|
|||||||
static void write(VPIN vpin, int value);
|
static void write(VPIN vpin, int value);
|
||||||
|
|
||||||
// write invokes the IODevice instance's _writeAnalogue method (not applicable for digital outputs)
|
// write invokes the IODevice instance's _writeAnalogue method (not applicable for digital outputs)
|
||||||
static void writeAnalogue(VPIN vpin, int value, uint8_t profile, uint16_t duration=0);
|
static void writeAnalogue(VPIN vpin, int value, uint8_t profile=0, uint16_t duration=0);
|
||||||
|
|
||||||
// isBusy returns true if the device is currently in an animation of some sort, e.g. is changing
|
// 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.
|
// the output over a period of time.
|
||||||
@ -203,13 +203,6 @@ protected:
|
|||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// _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. Returns false unless overridden in sub class.
|
|
||||||
virtual bool _isBusy(VPIN vpin) {
|
|
||||||
(void)vpin;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Method to perform updates on an ongoing basis (optionally implemented within device class)
|
// Method to perform updates on an ongoing basis (optionally implemented within device class)
|
||||||
virtual void _loop(unsigned long currentMicros) {
|
virtual void _loop(unsigned long currentMicros) {
|
||||||
(void)currentMicros; // Suppress compiler warning.
|
(void)currentMicros; // Suppress compiler warning.
|
||||||
@ -221,6 +214,11 @@ protected:
|
|||||||
// Destructor
|
// Destructor
|
||||||
virtual ~IODevice() {};
|
virtual ~IODevice() {};
|
||||||
|
|
||||||
|
// Non-virtual function
|
||||||
|
void delayUntil(unsigned long futureMicrosCount) {
|
||||||
|
_nextEntryTime = futureMicrosCount;
|
||||||
|
}
|
||||||
|
|
||||||
// Common object fields.
|
// Common object fields.
|
||||||
VPIN _firstVpin;
|
VPIN _firstVpin;
|
||||||
int _nPins;
|
int _nPins;
|
||||||
@ -242,6 +240,7 @@ private:
|
|||||||
static IODevice *findDevice(VPIN vpin);
|
static IODevice *findDevice(VPIN vpin);
|
||||||
|
|
||||||
IODevice *_nextDevice = 0;
|
IODevice *_nextDevice = 0;
|
||||||
|
unsigned long _nextEntryTime;
|
||||||
static IODevice *_firstDevice;
|
static IODevice *_firstDevice;
|
||||||
|
|
||||||
static IODevice *_nextLoopDevice;
|
static IODevice *_nextLoopDevice;
|
||||||
@ -276,7 +275,7 @@ private:
|
|||||||
// Device-specific write functions.
|
// Device-specific write functions.
|
||||||
void _write(VPIN vpin, int value) override;
|
void _write(VPIN vpin, int value) override;
|
||||||
void _writeAnalogue(VPIN vpin, int value, uint8_t profile, uint16_t duration) override;
|
void _writeAnalogue(VPIN vpin, int value, uint8_t profile, uint16_t duration) override;
|
||||||
bool _isBusy(VPIN vpin) override;
|
int _read(VPIN vpin) override; // returns the busy status of the device
|
||||||
void _loop(unsigned long currentMicros) override;
|
void _loop(unsigned long currentMicros) override;
|
||||||
void updatePosition(uint8_t pin);
|
void updatePosition(uint8_t pin);
|
||||||
void writeDevice(uint8_t pin, int value);
|
void writeDevice(uint8_t pin, int value);
|
||||||
|
@ -65,7 +65,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
DFPlayer(VPIN firstVpin, int nPins, HardwareSerial &serial) {
|
DFPlayer(VPIN firstVpin, int nPins, HardwareSerial &serial) {
|
||||||
_firstVpin = firstVpin;
|
_firstVpin = firstVpin;
|
||||||
_nPins = min(nPins, 3);
|
_nPins = nPins;
|
||||||
_serial = &serial;
|
_serial = &serial;
|
||||||
addDevice(this);
|
addDevice(this);
|
||||||
}
|
}
|
||||||
@ -159,7 +159,8 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _isBusy(VPIN) override {
|
// A read on any pin indicates whether the player is still playing.
|
||||||
|
int _read(VPIN) override {
|
||||||
return _playing;
|
return _playing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,9 +169,9 @@ void PCA9685::_writeAnalogue(VPIN vpin, int value, uint8_t profile, uint16_t dur
|
|||||||
s->fromPosition = s->currentPosition;
|
s->fromPosition = s->currentPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _isBusy returns true if the device is currently in executing an animation,
|
// _read returns true if the device is currently in executing an animation,
|
||||||
// changing the output over a period of time.
|
// changing the output over a period of time.
|
||||||
bool PCA9685::_isBusy(VPIN vpin) {
|
int PCA9685::_read(VPIN vpin) {
|
||||||
int pin = vpin - _firstVpin;
|
int pin = vpin - _firstVpin;
|
||||||
struct ServoData *s = _servoData[pin];
|
struct ServoData *s = _servoData[pin];
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
|
Loading…
Reference in New Issue
Block a user