diff --git a/lib/boatData/GwBoatData.cpp b/lib/boatData/GwBoatData.cpp index dfb8b39..cc1c9be 100644 --- a/lib/boatData/GwBoatData.cpp +++ b/lib/boatData/GwBoatData.cpp @@ -27,3 +27,56 @@ String GwBoatData::toJson() const { serializeJson(json,buf); return buf; } + +double formatCourse(double cv) +{ + double rt = cv * 180.0 / M_PI; + if (rt > 360) + rt -= 360; + if (rt < 0) + rt += 360; + return rt; +} +double formatDegToRad(double deg){ + return deg/180.0 * M_PI; +} +double formatWind(double cv) +{ + double rt = formatCourse(cv); + if (rt > 180) + rt = 180 - rt; + return rt; +} +double formatKnots(double cv) +{ + return cv * 3600.0 / 1852.0; +} + +uint32_t mtr2nm(uint32_t m) +{ + return m / 1852; +} +double mtr2nm(double m) +{ + return m / 1852; +} + +double kelvinToC(double v) +{ + return v - 273.15; +} +double formatLatitude(double v){ + return v; +} +double formatLongitude(double v){ + return v; +} +double formatFixed0(double v){ + return v; +} +double formatDepth(double v){ + return v; +} +uint32_t formatFixed0(uint32_t v){ + return v; +} \ No newline at end of file diff --git a/lib/boatData/GwBoatData.h b/lib/boatData/GwBoatData.h index dcde248..ce1ef62 100644 --- a/lib/boatData/GwBoatData.h +++ b/lib/boatData/GwBoatData.h @@ -92,44 +92,18 @@ template class GwBoatItem : public GwBoatItemBase{ } virtual int getLastSource(){return lastUpdateSource;} }; - -static double formatCourse(double cv) -{ - double rt = cv * 180.0 / M_PI; - if (rt > 360) - rt -= 360; - if (rt < 0) - rt += 360; - return rt; -} -static double formatDegToRad(double deg){ - return deg/180.0 * M_PI; -} -static double formatWind(double cv) -{ - double rt = formatCourse(cv); - if (rt > 180) - rt = 180 - rt; - return rt; -} -static double formatKnots(double cv) -{ - return cv * 3600.0 / 1852.0; -} - -static uint32_t mtr2nm(uint32_t m) -{ - return m / 1852; -} -static double mtr2nm(double m) -{ - return m / 1852; -} - -static double kelvinToC(double v) -{ - return v - 273.15; -} +double formatCourse(double cv); +double formatDegToRad(double deg); +double formatWind(double cv); +double formatKnots(double cv); +uint32_t mtr2nm(uint32_t m); +double mtr2nm(double m); +double kelvinToC(double v); +double formatLatitude(double v); +double formatLongitude(double v); +double formatFixed0(double v); +uint32_t formatFixed0(uint32_t v); +double formatDepth(double v); #define GWBOATDATA(type,name,time,fmt) \ GwBoatItem *name=new GwBoatItem(F(#name),F(#fmt),time,fmt,&values) ; @@ -154,20 +128,20 @@ class GwBoatData{ GWBOATDATA(double,Variation,4000,&formatCourse) GWBOATDATA(double,Deviation,4000,&formatCourse) GWBOATDATA(double,RudderPosition,4000,&formatCourse) - GWBOATDATA(double,Latitude,4000,NULL) - GWBOATDATA(double,Longitude,4000,NULL) - GWBOATDATA(double,Altitude,4000,NULL) - GWBOATDATA(double,WaterDepth,4000,NULL) - GWBOATDATA(double,SecondsSinceMidnight,4000,NULL) + GWBOATDATA(double,Latitude,4000,&formatLatitude) + GWBOATDATA(double,Longitude,4000,&formatLongitude) + GWBOATDATA(double,Altitude,4000,&formatFixed0) + GWBOATDATA(double,WaterDepth,4000,&formatDepth) + GWBOATDATA(double,SecondsSinceMidnight,4000,&formatFixed0) GWBOATDATA(double,WaterTemperature,4000,&kelvinToC) - GWBOATDATA(double,XTE,4000,NULL) + GWBOATDATA(double,XTE,4000,&formatFixed0) GWBOATDATA(double,DTW,4000,&mtr2nm) GWBOATDATA(double,BTW,4000,&formatCourse) - GWBOATDATA(double,WPLatitude,4000,NULL) - GWBOATDATA(double,WPLongitude,4000,NULL) + GWBOATDATA(double,WPLatitude,4000,&formatLatitude) + GWBOATDATA(double,WPLongitude,4000,&formatLongitude) GWBOATDATA(uint32_t,Log,0,&mtr2nm) GWBOATDATA(uint32_t,TripLog,0,&mtr2nm) - GWBOATDATA(uint32_t,DaysSince1970,4000,NULL) + GWBOATDATA(uint32_t,DaysSince1970,4000,&formatFixed0) public: GwBoatData(GwLog *logger); ~GwBoatData(); diff --git a/web/index.html b/web/index.html index c621333..cd0b5d7 100644 --- a/web/index.html +++ b/web/index.html @@ -405,6 +405,8 @@ formatWind: function(v){let x=parseFloat(v); return x.toFixed(0);}, mtr2nm: function(v){let x=parseFloat(v); return x.toFixed(2);}, kelvinToC: function(v){let x=parseFloat(v); return x.toFixed(0);}, + formatFixed0: function(v){let x=parseFloat(v); return x.toFixed(0);}, + formatDepth: function(v){let x=parseFloat(v); return x.toFixed(1);}, } function updateDashboard(data){ for (let n in data){