Skip to content

Commit

Permalink
Merge pull request #39 from cgalpin/ArduinoDue
Browse files Browse the repository at this point in the history
Restored SerialConsole changes plus NULL checks and added logging level of Off
  • Loading branch information
collin80 committed Oct 10, 2013
2 parents 89d8782 + b9d69da commit 04aa351
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 167 deletions.
4 changes: 4 additions & 0 deletions CanThrottle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ DeviceId CanThrottle::getId() {
return CANACCELPEDAL;
}

bool CanThrottle::isFaulted() {
return false;
}

#endif // CFG_ENABLE_DEVICE_CAN_THROTTLE
1 change: 1 addition & 0 deletions CanThrottle.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CanThrottle: public Throttle, CanObserver {
void handleTick();
void handleCanFrame(RX_CAN_FRAME *frame);
DeviceId getId();
bool isFaulted();

protected:

Expand Down
2 changes: 1 addition & 1 deletion GEVCU.ino
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void initializeDevices() {
deviceManager->addDevice(brake);
#endif
#ifdef CFG_ENABLE_DEVICE_CAN_THROTTLE_BRAKE
Throtle *brake = new CanThrottle();
Throttle *brake = new CanThrottle();
Logger::info("add device: CanThrottle brake (%X)", brake);
//brake->setup();
deviceManager->addDevice(brake);
Expand Down
15 changes: 10 additions & 5 deletions Heartbeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,18 @@ void Heartbeat::handleTick() {
led = !led;

if (throttleDebug) {
Logger::console("Status: isRunning: %T isFaulted: %T",
DeviceManager::getInstance()->getMotorController()->isRunning(),
DeviceManager::getInstance()->getMotorController()->isFaulted());
Logger::console("");
Logger::console("Motor Controller Status: isRunning: %T isFaulted: %T",
DeviceManager::getInstance()->getMotorController()->isRunning(),
DeviceManager::getInstance()->getMotorController()->isFaulted());
Logger::console("A0: %d, A1: %d, A2: %d, A3: %d", getAnalog(0), getAnalog(1), getAnalog(2), getAnalog(3));
Logger::console("D0: %d, D1: %d, D2: %d, D3: %d", getDigital(0), getDigital(1), getDigital(2), getDigital(3));
Logger::console("Throttle Output: %i", DeviceManager::getInstance()->getAccelerator()->getLevel());
Logger::console("Brake Output: %i", DeviceManager::getInstance()->getBrake()->getLevel());
Logger::console("Throttle Status: isFaulted: %T output: %i",
DeviceManager::getInstance()->getAccelerator()->isFaulted(),
DeviceManager::getInstance()->getAccelerator()->getLevel());
if ( DeviceManager::getInstance()->getBrake() != NULL ) {
Logger::console("Brake Output: %i", DeviceManager::getInstance()->getBrake()->getLevel());
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ void Logger::warn(DeviceId deviceId, char *message, ...) {
* printf() style, see Logger::log()
*/
void Logger::error(char *message, ...) {
if (logLevel > Error)
return;
va_list args;
va_start(args, message);
Logger::log((DeviceId) NULL, Error, message, args);
Expand All @@ -124,6 +126,8 @@ void Logger::error(char *message, ...) {
* printf() style, see Logger::log()
*/
void Logger::error(DeviceId deviceId, char *message, ...) {
if (logLevel > Error)
return;
va_list args;
va_start(args, message);
Logger::log(deviceId, Error, message, args);
Expand Down
2 changes: 1 addition & 1 deletion Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class Logger {
public:
enum LogLevel {
Debug, Info, Warn, Error
Debug, Info, Warn, Error, Off
};
static void debug(char *, ...);
static void debug(DeviceId, char *, ...);
Expand Down
12 changes: 8 additions & 4 deletions PotThrottle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void PotThrottle::doAccel() {
if (rawLevel1 > maximumLevel1) {
if (rawLevel1 > (maximumLevel1 + CFG_THROTTLE_TOLERANCE)) {
throttleStatus = ERR_HIGH_T1;
Logger::error(POTACCELPEDAL, "throttle 1 value out of range: %l", rawLevel1);
Logger::error(POTACCELPEDAL, "ERR_HIGH_T1: throttle 1 value out of range: %l", rawLevel1);
}
clampedLevel = maximumLevel1;
}
Expand All @@ -161,7 +161,7 @@ void PotThrottle::doAccel() {
if (rawLevel1 < minimumLevel1) {
if (rawLevel1 < tempLow) {
throttleStatus = ERR_LOW_T1;
Logger::error(POTACCELPEDAL, "throttle 1 value out of range: %l ", rawLevel1);
Logger::error(POTACCELPEDAL, "ERR_LOW_T1: throttle 1 value out of range: %l ", rawLevel1);
}
clampedLevel = minimumLevel1;
}
Expand All @@ -174,7 +174,7 @@ void PotThrottle::doAccel() {
if (rawLevel2 > maximumLevel2) {
if (rawLevel2 > (maximumLevel2 + CFG_THROTTLE_TOLERANCE)) {
throttleStatus = ERR_HIGH_T2;
Logger::error(POTACCELPEDAL, "throttle 2 value out of range: %l", rawLevel2);
Logger::error(POTACCELPEDAL, "ERR_HIGH_T2: throttle 2 value out of range: %l", rawLevel2);
}
clampedLevel = maximumLevel2;
}
Expand All @@ -185,7 +185,7 @@ void PotThrottle::doAccel() {
if (rawLevel2 < minimumLevel2) {
if (rawLevel2 < tempLow) {
throttleStatus = ERR_LOW_T2;
Logger::error(POTACCELPEDAL, "throttle 2 value out of range: %l", rawLevel2);
Logger::error(POTACCELPEDAL, "ERR_LOW_T2: throttle 2 value out of range: %l", rawLevel2);
}
clampedLevel = minimumLevel2;
}
Expand Down Expand Up @@ -235,6 +235,10 @@ void PotThrottle::handleTick() {
doAccel();
}

bool PotThrottle::isFaulted() {
return throttleStatus != OK;
}

PotThrottle::ThrottleStatus PotThrottle::getStatus() {
return throttleStatus;
}
Expand Down
1 change: 1 addition & 0 deletions PotThrottle.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class PotThrottle: public Throttle {

void handleTick();
void setup();
bool isFaulted();
ThrottleStatus getStatus();
int getRawThrottle1();
int getRawThrottle2();
Expand Down
Loading

0 comments on commit 04aa351

Please sign in to comment.