Hi guys,
Can you help me change/add the code in results: "P" for Pass, "X" for Shorts, "F" for Open. Instead of Bad for both F & X.
Please see code below.
Appreciate it
#ifndef TESTCABLE
#define TESTCABLE
class TestCable {
private:
int numTestWires;
char* name;
char results[MAX_TEST_WIRES];
int* pinSetOut;
int* pinSetIn;
public:
TestCable(char* nm, int ntw, int* pso, int* psi)
: name(nm), numTestWires(ntw), pinSetOut(pso), pinSetIn(psi) {
clearResults();
initPins();
}
char* printName() { lcd.print(name); }
void printResults() {
lcd.clear();
lcd.setCursor(0,0);
for (int i = 0; i < this->numTestWires; i++) {
if (i == 5) lcd.setCursor(0,1);
if (i == 10) lcd.setCursor(0,2);
if (i == 15) lcd.setCursor(0,3);
if (i == 20) lcd.setCursor(0,4);
lcd.print(i+1);
lcd.print(":");
lcd.print(this->results[i]);
lcd.print(" ");
}
validateCable();
}
bool testConnections() {
clearResults();
for (int i = 0; i < this->numTestWires; i++) {
pinMode(pinSetOut[i], OUTPUT);
delay(5);
digitalWrite(this->pinSetOut[i], LOW);
delay(5);
int activeInputs = 0;
for (int j = 0; j < this->numTestWires; j++) {
if (!digitalRead(this->pinSetIn[j]))
++activeInputs;
}
if (!activeInputs)
this->results[i] = 'F';
else if (activeInputs == 1) {
if (!digitalRead(this->pinSetIn[i]))
this->results[i] = 'P';
else
this->results[i] = 'X';
}
else if (activeInputs > 1)
this->results[i] = 'X';
digitalWrite(this->pinSetOut[i], HIGH);
pinMode(this->pinSetOut[i], INPUT_PULLUP);
}
return true;
}
private:
void clearResults() {
for(int i = 0; i < this->numTestWires; i++)
results[i] = '?';
}
void initPins() {
for (int i = 0; i < this->numTestWires; i++) {
pinMode(this->pinSetOut[i], INPUT_PULLUP);
digitalWrite(this->pinSetOut[i], HIGH);
pinMode(this->pinSetIn[i], INPUT_PULLUP);
digitalWrite(this->pinSetOut[i], HIGH);
}
}
bool validateCable() {
bool cableApproved = true;
for(int i = 0; i < this->numTestWires; i++) {
if (this->results[i] != 'P')
cableApproved = false;
}
lcd.setCursor(0,3);
if (cableApproved)
lcd.print(" Good Cable");
else
lcd.print(" Bad Cable");
return cableApproved;
}
void printConnections() {
for (int i = 0; i < this->numTestWires; i++)
Serial.print(digitalRead(this->pinSetOut[i]));
Serial.println();
for (int i = 0; i < this->numTestWires; i++)
Serial.print(digitalRead(this->pinSetIn[i]));
Serial.println();
Serial.println();
}
};
#endif