initial commit

This commit is contained in:
jazz committed 2026-09-01 18:18:51 -05:00
commit 44350539b2
4 files changed
+117

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
[*]
tab_width = 8;
indent_style = tabs;
+18
View File
@@ -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 $@
+16
View File
@@ -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)
+80
View File
@@ -0,0 +1,80 @@
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
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;
}