66 lines
1.5 KiB
C++
66 lines
1.5 KiB
C++
/*
|
||
* © Copyright 2014 – Urheberrechtshinweis
|
||
* Alle Rechte vorbehalten / All Rights Reserved
|
||
*
|
||
* Programmcode ist urheberrechtlich geschuetzt.
|
||
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
|
||
* Keine Verwendung ohne explizite Genehmigung.
|
||
* (vgl. § 106 ff UrhG / § 97 UrhG)
|
||
*/
|
||
|
||
#ifndef COMPASSDATA_H
|
||
#define COMPASSDATA_H
|
||
|
||
#include <cmath>
|
||
#include <sstream>
|
||
#include "../../math/Floatingpoint.h"
|
||
|
||
/** data received from a compass sensor */
|
||
struct CompassData {
|
||
|
||
/** azimuth angle. NAN if not available */
|
||
FPDefault azimuth = NAN;
|
||
|
||
/** describes the sensor's quality */
|
||
FPDefault quality01 = 0;
|
||
|
||
|
||
/** empty ctor */
|
||
CompassData() : azimuth(NAN) {;}
|
||
|
||
/** data ctor */
|
||
CompassData(const float azimuth) : azimuth(azimuth), quality01(0) {;}
|
||
|
||
/** data ctor */
|
||
CompassData(const float azimuth, const float quality01) : azimuth(azimuth), quality01(quality01) {;}
|
||
|
||
/** get an instance describing invalid data */
|
||
static CompassData INVALID() {
|
||
return CompassData(NAN);
|
||
}
|
||
|
||
/** convert to string */
|
||
std::string asString() const {
|
||
std::stringstream ss;
|
||
ss << "(" << azimuth << ")";
|
||
return ss.str();
|
||
}
|
||
|
||
/** is the compass data valid? [compass present] */
|
||
bool isValid() const {
|
||
return azimuth == azimuth;
|
||
}
|
||
|
||
bool operator == (const CompassData& o) const {
|
||
return EQ_OR_NAN(azimuth, o.azimuth) &&
|
||
EQ_OR_NAN(quality01, o.quality01);
|
||
}
|
||
|
||
private:
|
||
|
||
static inline bool EQ_OR_NAN(const FPDefault a, const FPDefault b) {return (a==b) || ( (a!=a) && (b!=b) );}
|
||
|
||
};
|
||
|
||
#endif // COMPASSDATA_H
|