Add simulation data in formater
This commit is contained in:
parent
2e887e9a81
commit
f9c61369a0
|
@ -17,41 +17,38 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
|
||||||
String windspeedFormat = commondata.config->getString(commondata.config->windspeedFormat); // [m/s|km/h|kn|bft]
|
String windspeedFormat = commondata.config->getString(commondata.config->windspeedFormat); // [m/s|km/h|kn|bft]
|
||||||
String tempFormat = commondata.config->getString(commondata.config->tempFormat); // [K|°C|°F]
|
String tempFormat = commondata.config->getString(commondata.config->tempFormat); // [K|°C|°F]
|
||||||
String dateFormat = commondata.config->getString(commondata.config->dateFormat); // [DE|GB|US]
|
String dateFormat = commondata.config->getString(commondata.config->dateFormat); // [DE|GB|US]
|
||||||
|
bool usesimudata = commondata.config->getBool(commondata.config->useSimuData); // [on|off]
|
||||||
|
|
||||||
if (! value->valid){
|
// If boat value not valid
|
||||||
|
if (! value->valid && !usesimudata){
|
||||||
result.svalue = "---";
|
result.svalue = "---";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
static const int bsize = 30;
|
static const int bsize = 30;
|
||||||
char buffer[bsize+1];
|
char buffer[bsize+1];
|
||||||
buffer[0]=0;
|
buffer[0]=0;
|
||||||
|
//########################################################
|
||||||
if (value->getFormat() == "formatDate"){
|
if (value->getFormat() == "formatDate"){
|
||||||
time_t tv=tNMEA0183Msg::daysToTime_t(value->value);
|
time_t tv=tNMEA0183Msg::daysToTime_t(value->value);
|
||||||
tmElements_t parts;
|
tmElements_t parts;
|
||||||
tNMEA0183Msg::breakTime(tv,parts);
|
tNMEA0183Msg::breakTime(tv,parts);
|
||||||
if(String(dateFormat) == "DE"){
|
if(usesimudata == false) {
|
||||||
snprintf(buffer,bsize,"%02d.%02d.%04d",parts.tm_mday,parts.tm_mon+1,parts.tm_year+1900);
|
if(String(dateFormat) == "DE"){
|
||||||
}
|
snprintf(buffer,bsize,"%02d.%02d.%04d",parts.tm_mday,parts.tm_mon+1,parts.tm_year+1900);
|
||||||
else if(String(dateFormat) == "GB"){
|
}
|
||||||
snprintf(buffer,bsize,"%02d/%02d/%04d",parts.tm_mday,parts.tm_mon+1,parts.tm_year+1900);
|
else if(String(dateFormat) == "GB"){
|
||||||
}
|
snprintf(buffer,bsize,"%02d/%02d/%04d",parts.tm_mday,parts.tm_mon+1,parts.tm_year+1900);
|
||||||
else if(String(dateFormat) == "US"){
|
}
|
||||||
snprintf(buffer,bsize,"%02d/%02d/%04d",parts.tm_mon+1,parts.tm_mday,parts.tm_year+1900);
|
else if(String(dateFormat) == "US"){
|
||||||
|
snprintf(buffer,bsize,"%02d/%02d/%04d",parts.tm_mon+1,parts.tm_mday,parts.tm_year+1900);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
snprintf(buffer,bsize,"%02d.%02d.%04d",parts.tm_mday,parts.tm_mon+1,parts.tm_year+1900);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
snprintf(buffer,bsize,"%02d.%02d.%04d",parts.tm_mday,parts.tm_mon+1,parts.tm_year+1900);
|
snprintf(buffer,bsize,"01.01.2022");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if(value->getFormat() == "formatTime"){
|
|
||||||
double inthr;
|
|
||||||
double intmin;
|
|
||||||
double intsec;
|
|
||||||
double val;
|
|
||||||
val=modf(value->value/3600.0,&inthr);
|
|
||||||
inthr += timeZone;
|
|
||||||
val=modf(val*3600.0/60.0,&intmin);
|
|
||||||
modf(val*60.0,&intsec);
|
|
||||||
snprintf(buffer,bsize,"%02.0f:%02.0f:%02.0f",inthr,intmin,intsec);
|
|
||||||
if(timeZone == 0){
|
if(timeZone == 0){
|
||||||
result.unit = "UTC";
|
result.unit = "UTC";
|
||||||
}
|
}
|
||||||
|
@ -59,14 +56,56 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
|
||||||
result.unit = "LOT";
|
result.unit = "LOT";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (value->getFormat() == "formatFixed0"){
|
//########################################################
|
||||||
snprintf(buffer,bsize,"%.0f",value->value);
|
else if(value->getFormat() == "formatTime"){
|
||||||
result.unit = "";
|
double inthr;
|
||||||
|
double intmin;
|
||||||
|
double intsec;
|
||||||
|
double val;
|
||||||
|
if(usesimudata == false) {
|
||||||
|
val=modf(value->value/3600.0,&inthr);
|
||||||
|
inthr += timeZone;
|
||||||
|
val=modf(val*3600.0/60.0,&intmin);
|
||||||
|
modf(val*60.0,&intsec);
|
||||||
|
snprintf(buffer,bsize,"%02.0f:%02.0f:%02.0f",inthr,intmin,intsec);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
static long sec;
|
||||||
|
static long lasttime;
|
||||||
|
if(millis() > lasttime + 990){
|
||||||
|
sec ++;
|
||||||
|
}
|
||||||
|
sec = sec % 60;
|
||||||
|
snprintf(buffer,bsize,"11:36:%02i", int(sec));
|
||||||
|
lasttime = millis();
|
||||||
|
}
|
||||||
|
if(timeZone == 0){
|
||||||
|
result.unit = "UTC";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
result.unit = "LOT";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
//########################################################
|
||||||
|
else if (value->getFormat() == "formatFixed0"){
|
||||||
|
if(usesimudata == false) {
|
||||||
|
snprintf(buffer,bsize,"%.0f",value->value);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
snprintf(buffer,bsize,"%.0f", 8.0 + float(random(0, 10)) / 10.0);
|
||||||
|
}
|
||||||
|
result.unit = "";
|
||||||
|
}
|
||||||
|
//########################################################
|
||||||
else if (value->getFormat() == "formatCourse"){
|
else if (value->getFormat() == "formatCourse"){
|
||||||
double course = value->value;
|
double course = 0;
|
||||||
|
if(usesimudata == false) {
|
||||||
|
course = value->value;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
course = 2.53 + float(random(0, 10) / 100.0);
|
||||||
|
}
|
||||||
course = course * 57.2958; // Unit conversion form rad to deg
|
course = course * 57.2958; // Unit conversion form rad to deg
|
||||||
result.unit = "Deg";
|
|
||||||
if(course < 10){
|
if(course < 10){
|
||||||
snprintf(buffer,bsize,"%2.1f",course);
|
snprintf(buffer,bsize,"%2.1f",course);
|
||||||
}
|
}
|
||||||
|
@ -76,9 +115,17 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
|
||||||
if(course >= 100){
|
if(course >= 100){
|
||||||
snprintf(buffer,bsize,"%3.0f",course);
|
snprintf(buffer,bsize,"%3.0f",course);
|
||||||
}
|
}
|
||||||
|
result.unit = "Deg";
|
||||||
}
|
}
|
||||||
|
//########################################################
|
||||||
else if (value->getFormat() == "formatKnots" || value->getFormat() == "formatWind"){
|
else if (value->getFormat() == "formatKnots" || value->getFormat() == "formatWind"){
|
||||||
double speed = value->value;
|
double speed = 0;
|
||||||
|
if(usesimudata == false) {
|
||||||
|
speed = value->value;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
speed = 4.0 + float(random(0, 40));
|
||||||
|
}
|
||||||
if(String(speedFormat) == "km/h" || String(windspeedFormat) == "km/h"){
|
if(String(speedFormat) == "km/h" || String(windspeedFormat) == "km/h"){
|
||||||
speed = speed * 3.6; // Unit conversion form m/s to km/h
|
speed = speed * 3.6; // Unit conversion form m/s to km/h
|
||||||
result.unit = "m/s";
|
result.unit = "m/s";
|
||||||
|
@ -148,8 +195,15 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//########################################################
|
||||||
else if (value->getFormat() == "formatRot"){
|
else if (value->getFormat() == "formatRot"){
|
||||||
double rotation = value->value;
|
double rotation = 0;
|
||||||
|
if(usesimudata == false) {
|
||||||
|
rotation = value->value;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
rotation = 0.04 + float(random(0, 10)) / 100.0;
|
||||||
|
}
|
||||||
rotation = rotation * 57.2958; // Unit conversion form rad/s to deg/s
|
rotation = rotation * 57.2958; // Unit conversion form rad/s to deg/s
|
||||||
result.unit = "deg/s";
|
result.unit = "deg/s";
|
||||||
if(rotation < 10){
|
if(rotation < 10){
|
||||||
|
@ -162,8 +216,15 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
|
||||||
snprintf(buffer,bsize,"%3.0f",rotation);
|
snprintf(buffer,bsize,"%3.0f",rotation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//########################################################
|
||||||
else if (value->getFormat() == "formatDop"){
|
else if (value->getFormat() == "formatDop"){
|
||||||
double dop = value->value;
|
double dop = 0;
|
||||||
|
if(usesimudata == false) {
|
||||||
|
dop = value->value;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
dop = 2.0 + float(random(0, 40)) / 10.0;
|
||||||
|
}
|
||||||
result.unit = "m";
|
result.unit = "m";
|
||||||
if(dop > 99.9){
|
if(dop > 99.9){
|
||||||
dop = 99.9;
|
dop = 99.9;
|
||||||
|
@ -175,48 +236,67 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
|
||||||
snprintf(buffer,bsize,"%2.1f",dop);
|
snprintf(buffer,bsize,"%2.1f",dop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//########################################################
|
||||||
else if (value->getFormat() == "formatLatitude"){
|
else if (value->getFormat() == "formatLatitude"){
|
||||||
double lat = value->value;
|
if(usesimudata == false) {
|
||||||
String latitude = "";
|
double lat = value->value;
|
||||||
String latdir = "";
|
String latitude = "";
|
||||||
float degree = int(lat);
|
String latdir = "";
|
||||||
float minute = (lat - degree) * 60;
|
float degree = int(lat);
|
||||||
float secound = (minute - int(minute)) * 60;
|
float minute = (lat - degree) * 60;
|
||||||
if(lat > 0){
|
float secound = (minute - int(minute)) * 60;
|
||||||
latdir = "N";
|
if(lat > 0){
|
||||||
|
latdir = "N";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
latdir = "S";
|
||||||
|
}
|
||||||
|
latitude = String(degree,0) + "\" " + String(minute,0) + "' " + String(secound, 4) + " " + latdir;
|
||||||
|
result.unit = "";
|
||||||
|
strcpy(buffer, latitude.c_str());
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
latdir = "S";
|
snprintf(buffer,bsize," 51\" 35' %2.4f", 2.0 + float(random(0, 1000)) / 1000.0);
|
||||||
}
|
}
|
||||||
latitude = String(degree,0) + "\" " + String(minute,0) + "' " + String(secound, 4) + " " + latdir;
|
|
||||||
result.unit = "";
|
|
||||||
strcpy(buffer, latitude.c_str());
|
|
||||||
}
|
}
|
||||||
|
//########################################################
|
||||||
else if (value->getFormat() == "formatLongitude"){
|
else if (value->getFormat() == "formatLongitude"){
|
||||||
double lon = value->value;
|
if(usesimudata == false) {
|
||||||
String longitude = "";
|
double lon = value->value;
|
||||||
String londir = "";
|
String longitude = "";
|
||||||
float degree = int(lon);
|
String londir = "";
|
||||||
float minute = (lon - degree) * 60;
|
float degree = int(lon);
|
||||||
float secound = (minute - int(minute)) * 60;
|
float minute = (lon - degree) * 60;
|
||||||
if(lon > 0){
|
float secound = (minute - int(minute)) * 60;
|
||||||
londir = "E";
|
if(lon > 0){
|
||||||
|
londir = "E";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
londir = "W";
|
||||||
|
}
|
||||||
|
longitude = String(degree,0) + "\" " + String(minute,0) + "' " + String(secound, 4) + " " + londir;
|
||||||
|
result.unit = "";
|
||||||
|
strcpy(buffer, longitude.c_str());
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
londir = "W";
|
snprintf(buffer,bsize," 15\" 06' %2.4f", 9.0 + float(random(0, 1000)) / 1000.0);
|
||||||
}
|
}
|
||||||
longitude = String(degree,0) + "\" " + String(minute,0) + "' " + String(secound, 4) + " " + londir;
|
|
||||||
result.unit = "";
|
|
||||||
strcpy(buffer, longitude.c_str());
|
|
||||||
}
|
}
|
||||||
|
//########################################################
|
||||||
else if (value->getFormat() == "formatDepth"){
|
else if (value->getFormat() == "formatDepth"){
|
||||||
double depth = value->value;
|
double depth = 0;
|
||||||
|
if(usesimudata == false) {
|
||||||
|
depth = value->value;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
depth = 18.0 + float(random(0, 100)) / 10.0;
|
||||||
|
}
|
||||||
if(String(lengthFormat) == "ft"){
|
if(String(lengthFormat) == "ft"){
|
||||||
depth = depth * 3.28084;
|
depth = depth * 3.28084;
|
||||||
result.unit = "ft";
|
result.unit = "ft";
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
result.unit = "m";
|
result.unit = "m";
|
||||||
}
|
}
|
||||||
if(depth < 10){
|
if(depth < 10){
|
||||||
snprintf(buffer,bsize,"%2.1f",depth);
|
snprintf(buffer,bsize,"%2.1f",depth);
|
||||||
|
@ -228,8 +308,15 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
|
||||||
snprintf(buffer,bsize,"%3.0f",depth);
|
snprintf(buffer,bsize,"%3.0f",depth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//########################################################
|
||||||
else if (value->getFormat() == "kelvinToC"){
|
else if (value->getFormat() == "kelvinToC"){
|
||||||
double temp = value->value;
|
double temp = 0;
|
||||||
|
if(usesimudata == false) {
|
||||||
|
temp = value->value;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
temp = 296.0 + float(random(0, 10)) / 10.0;
|
||||||
|
}
|
||||||
if(String(tempFormat) == "°C"){
|
if(String(tempFormat) == "°C"){
|
||||||
temp = temp - 273.15;
|
temp = temp - 273.15;
|
||||||
result.unit = "C";
|
result.unit = "C";
|
||||||
|
@ -251,8 +338,15 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
|
||||||
snprintf(buffer,bsize,"%3.0f",temp);
|
snprintf(buffer,bsize,"%3.0f",temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//########################################################
|
||||||
else if (value->getFormat() == "mtr2nm"){
|
else if (value->getFormat() == "mtr2nm"){
|
||||||
double distance = value->value;
|
double distance = 0;
|
||||||
|
if(usesimudata == false) {
|
||||||
|
distance = value->value;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
distance = 2960.0 + float(random(0, 10));
|
||||||
|
}
|
||||||
if(String(distanceFormat) == "km"){
|
if(String(distanceFormat) == "km"){
|
||||||
distance = distance * 0.001;
|
distance = distance * 0.001;
|
||||||
result.unit = "km";
|
result.unit = "km";
|
||||||
|
@ -261,8 +355,7 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){
|
||||||
distance = distance * 0.000539957;
|
distance = distance * 0.000539957;
|
||||||
result.unit = "nm";
|
result.unit = "nm";
|
||||||
}
|
}
|
||||||
else{
|
else{;
|
||||||
distance = distance * 0.000539957;
|
|
||||||
result.unit = "m";
|
result.unit = "m";
|
||||||
}
|
}
|
||||||
if(distance < 10){
|
if(distance < 10){
|
||||||
|
|
|
@ -76,15 +76,8 @@ class PageOneValue : public Page{
|
||||||
display.setCursor(20, 240);
|
display.setCursor(20, 240);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reading bus data or using simulation data
|
// Show bus data or using simulation data
|
||||||
if(simulation == true){
|
display.print(svalue1); // Real value as formated string
|
||||||
value1 = 84;
|
|
||||||
value1 += float(random(0, 120)) / 10; // Simulation data
|
|
||||||
display.print(value1,1);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
display.print(svalue1); // Real value as formated string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Key Layout
|
// Key Layout
|
||||||
display.setFont(&Ubuntu_Bold8pt7b);
|
display.setFont(&Ubuntu_Bold8pt7b);
|
||||||
|
|
Loading…
Reference in New Issue