Browse Source

#234

pull/235/head
mstroh76 6 months ago
parent
commit
fce0c49ae7
7 changed files with 142 additions and 130 deletions
  1. +7
    -33
      wiringPi/test/wiringpi_test1_sysfs.c
  2. +7
    -33
      wiringPi/test/wiringpi_test2_sysfs.c
  3. +6
    -32
      wiringPi/test/wiringpi_test3_device_wpi.c
  4. +6
    -32
      wiringPi/test/wiringpi_test4_device_phys.c
  5. +57
    -0
      wiringPi/test/wiringpi_test5_default.c
  6. +11
    -0
      wiringPi/test/wiringpi_test7_version.c
  7. +48
    -0
      wiringPi/test/wpi_test.h

wiringPi/test/wiringpi_test1_device.c → wiringPi/test/wiringpi_test1_sysfs.c View File

@@ -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 <wiringPi.h>
#include <stdio.h>
#include "wpi_test.h"
#include <stdlib.h>
#include <signal.h>
#include <string.h>
@@ -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<ToggleValue; loop++) {
digitalWriteEx(GPIO, LOW);
digitalWriteEx(GPIO, GPIOIN, LOW);
delayMicroseconds(600000);
digitalWriteEx(GPIO, HIGH);
digitalWriteEx(GPIO, GPIOIN, HIGH);
delayMicroseconds(600000);
}

@@ -69,9 +43,9 @@ int main (void) {
pullUpDnControl (GPIOIN, PUD_OFF);

for (int loop=1; loop<ToggleValue; loop++) {
pullUpDnControlEx (GPIO, PUD_DOWN);
pullUpDnControlEx (GPIO, GPIOIN, PUD_DOWN);
delayMicroseconds(600000);
pullUpDnControlEx (GPIO, PUD_UP);
pullUpDnControlEx (GPIO, GPIOIN, PUD_UP);
delayMicroseconds(600000);
}


wiringPi/test/wiringpi_test2_device.c → wiringPi/test/wiringpi_test2_sysfs.c View File

@@ -1,8 +1,7 @@
// WiringPi test program: Kernel char device interface / sysfs successor
// Compile: gcc -Wall wiringpi_test2_device.c -o wiringpi_test2_device -lwiringPi

#include <wiringPi.h>
#include <stdio.h>
#include "wpi_test.h"
#include <stdlib.h>
#include <signal.h>
#include <string.h>
@@ -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);

wiringPi/test/wiringpi_test3_device.c → wiringPi/test/wiringpi_test3_device_wpi.c View File

@@ -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 <wiringPi.h>
#include <stdio.h>
#include "wpi_test.h"
#include <stdlib.h>
#include <signal.h>
#include <string.h>
@@ -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);

wiringPi/test/wiringpi_test4_device.c → wiringPi/test/wiringpi_test4_device_phys.c View File

@@ -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 <wiringPi.h>
#include <stdio.h>
#include "wpi_test.h"
#include <stdlib.h>
#include <signal.h>
#include <string.h>
@@ -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);

+ 57
- 0
wiringPi/test/wiringpi_test5_default.c View File

@@ -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 <stdlib.h>
#include <signal.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>


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<ToggleValue; loop++) {
digitalWriteEx(GPIO, GPIOIN, LOW);
delayMicroseconds(600000);
digitalWriteEx(GPIO, GPIOIN, HIGH);
delayMicroseconds(600000);
}

digitalWrite(GPIO, LOW);

printf("\nWiringPi GPIO test program (using GPIO%d (input pull up/down) and GPIO%d (input))\n", GPIO, GPIOIN);
pullUpDnControl (GPIO, PUD_UP);
pinMode(GPIO, INPUT);
delayMicroseconds(3000000);
pullUpDnControl (GPIOIN, PUD_OFF);

for (int loop=1; loop<ToggleValue; loop++) {
pullUpDnControlEx (GPIO, GPIOIN, PUD_DOWN);
delayMicroseconds(600000);
pullUpDnControlEx (GPIO, GPIOIN, PUD_UP);
delayMicroseconds(600000);
}

//Error wrong direction - only for fun
digitalWrite(GPIO, LOW);

return(EXIT_SUCCESS);
}


+ 11
- 0
wiringPi/test/wiringpi_test7_version.c View File

@@ -0,0 +1,11 @@
#include "wpi_test.h"
#include "../../version.h"

int main (void) {
int major, minor;

wiringPiVersion(&major, &minor);

CheckSame("version major", major, VERSION_MAJOR);
CheckSame("version minor", minor, VERSION_MINOR);
}

+ 48
- 0
wiringPi/test/wpi_test.h View File

@@ -0,0 +1,48 @@

#include <wiringPi.h>
#include <stdio.h>

#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 );
}
}

Loading…
Cancel
Save