Skip to content

Commit d40478a

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

File tree

3 files changed

+240
-212
lines changed

3 files changed

+240
-212
lines changed

examples/NonReg/CheckVariant/CheckVariant.ino

Lines changed: 33 additions & 6 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))
@@ -27,8 +31,6 @@ void printPinName(PinName pname, bool asPN, bool val, bool ln) {
2731
}
2832

2933
void setup() {
30-
// Serial.setTx(PA9_R);
31-
// Serial.setRx(PA10_R);
3234
Serial.begin(115200);
3335
while (!Serial) {
3436
; // wait for serial port to connect. Needed for native USB port only
@@ -37,16 +39,41 @@ void setup() {
3739
}
3840

3941
void loop() {
42+
43+
bool testPassed = true;
44+
String testStatus;
45+
uint32_t blinkDelay;
46+
47+
Serial.println("#####");
4048
Serial.printf("NUM_DIGITAL_PINS = %i\n", NUM_DIGITAL_PINS);
4149
Serial.printf("NUM_ANALOG_INPUTS = %i\n", NUM_ANALOG_INPUTS);
4250

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

72+
/* Blink Led forever, slowly for test passed, and quickly for test failed */
4673
while (1) {
4774
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
48-
delay(1000); // wait for a second
75+
delay(blinkDelay);
4976
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
50-
delay(1000); // wait for a second
77+
delay(blinkDelay);
5178
}
5279
}
Lines changed: 12 additions & 23 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++) {
@@ -23,38 +30,20 @@ void checkAnalogPins(void) {
2330
res |= 4;
2431
}
2532
if (digitalPinToAnalogInput(pinnum_aTD_i) != i) {
26-
33+
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)