From 84d9a3d3a7eabc7e9bfc7170c4a6489740983b8a Mon Sep 17 00:00:00 2001 From: structix Date: Sun, 4 Sep 2016 20:58:29 +0200 Subject: [PATCH] Added example, added makefile --- gy521example.c | 14 ++++++++++++++ libgy521.c | 14 ++++++++------ makefile | 20 ++++++++++++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 gy521example.c create mode 100644 makefile diff --git a/gy521example.c b/gy521example.c new file mode 100644 index 0000000..bf3a987 --- /dev/null +++ b/gy521example.c @@ -0,0 +1,14 @@ +#include +#include +#include "libgy521.h" + +int main(void) { + wiringPiSetup(); + + setupgy521(); + + while (1) { + printf("AngleX = %f, AngleY = %f, AngleZ = %f\n", getAngleX(), getAngleY(), getAngleZ()); + delay(100); + } +} diff --git a/libgy521.c b/libgy521.c index cf6d6ab..3673d40 100644 --- a/libgy521.c +++ b/libgy521.c @@ -1,7 +1,9 @@ -#include +//#include +#include #include - -#include +#include +#include +#include "libgy521.h" //Constants @@ -19,12 +21,12 @@ int id; int setupgy521(void) { - if (id = wiringPiI2CSetup(MPU6050_I2C_ADDRESS) != -1) { + if ((id = wiringPiI2CSetup(MPU6050_I2C_ADDRESS)) != -1) { wiringPiI2CReadReg8(id, MPU6050_PWR_MGMT_1); wiringPiI2CWriteReg16(id, MPU6050_PWR_MGMT_1, 0); return EXIT_SUCCESS; } else { - return EXIT_FAILURE + return EXIT_FAILURE; } } @@ -70,5 +72,5 @@ float getAngleZ(void) { int x = getAccelX(); int y = getAccelY(); int z = getAccelZ(); - return atan((sqrt(po(y, 2) + pow(x, 2))) / z) * 180.0 / M_PI; + return atan((sqrt(pow(y, 2) + pow(x, 2))) / z) * 180.0 / M_PI; } diff --git a/makefile b/makefile new file mode 100644 index 0000000..1a4797a --- /dev/null +++ b/makefile @@ -0,0 +1,20 @@ +#Infos: http://www.ijon.de/comp/tutorials/makefile.html + + +VERSION = 1.0 +CC = /usr/bin/gcc +CFLAGS = -Wall -g -D_REENTRANT -DVERSION=\"$(VERSION)\" +#LDFLAGS = -lm -lpthread `gtk-config --cflags` `gtk-config --libs` -lgthread +LDFLAGS = -lwiringPi -lm + +OBJ = gy521example.o libgy521.o + +waterpicore: $(OBJ) + $(CC) $(CFLAGS) -o gy521example $(OBJ) $(LDFLAGS) + +%.o: %.c + $(CC) $(CFLAGS) -c $< + +.PHONY: clean +clean: + rm -r *.o