Permalink
Browse files

Adding NPushRotationTick that carries the rotation info.

  • Loading branch information...
1 parent a35a99f commit dc691c7b9f9bae75c55ff4d3f317dd17704138f8 cpscotti committed Apr 28, 2011
Showing with 88 additions and 0 deletions.
  1. +54 −0 PushBurton2/npushrotationstick.cpp
  2. +34 −0 PushBurton2/npushrotationstick.h
@@ -0,0 +1,54 @@
+#include "npushrotationstick.h"
+
+NPushRotationsTick::NPushRotationsTick(double a_rawDegs, quint64 a_msecsToEpoch)
+{
+ msecsToEpoch = a_msecsToEpoch;
+ rawDegs = a_rawDegs;
+
+ updateCleanDegs();
+}
+
+NPushRotationsTick::~NPushRotationsTick()
+{
+}
+
+void NPushRotationsTick::append_to_xml(QDomDocument& doc, QDomElement& root) const
+{
+ //Not necessary. Append is deprecated
+}
+
+void NPushRotationsTick::dump_to_xml(QXmlStreamWriter& xml) const
+{
+ xml.writeStartElement("rot_count");
+
+ xml.writeAttribute("tstamp", QString::number(((double)msecsToEpoch)/(double)1000.0, 'f', 3));
+ xml.writeAttribute("clean_degrees", QString::number(cleanDegs, 'f', 1) );
+ xml.writeAttribute("raw_degrees", QString::number(rawDegs, 'f', 3) );
+ xml.writeEndElement();//rot_count
+}
+
+QString NPushRotationsTick::get_pretty_print() const
+{
+ return QString(("Spinning [%1]")).arg(QString::number(cleanDegs));
+}
+
+void NPushRotationsTick::updateCleanDegs()
+{
+ if(fabs(rawDegs) > 90.0) {
+ if(rawDegs > 0)
+ cleanDegs = ceil(rawDegs/180.0);
+ else
+ cleanDegs = floor(rawDegs/180.0);
+ } else {
+ if(fabs(rawDegs) > 45.0) {
+ if(rawDegs>0)
+ cleanDegs = 0.5;
+ else
+ cleanDegs = -0.5;
+ } else {
+ cleanDegs = 0.0;
+ }
+ }
+
+ cleanDegs *= 180;
+}
@@ -0,0 +1,34 @@
+#ifndef ROTATIONSTICK_H
+#define ROTATIONSTICK_H
+
+#include <QtXml>
+#include <QString>
+#include <QObject>
+
+#include "npushlogtick.h"
+#include "math.h"
+
+class NPushRotationsTick : public NPushLogTick
+{
+public:
+ NPushRotationsTick(double a_rawDegs, quint64 a_msecsToEpoch);
+
+ ~NPushRotationsTick();
+
+ void append_to_xml(QDomDocument& doc, QDomElement& root) const;
+ void dump_to_xml(QXmlStreamWriter& xml) const;
+ QString get_pretty_print() const;
+
+
+public:
+ quint64 msecsToEpoch;
+
+ double rawDegs;
+ double cleanDegs;
+
+private:
+ void updateCleanDegs();
+
+};
+
+#endif // ROTATIONSTICK_H

0 comments on commit dc691c7

Please sign in to comment.