small update

This commit is contained in:
Resize_Overdue2_Saxophone_Quicksand 2026-03-11 04:50:13 +07:00
parent 2a9d55de91
commit 4fcfd03f5c
18 changed files with 96 additions and 32 deletions

View File

@ -1 +1 @@
{"trip":"A", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"A", "speed":"0", "time":"", "dist":"0", "stime":""}

View File

@ -1 +1 @@
{"trip":"B", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"B", "speed":"1", "time":"", "dist":"", "stime":""}

View File

@ -1 +1 @@
{"trip":"C", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"C", "speed":"1", "time":"", "dist":"", "stime":""}

View File

@ -1 +1 @@
{"trip":"D", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"D", "speed":"1", "time":"", "dist":"", "stime":""}

View File

@ -1 +1 @@
{"trip":"E", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"E", "speed":"1", "time":"", "dist":"", "stime":""}

View File

@ -1 +1 @@
{"trip":"F", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"F", "speed":"1", "time":"", "dist":"", "stime":""}

View File

@ -1 +1 @@
{"trip":"G", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"G", "speed":"1", "time":"", "dist":"", "stime":""}

View File

@ -1 +1 @@
{"trip":"H", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"H", "speed":"1", "time":"", "dist":"", "stime":""}

View File

@ -1 +1 @@
{"trip":"I", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"I", "speed":"1", "time":"", "dist":"", "stime":""}

View File

@ -1 +1 @@
{"trip":"J", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"J", "speed":"1", "time":"", "dist":"", "stime":""}

View File

@ -1 +1 @@
{"trip":"K", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"K", "speed":"1", "time":"", "dist":"", "stime":""}

View File

@ -1 +1 @@
{"trip":"L", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"L", "speed":"1", "time":"", "dist":"", "stime":""}

View File

@ -1 +1 @@
{"trip":"M", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"M", "speed":"1", "time":"", "dist":"", "stime":""}

View File

@ -1 +1 @@
{"trip":"N", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"N", "speed":"1", "time":"", "dist":"", "stime":""}

View File

@ -1 +1 @@
{"trip":"O", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"O", "speed":"1", "time":"", "dist":"", "stime":""}

View File

@ -1 +1 @@
{"trip":"P", "speed":"", "time":"", "dist":"", "stime":""}
{"trip":"P", "speed":"1", "time":"", "dist":"", "stime":""}

View File

@ -18,3 +18,5 @@ lib_deps =
https://github.com/JChristensen/JC_Button.git
https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library.git
https://github.com/cyberp/AT24Cx.git
me-no-dev/ESPAsyncWebServer@1.2.4
bblanchon/ArduinoJson@6.21.4

View File

@ -322,7 +322,7 @@ byte prevTrip=0;
//
//
void saveCount();
void notFound(AsyncWebServerRequest *request) {
request->send(404);
@ -388,8 +388,10 @@ boolean writeFile(fs::FS &fs, const char * path, const char * message){
// Replaces placeholder with stored values
String processor(const String& var){
//Serial.println(var);
#ifdef DEBUG
Serial.print("Processor ");
Serial.print(var);
#endif
if(var == "ssidString"){
return readFile(SPIFFS, "/ssidString.txt");
}
@ -411,8 +413,10 @@ String processor(const String& var){
return String();
}
String processorConstant(const String& var){
#ifdef DEBUG
Serial.print("proConst->");
Serial.print(var);
#endif
return String();
}
@ -659,9 +663,13 @@ String getSplitValue(String data, char separator, int index)
return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}
unsigned long getValueSetTime(const char* st){
#ifdef DEBUG
Serial.print("getValueSetTime=");Serial.println(st);
#endif
if (!isShortTime(st)) {
#ifdef DEBUG
Serial.println("getValueSetTime=-1");
#endif
return -1;
}
String x = getSplitValue(st, ':', 0);
@ -736,17 +744,23 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
String ctotrip=doc["ctotrip"];
float editodo1=doc["editodo1"].as<float>();
float editodo2=doc["editodo2"].as<float>();
#ifdef DEBUG
Serial.println(editodo1);
Serial.println(editodo2);
#endif
if (resetodo!="null"){
if (isDecimal(resetodo)){
if(resetodo=="1"){
#ifdef DEBUG
Serial.print("resetodo=");Serial.println(resetodo);
#endif
count1 = 0;
backcount1 = 0;
time1 = VSSCount;
} else if(resetodo=="2"){
#ifdef DEBUG
Serial.print("resetodo=");Serial.println(resetodo);
#endif
count2 = 0;
backcount2 = 0;
time2 = VSSCount;
@ -756,11 +770,15 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
if (copytoodo!="null"){
if (isDecimal(copytoodo)){
if(copytoodo=="2"){
#ifdef DEBUG
Serial.print("copytoodo=");Serial.println(copytoodo);
#endif
count2 = count1; //no yet UNDO next update can UNDO
backcount2 = 0;
} else if(copytoodo=="1"){
#ifdef DEBUG
Serial.print("copytoodo=");Serial.println(copytoodo);
#endif
count1 = count2; //no yet UNDO next update can UNDO
backcount1 = 0;
}
@ -769,7 +787,9 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
if (direction1!="null"){
if (isDecimal(direction1)){
if(direction1.toInt()>=0 && direction1.toInt()<=3){
#ifdef DEBUG
Serial.print("direction1=");Serial.println(direction1);
#endif
dircount1=direction1.toInt();
}
}
@ -777,7 +797,9 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
if (direction2!="null"){
if (isDecimal(direction2)){
if(direction2.toInt()>=0 && direction2.toInt()<=3){
#ifdef DEBUG
Serial.print("direction2=");Serial.println(direction2);
#endif
dircount2=direction2.toInt();
}
}
@ -785,10 +807,14 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
if (toggle!="null"){
if (isDecimal(toggle)){
if(toggle=="1"){
#ifdef DEBUG
Serial.print("toggle=");Serial.println(toggle);
#endif
showTIME = !showTIME;
} else if(toggle=="2"){
#ifdef DEBUG
Serial.print("toggle=");Serial.println(toggle);
#endif
showTIME = !showTIME;
}
}
@ -803,21 +829,31 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
starttractmin = Trip[curTrip].startMin;
starttracthour = Trip[curTrip].startHour;
}
#ifdef DEBUG
Serial.print(curTrip);Serial.print(";");Serial.print(constanta);Serial.print(";");
Serial.print(starttracthour);Serial.print(";");Serial.print(temptrip);Serial.println(";");
#endif
}
if (editodo1!=0){
// if (isFloat(editodo1)){
distance1 = editodo1;
mem.writeFloat(832,distance1);
count1 = (unsigned long)(distance1 * Calibration) + 5;
//saveCount();
#ifdef DEBUG
Serial.print("editodo1=");Serial.println(editodo1);
#endif
// }
}
if (editodo2!=0){
// if (isFloat(editodo2)){
distance2 = editodo2;
count2 = (unsigned long)(distance2 * Calibration) + 5;
mem.writeFloat(864,distance2);
//saveCount();
#ifdef DEBUG
Serial.print("editodo2=");Serial.println(editodo2);
#endif
// }
}
}
@ -834,9 +870,11 @@ void onWsEventCalibration(AsyncWebSocket * server, AsyncWebSocketClient * client
} else if(type == WS_EVT_DISCONNECT){
globalClientCalib--;
if (globalClientCalib<=0) gHasCalibClient=false;
#ifdef DEBUG
Serial.println("wscal Client disconnected");
Serial.print("Calib Client=");Serial.println(globalClientCalib);
Serial.print("IPAdd client:"); Serial.println(client->remoteIP());
#endif
} else if(type == WS_EVT_DATA){
Serial.print("wscal IPAdd client:"); Serial.println(client->remoteIP());
Serial.printf("[%u] get Text: %s\n", len, data);
@ -857,11 +895,15 @@ void onWsEventCalibration(AsyncWebSocket * server, AsyncWebSocketClient * client
String setcaldis=doc["setcaldis"];
String setcaldisman=doc["setcaldisman"]; //set calibation distance manual
String calstart=doc["calstart"];
#ifdef DEBUG
Serial.print("setcaldis=");Serial.println(setcaldis);
Serial.print("setcaldisman=");Serial.println(setcaldisman);
Serial.print("calstart=");Serial.println(calstart);
#endif
if (setcaldis!="null"){
if (isFloat(setcaldis)){
Serial.print("setcaldis=");Serial.println(setcaldis.toInt());
calibrationDistance=setcaldis.toInt();
}
@ -876,7 +918,9 @@ void onWsEventCalibration(AsyncWebSocket * server, AsyncWebSocketClient * client
if (calstart!="null"){
if (isDecimal(calstart)){
if(calstart=="1"){
#ifdef DEBUG
Serial.print("calstart=");Serial.println("START");
#endif
Calibrationcount = 0;
startCalibration = VSSCount;
Calibrationtime = startCalibration;
@ -889,7 +933,9 @@ void onWsEventCalibration(AsyncWebSocket * server, AsyncWebSocketClient * client
oneMeter=(float)(Calibration)/1000*(float)calibrationDistance;
calibrationON=false;
}
#ifdef DEBUG
Serial.print("calstart=");Serial.println("STOP");
#endif
}
}
}
@ -934,7 +980,9 @@ void onWsEventSetTime(AsyncWebSocket * server, AsyncWebSocketClient * client, Aw
}
// String setTime=doc["setTime"];
const char* setTime = doc["setTime"].as<const char*>();
#ifdef DEBUG
Serial.print("setTime=");Serial.println(setTime);
#endif
struct ts mts;
struct tm mtm;
if (setTime!=NULL){
@ -943,8 +991,10 @@ void onWsEventSetTime(AsyncWebSocket * server, AsyncWebSocketClient * client, Aw
uint8_t xHourVal=(uint8_t)(x.toInt());
String y = getSplitValue(setTime, ':', 1);
int yMinVal=(uint8_t)(y.toInt());
#ifdef DEBUG
Serial.print("x=");Serial.println(xHourVal);
Serial.print("y=");Serial.println(yMinVal);
#endif
//// DS3231_get(&mts);
mts = t;
mts.sec=0;
@ -1013,6 +1063,7 @@ unsigned long memretrieveLong(int startaddress, byte rrpointersize, unsigned lon
int lastpointer = 0;
unsigned long seqnumber = 0;
int pointeradd = 0;
Serial.println("memretrieveLong");
for (int i = 0; i<rrpointersize; i++) {
pointeradd = startaddress+(i*32);
seqnumber = mem.readLong(pointeradd);
@ -1086,6 +1137,7 @@ void constantatodigit()
}
void setSpiffSpeedInConstanta(float mConstanta, uint8_t setSpiffcurTrip){
Serial.println("setSpiffSpeedInConstanta");
char filename[7] = "/tripZ";
setSpiffcurTrip+=65;
filename[5]=setSpiffcurTrip;
@ -1107,7 +1159,9 @@ void setSpiffSpeedInConstanta(float mConstanta, uint8_t setSpiffcurTrip){
result="";
serializeJson(doc,result);
writeFile(SPIFFS, filename, result.c_str());
#ifdef DEBUG
Serial.print("Write speed:");Serial.println(result);
#endif
Trip[setSpiffcurTrip].speed = mConstanta;
}
@ -1544,6 +1598,7 @@ void saveCount()
{
if (count1 != prevcount1) {
count1Seq++;
//Serial.println(count1Seq);
memwritingLong(count1Address, RRcountSIZE, count1Seq, count1);//(int startaddress, byte RRsize, unsigned long seq, unsigned long Data)
prevcount1 = count1;
}
@ -1552,6 +1607,7 @@ void saveCount()
#ifdef DEBUG
Serial.print("count1=");Serial.print(count1);Serial.print(";count2=");Serial.print(count2);Serial.print("countdiff=");Serial.println(count1count2diff);
#endif
Serial.print("count1=");Serial.print(count1);Serial.print(";count2=");Serial.print(count2);Serial.print("countdiff=");Serial.println(count1count2diff);
count1count2diff = count1-count2;
int pointer = count1count2diffAddress*32;
mem.writeLong(pointer,count1count2diff);
@ -2508,11 +2564,13 @@ void convertJsonTripToTripStruct(uint8_t iTrip, const char* strJson){ //this als
Serial.print(String(char(iTrip)));Serial.print(mspeed);Serial.print(" VS ");Serial.println(doc["speed"].as<String>());
#endif
// if (Trip[iTrip].speed!=doc["speed"])
Serial.println("hohoho");
//Serial.println("hohoho");
// if (strJson=="")
if (strcmp(mspeed, doc["speed"].as<const char*>()) != 0)
{
#ifdef DEBUG
Serial.print(String(char(iTrip)));Serial.println(" speed is different");
#endif
// Serial.print(String(char(iTrip)));Serial.print(Trip[iTrip].speed);Serial.print(" VS ");Serial.println(doc["speed"].as<String>());
// Trip[iTrip].speed = doc["speed"];
}
@ -2521,11 +2579,12 @@ void convertJsonTripToTripStruct(uint8_t iTrip, const char* strJson){ //this als
// Serial.print(String(iTrip));Serial.print(Trip[iTrip].subTime);Serial.print(" VS ");Serial.println(doc["time"].as<String>());
// Trip[iTrip].subTime = doc["time"];
// }
Trip[iTrip].speed = doc["speed"];
Trip[iTrip].distance = doc["dist"];
Trip[iTrip].subTime = doc["time"];
}
void fillTripArray(){ //run by setup()
Serial.println("fillTripArray");
char tempTrip[7]="/tripZ";
// Serial.println(tempTrip);
String tempReadFile;
@ -2663,7 +2722,7 @@ char* unConstChar(const char* s) {
void getTripFromSPIFF(uint8_t charcurTrip, char *pDist, char *pSpeed, char *pTime, char *psTime){ //read from the source ie:from mem and from SPIFF. not read fromStruct Trip.
// void getTripFromSPIFF(uint8_t charcurTrip, char *&pDist, char **pSpeed, char **pTime, char **psTime){
// Serial.print((uint32_t) psTime);Serial.print(";");Serial.print((uint32_t) *psTime);Serial.print(";");Serial.println((uint32_t) **psTime);
//Serial.print((uint32_t) psTime);Serial.print(";");Serial.print((uint32_t) *psTime);Serial.print(";");//Serial.println((uint32_t) **psTime);
DynamicJsonDocument doc(200);
char filename[7] = "/tripZ";
filename[5]=charcurTrip;
@ -2680,18 +2739,20 @@ void getTripFromSPIFF(uint8_t charcurTrip, char *pDist, char *pSpeed, char *pTi
#endif
deserializeJson(doc, tempTrip);
float speedinconstanta = getMemSpeedInConstanta(charcurTrip-65);
tempsTime = getShortsTime(charcurTrip-65);
tempsTime.toCharArray(psTime, 10); // cannot use strcpy
//float speedinconstanta = getMemSpeedInConstanta(charcurTrip-65);
//float speedinconstanta = getMemSpeedInConstanta(charcurTrip-65);
//tempsTime = getShortsTime(charcurTrip-65);
//tempsTime.toCharArray(psTime, 10); // cannot use strcpy
// Serial.print(speedinconstanta);Serial.print(";");
// Serial.print(tempsTime);Serial.println(";");
// pDist = unConstChar( doc["dist"].as<const char*>());
strcpy(pDist, doc["dist"]);
strcpy(pSpeed, doc["speed"]);
strcpy(psTime, doc["stime"]);
// pTime = (char*)doc["time"].as<const char*>();
strcpy(pTime, doc["time"]);
dtostrf(speedinconstanta,6,4,pSpeed);
//dtostrf(speedinconstanta,6,4,pSpeed);
// dtostrf(speedinconstanta,1,4,gSpeed);
// Serial.println(gsTime);
}
@ -2715,6 +2776,7 @@ void handleConstantaHTML(AsyncWebServerRequest *request) {
char xSpeed[8];
char xTime[8];
char xsTime[8];
//Serial.println("before for");
for (uint8_t i=65; i<(TRIPSIZE+65); i++){
PAGEROW = FPSTR(HTML_CONSTROW);
PAGEROW.replace("%A%", String(char(i)));
@ -2888,12 +2950,12 @@ Trip[9].startSec = 58;
Wire.begin(I2C_SDA, I2C_SCL, FREQHZ); //for lolin32lite sda=15; scl=13 //Dont move up or down
//**************************LCD Setup********************************
delay(100);
delay(150);
// lcd.begin (20,4); // initialize the lcd
// lcd.init();
lcd.begin();
// lcd2.begin();
Serial.println("after LCD");
// Switch on the backlight
/// lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
// lcd.noBacklight();
@ -2917,11 +2979,11 @@ Trip[9].startSec = 58;
min60=t.min;
hour24=t.hour;
Serial.println("after gettime");
//mainMenu();
printUPchar();
printDOWNchar();
delay(100); // delay for reading mem.read
delay(200); // delay for reading mem.read
count1 = memretrieveLong(count1Address, RRcountSIZE, count1Seq); //(int startaddress, byte RRsize, unsigned long seq)
Serial.println(count1Seq);
int countaddresspointer = count1count2diffAddress*32;
@ -2990,7 +3052,7 @@ Serial.println("calibration and constanta");
Serial.println(constanta);
//#endif
constantatodigit();
Serial.println("after constantatodigit");
// Serial.print(digit1);Serial.print(digit2); Serial.print(digit3); Serial.print(digit4);Serial.print(digit5);Serial.println(digit6);
// Serial.println(constanta,5);
//Serial.print(digitalRead(UP_pin));Serial.print(digitalRead(DOWN_pin));Serial.print(digitalRead(LEFT_pin));Serial.print(digitalRead(RIGHT_pin));Serial.println(digitalRead(OK_pin));
@ -3147,7 +3209,7 @@ Serial.println("calibration and constanta");
delay(1);
}
semaphoreS = false;
Serial.println("load1 /bootstrap.css");Serial.println(millis());
Serial.println("loaded /bootstrap.css");Serial.println(millis());
request->send(SPIFFS, "/bootstrap.css", "text/css");
// request->send(SPIFFS, "/tripA", "text/plain");
semaphoreS = true;
@ -3161,7 +3223,7 @@ Serial.println("calibration and constanta");
delay(1);
}
semaphoreS = false;
Serial.print("load1 /bootstrap.bundle.min.js");Serial.println(millis());
Serial.print("loaded /bootstrap");Serial.println(millis());
// request->send(SPIFFS, "/tripA", "text/plain");
request->send(SPIFFS, "/bootstrap.bundle.min.js", "text/javascript");
semaphoreS = true;