mirror of
https://github.com/bcomsugi/VSS_Rally_V3.git
synced 2026-01-09 18:02:38 +07:00
fix some bug
This commit is contained in:
parent
7e2ed058a6
commit
bda7666301
121
src/index.h
121
src/index.h
@ -65,42 +65,54 @@ const char HTML_startrally[] PROGMEM = R"rawliteral(
|
||||
};
|
||||
ws.onmessage = function(event) {
|
||||
// console.log(event.data);
|
||||
let data = JSON.parse(event.data);
|
||||
// if (data.hasOwnProperty("ping")) {
|
||||
// console.log("with ping key");
|
||||
// ping++;
|
||||
// } else{
|
||||
let curTrack=document.getElementById("currenttrack").innerHTML;
|
||||
let tripSpeed=document.getElementById("tripspeed").innerHTML;
|
||||
let tripDist=document.getElementById("tripdist").innerHTML;
|
||||
let tripTime=document.getElementById("triptime").innerHTML;
|
||||
let tripsTime=document.getElementById("tripstime").innerHTML;
|
||||
if(curTrack==data.Trip){
|
||||
if(tripSpeed!=data.TSpeed || tripDist != data.TDist || tripTime!=data.TTime ||tripsTime!=data.TsTime){
|
||||
console.log("Refresh Trip "+data.Trip);
|
||||
changeTrip(data.Trip);
|
||||
}
|
||||
}
|
||||
ping++;
|
||||
document.getElementById("counter").innerHTML = data.counter+";"+data.counter2;
|
||||
document.getElementById("currenttime").innerHTML = data.Time;
|
||||
document.getElementById("currenttrack").innerHTML = data.Trip;
|
||||
document.getElementById("tripspeed").innerHTML = data.TSpeed;
|
||||
document.getElementById("tripdist").innerHTML = data.TDist;
|
||||
document.getElementById("triptime").innerHTML = data.TTime;
|
||||
document.getElementById("tripstime").innerHTML = data.TsTime;
|
||||
document.getElementById("currentspeed").innerHTML = data.curSpeed;
|
||||
document.getElementById("dir1").innerHTML = data.dir1;
|
||||
document.getElementById("dir2").innerHTML = data.dir2;
|
||||
document.getElementById("odo1").innerHTML = data.curDist1;
|
||||
document.getElementById("odo2").innerHTML = data.curDist2;
|
||||
document.getElementById("time1").innerHTML = data.time1;
|
||||
document.getElementById("time2").innerHTML = data.time2;
|
||||
document.getElementById("tdiff1").innerHTML = data.TDiff;
|
||||
document.getElementById("tdiff2").innerHTML = data.TDiff;
|
||||
// }
|
||||
if(event.data && IsJsonString(event.data)){
|
||||
let data = JSON.parse(event.data);
|
||||
// if (data.hasOwnProperty("ping")) {
|
||||
// console.log("with ping key");
|
||||
// ping++;
|
||||
// } else{
|
||||
let curTrack=document.getElementById("currenttrack").innerHTML;
|
||||
let tripSpeed=document.getElementById("tripspeed").innerHTML;
|
||||
let tripDist=document.getElementById("tripdist").innerHTML;
|
||||
let tripTime=document.getElementById("triptime").innerHTML;
|
||||
let tripsTime=document.getElementById("tripstime").innerHTML;
|
||||
if(curTrack==data.Trip){
|
||||
if(tripSpeed!=data.TSpeed || tripDist != data.TDist || tripTime!=data.TTime ||tripsTime!=data.TsTime){
|
||||
console.log("Refresh Trip "+data.Trip);
|
||||
changeTrip(data.Trip);
|
||||
}
|
||||
}
|
||||
ping++;
|
||||
document.getElementById("counter").innerHTML = data.counter+";"+data.counter2;
|
||||
document.getElementById("currenttime").innerHTML = data.Time;
|
||||
document.getElementById("currenttrack").innerHTML = data.Trip;
|
||||
document.getElementById("tripspeed").innerHTML = data.TSpeed;
|
||||
document.getElementById("tripdist").innerHTML = data.TDist;
|
||||
document.getElementById("triptime").innerHTML = data.TTime;
|
||||
document.getElementById("tripstime").innerHTML = data.TsTime;
|
||||
document.getElementById("currentspeed").innerHTML = data.curSpeed;
|
||||
document.getElementById("dir1").innerHTML = data.dir1;
|
||||
document.getElementById("dir2").innerHTML = data.dir2;
|
||||
document.getElementById("odo1").innerHTML = data.curDist1;
|
||||
document.getElementById("odo2").innerHTML = data.curDist2;
|
||||
document.getElementById("time1").innerHTML = data.time1;
|
||||
document.getElementById("time2").innerHTML = data.time2;
|
||||
document.getElementById("tdiff1").innerHTML = data.TDiff;
|
||||
document.getElementById("tdiff2").innerHTML = data.TDiff;
|
||||
// }
|
||||
} else console.log(event.data);
|
||||
};
|
||||
}
|
||||
|
||||
function IsJsonString(str) {
|
||||
try {
|
||||
JSON.parse(str);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const checkhealt = setInterval(checkPing, 1000); //heartbeat
|
||||
|
||||
function checkPing(){
|
||||
@ -176,7 +188,7 @@ const char HTML_startrally[] PROGMEM = R"rawliteral(
|
||||
</div>
|
||||
<!--//ODO1-->
|
||||
<div class="row">
|
||||
<div class="col-5 "><h3>OD 1>> <span id="odo1">123.456</span> km</h3></div>
|
||||
<div class="col-5 "><h3>OD 1>> <span id="odo1">123.456</span> Km</h3></div>
|
||||
<div class="col-3"><h3><span id="dir1">DIRECT</span></h3></div>
|
||||
<div class="col-1"><h3><span id="tdiff1">TDiff</span>:</h3></div>
|
||||
<div class="col-3 text-end"><h3><span id="time1">00:00:00</span></h3></div>
|
||||
@ -203,7 +215,7 @@ const char HTML_startrally[] PROGMEM = R"rawliteral(
|
||||
-->
|
||||
<!--//ODO2-->
|
||||
<div class="row">
|
||||
<div class="col-5 "><h3>OD 2>> <span id="odo2">123.456</span> km</h3></div>
|
||||
<div class="col-5 "><h3>OD 2>> <span id="odo2">123.456</span> Km</h3></div>
|
||||
<div class="col-3 "><h3><span id="dir2">DIRECT</span></h3></div>
|
||||
<div class="col-1"><h3><span id="tdiff2">TDiff</span>:</h3></div>
|
||||
<div class="col-3 text-end"><h3><span id="time2">00:00:00</span></h3></div>
|
||||
@ -505,20 +517,31 @@ const char HTML_SETTIME[] PROGMEM = R"rawliteral(
|
||||
}
|
||||
};
|
||||
ws.onmessage = function(event) {
|
||||
console.log(event.data);
|
||||
var data = JSON.parse(event.data);
|
||||
if (data.NTPTime=="N/A") document.getElementById("btnNTP").disabled = true;
|
||||
else document.getElementById("btnNTP").disabled = false;
|
||||
document.getElementById("counter").innerHTML = data.counter+";"+data.counter2;
|
||||
document.getElementById("currenttrack").innerHTML = data.curTrip;
|
||||
document.getElementById("currenttime").innerHTML = data.curTime;
|
||||
document.getElementById("speed").innerHTML = data.curTripSpeed;
|
||||
document.getElementById("ntptime").innerHTML = data.NTPTime;
|
||||
// document.getElementById("calman").innerHTML = data.calman;
|
||||
// document.getElementById("calkm").innerHTML = data.calkm;
|
||||
// document.getElementById("calmeter").innerHTML = data.calmeter;
|
||||
// document.getElementById("calval").innerHTML = data.calval;
|
||||
// console.log(event.data);
|
||||
if (IsJsonString(event.data)){
|
||||
var data = JSON.parse(event.data);
|
||||
if (data.NTPTime=="N/A") document.getElementById("btnNTP").disabled = true;
|
||||
else document.getElementById("btnNTP").disabled = false;
|
||||
document.getElementById("counter").innerHTML = data.counter+";"+data.counter2;
|
||||
document.getElementById("currenttrack").innerHTML = data.curTrip;
|
||||
document.getElementById("currenttime").innerHTML = data.curTime;
|
||||
document.getElementById("speed").innerHTML = data.curTripSpeed;
|
||||
document.getElementById("ntptime").innerHTML = data.NTPTime;
|
||||
// document.getElementById("calman").innerHTML = data.calman;
|
||||
// document.getElementById("calkm").innerHTML = data.calkm;
|
||||
// document.getElementById("calmeter").innerHTML = data.calmeter;
|
||||
// document.getElementById("calval").innerHTML = data.calval;
|
||||
} else console.log(event.data);
|
||||
};
|
||||
|
||||
function IsJsonString(str) {
|
||||
try {
|
||||
JSON.parse(str);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
</script>
|
||||
</head><body>
|
||||
<!--
|
||||
|
||||
759
src/main.cpp
759
src/main.cpp
@ -1700,404 +1700,405 @@ void fillSetTimeJsonForESP32()
|
||||
|
||||
|
||||
|
||||
void redrawrallyMenu()
|
||||
{
|
||||
// Serial.println("redrawRM");
|
||||
// DS3231_get(&t); //Get time
|
||||
//runningtime(6,0);
|
||||
//float distance, distance1, distance2;
|
||||
// void redrawrallyMenu()
|
||||
// {
|
||||
// // Serial.println("redrawRM");
|
||||
// // DS3231_get(&t); //Get time
|
||||
// //runningtime(6,0);
|
||||
// //float distance, distance1, distance2;
|
||||
|
||||
//Serial.print(tempcount1);Serial.print(";"); Serial.print(time1);Serial.print("; ");Serial.print(Calibration); Serial.print(";"); Serial.println(count1);
|
||||
updateCount();
|
||||
// //Serial.print(tempcount1);Serial.print(";"); Serial.print(time1);Serial.print("; ");Serial.print(Calibration); Serial.print(";"); Serial.println(count1);
|
||||
// updateCount();
|
||||
|
||||
distance1 = (float)count1/((float)Calibration); // * 1);
|
||||
distance2 = (float)count2/((float)Calibration);
|
||||
float speed1=0;
|
||||
// distance1 = (float)count1/((float)Calibration); // * 1);
|
||||
// distance2 = (float)count2/((float)Calibration);
|
||||
// float speed1=0;
|
||||
|
||||
if ((distance1 - startdistance) > 0) {
|
||||
speed1 = (distance1-startdistance)/(millis()-startspeed)*3600000;
|
||||
}
|
||||
// if ((distance1 - startdistance) > 0) {
|
||||
// speed1 = (distance1-startdistance)/(millis()-startspeed)*3600000;
|
||||
// }
|
||||
|
||||
startdistance = distance1;
|
||||
startspeed = millis(); //startspeed is only one no startspeed2
|
||||
// Serial.println("redrawRM 1");
|
||||
if ((millis()-startsavemillis)>0) {
|
||||
// startdistance = distance1;
|
||||
// startspeed = millis(); //startspeed is only one no startspeed2
|
||||
// // Serial.println("redrawRM 1");
|
||||
// if ((millis()-startsavemillis)>0) {
|
||||
|
||||
if (distance1 != prevdistance1) {
|
||||
mem.writeFloat(832,distance1);
|
||||
prevdistance1 = distance1;
|
||||
}
|
||||
if (distance2 != prevdistance2) {
|
||||
mem.writeFloat(864,distance2);
|
||||
prevdistance2 = distance2;
|
||||
}
|
||||
saveCount();
|
||||
startsavemillis=millis()+2500;
|
||||
}
|
||||
//Serial.print(tempcount1);Serial.print(";"); Serial.print(time1);Serial.print("; ");Serial.print(Calibration); Serial.print(";"); Serial.println(count1);
|
||||
// if (distance1 != prevdistance1) {
|
||||
// mem.writeFloat(832,distance1);
|
||||
// prevdistance1 = distance1;
|
||||
// }
|
||||
// if (distance2 != prevdistance2) {
|
||||
// mem.writeFloat(864,distance2);
|
||||
// prevdistance2 = distance2;
|
||||
// }
|
||||
// saveCount();
|
||||
// startsavemillis=millis()+2500;
|
||||
// }
|
||||
// //Serial.print(tempcount1);Serial.print(";"); Serial.print(time1);Serial.print("; ");Serial.print(Calibration); Serial.print(";"); Serial.println(count1);
|
||||
|
||||
//Serial.print(millis());Serial.print(";");Serial.println(distance1,3);
|
||||
//Serial.print(starttracthour); Serial.print(":"); Serial.print(starttractmin); Serial.print(":"); Serial.println(starttractsec);
|
||||
//Serial.println(distance2,3);
|
||||
// //Serial.print(millis());Serial.print(";");Serial.println(distance1,3);
|
||||
// //Serial.print(starttracthour); Serial.print(":"); Serial.print(starttractmin); Serial.print(":"); Serial.println(starttractsec);
|
||||
// //Serial.println(distance2,3);
|
||||
|
||||
// lcd.setCursor(4,0);
|
||||
// lcd.print(Trip[curTrip].sub);
|
||||
// lcd.setCursor(0,2);
|
||||
// // lcd.setCursor(4,0);
|
||||
// // lcd.print(Trip[curTrip].sub);
|
||||
// // lcd.setCursor(0,2);
|
||||
|
||||
// lcd.print(Trip[curTrip].speed);
|
||||
// lcd.print("Km/H");
|
||||
// // lcd.print(Trip[curTrip].speed);
|
||||
// // lcd.print("Km/H");
|
||||
|
||||
runningtime(6,0);
|
||||
// runningtime(6,0);
|
||||
|
||||
// lcd.setCursor(11,2);
|
||||
// char cur_speed_str[6];
|
||||
int speedtemp=(int)speed1;
|
||||
int speedtemp2=(int)((speed1 - (int)speed1)*10);
|
||||
// // lcd.setCursor(11,2);
|
||||
// // char cur_speed_str[6];
|
||||
// int speedtemp=(int)speed1;
|
||||
// int speedtemp2=(int)((speed1 - (int)speed1)*10);
|
||||
|
||||
sprintf(gcur_speed_str, "%3d.%01d", speedtemp , speedtemp2 );
|
||||
// Serial.print(count1); Serial.print(";");Serial.print(Calibration); Serial.print(";");Serial.print(speed1); Serial.print(";");Serial.println(cur_speed_str);
|
||||
// Serial.print(distance1); Serial.print(";");Serial.print(startdistance); Serial.print(";");Serial.print(startspeed); Serial.println(";");
|
||||
// lcd.print(cur_speed_str);
|
||||
// char cur_distance1_str[7];
|
||||
// char cur_distance2_str[7];
|
||||
// lcd.setCursor(0,1);
|
||||
// sprintf(gcur_speed_str, "%3d.%01d", speedtemp , speedtemp2 );
|
||||
// // Serial.print(count1); Serial.print(";");Serial.print(Calibration); Serial.print(";");Serial.print(speed1); Serial.print(";");Serial.println(cur_speed_str);
|
||||
// // Serial.print(distance1); Serial.print(";");Serial.print(startdistance); Serial.print(";");Serial.print(startspeed); Serial.println(";");
|
||||
// // lcd.print(cur_speed_str);
|
||||
// // char cur_distance1_str[7];
|
||||
// // char cur_distance2_str[7];
|
||||
// // lcd.setCursor(0,1);
|
||||
|
||||
if (distance1<100) {
|
||||
sprintf(gcur_distance1_str, "%02d.%03d", (int)distance1, (int)((distance1 - (int)distance1)*1000));
|
||||
}
|
||||
else if (distance1<1000) {
|
||||
sprintf(gcur_distance1_str, "%02d.%02d", (int)distance1, (int)((distance1 - (int)distance1)*100));
|
||||
}
|
||||
else {
|
||||
sprintf(gcur_distance1_str, "%03d.%01d", (int)distance1, (int)((distance1 - (int)distance1)*10));
|
||||
}
|
||||
// lcd.print(cur_distance1_str);
|
||||
// if (distance1<100) {
|
||||
// sprintf(gcur_distance1_str, "%02d.%03d", (int)distance1, (int)((distance1 - (int)distance1)*1000));
|
||||
// }
|
||||
// else if (distance1<1000) {
|
||||
// sprintf(gcur_distance1_str, "%02d.%02d", (int)distance1, (int)((distance1 - (int)distance1)*100));
|
||||
// }
|
||||
// else {
|
||||
// sprintf(gcur_distance1_str, "%03d.%01d", (int)distance1, (int)((distance1 - (int)distance1)*10));
|
||||
// }
|
||||
// // lcd.print(cur_distance1_str);
|
||||
|
||||
// lcd.setCursor(0,3);
|
||||
if (distance2<100) {
|
||||
sprintf(gcur_distance2_str, "%02d.%03d", (int)distance2, (int)((distance2 - (int)distance2)*1000));
|
||||
}
|
||||
else if (distance2<1000) {
|
||||
sprintf(gcur_distance2_str, "%02d.%02d", (int)distance2, (int)((distance2 - (int)distance2)*100));
|
||||
}
|
||||
else {
|
||||
sprintf(gcur_distance2_str, "%03d.%01d", (int)distance2, (int)((distance2 - (int)distance2)*10));
|
||||
}
|
||||
// lcd.print(cur_distance2_str);
|
||||
// Serial.print(";redrawRM 3;");
|
||||
float distancetime1 = distance1 * 60 / constanta;
|
||||
float distancetime2 = distance2 * 60 / constanta;
|
||||
// // lcd.setCursor(0,3);
|
||||
// if (distance2<100) {
|
||||
// sprintf(gcur_distance2_str, "%02d.%03d", (int)distance2, (int)((distance2 - (int)distance2)*1000));
|
||||
// }
|
||||
// else if (distance2<1000) {
|
||||
// sprintf(gcur_distance2_str, "%02d.%02d", (int)distance2, (int)((distance2 - (int)distance2)*100));
|
||||
// }
|
||||
// else {
|
||||
// sprintf(gcur_distance2_str, "%03d.%01d", (int)distance2, (int)((distance2 - (int)distance2)*10));
|
||||
// }
|
||||
// // lcd.print(cur_distance2_str);
|
||||
// // Serial.print(";redrawRM 3;");
|
||||
// float distancetime1 = distance1 * 60 / constanta;
|
||||
// float distancetime2 = distance2 * 60 / constanta;
|
||||
|
||||
//Calculating all about TIME,TDiff(including passing 23:59:59)
|
||||
// lcd.setCursor(9,1);
|
||||
int secs1, mins1, hours1;
|
||||
// //Calculating all about TIME,TDiff(including passing 23:59:59)
|
||||
// // lcd.setCursor(9,1);
|
||||
// int secs1, mins1, hours1;
|
||||
|
||||
secs1 = (distancetime1-(int)distancetime1)*60;
|
||||
mins1 = (int)distancetime1 % 60;
|
||||
hours1 = (int)distancetime1 / 60;
|
||||
unsigned long totcurrentsecs = t.sec + (t.min*60) + ((long)t.hour*3600);
|
||||
unsigned long totsecs1 = secs1 + (mins1*60) + ((long)hours1*3600);
|
||||
unsigned long totstarttractsecs = starttractsec + (starttractmin*60) + ((long)starttracthour*3600);
|
||||
unsigned long tottime1 = totsecs1 + totstarttractsecs;
|
||||
boolean negatifsign1 = false;
|
||||
boolean negatifsign2 = false;
|
||||
// Serial.print(";redrawRM 4;");
|
||||
//Serial.print((long)starttracthour*3600); Serial.print(";"); Serial.print(starttractmin*60); Serial.println(";");
|
||||
//Serial.print(totsecs1); Serial.print(";"); Serial.print(totstarttractsecs); Serial.print(";");
|
||||
//Serial.print(tottime1);Serial.print(";");Serial.println(totcurrentsecs);
|
||||
if (totcurrentsecs<totstarttractsecs) totcurrentsecs+=86400;
|
||||
// secs1 = (distancetime1-(int)distancetime1)*60;
|
||||
// mins1 = (int)distancetime1 % 60;
|
||||
// hours1 = (int)distancetime1 / 60;
|
||||
// unsigned long totcurrentsecs = t.sec + (t.min*60) + ((long)t.hour*3600);
|
||||
// unsigned long totsecs1 = secs1 + (mins1*60) + ((long)hours1*3600);
|
||||
// unsigned long totstarttractsecs = starttractsec + (starttractmin*60) + ((long)starttracthour*3600);
|
||||
// unsigned long tottime1 = totsecs1 + totstarttractsecs;
|
||||
// boolean negatifsign1 = false;
|
||||
// boolean negatifsign2 = false;
|
||||
// // Serial.print(";redrawRM 4;");
|
||||
// //Serial.print((long)starttracthour*3600); Serial.print(";"); Serial.print(starttractmin*60); Serial.println(";");
|
||||
// //Serial.print(totsecs1); Serial.print(";"); Serial.print(totstarttractsecs); Serial.print(";");
|
||||
// //Serial.print(tottime1);Serial.print(";");Serial.println(totcurrentsecs);
|
||||
// if (totcurrentsecs<totstarttractsecs) totcurrentsecs+=86400;
|
||||
|
||||
if (!showTIME) {
|
||||
if (tottime1 >= totcurrentsecs) { //positif means we are too fast, slow down please.
|
||||
// Serial.println("pos");
|
||||
negatifsign1 = false;
|
||||
tottime1 = tottime1 - totcurrentsecs;
|
||||
}
|
||||
else { //negatif means we need to hurry, its late
|
||||
// Serial.println("neg");
|
||||
negatifsign1 = true;
|
||||
tottime1 = totcurrentsecs - tottime1;
|
||||
}
|
||||
}
|
||||
//Serial.print(negatifsign1);Serial.print(";"); Serial.println(tottime1);
|
||||
hours1 = ((int)(tottime1 / 3600))%24;
|
||||
mins1 = (int)((tottime1 % 3600)/60);
|
||||
secs1 = (tottime1 % 60);
|
||||
// if (!showTIME) {
|
||||
// if (tottime1 >= totcurrentsecs) { //positif means we are too fast, slow down please.
|
||||
// // Serial.println("pos");
|
||||
// negatifsign1 = false;
|
||||
// tottime1 = tottime1 - totcurrentsecs;
|
||||
// }
|
||||
// else { //negatif means we need to hurry, its late
|
||||
// // Serial.println("neg");
|
||||
// negatifsign1 = true;
|
||||
// tottime1 = totcurrentsecs - tottime1;
|
||||
// }
|
||||
// }
|
||||
// //Serial.print(negatifsign1);Serial.print(";"); Serial.println(tottime1);
|
||||
// hours1 = ((int)(tottime1 / 3600))%24;
|
||||
// mins1 = (int)((tottime1 % 3600)/60);
|
||||
// secs1 = (tottime1 % 60);
|
||||
|
||||
// char cur_time1_str[12];
|
||||
if (showTIME) {
|
||||
// sprintf(cur_time1_str, "%s %02d:%02d:%02d", dircount[dircount1], hours1, mins1, secs1);
|
||||
sprintf(gcur_time1_str, " %02d:%02d:%02d", hours1, mins1, secs1);
|
||||
}
|
||||
else {
|
||||
// if (hours1 < 10) sprintf(cur_time1_str, "%s %s%01d:%02d:%02d", dircount[dircount1], (negatifsign1?"-":" "), hours1, mins1, secs1);
|
||||
if (hours1 < 10) sprintf(gcur_time1_str, " %s%01d:%02d:%02d", (negatifsign1?"-":" "), hours1, mins1, secs1);
|
||||
// else sprintf(cur_time1_str, "%s%s%02d:%02d:%02d", dircount[dircount1], (negatifsign1?"-":" "), hours1, mins1, secs1);
|
||||
else sprintf(gcur_time1_str, "%s%02d:%02d:%02d", (negatifsign1?"-":" "), hours1, mins1, secs1);
|
||||
// // char cur_time1_str[12];
|
||||
// if (showTIME) {
|
||||
// // sprintf(cur_time1_str, "%s %02d:%02d:%02d", dircount[dircount1], hours1, mins1, secs1);
|
||||
// sprintf(gcur_time1_str, " %02d:%02d:%02d", hours1, mins1, secs1);
|
||||
// }
|
||||
// else {
|
||||
// // if (hours1 < 10) sprintf(cur_time1_str, "%s %s%01d:%02d:%02d", dircount[dircount1], (negatifsign1?"-":" "), hours1, mins1, secs1);
|
||||
// if (hours1 < 10) sprintf(gcur_time1_str, " %s%01d:%02d:%02d", (negatifsign1?"-":" "), hours1, mins1, secs1);
|
||||
// // else sprintf(cur_time1_str, "%s%s%02d:%02d:%02d", dircount[dircount1], (negatifsign1?"-":" "), hours1, mins1, secs1);
|
||||
// else sprintf(gcur_time1_str, "%s%02d:%02d:%02d", (negatifsign1?"-":" "), hours1, mins1, secs1);
|
||||
|
||||
}
|
||||
// lcd.setCursor(9,1);
|
||||
// lcd.print(cur_time1_str);
|
||||
// Serial.println(cur_time1_str);
|
||||
// Serial.print((hours1));Serial.print(":");Serial.print((mins1));Serial.print(":");Serial.println((secs1));
|
||||
// Serial.print(";redrawRM 5;");
|
||||
// Print Second TIME
|
||||
// lcd.setCursor(9,3);
|
||||
int secs2, mins2, hours2;
|
||||
secs2 = (distancetime2-(int)distancetime2)*60;
|
||||
mins2 = (int)distancetime2 % 60;
|
||||
hours2 = (int)distancetime2 / 60;
|
||||
// }
|
||||
// // lcd.setCursor(9,1);
|
||||
// // lcd.print(cur_time1_str);
|
||||
// // Serial.println(cur_time1_str);
|
||||
// // Serial.print((hours1));Serial.print(":");Serial.print((mins1));Serial.print(":");Serial.println((secs1));
|
||||
// // Serial.print(";redrawRM 5;");
|
||||
// // Print Second TIME
|
||||
// // lcd.setCursor(9,3);
|
||||
// int secs2, mins2, hours2;
|
||||
// secs2 = (distancetime2-(int)distancetime2)*60;
|
||||
// mins2 = (int)distancetime2 % 60;
|
||||
// hours2 = (int)distancetime2 / 60;
|
||||
|
||||
unsigned long totsecs2 = secs2 + (mins2*60) + ((long)hours2*3600);
|
||||
unsigned long tottime2 = totsecs2 + totstarttractsecs;
|
||||
// unsigned long totsecs2 = secs2 + (mins2*60) + ((long)hours2*3600);
|
||||
// unsigned long tottime2 = totsecs2 + totstarttractsecs;
|
||||
|
||||
if (!showTIME) {
|
||||
if (tottime2 >= totcurrentsecs) { //positif means we are too fast, slow down please.
|
||||
negatifsign2 = false;
|
||||
tottime2 = tottime2 - totcurrentsecs;
|
||||
}
|
||||
else { //negatif means we need to hurry, its late
|
||||
negatifsign2 = true;
|
||||
tottime2 = totcurrentsecs - tottime2 ;
|
||||
}
|
||||
}
|
||||
// Serial.print(";redrawRM 6;");
|
||||
hours2 = ((int)(tottime2 / 3600))%24;
|
||||
mins2 = (int)((tottime2 % 3600)/60);
|
||||
secs2 = (tottime2 % 60);
|
||||
// char cur_time2_str[12];
|
||||
if (showTIME) {
|
||||
sprintf(gcur_time2_str, " %02d:%02d:%02d", hours2, mins2, secs2);
|
||||
}
|
||||
else {
|
||||
if (hours2<10) sprintf(gcur_time2_str, " %s%01d:%02d:%02d", (negatifsign2?"-":" "), hours2, mins2, secs2);
|
||||
else sprintf(gcur_time2_str, "%s%02d:%02d:%02d", (negatifsign2?"-":" "), hours2, mins2, secs2);
|
||||
}
|
||||
// if (!showTIME) {
|
||||
// if (tottime2 >= totcurrentsecs) { //positif means we are too fast, slow down please.
|
||||
// negatifsign2 = false;
|
||||
// tottime2 = tottime2 - totcurrentsecs;
|
||||
// }
|
||||
// else { //negatif means we need to hurry, its late
|
||||
// negatifsign2 = true;
|
||||
// tottime2 = totcurrentsecs - tottime2 ;
|
||||
// }
|
||||
// }
|
||||
// // Serial.print(";redrawRM 6;");
|
||||
// hours2 = ((int)(tottime2 / 3600))%24;
|
||||
// mins2 = (int)((tottime2 % 3600)/60);
|
||||
// secs2 = (tottime2 % 60);
|
||||
// // char cur_time2_str[12];
|
||||
// if (showTIME) {
|
||||
// sprintf(gcur_time2_str, " %02d:%02d:%02d", hours2, mins2, secs2);
|
||||
// }
|
||||
// else {
|
||||
// if (hours2<10) sprintf(gcur_time2_str, " %s%01d:%02d:%02d", (negatifsign2?"-":" "), hours2, mins2, secs2);
|
||||
// else sprintf(gcur_time2_str, "%s%02d:%02d:%02d", (negatifsign2?"-":" "), hours2, mins2, secs2);
|
||||
// }
|
||||
|
||||
lcd.setCursor(4,0);
|
||||
lcd.print(Trip[curTrip].sub);
|
||||
lcd.setCursor(0,2);
|
||||
lcd.print(Trip[curTrip].speed);
|
||||
lcd.print("Km/H");
|
||||
// lcd.setCursor(4,0);
|
||||
// lcd.print(Trip[curTrip].sub);
|
||||
// lcd.setCursor(0,2);
|
||||
// lcd.print(Trip[curTrip].speed);
|
||||
// lcd.print("Km/H");
|
||||
|
||||
lcd.setCursor(11,2);
|
||||
lcd.print(gcur_speed_str);
|
||||
lcd.print("Km/H");
|
||||
// lcd.setCursor(11,2);
|
||||
// lcd.print(gcur_speed_str);
|
||||
// lcd.setCursor(16,2);
|
||||
// lcd.print("Km/H");
|
||||
|
||||
lcd.setCursor(0,1);
|
||||
// lcd.setCursor(0,1);
|
||||
|
||||
lcd.print(gcur_distance1_str);
|
||||
lcd.print("Km");
|
||||
// lcd.print(gcur_distance1_str);
|
||||
// lcd.print("Km");
|
||||
|
||||
lcd.setCursor(9,1);
|
||||
lcd.print(dircount[dircount1]);
|
||||
lcd.print(gcur_time1_str);
|
||||
// lcd.setCursor(9,1);
|
||||
// lcd.print(dircount[dircount1]);
|
||||
// lcd.print(gcur_time1_str);
|
||||
|
||||
|
||||
lcd.setCursor(0,3);
|
||||
// lcd.setCursor(0,3);
|
||||
|
||||
lcd.print(gcur_distance2_str);
|
||||
lcd.print("Km");
|
||||
// lcd.print(gcur_distance2_str);
|
||||
// lcd.print("Km");
|
||||
|
||||
lcd.setCursor(9,3);
|
||||
lcd.print(dircount[dircount2]);
|
||||
lcd.print(gcur_time2_str);
|
||||
// lcd.setCursor(9,3);
|
||||
// lcd.print(dircount[dircount2]);
|
||||
// lcd.print(gcur_time2_str);
|
||||
|
||||
// Serial.print("x=");Serial.print(x);Serial.print("y=");Serial.print(y);Serial.println("");
|
||||
// // Serial.print("x=");Serial.print(x);Serial.print("y=");Serial.print(y);Serial.println("");
|
||||
|
||||
lcd.setCursor(x,y);
|
||||
// Serial.println("END redrawRM");
|
||||
}
|
||||
// lcd.setCursor(x,y);
|
||||
// // Serial.println("END redrawRM");
|
||||
// }
|
||||
|
||||
void calculationRally_BACKUP() //calculation only ESP32
|
||||
{
|
||||
DynamicJsonDocument getRally(1024);
|
||||
deserializeJson(getRally, strRallyJson);
|
||||
// DS3231_get(&t); //Get time
|
||||
// Serial.println("startCRal");
|
||||
updateCount();
|
||||
// void calculationRally_BACKUP() //calculation only ESP32
|
||||
// {
|
||||
// DynamicJsonDocument getRally(1024);
|
||||
// deserializeJson(getRally, strRallyJson);
|
||||
// // DS3231_get(&t); //Get time
|
||||
// // Serial.println("startCRal");
|
||||
// updateCount();
|
||||
|
||||
distance1 = (float)count1/((float)Calibration); // * 1);
|
||||
distance2 = (float)count2/((float)Calibration);
|
||||
float speed1=0;
|
||||
// distance1 = (float)count1/((float)Calibration); // * 1);
|
||||
// distance2 = (float)count2/((float)Calibration);
|
||||
// float speed1=0;
|
||||
|
||||
if ((distance1 - startdistance) > 0) {
|
||||
speed1 = (distance1-startdistance)/(millis()-startspeed)*3600000;
|
||||
}
|
||||
// if ((distance1 - startdistance) > 0) {
|
||||
// speed1 = (distance1-startdistance)/(millis()-startspeed)*3600000;
|
||||
// }
|
||||
|
||||
startdistance = distance1;
|
||||
startspeed = millis(); //startspeed is only one no startspeed2
|
||||
// startdistance = distance1;
|
||||
// startspeed = millis(); //startspeed is only one no startspeed2
|
||||
|
||||
if ((millis()-startsavemillis)>0) {
|
||||
// if ((millis()-startsavemillis)>0) {
|
||||
|
||||
if (distance1 != prevdistance1) {
|
||||
mem.writeFloat(832,distance1);
|
||||
prevdistance1 = distance1;
|
||||
}
|
||||
if (distance2 != prevdistance2) {
|
||||
mem.writeFloat(864,distance2);
|
||||
prevdistance2 = distance2;
|
||||
}
|
||||
saveCount();
|
||||
startsavemillis=millis()+2500;
|
||||
}
|
||||
// if (distance1 != prevdistance1) {
|
||||
// mem.writeFloat(832,distance1);
|
||||
// prevdistance1 = distance1;
|
||||
// }
|
||||
// if (distance2 != prevdistance2) {
|
||||
// mem.writeFloat(864,distance2);
|
||||
// prevdistance2 = distance2;
|
||||
// }
|
||||
// saveCount();
|
||||
// startsavemillis=millis()+2500;
|
||||
// }
|
||||
|
||||
// lcd.setCursor(4,0);
|
||||
// lcd.print(Trip[curTrip].sub);
|
||||
// lcd.setCursor(0,2);
|
||||
// // lcd.setCursor(4,0);
|
||||
// // lcd.print(Trip[curTrip].sub);
|
||||
// // lcd.setCursor(0,2);
|
||||
|
||||
// lcd.print(Trip[curTrip].speed);
|
||||
// lcd.print("Km/H");
|
||||
getRally["Trip"]=String(Trip[curTrip].sub); /////
|
||||
getRally["TSpeed"]=String(Trip[curTrip].speed); /////
|
||||
char sTime[9]; //global can move to the sprintf to change change constanta
|
||||
sprintf(sTime, "%02u:%02u:%02u", Trip[curTrip].startHour, Trip[curTrip].startMin, Trip[curTrip].startSec);
|
||||
getRally["TsTime"]=sTime; /////
|
||||
getRally["TTime"]=String(Trip[curTrip].subTime); /////
|
||||
getRally["TDist"]=String(Trip[curTrip].distance); /////
|
||||
// // lcd.print(Trip[curTrip].speed);
|
||||
// // lcd.print("Km/H");
|
||||
// getRally["Trip"]=String(Trip[curTrip].sub); /////
|
||||
// getRally["TSpeed"]=String(Trip[curTrip].speed); /////
|
||||
// char sTime[9]; //global can move to the sprintf to change change constanta
|
||||
// sprintf(sTime, "%02u:%02u:%02u", Trip[curTrip].startHour, Trip[curTrip].startMin, Trip[curTrip].startSec);
|
||||
// getRally["TsTime"]=sTime; /////
|
||||
// getRally["TTime"]=String(Trip[curTrip].subTime); /////
|
||||
// getRally["TDist"]=String(Trip[curTrip].distance); /////
|
||||
|
||||
// Serial.print(Trip[curTrip].sub);Serial.print(Trip[curTrip].speed);Serial.print(";");Serial.println(Trip[curTrip].startHour);
|
||||
// // Serial.print(Trip[curTrip].sub);Serial.print(Trip[curTrip].speed);Serial.print(";");Serial.println(Trip[curTrip].startHour);
|
||||
|
||||
gcurTime = runningtimeforESP32(6,0);
|
||||
// String curTime = runningtimeforESP32(6,0);
|
||||
// char curTime []= runningtimeforESP32(6,0);
|
||||
getRally["Time"]=gcurTime;
|
||||
// lcd.setCursor(11,2);
|
||||
// char cur_speed_str[6];
|
||||
sprintf(gcur_speed_str, "%3d.%01d", (int)speed1, (int)((speed1 - (int)speed1)*10));
|
||||
// lcd.print(cur_speed_str);
|
||||
getRally["curSpeed"]=gcur_speed_str; /////
|
||||
// gcurTime = runningtimeforESP32(6,0);
|
||||
// // String curTime = runningtimeforESP32(6,0);
|
||||
// // char curTime []= runningtimeforESP32(6,0);
|
||||
// getRally["Time"]=gcurTime;
|
||||
// // lcd.setCursor(11,2);
|
||||
// // char cur_speed_str[6];
|
||||
// sprintf(gcur_speed_str, "%3d.%01d", (int)speed1, (int)((speed1 - (int)speed1)*10));
|
||||
// // lcd.print(cur_speed_str);
|
||||
// getRally["curSpeed"]=gcur_speed_str; /////
|
||||
|
||||
// char cur_distance1_plain[7];
|
||||
// char cur_distance2_plain[7];
|
||||
// lcd.setCursor(0,1);
|
||||
// // char cur_distance1_plain[7];
|
||||
// // char cur_distance2_plain[7];
|
||||
// // lcd.setCursor(0,1);
|
||||
|
||||
if (distance1<100) {
|
||||
sprintf(gcur_distance1_str, "%02d.%03d", (int)distance1, (int)((distance1 - (int)distance1)*1000));
|
||||
}
|
||||
else if (distance1<1000) {
|
||||
sprintf(gcur_distance1_str, "%02d.%02d", (int)distance1, (int)((distance1 - (int)distance1)*100));
|
||||
}
|
||||
else {
|
||||
sprintf(gcur_distance1_str, "%03d.%01d", (int)distance1, (int)((distance1 - (int)distance1)*10));
|
||||
}
|
||||
// if (distance1<100) {
|
||||
// sprintf(gcur_distance1_str, "%02d.%03d", (int)distance1, (int)((distance1 - (int)distance1)*1000));
|
||||
// }
|
||||
// else if (distance1<1000) {
|
||||
// sprintf(gcur_distance1_str, "%02d.%02d", (int)distance1, (int)((distance1 - (int)distance1)*100));
|
||||
// }
|
||||
// else {
|
||||
// sprintf(gcur_distance1_str, "%03d.%01d", (int)distance1, (int)((distance1 - (int)distance1)*10));
|
||||
// }
|
||||
|
||||
// lcd.print(cur_distance1_str);
|
||||
getRally["curDist1"]=String(gcur_distance1_str);
|
||||
// lcd.setCursor(0,3);
|
||||
// // lcd.print(cur_distance1_str);
|
||||
// getRally["curDist1"]=String(gcur_distance1_str);
|
||||
// // lcd.setCursor(0,3);
|
||||
|
||||
if (distance2<100) {
|
||||
sprintf(gcur_distance2_str, "%02d.%03d", (int)distance2, (int)((distance2 - (int)distance2)*1000));
|
||||
}
|
||||
else if (distance2<1000) {
|
||||
sprintf(gcur_distance2_str, "%02d.%02d", (int)distance2, (int)((distance2 - (int)distance2)*100));
|
||||
}
|
||||
else {
|
||||
sprintf(gcur_distance2_str, "%03d.%01d", (int)distance2, (int)((distance2 - (int)distance2)*10));
|
||||
}
|
||||
// if (distance2<100) {
|
||||
// sprintf(gcur_distance2_str, "%02d.%03d", (int)distance2, (int)((distance2 - (int)distance2)*1000));
|
||||
// }
|
||||
// else if (distance2<1000) {
|
||||
// sprintf(gcur_distance2_str, "%02d.%02d", (int)distance2, (int)((distance2 - (int)distance2)*100));
|
||||
// }
|
||||
// else {
|
||||
// sprintf(gcur_distance2_str, "%03d.%01d", (int)distance2, (int)((distance2 - (int)distance2)*10));
|
||||
// }
|
||||
|
||||
// lcd.print(cur_distance2_str);
|
||||
getRally["curDist2"]=gcur_distance2_str;
|
||||
// // lcd.print(cur_distance2_str);
|
||||
// getRally["curDist2"]=gcur_distance2_str;
|
||||
|
||||
float distancetime1 = distance1 * 60 / constanta;
|
||||
float distancetime2 = distance2 * 60 / constanta;
|
||||
// float distancetime1 = distance1 * 60 / constanta;
|
||||
// float distancetime2 = distance2 * 60 / constanta;
|
||||
|
||||
//Calculating all about TIME,TDiff(including passing 23:59:59)
|
||||
// lcd.setCursor(9,1);
|
||||
int secs1, mins1, hours1;
|
||||
// //Calculating all about TIME,TDiff(including passing 23:59:59)
|
||||
// // lcd.setCursor(9,1);
|
||||
// int secs1, mins1, hours1;
|
||||
|
||||
secs1 = (distancetime1-(int)distancetime1)*60;
|
||||
mins1 = (int)distancetime1 % 60;
|
||||
hours1 = (int)distancetime1 / 60;
|
||||
unsigned long totcurrentsecs = t.sec + (t.min*60) + ((long)t.hour*3600);
|
||||
unsigned long totsecs1 = secs1 + (mins1*60) + ((long)hours1*3600);
|
||||
unsigned long totstarttractsecs = starttractsec + (starttractmin*60) + ((long)starttracthour*3600);
|
||||
unsigned long tottime1 = totsecs1 + totstarttractsecs;
|
||||
boolean negatifsign = false;
|
||||
// secs1 = (distancetime1-(int)distancetime1)*60;
|
||||
// mins1 = (int)distancetime1 % 60;
|
||||
// hours1 = (int)distancetime1 / 60;
|
||||
// unsigned long totcurrentsecs = t.sec + (t.min*60) + ((long)t.hour*3600);
|
||||
// unsigned long totsecs1 = secs1 + (mins1*60) + ((long)hours1*3600);
|
||||
// unsigned long totstarttractsecs = starttractsec + (starttractmin*60) + ((long)starttracthour*3600);
|
||||
// unsigned long tottime1 = totsecs1 + totstarttractsecs;
|
||||
// boolean negatifsign = false;
|
||||
|
||||
if (totcurrentsecs<totstarttractsecs) totcurrentsecs+=86400;
|
||||
// if (totcurrentsecs<totstarttractsecs) totcurrentsecs+=86400;
|
||||
|
||||
if (!showTIME) {
|
||||
//if ((long)(tottime1 - totcurrentsecs)>=0) { //positif means we are too fast, slow down please.
|
||||
if (tottime1 >= totcurrentsecs) { //positif means we are too fast, slow down please.
|
||||
// Serial.println("pos");
|
||||
negatifsign = false;
|
||||
tottime1 = tottime1 - totcurrentsecs;
|
||||
}
|
||||
else { //negatif means we need to hurry, its late
|
||||
// Serial.println("neg");
|
||||
negatifsign = true;
|
||||
tottime1 = totcurrentsecs - tottime1;
|
||||
}
|
||||
}
|
||||
//Serial.print(negatifsign);Serial.print(";"); Serial.println(tottime1);
|
||||
hours1 = ((int)(tottime1 / 3600))%24;
|
||||
mins1 = (int)((tottime1 % 3600)/60);
|
||||
secs1 = (tottime1 % 60);
|
||||
// if (!showTIME) {
|
||||
// //if ((long)(tottime1 - totcurrentsecs)>=0) { //positif means we are too fast, slow down please.
|
||||
// if (tottime1 >= totcurrentsecs) { //positif means we are too fast, slow down please.
|
||||
// // Serial.println("pos");
|
||||
// negatifsign = false;
|
||||
// tottime1 = tottime1 - totcurrentsecs;
|
||||
// }
|
||||
// else { //negatif means we need to hurry, its late
|
||||
// // Serial.println("neg");
|
||||
// negatifsign = true;
|
||||
// tottime1 = totcurrentsecs - tottime1;
|
||||
// }
|
||||
// }
|
||||
// //Serial.print(negatifsign);Serial.print(";"); Serial.println(tottime1);
|
||||
// hours1 = ((int)(tottime1 / 3600))%24;
|
||||
// mins1 = (int)((tottime1 % 3600)/60);
|
||||
// secs1 = (tottime1 % 60);
|
||||
|
||||
// char cur_time1_str[12];
|
||||
// char cur_time1_plain[10];
|
||||
// // char cur_time1_str[12];
|
||||
// // char cur_time1_plain[10];
|
||||
|
||||
if (showTIME) {
|
||||
sprintf(gcur_time1_str, " %02d:%02d:%02d", hours1, mins1, secs1);
|
||||
}
|
||||
else {
|
||||
if (hours1<10) sprintf(gcur_time1_str, " %s%01d:%02d:%02d", (negatifsign?"-":" "), hours1, mins1, secs1);
|
||||
else sprintf(gcur_time1_str, "%s%02d:%02d:%02d", (negatifsign?"-":" "), hours1, mins1, secs1);
|
||||
}
|
||||
// lcd.print(cur_time1_str);
|
||||
getRally["time1"]=gcur_time1_str;
|
||||
getRally["dir1"]=dircount[dircount1];
|
||||
// if (showTIME) {
|
||||
// sprintf(gcur_time1_str, " %02d:%02d:%02d", hours1, mins1, secs1);
|
||||
// }
|
||||
// else {
|
||||
// if (hours1<10) sprintf(gcur_time1_str, " %s%01d:%02d:%02d", (negatifsign?"-":" "), hours1, mins1, secs1);
|
||||
// else sprintf(gcur_time1_str, "%s%02d:%02d:%02d", (negatifsign?"-":" "), hours1, mins1, secs1);
|
||||
// }
|
||||
// // lcd.print(cur_time1_str);
|
||||
// getRally["time1"]=gcur_time1_str;
|
||||
// getRally["dir1"]=dircount[dircount1];
|
||||
|
||||
// Print Second TIME
|
||||
// lcd.setCursor(9,3);
|
||||
int secs2, mins2, hours2;
|
||||
// // Print Second TIME
|
||||
// // lcd.setCursor(9,3);
|
||||
// int secs2, mins2, hours2;
|
||||
|
||||
secs2 = (distancetime2-(int)distancetime2)*60;
|
||||
mins2 = (int)distancetime2 % 60;
|
||||
hours2 = (int)distancetime2 / 60;
|
||||
// secs2 = (distancetime2-(int)distancetime2)*60;
|
||||
// mins2 = (int)distancetime2 % 60;
|
||||
// hours2 = (int)distancetime2 / 60;
|
||||
|
||||
unsigned long totsecs2 = secs2 + (mins2*60) + ((long)hours2*3600);
|
||||
unsigned long tottime2 = totsecs2 + totstarttractsecs;
|
||||
//Serial.println(tottime2);
|
||||
// unsigned long totsecs2 = secs2 + (mins2*60) + ((long)hours2*3600);
|
||||
// unsigned long tottime2 = totsecs2 + totstarttractsecs;
|
||||
// //Serial.println(tottime2);
|
||||
|
||||
if (!showTIME) {
|
||||
if (tottime2 >= totcurrentsecs) { //positif means we are too fast, slow down please.
|
||||
negatifsign = false;
|
||||
tottime2 = tottime2 - totcurrentsecs;
|
||||
}
|
||||
else { //negatif means we need to hurry, its late
|
||||
negatifsign = true;
|
||||
tottime2 = totcurrentsecs - tottime2 ;
|
||||
}
|
||||
}
|
||||
// if (!showTIME) {
|
||||
// if (tottime2 >= totcurrentsecs) { //positif means we are too fast, slow down please.
|
||||
// negatifsign = false;
|
||||
// tottime2 = tottime2 - totcurrentsecs;
|
||||
// }
|
||||
// else { //negatif means we need to hurry, its late
|
||||
// negatifsign = true;
|
||||
// tottime2 = totcurrentsecs - tottime2 ;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Serial.println("MidCRal");
|
||||
// // Serial.println("MidCRal");
|
||||
|
||||
hours2 = ((int)(tottime2 / 3600))%24;
|
||||
mins2 = (int)((tottime2 % 3600)/60);
|
||||
secs2 = (tottime2 % 60);
|
||||
// char cur_time2_str[12];
|
||||
// char cur_time2_plain[9];
|
||||
// hours2 = ((int)(tottime2 / 3600))%24;
|
||||
// mins2 = (int)((tottime2 % 3600)/60);
|
||||
// secs2 = (tottime2 % 60);
|
||||
// // char cur_time2_str[12];
|
||||
// // char cur_time2_plain[9];
|
||||
|
||||
if (showTIME) {
|
||||
sprintf(gcur_time2_str, " %02d:%02d:%02d", hours2, mins2, secs2);
|
||||
}
|
||||
else {
|
||||
if (hours2<10) sprintf(gcur_time2_str, " %s%01d:%02d:%02d", (negatifsign?"-":" "), hours2, mins2, secs2);
|
||||
else sprintf(gcur_time2_str, "%s%02d:%02d:%02d", (negatifsign?"-":" "), hours2, mins2, secs2);
|
||||
}
|
||||
// if (showTIME) {
|
||||
// sprintf(gcur_time2_str, " %02d:%02d:%02d", hours2, mins2, secs2);
|
||||
// }
|
||||
// else {
|
||||
// if (hours2<10) sprintf(gcur_time2_str, " %s%01d:%02d:%02d", (negatifsign?"-":" "), hours2, mins2, secs2);
|
||||
// else sprintf(gcur_time2_str, "%s%02d:%02d:%02d", (negatifsign?"-":" "), hours2, mins2, secs2);
|
||||
// }
|
||||
|
||||
// lcd.print(cur_time2_str);
|
||||
getRally["time2"]=gcur_time2_str;
|
||||
getRally["dir2"]=dircount[dircount2];
|
||||
// // lcd.print(cur_time2_str);
|
||||
// getRally["time2"]=gcur_time2_str;
|
||||
// getRally["dir2"]=dircount[dircount2];
|
||||
|
||||
// lcd.setCursor(x,y);
|
||||
getRally["counter"]=VSSCount;
|
||||
strRallyJson="";
|
||||
serializeJson(getRally, strRallyJson);
|
||||
// Serial.println("ENDCRal");
|
||||
} ///// calculation only for esp32
|
||||
// // lcd.setCursor(x,y);
|
||||
// getRally["counter"]=VSSCount;
|
||||
// strRallyJson="";
|
||||
// serializeJson(getRally, strRallyJson);
|
||||
// // Serial.println("ENDCRal");
|
||||
// } ///// calculation only for esp32
|
||||
|
||||
|
||||
void calculationRally() //calculation only ESP32
|
||||
@ -2110,14 +2111,36 @@ void calculationRally() //calculation only ESP32
|
||||
float speed1=0;
|
||||
distance2 = (float)count2/((float)Calibration);
|
||||
distance1 = (float)count1/((float)Calibration); // * 1);
|
||||
|
||||
if ((distance1 - startdistance) > 0) {
|
||||
speed1 = (distance1-startdistance)/(millis()-startspeed)*3600000;
|
||||
if(distance1>=9999 || distance1<=-99) {
|
||||
distance1=0;
|
||||
count1 = 0;
|
||||
backcount1 = 0;
|
||||
time1 = VSSCount;
|
||||
}
|
||||
if(distance2>=9999 || distance2<=-99) {
|
||||
distance2=0;
|
||||
count2 = 0;
|
||||
backcount2 = 0;
|
||||
time2 = VSSCount;
|
||||
}
|
||||
// Serial.print(dircount1);
|
||||
if (dircount1!=FREEZE){ //if direction is freeze on the first odo, then calculate speed from second odo
|
||||
// Serial.print(";not freeze;");Serial.println(distance1);
|
||||
// if ((distance1 - startdistance) > 0) {
|
||||
speed1 = (distance1-startdistance)/(millis()-startspeed)*3600000;
|
||||
// }
|
||||
startdistance = distance1;
|
||||
} else {
|
||||
// Serial.print(";not freeze;");Serial.println(distance1);
|
||||
// if ((distance2 - startdistance) > 0) {
|
||||
speed1 = (distance2-startdistance)/(millis()-startspeed)*3600000;
|
||||
// }
|
||||
startdistance = distance2;
|
||||
}
|
||||
startspeed = millis(); //startspeed is only one no startspeed2
|
||||
startdistance = distance1;
|
||||
|
||||
|
||||
// startdistance = distance1;
|
||||
if(speed1 > 200 || speed1 < -200) speed1 = 0;
|
||||
|
||||
if ((millis()-startsavemillis)>0) {
|
||||
|
||||
if (distance1 != prevdistance1) {
|
||||
@ -2135,28 +2158,43 @@ void calculationRally() //calculation only ESP32
|
||||
delay(1);
|
||||
gcurTime = runningtimeforESP32(6,0);
|
||||
|
||||
sprintf(gcur_speed_str, "%3d.%01d", (int)speed1, (int)((speed1 - (int)speed1)*10));
|
||||
|
||||
if (distance1<100) {
|
||||
sprintf(gcur_distance1_str, "%02d.%03d", (int)distance1, (int)((distance1 - (int)distance1)*1000));
|
||||
sprintf(gcur_speed_str, "%3.01f", speed1);
|
||||
// sprintf(gcur_speed_str, "%3.01f", (int)speed1, (int)((speed1 - (int)speed1)*10));
|
||||
if (distance1<0) {
|
||||
sprintf(gcur_distance1_str, "%02.02f", distance1);
|
||||
}
|
||||
else if (distance1<100) {
|
||||
// sprintf(gcur_distance1_str, "%02d.%03d", (int)distance1, (int)((distance1 - (int)distance1)*1000));
|
||||
sprintf(gcur_distance1_str, "%02.03f", distance1);
|
||||
}
|
||||
else if (distance1<1000) {
|
||||
sprintf(gcur_distance1_str, "%02d.%02d", (int)distance1, (int)((distance1 - (int)distance1)*100));
|
||||
// sprintf(gcur_distance1_str, "%02d.%02d", (int)distance1, (int)((distance1 - (int)distance1)*100));
|
||||
sprintf(gcur_distance1_str, "%03.02f", distance1);
|
||||
}
|
||||
else {
|
||||
sprintf(gcur_distance1_str, "%03d.%01d", (int)distance1, (int)((distance1 - (int)distance1)*10));
|
||||
// sprintf(gcur_distance1_str, "%03d.%01d", (int)distance1, (int)((distance1 - (int)distance1)*10));
|
||||
sprintf(gcur_distance1_str, "%04.01f", distance1);
|
||||
}
|
||||
// Serial.print(distance2);Serial.print(";");Serial.println(count2);
|
||||
|
||||
if (distance2<100) {
|
||||
sprintf(gcur_distance2_str, "%02d.%03d", (int)distance2, (int)((distance2 - (int)distance2)*1000));
|
||||
if (distance2<0) {
|
||||
sprintf(gcur_distance2_str, "%02.02f", distance2);
|
||||
// Serial.println(gcur_distance2_str);
|
||||
}
|
||||
else if (distance2<100) {
|
||||
// sprintf(gcur_distance2_str, "%02d.%03d", (int)distance2, (int)((distance2 - (int)distance2)*1000));
|
||||
sprintf(gcur_distance2_str, "%02.03f", distance2);
|
||||
}
|
||||
else if (distance2<1000) {
|
||||
sprintf(gcur_distance2_str, "%02d.%02d", (int)distance2, (int)((distance2 - (int)distance2)*100));
|
||||
// sprintf(gcur_distance2_str, "%02d.%02d", (int)distance2, (int)((distance2 - (int)distance2)*100));
|
||||
sprintf(gcur_distance2_str, "%03.02f", distance2);
|
||||
}
|
||||
else {
|
||||
sprintf(gcur_distance2_str, "%03d.%01d", (int)distance2, (int)((distance2 - (int)distance2)*10));
|
||||
// sprintf(gcur_distance2_str, "%03d.%01d", (int)distance2, (int)((distance2 - (int)distance2)*10));
|
||||
sprintf(gcur_distance2_str, "%04.01f", distance2);
|
||||
}
|
||||
delay(1);
|
||||
|
||||
// delay(1);
|
||||
float distancetime1 = distance1 * 60 / constanta;
|
||||
float distancetime2 = distance2 * 60 / constanta;
|
||||
|
||||
@ -2247,7 +2285,7 @@ void fillRallyJsonWithData() {
|
||||
getRally["TDist"]=String(Trip[curTrip].distance);
|
||||
getRally["Time"]=gcurTime;
|
||||
getRally["curSpeed"]=gcur_speed_str;
|
||||
getRally["curDist1"]=String(gcur_distance1_str);
|
||||
getRally["curDist1"]=gcur_distance1_str;
|
||||
getRally["curDist2"]=gcur_distance2_str;
|
||||
getRally["time1"]=gcur_time1_str;
|
||||
getRally["dir1"]=dircount[dircount1];
|
||||
@ -2796,7 +2834,7 @@ Trip[9].startSec = 58;
|
||||
|
||||
// Switch on the backlight
|
||||
/// lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
|
||||
// lcd.backlight();
|
||||
// lcd.noBacklight();
|
||||
// lcd2.backlight();
|
||||
/// lcd.setBacklight(LED_ON);
|
||||
|
||||
@ -4321,11 +4359,12 @@ void loop() //loop from VSS RALLY V2
|
||||
// Serial.print("calculationRallyTime=");Serial.println(micros()-broadcastwebsocket);
|
||||
iscalculatingRally=false;
|
||||
// Serial.println(strRallyJson);
|
||||
if (strRallyJson){
|
||||
ws.textAll(strRallyJson);
|
||||
} else {
|
||||
Serial.print("strRallyJson error:");Serial.println(strRallyJson);
|
||||
}
|
||||
if (strRallyJson){
|
||||
ws.textAll(strRallyJson);
|
||||
} else {
|
||||
Serial.print("strRallyJson error:");Serial.println(strRallyJson);
|
||||
|
||||
}
|
||||
// Serial.print("calculationRallyToTTime=");Serial.println(micros()-broadcastwebsocket);
|
||||
broadcastwebsocket = millis();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user