prototypes/move funcs to bottom

This commit is contained in:
jazz committed 2026-09-01 19:49:26 -05:00
1 parent 296faef6af
commit 77f687321d
1 file changed
+40 -33
+40 -33
View File
@@ -3,6 +3,46 @@
#include <wiringPi.h> #include <wiringPi.h>
void get_one(int *a, int p);
void get_all(int *a);
void put_all_quiet(int *a);
void put_all_oneline(int *a);
void put_all_pretty(int *a);
int main(int argc, char *argv[]) {
/*
* pins[] array: GPIO pins only, input only; using WiringPi num scheme
* 0: placeholder
* 1-31: WiringPi 1-31
*/
int pins[32];
int pin;
wiringPiSetupPinType(WPI_PIN_WPI);
//printf("%i\n", argc);
switch (argc) {
case 1: // print everything
get_all(pins);
put_all_pretty(pins);
break;
case 2: // print 1 pin
pin = atoi(argv[1]);
if ((pin >= 1) && (pin <= 31)) {
get_one(pins, pin);
printf("%d\n", pins[pin]);
}
break;
default: // no
fprintf(stderr, "err: too many args (%d)\n", argc-1);
return EXIT_FAILURE;
break;
}
return EXIT_SUCCESS;
}
void get_one(int *a, int p) { void get_one(int *a, int p) {
a[p] = digitalRead(p); a[p] = digitalRead(p);
return; return;
@@ -57,36 +97,3 @@ void put_all_pretty(int *a) {
printf("\nPin 31:\t\t%d\n", a[31]); printf("\nPin 31:\t\t%d\n", a[31]);
} }
int main(int argc, char *argv[]) {
/*
* pins[] array: GPIO pins only, input only; using WiringPi num scheme
* 0: placeholder
* 1-31: WiringPi 1-31
*/
int pins[32];
int pin;
wiringPiSetupPinType(WPI_PIN_WPI);
//printf("%i\n", argc);
switch (argc) {
case 1: // print everything
get_all(pins);
put_all_pretty(pins);
break;
case 2: // print 1 pin
pin = atoi(argv[1]);
if ((pin >= 1) && (pin <= 31)) {
get_one(pins, pin);
printf("%d\n", pins[pin]);
}
break;
default: // no
fprintf(stderr, "err: too many args (%d)\n", argc-1);
return EXIT_FAILURE;
break;
}
return EXIT_SUCCESS;
}