From fce0c49ae7162ab637706144d56809caa14b8799 Mon Sep 17 00:00:00 2001 From: mstroh76 Date: Sun, 5 May 2024 14:43:13 +0200 Subject: [PATCH] #234 --- wiringPi/test/wiringpi_test1_device.c | 83 ------------------------------ wiringPi/test/wiringpi_test1_sysfs.c | 57 ++++++++++++++++++++ wiringPi/test/wiringpi_test2_device.c | 80 ---------------------------- wiringPi/test/wiringpi_test2_sysfs.c | 54 +++++++++++++++++++ wiringPi/test/wiringpi_test3_device.c | 80 ---------------------------- wiringPi/test/wiringpi_test3_device_wpi.c | 54 +++++++++++++++++++ wiringPi/test/wiringpi_test4_device.c | 80 ---------------------------- wiringPi/test/wiringpi_test4_device_phys.c | 54 +++++++++++++++++++ wiringPi/test/wiringpi_test5_default.c | 57 ++++++++++++++++++++ wiringPi/test/wiringpi_test7_version.c | 11 ++++ wiringPi/test/wpi_test.h | 48 +++++++++++++++++ 11 files changed, 335 insertions(+), 323 deletions(-) delete mode 100644 wiringPi/test/wiringpi_test1_device.c create mode 100644 wiringPi/test/wiringpi_test1_sysfs.c delete mode 100644 wiringPi/test/wiringpi_test2_device.c create mode 100644 wiringPi/test/wiringpi_test2_sysfs.c delete mode 100644 wiringPi/test/wiringpi_test3_device.c create mode 100644 wiringPi/test/wiringpi_test3_device_wpi.c delete mode 100644 wiringPi/test/wiringpi_test4_device.c create mode 100644 wiringPi/test/wiringpi_test4_device_phys.c create mode 100644 wiringPi/test/wiringpi_test5_default.c create mode 100644 wiringPi/test/wiringpi_test7_version.c create mode 100644 wiringPi/test/wpi_test.h diff --git a/wiringPi/test/wiringpi_test1_device.c b/wiringPi/test/wiringpi_test1_device.c deleted file mode 100644 index 189dd9f..0000000 --- a/wiringPi/test/wiringpi_test1_device.c +++ /dev/null @@ -1,83 +0,0 @@ -// WiringPi test program: Kernel char device interface / sysfs successor -// Compile: gcc -Wall wiringpi_test1_device.c -o wiringpi_test1_device -lwiringPi - -#include -#include -#include -#include -#include -#include -#include - - -const int GPIO = 19; -const int GPIOIN = 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) { - - printf("WiringPi GPIO test program 1 (using GPIO%d (output) and GPIO%d (input) via sys)\n", GPIO, GPIOIN); - printf(" testing digitalWrite, digitalRead and pullUpDnControl\n"); - - if (wiringPiSetupSys() == -1) { - printf("wiringPiSetupGpioDevice failed\n\n"); - exit(EXIT_FAILURE); - } - pinMode(GPIOIN, INPUT); - pinMode(GPIO, OUTPUT); - - printf("toggle %d times ...\n", ToggleValue); - for (int loop=1; loop +#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) via sys)\n", GPIO, GPIOIN); + printf(" testing digitalWrite, digitalRead and pullUpDnControl\n"); + + if (wiringPiSetupSys() == -1) { + printf("wiringPiSetupSys failed\n\n"); + exit(EXIT_FAILURE); + } + pinMode(GPIOIN, INPUT); + pinMode(GPIO, OUTPUT); + + printf("toggle %d times ...\n", ToggleValue); + for (int loop=1; loop -#include -#include -#include -#include -#include -#include - - -const int GPIO = 19; -const int GPIOIN = 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) { - - printf("WiringPi GPIO test program 2 (using GPIO%d (output) and GPIO%d (input) via sys)\n", GPIO, GPIOIN); - printf(" testing pullUpDnControl and pinMode PM_OFF\n"); - - if (wiringPiSetupSys() == -1) { - printf("wiringPiSetupSys failed\n\n"); - exit(EXIT_FAILURE); - } - pinMode(GPIOIN, INPUT); - pinMode(GPIO, OUTPUT); - - printf("\nTest output\n"); - digitalWriteEx(GPIO, HIGH); - delayMicroseconds(600000); - digitalWriteEx(GPIO, LOW); - delayMicroseconds(600000); - - printf("\nTest output off with pull up\n"); - pinMode(GPIO, OUTPUT); - digitalWriteEx(GPIO, LOW); - pullUpDnControl (GPIO, PUD_UP); - pinMode(GPIO, PM_OFF); - delayMicroseconds(600000); - printf("out = off "); - CheckGPIO(HIGH); - delayMicroseconds(600000); - - printf("\nTest output off with pull down\n"); - pullUpDnControl (GPIO, PUD_DOWN); - pinMode(GPIO, PM_OFF); - delayMicroseconds(600000); - printf("out = off "); - CheckGPIO(LOW); - delayMicroseconds(600000); - - return(EXIT_SUCCESS); -} diff --git a/wiringPi/test/wiringpi_test2_sysfs.c b/wiringPi/test/wiringpi_test2_sysfs.c new file mode 100644 index 0000000..454e112 --- /dev/null +++ b/wiringPi/test/wiringpi_test2_sysfs.c @@ -0,0 +1,54 @@ +// WiringPi test program: Kernel char device interface / sysfs successor +// Compile: gcc -Wall wiringpi_test2_device.c -o wiringpi_test2_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 2 (using GPIO%d (output) and GPIO%d (input) via sys)\n", GPIO, GPIOIN); + printf(" testing pullUpDnControl and pinMode PM_OFF\n"); + + if (wiringPiSetupSys() == -1) { + printf("wiringPiSetupSys failed\n\n"); + exit(EXIT_FAILURE); + } + pinMode(GPIOIN, INPUT); + pinMode(GPIO, OUTPUT); + + printf("\nTest output\n"); + digitalWriteEx(GPIO, GPIOIN, HIGH); + delayMicroseconds(600000); + digitalWriteEx(GPIO, GPIOIN, LOW); + delayMicroseconds(600000); + + printf("\nTest output off with pull up\n"); + pinMode(GPIO, OUTPUT); + digitalWriteEx(GPIO, GPIOIN, LOW); + pullUpDnControl (GPIO, PUD_UP); + pinMode(GPIO, PM_OFF); + delayMicroseconds(600000); + printf("out = off "); + CheckGPIO(GPIO, GPIOIN, HIGH); + delayMicroseconds(600000); + + printf("\nTest output off with pull down\n"); + pullUpDnControl (GPIO, PUD_DOWN); + pinMode(GPIO, PM_OFF); + delayMicroseconds(600000); + printf("out = off "); + CheckGPIO(GPIO, GPIOIN, LOW); + delayMicroseconds(600000); + + return(EXIT_SUCCESS); +} diff --git a/wiringPi/test/wiringpi_test3_device.c b/wiringPi/test/wiringpi_test3_device.c deleted file mode 100644 index 362ae68..0000000 --- a/wiringPi/test/wiringpi_test3_device.c +++ /dev/null @@ -1,80 +0,0 @@ -// WiringPi test program: Kernel char device interface / sysfs successor -// Compile: gcc -Wall wiringpi_test3_device.c -o wiringpi_test3_device -lwiringPi - -#include -#include -#include -#include -#include -#include -#include - - -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) { - - printf("WiringPi GPIO test program 2 (using WiringPi GPIO%d (output) and GPIO%d (input) via GPIO device)\n", GPIO, GPIOIN); - printf(" testing pullUpDnControl and pinMode PM_OFF\n"); - - if (wiringPiSetupGpioDevice(WPI_PIN_WPI) == -1) { - printf("wiringPiSetupGpioDevice failed\n\n"); - exit(EXIT_FAILURE); - } - pinMode(GPIOIN, INPUT); - pinMode(GPIO, OUTPUT); - - printf("\nTest output\n"); - digitalWriteEx(GPIO, HIGH); - delayMicroseconds(600000); - digitalWriteEx(GPIO, LOW); - delayMicroseconds(600000); - - printf("\nTest output off with pull up\n"); - pinMode(GPIO, OUTPUT); - digitalWriteEx(GPIO, LOW); - pullUpDnControl (GPIO, PUD_UP); - pinMode(GPIO, PM_OFF); - delayMicroseconds(600000); - printf("out = off "); - CheckGPIO(HIGH); - delayMicroseconds(600000); - - printf("\nTest output off with pull down\n"); - pullUpDnControl (GPIO, PUD_DOWN); - pinMode(GPIO, PM_OFF); - delayMicroseconds(600000); - printf("out = off "); - CheckGPIO(LOW); - delayMicroseconds(600000); - - return(EXIT_SUCCESS); -} diff --git a/wiringPi/test/wiringpi_test3_device_wpi.c b/wiringPi/test/wiringpi_test3_device_wpi.c new file mode 100644 index 0000000..179f09c --- /dev/null +++ b/wiringPi/test/wiringpi_test3_device_wpi.c @@ -0,0 +1,54 @@ +// WiringPi test program: Kernel char device interface / sysfs successor +// Compile: gcc -Wall wiringpi_test3_device.c -o wiringpi_test3_device -lwiringPi + +#include "wpi_test.h" +#include +#include +#include +#include +#include + + +const int GPIO = 24; //BCM 19 +const int GPIOIN = 25; //BCM 26; +const int ToggleValue = 4; + + +int main (void) { + + printf("WiringPi GPIO test program 2 (using WiringPi GPIO%d (output) and GPIO%d (input) via GPIO device)\n", GPIO, GPIOIN); + printf(" testing pullUpDnControl and pinMode PM_OFF\n"); + + if (wiringPiSetupGpioDevice(WPI_PIN_WPI) == -1) { + printf("wiringPiSetupGpioDevice failed\n\n"); + exit(EXIT_FAILURE); + } + pinMode(GPIOIN, INPUT); + pinMode(GPIO, OUTPUT); + + printf("\nTest output\n"); + digitalWriteEx(GPIO, GPIOIN, HIGH); + delayMicroseconds(600000); + digitalWriteEx(GPIO, GPIOIN, LOW); + delayMicroseconds(600000); + + printf("\nTest output off with pull up\n"); + pinMode(GPIO, OUTPUT); + digitalWriteEx(GPIO, GPIOIN, LOW); + pullUpDnControl (GPIO, PUD_UP); + pinMode(GPIO, PM_OFF); + delayMicroseconds(600000); + printf("out = off "); + CheckGPIO(GPIO, GPIOIN, HIGH); + delayMicroseconds(600000); + + printf("\nTest output off with pull down\n"); + pullUpDnControl (GPIO, PUD_DOWN); + pinMode(GPIO, PM_OFF); + delayMicroseconds(600000); + printf("out = off "); + CheckGPIO(GPIO, GPIOIN, LOW); + delayMicroseconds(600000); + + return(EXIT_SUCCESS); +} diff --git a/wiringPi/test/wiringpi_test4_device.c b/wiringPi/test/wiringpi_test4_device.c deleted file mode 100644 index f336212..0000000 --- a/wiringPi/test/wiringpi_test4_device.c +++ /dev/null @@ -1,80 +0,0 @@ -// WiringPi test program: Kernel char device interface / sysfs successor -// Compile: gcc -Wall wiringpi_test4_device.c -o wiringpi_test4_device -lwiringPi - -#include -#include -#include -#include -#include -#include -#include - - -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) { - - printf("WiringPi GPIO test program 2 (using physical GPIO%d (output) and GPIO%d (input) via GPIO device)\n", GPIO, GPIOIN); - printf(" testing pullUpDnControl and pinMode PM_OFF\n"); - - if (wiringPiSetupGpioDevice(WPI_PIN_PHYS) == -1) { - printf("wiringPiSetupGpioDevice failed\n\n"); - exit(EXIT_FAILURE); - } - pinMode(GPIOIN, INPUT); - pinMode(GPIO, OUTPUT); - - printf("\nTest output\n"); - digitalWriteEx(GPIO, HIGH); - delayMicroseconds(600000); - digitalWriteEx(GPIO, LOW); - delayMicroseconds(600000); - - printf("\nTest output off with pull up\n"); - pinMode(GPIO, OUTPUT); - digitalWriteEx(GPIO, LOW); - pullUpDnControl (GPIO, PUD_UP); - pinMode(GPIO, PM_OFF); - delayMicroseconds(600000); - printf("out = off "); - CheckGPIO(HIGH); - delayMicroseconds(600000); - - printf("\nTest output off with pull down\n"); - pullUpDnControl (GPIO, PUD_DOWN); - pinMode(GPIO, PM_OFF); - delayMicroseconds(600000); - printf("out = off "); - CheckGPIO(LOW); - delayMicroseconds(600000); - - return(EXIT_SUCCESS); -} diff --git a/wiringPi/test/wiringpi_test4_device_phys.c b/wiringPi/test/wiringpi_test4_device_phys.c new file mode 100644 index 0000000..9970aa5 --- /dev/null +++ b/wiringPi/test/wiringpi_test4_device_phys.c @@ -0,0 +1,54 @@ +// WiringPi test program: Kernel char device interface / sysfs successor +// Compile: gcc -Wall wiringpi_test4_device.c -o wiringpi_test4_device -lwiringPi + +#include "wpi_test.h" +#include +#include +#include +#include +#include + + +const int GPIO = 35; //BCM 19 +const int GPIOIN = 37; //BCM 26; +const int ToggleValue = 4; + + +int main (void) { + + printf("WiringPi GPIO test program 2 (using physical GPIO%d (output) and GPIO%d (input) via GPIO device)\n", GPIO, GPIOIN); + printf(" testing pullUpDnControl and pinMode PM_OFF\n"); + + if (wiringPiSetupGpioDevice(WPI_PIN_PHYS) == -1) { + printf("wiringPiSetupGpioDevice failed\n\n"); + exit(EXIT_FAILURE); + } + pinMode(GPIOIN, INPUT); + pinMode(GPIO, OUTPUT); + + printf("\nTest output\n"); + digitalWriteEx(GPIO, GPIOIN, HIGH); + delayMicroseconds(600000); + digitalWriteEx(GPIO, GPIOIN, LOW); + delayMicroseconds(600000); + + printf("\nTest output off with pull up\n"); + pinMode(GPIO, OUTPUT); + digitalWriteEx(GPIO, GPIOIN, LOW); + pullUpDnControl (GPIO, PUD_UP); + pinMode(GPIO, PM_OFF); + delayMicroseconds(600000); + printf("out = off "); + CheckGPIO(GPIO, GPIOIN, HIGH); + delayMicroseconds(600000); + + printf("\nTest output off with pull down\n"); + pullUpDnControl (GPIO, PUD_DOWN); + pinMode(GPIO, PM_OFF); + delayMicroseconds(600000); + printf("out = off "); + 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 ); + } +}