diff --git a/wiringPi/test/wiringpi_test1_device.c b/wiringPi/test/wiringpi_test1_sysfs.c similarity index 59% rename from wiringPi/test/wiringpi_test1_device.c rename to wiringPi/test/wiringpi_test1_sysfs.c index 189dd9f..be90616 100644 --- a/wiringPi/test/wiringpi_test1_device.c +++ b/wiringPi/test/wiringpi_test1_sysfs.c @@ -1,8 +1,7 @@ // WiringPi test program: Kernel char device interface / sysfs successor // Compile: gcc -Wall wiringpi_test1_device.c -o wiringpi_test1_device -lwiringPi -#include -#include +#include "wpi_test.h" #include #include #include @@ -12,33 +11,8 @@ const int GPIO = 19; const int GPIOIN = 26; -const int ToggleValue = 4; +const int ToggleValue = 4; -void CheckGPIO(int out) { - int in = digitalRead(GPIOIN); - int read = digitalRead(GPIO); - - int pass = 0; - if (out==in && in==read) { - pass = 1; - } - printf("GPIO%d = %d (GPIO%d = %d) -> %s\n", GPIOIN, in, GPIO, read, pass ? "passed":"failed" ); -} - -void digitalWriteEx(int pin, int mode) { - digitalWrite(pin, mode); - printf("out = %d ", mode); - delayMicroseconds(5000); - CheckGPIO(mode); -} - -void pullUpDnControlEx (int pin ,int mode) { - pullUpDnControl (pin, mode); - int out = mode==PUD_UP ? 1:0; - printf("in = %4s ", mode==PUD_UP ? "up":"down"); - delayMicroseconds(5000); - CheckGPIO(out); -} int main (void) { @@ -46,7 +20,7 @@ int main (void) { printf(" testing digitalWrite, digitalRead and pullUpDnControl\n"); if (wiringPiSetupSys() == -1) { - printf("wiringPiSetupGpioDevice failed\n\n"); + printf("wiringPiSetupSys failed\n\n"); exit(EXIT_FAILURE); } pinMode(GPIOIN, INPUT); @@ -54,9 +28,9 @@ int main (void) { printf("toggle %d times ...\n", ToggleValue); for (int loop=1; loop -#include +#include "wpi_test.h" #include #include #include @@ -12,33 +11,8 @@ const int GPIO = 19; const int GPIOIN = 26; -const int ToggleValue = 4; +const int ToggleValue = 4; -void CheckGPIO(int out) { - int in = digitalRead(GPIOIN); - int read = digitalRead(GPIO); - - int pass = 0; - if (out==in && in==read) { - pass = 1; - } - printf("GPIO%d = %d (GPIO%d = %d) -> %s\n", GPIOIN, in, GPIO, read, pass ? "passed":"failed" ); -} - -void digitalWriteEx(int pin, int mode) { - digitalWrite(pin, mode); - printf("out = %d ", mode); - delayMicroseconds(5000); - CheckGPIO(mode); -} - -void pullUpDnControlEx (int pin ,int mode) { - pullUpDnControl (pin, mode); - int out = mode==PUD_UP ? 1:0; - printf("in = %4s ", mode==PUD_UP ? "up":"down"); - delayMicroseconds(5000); - CheckGPIO(out); -} int main (void) { @@ -53,19 +27,19 @@ int main (void) { pinMode(GPIO, OUTPUT); printf("\nTest output\n"); - digitalWriteEx(GPIO, HIGH); + digitalWriteEx(GPIO, GPIOIN, HIGH); delayMicroseconds(600000); - digitalWriteEx(GPIO, LOW); + digitalWriteEx(GPIO, GPIOIN, LOW); delayMicroseconds(600000); printf("\nTest output off with pull up\n"); pinMode(GPIO, OUTPUT); - digitalWriteEx(GPIO, LOW); + digitalWriteEx(GPIO, GPIOIN, LOW); pullUpDnControl (GPIO, PUD_UP); pinMode(GPIO, PM_OFF); delayMicroseconds(600000); printf("out = off "); - CheckGPIO(HIGH); + CheckGPIO(GPIO, GPIOIN, HIGH); delayMicroseconds(600000); printf("\nTest output off with pull down\n"); @@ -73,7 +47,7 @@ int main (void) { pinMode(GPIO, PM_OFF); delayMicroseconds(600000); printf("out = off "); - CheckGPIO(LOW); + CheckGPIO(GPIO, GPIOIN, LOW); delayMicroseconds(600000); return(EXIT_SUCCESS); diff --git a/wiringPi/test/wiringpi_test3_device.c b/wiringPi/test/wiringpi_test3_device_wpi.c similarity index 62% rename from wiringPi/test/wiringpi_test3_device.c rename to wiringPi/test/wiringpi_test3_device_wpi.c index 362ae68..179f09c 100644 --- a/wiringPi/test/wiringpi_test3_device.c +++ b/wiringPi/test/wiringpi_test3_device_wpi.c @@ -1,8 +1,7 @@ // WiringPi test program: Kernel char device interface / sysfs successor // Compile: gcc -Wall wiringpi_test3_device.c -o wiringpi_test3_device -lwiringPi -#include -#include +#include "wpi_test.h" #include #include #include @@ -14,31 +13,6 @@ const int GPIO = 24; //BCM 19 const int GPIOIN = 25; //BCM 26; const int ToggleValue = 4; -void CheckGPIO(int out) { - int in = digitalRead(GPIOIN); - int read = digitalRead(GPIO); - - int pass = 0; - if (out==in && in==read) { - pass = 1; - } - printf("GPIO%d = %d (GPIO%d = %d) -> %s\n", GPIOIN, in, GPIO, read, pass ? "passed":"failed" ); -} - -void digitalWriteEx(int pin, int mode) { - digitalWrite(pin, mode); - printf("out = %d ", mode); - delayMicroseconds(5000); - CheckGPIO(mode); -} - -void pullUpDnControlEx (int pin ,int mode) { - pullUpDnControl (pin, mode); - int out = mode==PUD_UP ? 1:0; - printf("in = %4s ", mode==PUD_UP ? "up":"down"); - delayMicroseconds(5000); - CheckGPIO(out); -} int main (void) { @@ -53,19 +27,19 @@ int main (void) { pinMode(GPIO, OUTPUT); printf("\nTest output\n"); - digitalWriteEx(GPIO, HIGH); + digitalWriteEx(GPIO, GPIOIN, HIGH); delayMicroseconds(600000); - digitalWriteEx(GPIO, LOW); + digitalWriteEx(GPIO, GPIOIN, LOW); delayMicroseconds(600000); printf("\nTest output off with pull up\n"); pinMode(GPIO, OUTPUT); - digitalWriteEx(GPIO, LOW); + digitalWriteEx(GPIO, GPIOIN, LOW); pullUpDnControl (GPIO, PUD_UP); pinMode(GPIO, PM_OFF); delayMicroseconds(600000); printf("out = off "); - CheckGPIO(HIGH); + CheckGPIO(GPIO, GPIOIN, HIGH); delayMicroseconds(600000); printf("\nTest output off with pull down\n"); @@ -73,7 +47,7 @@ int main (void) { pinMode(GPIO, PM_OFF); delayMicroseconds(600000); printf("out = off "); - CheckGPIO(LOW); + CheckGPIO(GPIO, GPIOIN, LOW); delayMicroseconds(600000); return(EXIT_SUCCESS); diff --git a/wiringPi/test/wiringpi_test4_device.c b/wiringPi/test/wiringpi_test4_device_phys.c similarity index 62% rename from wiringPi/test/wiringpi_test4_device.c rename to wiringPi/test/wiringpi_test4_device_phys.c index f336212..9970aa5 100644 --- a/wiringPi/test/wiringpi_test4_device.c +++ b/wiringPi/test/wiringpi_test4_device_phys.c @@ -1,8 +1,7 @@ // WiringPi test program: Kernel char device interface / sysfs successor // Compile: gcc -Wall wiringpi_test4_device.c -o wiringpi_test4_device -lwiringPi -#include -#include +#include "wpi_test.h" #include #include #include @@ -14,31 +13,6 @@ const int GPIO = 35; //BCM 19 const int GPIOIN = 37; //BCM 26; const int ToggleValue = 4; -void CheckGPIO(int out) { - int in = digitalRead(GPIOIN); - int read = digitalRead(GPIO); - - int pass = 0; - if (out==in && in==read) { - pass = 1; - } - printf("GPIO%d = %d (GPIO%d = %d) -> %s\n", GPIOIN, in, GPIO, read, pass ? "passed":"failed" ); -} - -void digitalWriteEx(int pin, int mode) { - digitalWrite(pin, mode); - printf("out = %d ", mode); - delayMicroseconds(5000); - CheckGPIO(mode); -} - -void pullUpDnControlEx (int pin ,int mode) { - pullUpDnControl (pin, mode); - int out = mode==PUD_UP ? 1:0; - printf("in = %4s ", mode==PUD_UP ? "up":"down"); - delayMicroseconds(5000); - CheckGPIO(out); -} int main (void) { @@ -53,19 +27,19 @@ int main (void) { pinMode(GPIO, OUTPUT); printf("\nTest output\n"); - digitalWriteEx(GPIO, HIGH); + digitalWriteEx(GPIO, GPIOIN, HIGH); delayMicroseconds(600000); - digitalWriteEx(GPIO, LOW); + digitalWriteEx(GPIO, GPIOIN, LOW); delayMicroseconds(600000); printf("\nTest output off with pull up\n"); pinMode(GPIO, OUTPUT); - digitalWriteEx(GPIO, LOW); + digitalWriteEx(GPIO, GPIOIN, LOW); pullUpDnControl (GPIO, PUD_UP); pinMode(GPIO, PM_OFF); delayMicroseconds(600000); printf("out = off "); - CheckGPIO(HIGH); + CheckGPIO(GPIO, GPIOIN, HIGH); delayMicroseconds(600000); printf("\nTest output off with pull down\n"); @@ -73,7 +47,7 @@ int main (void) { pinMode(GPIO, PM_OFF); delayMicroseconds(600000); printf("out = off "); - CheckGPIO(LOW); + CheckGPIO(GPIO, GPIOIN, LOW); delayMicroseconds(600000); return(EXIT_SUCCESS); diff --git a/wiringPi/test/wiringpi_test5_default.c b/wiringPi/test/wiringpi_test5_default.c new file mode 100644 index 0000000..e025aaf --- /dev/null +++ b/wiringPi/test/wiringpi_test5_default.c @@ -0,0 +1,57 @@ +// WiringPi test program: Kernel char device interface / sysfs successor +// Compile: gcc -Wall wiringpi_test1_device.c -o wiringpi_test1_device -lwiringPi + +#include "wpi_test.h" +#include +#include +#include +#include +#include + + +const int GPIO = 19; +const int GPIOIN = 26; +const int ToggleValue = 4; + + +int main (void) { + + printf("WiringPi GPIO test program 1 (using GPIO%d (output) and GPIO%d (input))\n", GPIO, GPIOIN); + printf(" testing digitalWrite, digitalRead and pullUpDnControl\n"); + + if (wiringPiSetupGpio() == -1) { + printf("wiringPiSetupGpio failed\n\n"); + exit(EXIT_FAILURE); + } + pinMode(GPIOIN, INPUT); + pinMode(GPIO, OUTPUT); + + printf("toggle %d times ...\n", ToggleValue); + for (int loop=1; loop +#include + +#define COLORDEF "\x1B[0m" +#define COLORRED "\x1B[31m" +#define COLORGRN "\x1B[32m" + +void CheckGPIO(int GPIO, int GPIOIN, int out) { + int in = digitalRead(GPIOIN); + int read = digitalRead(GPIO); + + int pass = 0; + if (out==in && in==read) { + pass = 1; + } + if (pass) { + printf("GPIO%d = %d (GPIO%d = %d) -> %spassed%s\n", GPIOIN, in, GPIO, read, COLORGRN, COLORDEF ); + } else { + printf("GPIO%d = %d (GPIO%d = %d) -> %sfailed%s\n", GPIOIN, in, GPIO, read, COLORRED, COLORDEF ); + } +} + + +void digitalWriteEx(int GPIO, int GPIOIN, int mode) { + digitalWrite(GPIO, mode); + printf("out = %d ", mode); + delayMicroseconds(5000); + CheckGPIO(GPIO, GPIOIN, mode); +} + + +void pullUpDnControlEx (int GPIO, int GPIOIN, int mode) { + pullUpDnControl (GPIO, mode); + int out = mode==PUD_UP ? 1:0; + printf("in = %4s ", mode==PUD_UP ? "up":"down"); + delayMicroseconds(5000); + CheckGPIO(GPIO, GPIOIN, out); +} + + +void CheckSame(const char* msg, int value, int expect) { + if (value==expect) { + printf("%s -> %spassed%s\n", msg, COLORGRN, COLORDEF ); + } else { + printf("%s -> %sfailed%s\n", msg, COLORRED, COLORDEF ); + } +}