From dcd713d443d683f0440e65cf69d88f2bcaf89c42 Mon Sep 17 00:00:00 2001 From: Jeremy Tan Date: Fri, 27 Sep 2013 09:17:37 +0800 Subject: [PATCH] Interops with non-BBB platforms --- server/bbb_pin.c | 1 + server/bbb_pin.h | 20 ++++++++++++++++++++ server/common.h | 5 +++++ server/run.sh | Bin 2275 -> 2498 bytes server/sensor.c | 5 +++++ 5 files changed, 31 insertions(+) diff --git a/server/bbb_pin.c b/server/bbb_pin.c index 373bbac..5fb7874 100644 --- a/server/bbb_pin.c +++ b/server/bbb_pin.c @@ -4,6 +4,7 @@ * THIS CODE IS NOT THREADSAFE */ +#define _BBB_PIN_SRC #include "bbb_pin.h" #include diff --git a/server/bbb_pin.h b/server/bbb_pin.h index ef8e1be..ce91e5a 100644 --- a/server/bbb_pin.h +++ b/server/bbb_pin.h @@ -10,6 +10,7 @@ #include "bbb_pin_defines.h" +#if defined(_BBB) || defined(_BBB_PIN_SRC) // Initialise / Deinitialise functions extern void GPIO_Export(int pin); extern void GPIO_Unexport(int pin); @@ -28,8 +29,27 @@ extern int ADC_Read(int pin); extern void PWM_Set(int pin, bool polarity, long period, long duty); // period and duty are in ns extern void PWM_Stop(int pin); +#else +//Empty defines so it compiles on any platform that's not the BBB +#define GPIO_Export(pin) +#define GPIO_Unexport(pin) +#define PWM_Export(pin) +#define PWM_Unexport(pin) +#define ADC_Export(pin) +#define ADC_Unexport(pin) + +#define GPIO_Read(pin) 0 +#define GPIO_Set(pin, value) + +#define ADC_Read(pin) 0 + +#define PWM_Set(pin, polarity, period, duty) +#define PWM_Stop(Pin) + + +#endif //_BBB #endif //_BBB_PIN_H diff --git a/server/common.h b/server/common.h index 43bb8bd..0092598 100644 --- a/server/common.h +++ b/server/common.h @@ -10,6 +10,11 @@ #define _BSD_SOURCE #define _XOPEN_SOURCE 600 +/** Determine if we're running on the BBB **/ +#ifdef __arm__ +#define _BBB +#endif + /** The current API version **/ #define API_VERSION 0 diff --git a/server/run.sh b/server/run.sh index c3e134cbb708ccf275fcabf1f67bdac359228108..98002e98facd10519fb0bfbf53f34309a5af81c4 100755 GIT binary patch delta 119 zcmaDXcu07{OxMgbh3IGnB^8a*yu{p81>IatB?U!W1+B!QTrCBK*jQ_Yl8n?mF3!~C zjC=*Z{1Szt(!9LPymW>9Jdlinlamt{=R_W}$@kdBCPwfva!yQB6X#Uc(=RS5N=?jF UPy=eM$ShGX;7ZHfINgT>0FMhJx&QzG delta 11 ScmX>k{8(_p%*_>yUK{`)CIoQ+ diff --git a/server/sensor.c b/server/sensor.c index 63e69d8..c3444bf 100644 --- a/server/sensor.c +++ b/server/sensor.c @@ -251,6 +251,11 @@ bool Sensor_Read(Sensor * s, DataPoint * d) s->newest_data.time_stamp = d->time_stamp; s->newest_data.value = d->value; } + +#ifdef _BBB + //Not all cases have usleep, easiest here. + usleep(1000000); +#endif return result; } -- 2.20.1