Explorar o código

added configure option (--enable-raspi) for raspberry pi io

FlorianPalm %!s(int64=10) %!d(string=hai) anos
pai
achega
e24035b06b
Modificáronse 2 ficheiros con 68 adicións e 0 borrados
  1. 49 0
      examples/src/raspberrypi_io.c
  2. 19 0
      examples/src/raspberrypi_io.h

+ 49 - 0
examples/src/raspberrypi_io.c

@@ -0,0 +1,49 @@
+/*
+ * raspberrypi_io.c
+ *
+ *  Created on: 23.06.2014
+ *      Author: root
+ */
+
+#include "raspberrypi_io.h"
+#ifdef RASPI
+int readTemp(float *temp){
+	FILE *ptr_file;
+	char buf[1000];
+	char delimiter[] = "=";
+	char *ptr_temp;
+	long temperaturInmC;
+
+	ptr_file =fopen("/sys/bus/w1/devices/10-000802c607f3/w1_slave","r");
+	if (!ptr_file){
+		puts("ERROR: no sensor");
+		return 1;
+	}
+
+	fgets(buf, 1000, ptr_file);
+
+	fgets(buf, 1000, ptr_file);
+
+	ptr_temp = strtok(buf, (int) delimiter);
+
+	ptr_temp = strtok((void*)0, (int) delimiter);
+
+	temperaturInmC = atol(ptr_temp);
+
+	fclose(ptr_file);
+
+	*temp = (float)temperaturInmC/1000;
+	return 0;
+}
+
+int writeLEDred(int state){
+	if (wiringPiSetup() == -1){
+		return 1;
+	}
+	pinMode(0, OUTPUT);
+
+	digitalWrite(0, state);
+
+	return 0;
+}
+#endif

+ 19 - 0
examples/src/raspberrypi_io.h

@@ -0,0 +1,19 @@
+/*
+ * raspberrypi_io.h
+ *
+ *  Created on: 23.06.2014
+ *      Author: root
+ */
+
+#ifndef RASPBERRYPI_IO_H_
+#define RASPBERRYPI_IO_H_
+#ifdef RASPI
+	#include <wiringPi.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+
+int readTemp(float *temp);
+int writeLEDred(int state);
+
+#endif /* RASPBERRYPI_IO_H_ */