Added serial.begin / serial.end logic

This commit is contained in:
Mike C 2013-04-09 18:05:22 -04:00
parent 4c3ded46ea
commit 18e6356df1
2 changed files with 50 additions and 2 deletions

View file

@ -40,6 +40,29 @@ linespeed Config::getLineSpeed() {
return currentLineSpeed; return currentLineSpeed;
} }
int Config::getLineSpeedBaud() {
switch (currentLineSpeed) {
case 1: // twentyFourHundredBaud
return 2400;
break;
case 2: // ninetySixHundredBaud
return 9600;
break;
case 3: // nineteenTwoK
return 19200;
break;
case 4: // thirtyeightFourK
return 38400;
break;
case 5: // fiftysevenFiveK
return 57600;
break;
case 6: // oneNineteenTwoK
return 119200;
break;
}
}
ttlvoltage Config::getVoltage() { ttlvoltage Config::getVoltage() {
return currentVoltage; return currentVoltage;
} }
@ -63,6 +86,30 @@ int Config::getTimeoutMilis() {
} }
void Config::setMode(serialmode mode) { void Config::setMode(serialmode mode) {
switch (currentMode) {
case 1: // ttl
Serial1.end();
break;
case 2: // db9_null
Serial2.end();
break;
case 3: // cisco
Serial3.end();
break;
}
switch (mode) {
case 1: // ttl
Serial1.begin(getLineSpeedBaud());
break;
case 2: // db9_null
Serial2.begin(getLineSpeedBaud());
break;
case 3: // cisco
Serial3.begin(getLineSpeedBaud());
break;
}
currentMode = mode; currentMode = mode;
} }
@ -96,8 +143,8 @@ void Config::setTimeout(timeout aTimeout) {
} }
void Config::setDefaults() { void Config::setDefaults() {
setMode(ttl);
setLineSpeed(oneNineteenTwoK);
setVoltage(onePointEight); setVoltage(onePointEight);
setLineSpeed(oneNineteenTwoK);
setMode(ttl);
setTimeout(thirtyseconds); setTimeout(thirtyseconds);
} }

View file

@ -36,6 +36,7 @@ public:
void setTimeout(timeout aTimeout); void setTimeout(timeout aTimeout);
serialmode getSerialMode(); serialmode getSerialMode();
linespeed getLineSpeed(); linespeed getLineSpeed();
int getLineSpeedBaud();
ttlvoltage getVoltage(); ttlvoltage getVoltage();
timeout getTimeout(); timeout getTimeout();
int getTimeoutMilis(); int getTimeoutMilis();