From 3cda869c6e15de7c00e7817172f248e2e2be01ea Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Mon, 18 Mar 2024 21:17:51 +0100 Subject: [PATCH] Allow no shield --- MotorDrivers.h | 6 +++++- TrackManager.cpp | 10 +++++++--- TrackManager.h | 6 +++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/MotorDrivers.h b/MotorDrivers.h index 907c11b..9e5f85b 100644 --- a/MotorDrivers.h +++ b/MotorDrivers.h @@ -1,7 +1,7 @@ /* * © 2022-2023 Paul M. Antoine * © 2021 Fred Decker - * © 2020-2023 Harald Barth + * © 2020-2024 Harald Barth * (c) 2020 Chris Harlow. All rights reserved. * (c) 2021 Fred Decker. All rights reserved. * (c) 2020 Harald Barth. All rights reserved. @@ -57,6 +57,10 @@ // of the brake pin on the motor bridge is inverted // (HIGH == release brake) +// You can have a CS wihout any possibility to do any track signal. +// That's strange but possible. +#define NO_SHIELD F("No shield at all") + // Arduino STANDARD Motor Shield, used on different architectures: #if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_STM32) diff --git a/TrackManager.cpp b/TrackManager.cpp index e357e7f..338b11c 100644 --- a/TrackManager.cpp +++ b/TrackManager.cpp @@ -1,6 +1,6 @@ /* * © 2022 Chris Harlow - * © 2022,2023 Harald Barth + * © 2022-2024 Harald Barth * © 2023 Colin Murdoch * All rights reserved. * @@ -41,7 +41,7 @@ MotorDriver * TrackManager::track[MAX_TRACKS]; int16_t TrackManager::trackDCAddr[MAX_TRACKS]; -byte TrackManager::lastTrack=0; +int8_t TrackManager::lastTrack=-1; bool TrackManager::progTrackSyncMain=false; bool TrackManager::progTrackBoosted=false; int16_t TrackManager::joinRelay=UNUSED_PIN; @@ -498,7 +498,11 @@ void TrackManager::setTrackPower(TRACK_MODE trackmodeToMatch, POWERMODE powermod // Set track power for this track, inependent of mode void TrackManager::setTrackPower(POWERMODE powermode, byte t) { - MotorDriver *driver=track[t]; + MotorDriver *driver=track[t]; + if (driver == NULL) { // track is not defined at all + DIAG(F("Error: Track %c does not exist"), t+'A'); + return; + } TRACK_MODE trackmode = driver->getMode(); POWERMODE oldpower = driver->getPower(); if (trackmode & TRACK_MODE_NONE) { diff --git a/TrackManager.h b/TrackManager.h index c1f314a..7dce0ee 100644 --- a/TrackManager.h +++ b/TrackManager.h @@ -1,6 +1,6 @@ /* * © 2022 Chris Harlow - * © 2022 Harald Barth + * © 2022-2024 Harald Barth * © 2023 Colin Murdoch * * All rights reserved. @@ -46,7 +46,7 @@ const byte TRACK_POWER_1=1, TRACK_POWER_ON=1; class TrackManager { public: static void Setup(const FSH * shieldName, - MotorDriver * track0, + MotorDriver * track0=NULL, MotorDriver * track1=NULL, MotorDriver * track2=NULL, MotorDriver * track3=NULL, @@ -108,7 +108,7 @@ class TrackManager { private: static void addTrack(byte t, MotorDriver* driver); - static byte lastTrack; + static int8_t lastTrack; static byte nextCycleTrack; static void applyDCSpeed(byte t);