Browse Source

#219 test2

pull/228/head
mstroh76 6 months ago
parent
commit
5e6018ec07
2 changed files with 84 additions and 4 deletions
  1. +4
    -4
      wiringPi/test/wiringpi_test1_device.c
  2. +80
    -0
      wiringPi/test/wiringpi_test2_device.c

+ 4
- 4
wiringPi/test/wiringpi_test1_device.c View File

@@ -10,7 +10,6 @@
#include <sys/time.h>


//const int GPIO = 24; //LED
const int GPIO = 19;
const int GPIOIN = 26;
const int ToggleValue = 4;
@@ -43,7 +42,8 @@ void pullUpDnControlEx (int pin ,int mode) {

int main (void) {

printf("WiringPi GPIO test program (using GPIO%d (output) and GPIO%d (input) via sys)\n", GPIO, GPIOIN);
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");
@@ -68,12 +68,12 @@ int main (void) {
delayMicroseconds(3000000);
pullUpDnControl (GPIOIN, PUD_OFF);

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

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


+ 80
- 0
wiringPi/test/wiringpi_test2_device.c View File

@@ -0,0 +1,80 @@
// 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 <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;

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("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);
}

Loading…
Cancel
Save