Skip to content

Commit 9474511

Browse files
committed
CheckVariant: add test status
Signed-off-by: Alexandre Bourdiol <[email protected]>
1 parent cbff863 commit 9474511

File tree

3 files changed

+239
-209
lines changed

3 files changed

+239
-209
lines changed

examples/NonReg/CheckVariant/CheckVariant.ino

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* This sketch check, digital and analog pins defined in the variant
3+
*/
4+
15
#include "utils.h"
26

37
#define PORTx(pn) (char)('A' + STM_PORT(pn))
@@ -37,16 +41,41 @@ void setup() {
3741
}
3842

3943
void loop() {
44+
45+
bool testPassed = true;
46+
String testStatus;
47+
uint32_t blinkDelay;
48+
49+
Serial.println("#####");
4050
Serial.printf("NUM_DIGITAL_PINS = %i\n", NUM_DIGITAL_PINS);
4151
Serial.printf("NUM_ANALOG_INPUTS = %i\n", NUM_ANALOG_INPUTS);
4252

43-
checkDigitalPins();
44-
checkAnalogPins();
53+
/* Run the different tests */
54+
if (!checkDigitalPins()) {
55+
testPassed = false;
56+
}
57+
if (!checkAnalogPins()) {
58+
testPassed = false;
59+
}
60+
61+
/* Display test result */
62+
if (testPassed) {
63+
testStatus = "PASSED";
64+
blinkDelay = 1000;
65+
} else {
66+
testStatus = "FAILED";
67+
blinkDelay = 200;
68+
}
69+
Serial.println("");
70+
Serial.println("########################################");
71+
Serial.printf("#### Test %s\n", testStatus.c_str());
72+
Serial.println("########################################");
4573

74+
/* Blink Led forever, slowly for test passed, and quickly for test failed */
4675
while (1) {
4776
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
48-
delay(1000); // wait for a second
77+
delay(blinkDelay);
4978
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
50-
delay(1000); // wait for a second
79+
delay(blinkDelay);
5180
}
5281
}
Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
/*
2+
* Check Analog pins
3+
* Return true in case of test passed
4+
* Return false in case of test failed
5+
*/
6+
bool checkAnalogPins(void) {
7+
bool testPassed = true;
18

2-
void checkAnalogPins(void) {
9+
Serial.println("#####");
310
Serial.println("Checking analog pins definition...");
411

512
for ( uint32_t i = 0; i < (NUM_ANALOG_INPUTS); i++) {
@@ -26,35 +33,17 @@ void checkAnalogPins(void) {
2633

2734
res |= 8;
2835
}
29-
/*
30-
pname: Pin of type PinName (PY_n)
31-
asPN: true display as a PinName, false as a pin number (PYn)
32-
val: display value or not
33-
ln: carriage return or not
34-
*/
36+
3537
if (res) {
3638
Serial.printf("A%i defined as %i with pin name: ", i, A0 + i);
3739
printPinName(pn_aTpn_Ax, true, true, false);
3840
Serial.print(" and pin number: ");
3941
printPinName(pn_aTpn_Ax, false, true, false);
4042
Serial.printf(" --> %i\n", res);
4143
Serial.printf(" --> digitalPinToAnalogInput(%i) = %i\n", pinnum_aTD_i, digitalPinToAnalogInput(pinnum_aTD_i));
42-
43-
44-
// Serial.print("\tPin name ");
45-
// printPinName(pn_Ax, true, true, false);
46-
// Serial.print(" have to be indexed higher than NUM_ANALOG_INPUTS (");
47-
// Serial.print(NUM_ANALOG_INPUTS);
48-
// Serial.println(") to be able to use:");
49-
// PinName pn_Ax_analog = analogInputToPinName(pinNametoDigitalPin(pn_Ax));
50-
// Serial.print("\tAnalogRead(");
51-
// printPinName(pn_Ax, false, false, false);
52-
// Serial.print(") --> which currently use pin name: ");
53-
// printPinName(pn_Ax_analog, true, true, false);
54-
// Serial.print(" and pin number: ");
55-
// printPinName(pn_Ax_analog, false, true, true);
44+
testPassed = false;
5645
}
5746
}
5847
Serial.println("End check analog pins");
59-
Serial.println("#####");
48+
return testPassed;
6049
}

0 commit comments

Comments
 (0)