Skip to content

Commit 3eb0f29

Browse files
committed
Add pedal positionChanged() function
Similar to gearChanged() for the shifter, this saves the 'changed' return value from the update function so it can be retrieved later to see if any of the pedal positions have changed since the last call.
1 parent 6d574d2 commit 3eb0f29

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/SimRacing.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,19 @@ void AnalogInput::setCalibration(AnalogInput::Calibration newCal) {
311311
//#########################################################
312312

313313
Pedals::Pedals(AnalogInput* dataPtr, uint8_t nPedals, uint8_t detectPin)
314-
: pedalData(dataPtr), NumPedals(nPedals), detector(detectPin)
314+
:
315+
pedalData(dataPtr),
316+
NumPedals(nPedals),
317+
detector(detectPin),
318+
changed(false)
315319
{}
316320

317321
void Pedals::begin() {
318322
update(); // set initial pedal position
319323
}
320324

321325
bool Pedals::update() {
322-
bool changed = false;
326+
changed = false;
323327

324328
detector.poll();
325329
if (detector.getState() == DeviceConnection::Connected) {

src/SimRacing.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,13 @@ namespace SimRacing {
331331
*/
332332
int getNumPedals() const { return this->NumPedals; }
333333

334+
/**
335+
* Checks whether the current pedal positions have changed since the last update.
336+
*
337+
* @return 'true' if position has changed, 'false' otherwise
338+
*/
339+
bool positionChanged() const { return changed; }
340+
334341
/**
335342
* Calibrate a pedal's min/max values for rescaling.
336343
*
@@ -362,6 +369,7 @@ namespace SimRacing {
362369
AnalogInput* pedalData; ///< pointer to the pedal data
363370
const int NumPedals; ///< number of pedals managed by this class
364371
DeviceConnection detector; ///< detector instance for checking if the pedals are connected
372+
bool changed; ///< whether the pedal position has changed since the previous update
365373
};
366374

367375

0 commit comments

Comments
 (0)