From 21d397bc2e3c5253647cd5af6c78a56853c7bcee Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Sun, 22 Sep 2019 22:07:06 +0200 Subject: hardware geht erst mal --- .gitignore | 1 + Makefile | 8 +++++++ blink.c | 73 -------------------------------------------------------------- sensor.c | 38 ++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 73 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile delete mode 100644 blink.c create mode 100644 sensor.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c976511 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +sensor diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..87db357 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +CFLAGS=-Werror -O3 -pedantic + +sensor: sensor.c + gcc -o "$@" $(CFLAGS) -lwiringx $^ + +all: sensor + +.PHONY: all diff --git a/blink.c b/blink.c deleted file mode 100644 index 4598503..0000000 --- a/blink.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - Copyright (c) 2016 CurlyMo - - This Source Code Form is subject to the terms of the Mozilla Public - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. -*/ - -#include -#include -#include -#include -#include - -#include "wiringx.h" -#include "../src/platform/platform.h" - -char *usage = - "Usage: %s platform GPIO\n" - " GPIO is the GPIO to write to\n" - "Example: %s raspberrypi2 10\n"; - -int main(int argc, char *argv[]) { - char *str = NULL, *platform = NULL; - char usagestr[130]; - int gpio = 0, invalid = 0; - - memset(usagestr, '\0', 130); - - // expect only 1 argument => argc must be 2 - if(argc != 3) { - snprintf(usagestr, 129, usage, argv[0], argv[0]); - puts(usagestr); - return -1; - } - - // check for a valid, numeric argument - platform = argv[1]; - str = argv[2]; - while(*str != '\0') { - if(!isdigit(*str)) { - invalid = 1; - } - str++; - } - if(invalid == 1) { - printf("%s: Invalid GPIO %s\n", argv[0], argv[2]); - return -1; - } - - gpio = atoi(argv[2]); - - if(wiringXSetup(platform, NULL) == -1) { - wiringXGC(); - return -1; - } - - if(wiringXValidGPIO(gpio) != 0) { - printf("%s: Invalid GPIO %d\n", argv[0], gpio); - wiringXGC(); - return -1; - } - - pinMode(gpio, PINMODE_OUTPUT); - while(1) { - printf("Writing to GPIO %d: High\n", gpio); - digitalWrite(gpio, HIGH); - sleep(1); - printf("Writing to GPIO %d: Low\n", gpio); - digitalWrite(gpio, LOW); - sleep(1); - } -} diff --git a/sensor.c b/sensor.c new file mode 100644 index 0000000..2c933da --- /dev/null +++ b/sensor.c @@ -0,0 +1,38 @@ +/* + Copyright (c) 2016 CurlyMo + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. +*/ + +#include +#include +#include +#include +#include + +#include "wiringx.h" + +int main() { + + if(wiringXSetup("raspberrypi3", NULL) == -1) { + wiringXGC(); + return -1; + } + + pinMode(9, PINMODE_OUTPUT); + digitalWrite(9, HIGH); + pinMode(8, PINMODE_OUTPUT); + pinMode(9, PINMODE_INPUT); + while(1) { + printf("Writing to GPIO %d: High\n", 8); + digitalWrite(8, HIGH); +printf("Reading from GPIO %d: %d\n", 9, digitalRead(9)); + usleep(100000); + printf("Writing to GPIO %d: Low\n", 8); + digitalWrite(8, LOW); +printf("Reading from GPIO %d: %d\n", 9, digitalRead(9)); + usleep(100000); + } +} -- cgit v1.2.3-54-g00ecf