commit 44350539b269e766dddd9bfeee245d79b5842d96 Author: jazz (rpi5) Date: Tue Sep 1 18:18:51 2026 -0500 initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4d23a18 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,3 @@ +[*] +tab_width = 8; +indent_style = tabs; diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5c7c8b4 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +TARGET=pinmon +CC=gcc +CFLAGS=-Wall +LDFLAGS=-lwiringPi + +SRC=$(wildcard *.c) +OBJ=$(SRC:.c=.o) + +all: $(TARGET) + +$(TARGET): $(OBJ) + $(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -o $(TARGET) + +clean: + rm -f $(TARGET) *.o + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ diff --git a/README.org b/README.org new file mode 100644 index 0000000..baae01a --- /dev/null +++ b/README.org @@ -0,0 +1,16 @@ +* pinmon + +** requirements + +you need [[https://github.com/WiringPi/WiringPi][WiringPi]]. +download the latest source release and compile it, or install it using your operating system's package manager. + +** usage + +run with no arguments: print everything + +pass a single integer argument from 1-31 to read a single pin + +** todo + +output formatting options (implemented, but not accessible) diff --git a/main.c b/main.c new file mode 100644 index 0000000..e4b4312 --- /dev/null +++ b/main.c @@ -0,0 +1,80 @@ +#include +#include + +#include + +void get_one(int *a, int p) { + a[p] = digitalRead(p); + return; +} + +void get_all(int *a) { + for (int i = 1; i < 32; i++) { + a[i] = digitalRead(i); + } + return; +} + +void print_all_quiet(int *a) { + for (int i = 1; i <= 31; i++) { + if (i % 10) { + printf("%d ", a[i]); + } else if (i == 30) { + printf("%d ", a[i]); + } else { + putchar('\n'); + } + } +} + +void print_all_oneline(int *a) { + for (int i = 1; i <= 31; i++) + printf("%d ", a[i]); + + putchar('\n'); +} + +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[31]; + int pin; + + wiringPiSetupPinType(WPI_PIN_WPI); + //printf("%i\n", argc); + + switch (argc) { + case 1: // print everything + get_all(pins); + printf("Pins 1-10:\n\t"); + for (int i = 1; i <= 10; i++) { + printf("%d ", pins[i]); + } + printf("\nPins 11-20:\n\t"); + for (int i = 11; i <= 20; i++) { + printf("%d ", pins[i]); + } + printf("\nPins 21-30:\n\t"); + for (int i = 21; i <= 30; i++) { + printf("%d ", pins[i]); + } + putchar('\n'); + 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; +}