test
Revision 0:cf00868b46a7, committed 2017-06-07
- Comitter:
- chasefarmer2808
- Date:
- Wed Jun 07 03:42:57 2017 +0000
- Commit message:
- test
Changed in this revision
GliderFuncTest.cpp | Show annotated file Show diff for this revision Revisions of this file |
GliderFuncTest.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r cf00868b46a7 GliderFuncTest.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GliderFuncTest.cpp Wed Jun 07 03:42:57 2017 +0000 @@ -0,0 +1,69 @@ +#include "GliderFuncTest.h" + +GliderFuncTest::GliderFuncTest(PinName sda, PinName scl, PinName tx, PinName rx, PinName solarVolt, PinName pitot, PinName buzzer) + : pitotInput(pitot), buzzerOutput(buzzer), solarInput(solarVolt) { + xbee = new Serial(tx, rx); + hmc = new HMC5883L(sda, scl); + hmc->init(); + bmp = new BMP180(sda, scl); + bmp->Initialize(64, BMP180_OSS_ULTRA_LOW_POWER); +} + +bool GliderFuncTest::testCompass() { + bool res = false; + + this->heading = this->hmc->getHeading(); + + if (this->heading >= 0) { + res = true; + } + + return res; +} + +bool GliderFuncTest::testBMP180() { + bool res = false; + + bmp->ReadData(&this->temp, &this->pressure, &this->alt); + + if (this->temp > 0 && this->pressure > 0 && this->alt > 0) { + res = true; + } + + return res; +} + +bool GliderFuncTest::testSolarVoltage() { + bool res = false; + + solarVoltage = solarInput.read_u16() * PITO_ADC_RATIO; + solarVoltage = solarVoltage / SOLAR_V_DIVIDER; + + if (solarVoltage > 0) { + res = true; + } + + return res; +} + +bool GliderFuncTest::testPitotTube() { + bool res = false; + + float vInput = this->pitotInput.read_u16() * PITO_ADC_RATIO; + vInput = vInput / PITO_V_DIVIDER; + + float diffPressure = (vInput - 0.5) / (0.2 * 5.0); //kPa + this->speed = sqrt((2*diffPressure) / AIR_DENSITY); + + if (this->speed > 0) { + res = true; + } + + return res; +} + +bool GliderFuncTest::testBuzzer() { + buzzerOutput.beep(700, 4, false); + return true; +} +
diff -r 000000000000 -r cf00868b46a7 GliderFuncTest.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GliderFuncTest.h Wed Jun 07 03:42:57 2017 +0000 @@ -0,0 +1,42 @@ +#ifndef GliderFuncTest_H +#define GliderFuncTest_H + +#include "mbed.h" +#include "HMC5883L.h" +#include "BMP180.h" +#include "beep.h" +#include <string> + +#define PITO_V_DIVIDER 0.6666 +#define SOLAR_V_DIVIDER 0.5 +#define PITO_ADC_RATIO 3.3 / 0xffff + +#define AIR_DENSITY 1.225 //kg per m3 + + +class GliderFuncTest { +public: + GliderFuncTest(PinName sda, PinName scl, PinName tx, PinName rx, PinName solarVolt, PinName pitot, PinName buzzer); + + double heading; //degrees from north + float pressure; //hpa + float temp; //C + float alt; //m + float speed; //m per s + float solarVoltage; //volts + HMC5883L* hmc; //magnetometer object + BMP180* bmp; //pressor sensor object + Serial* xbee; + + AnalogIn pitotInput; + AnalogIn solarInput; + Beep buzzerOutput; + + bool testCompass(); + bool testBMP180(); + bool testSolarVoltage(); + bool testPitotTube(); + bool testBuzzer(); +}; + +#endif \ No newline at end of file