From 0e6ab0d5940b744f3166dead074242142278fdc0 Mon Sep 17 00:00:00 2001 From: Alexander Tonn Date: Wed, 12 Aug 2026 15:38:53 +0200 Subject: [PATCH 1/3] fixed timeout issue because of wrong EoL check --- .vscode/c_cpp_properties.json | 18 +++++++++++ .vscode/launch.json | 24 ++++++++++++++ .vscode/settings.json | 59 +++++++++++++++++++++++++++++++++++ src/EasyNextionLibrary.cpp | 26 +++++++++------ 4 files changed, 118 insertions(+), 9 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..34d5b87 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-cygwin-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "C:/cygwin64/bin/gcc.exe", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "linux-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..540cd3c --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "d:/Github/EasyNextionLibrary/src", + "program": "d:/Github/EasyNextionLibrary/src/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "C:\\cygwin64\\bin\\gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c0b4b55 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "C:/cygwin64/bin/gcc", + "C_Cpp_Runner.cppCompilerPath": "C:/cygwin64/bin/g++", + "C_Cpp_Runner.debuggerPath": "C:/cygwin64/bin/gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/src/EasyNextionLibrary.cpp b/src/EasyNextionLibrary.cpp index 469598f..619834b 100644 --- a/src/EasyNextionLibrary.cpp +++ b/src/EasyNextionLibrary.cpp @@ -82,7 +82,7 @@ String EasyNex::readStr(String TextComponent){ String _Textcomp = TextComponent; bool _endOfCommandFound = false; - char _tempChar; + uint8_t _tempChar; _tmr1 = millis(); while(_serial->available()){ // Waiting for NO bytes on Serial, @@ -175,7 +175,7 @@ uint32_t EasyNex::readNumber(String component){ _comp = component; bool _endOfCommandFound = false; - char _tempChar; + uint8_t _tempChar; _numberValue = 777777; // The function will return this number in case it fails to read the new number @@ -240,13 +240,21 @@ uint32_t EasyNex::readNumber(String component){ while(_endOfCommandFound == false){ // As long as the three 0xFF bytes have NOT been found, run the commands inside the loop - _tempChar = _serial->read(); // Read the next byte of the Serial - - if(_tempChar == 0xFF || _tempChar == 0xFFFFFFFF){ // If the read byte is the end command byte, - _endBytes++ ; // Add one to the _endBytes counter - if(_endBytes == 3){ - _endOfCommandFound = true; // If the counter is equal to 3, we have the end command - } + _tempChar = _serial->read(); // Read the next byte of the Serial + + if (_tempChar == 0xFFFFFFFF) + { // If the read byte is the end command byte, + _endOfCommandFound = true; // If the counter is equal to 3, we have the end command + break; + } + if (_tempChar == 0xFF) + { // If the read byte is the end command byte, + _endBytes++; // Add one to the _endBytes counter + if (_endBytes == 3) + { + _endOfCommandFound = true; // If the counter is equal to 3, we have the end command + } + } }else{ // If the read byte is NOT the end command byte, _numberValue = 777777; break; From ba641a2329bc1d011420a2c0703bb76400981bf1 Mon Sep 17 00:00:00 2001 From: Alexander Tonn Date: Mon, 24 Aug 2026 15:35:48 +0200 Subject: [PATCH 2/3] Timeout of the read functions can be adjusted now, because the constant 1000ms is blocking the mcu to much if a lot of values have to be read --- src/EasyNextionLibrary.cpp | 18 +++++++++--------- src/EasyNextionLibrary.h | 4 +++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/EasyNextionLibrary.cpp b/src/EasyNextionLibrary.cpp index 619834b..5eb6214 100644 --- a/src/EasyNextionLibrary.cpp +++ b/src/EasyNextionLibrary.cpp @@ -87,7 +87,7 @@ String EasyNex::readStr(String TextComponent){ _tmr1 = millis(); while(_serial->available()){ // Waiting for NO bytes on Serial, // as other commands could be sent in that time. - if((millis() - _tmr1) > 1000UL){ // Waiting... But not forever...after the timeout + if((millis() - _tmr1) > _readTimeout){ // Waiting... But not forever...after the timeout _readString = "ERROR"; break; // Exit from the loop due to timeout. Return ERROR }else{ @@ -110,7 +110,7 @@ String EasyNex::readStr(String TextComponent){ _tmr1 = millis(); while(_serial->available() < 4){ // Waiting for bytes to come to Serial, an empty Textbox will send 4 bytes // and this the minimmum number that we are waiting for (70 FF FF FF) - if((millis() - _tmr1) > 400UL){ // Waiting... But not forever...after the timeout + if((millis() - _tmr1) > _readTimeout){ // Waiting... But not forever...after the timeout _readString = "ERROR"; break; // Exit the loop due to timeout. Return ERROR } @@ -125,7 +125,7 @@ String EasyNex::readStr(String TextComponent){ _start_char = _serial->read(); } - if((millis() - _tmr1) > 100UL){ // Waiting... But not forever...... + if((millis() - _tmr1) > _readTimeout){ // Waiting... But not forever...... _readString = "ERROR"; // If the 0x70 is not found within the given time, break the while() // to avoid being stuck inside the while() loop break; @@ -151,7 +151,7 @@ String EasyNex::readStr(String TextComponent){ } } - if((millis() - _tmr1) > 1000UL){ // Waiting... But not forever...... + if((millis() - _tmr1) > _readTimeout){ // Waiting... But not forever...... _readString = "ERROR"; // If the end of the command is NOT found in the time given, // break the while break; @@ -182,7 +182,7 @@ uint32_t EasyNex::readNumber(String component){ _tmr1 = millis(); while(_serial->available()){ // Waiting for NO bytes on Serial, // as other commands could be sent in that time. - if((millis() - _tmr1) > 1000UL){ // Waiting... But not forever...after the timeout + if((millis() - _tmr1) > _readTimeout){ // Waiting... But not forever...after the timeout _numberValue = 777777; break; // Exit from the loop due to timeout. Return 777777 }else{ @@ -205,7 +205,7 @@ uint32_t EasyNex::readNumber(String component){ _tmr1 = millis(); while(_serial->available() < 8){ // Waiting for bytes to come to Serial, // we are waiting for 8 bytes - if((millis() - _tmr1) > 400UL){ // Waiting... But not forever...after the timeout + if((millis() - _tmr1) > _readTimeout){ // Waiting... But not forever...after the timeout _numberValue = 777777; break; // Exit the loop due to timeout. Return 777777 } @@ -220,7 +220,7 @@ uint32_t EasyNex::readNumber(String component){ _start_char = _serial->read(); } - if((millis() - _tmr1) > 100UL){ // Waiting... But not forever...... + if((millis() - _tmr1) > _readTimeout){ // Waiting... But not forever...... _numberValue = 777777; // If the 0x71 is not found within the given time, break the while() // to avoid being stuck inside the while() loop break; @@ -255,12 +255,12 @@ uint32_t EasyNex::readNumber(String component){ _endOfCommandFound = true; // If the counter is equal to 3, we have the end command } } - }else{ // If the read byte is NOT the end command byte, + else{ // If the read byte is NOT the end command byte, _numberValue = 777777; break; } - if((millis() - _tmr1) > 1000UL){ // Waiting... But not forever...... + if((millis() - _tmr1) > _readTimeout){ // Waiting... But not forever...... _numberValue = 777777; // If the end of the command is NOT found in the time given, // break the while break; diff --git a/src/EasyNextionLibrary.h b/src/EasyNextionLibrary.h index 48bf41b..7b16404 100644 --- a/src/EasyNextionLibrary.h +++ b/src/EasyNextionLibrary.h @@ -86,6 +86,7 @@ class EasyNex { uint32_t readNumber(String); String readStr(String); int readByte(); + void setReadTimeout(uint32_t timeout) { _readTimeout = timeout; } //--------------------------------------- // public variables @@ -118,7 +119,7 @@ class EasyNex { HardwareSerial* _serial; void readCommand(void); void callTriggerFunction(void); - + //---------------------------------------------- // for function writeNum() (write to numeric attribute) //------------------------------------------------ @@ -136,6 +137,7 @@ class EasyNex { String _comp; uint8_t _numericBuffer[4]; uint32_t _numberValue; + uint32_t _readTimeout = 1000; //--------------------------------------- // for General functions From 9a4685ba8de999f19a764b42ed08fe1aa1b04327 Mon Sep 17 00:00:00 2001 From: Alexander Tonn Date: Wed, 26 Aug 2026 15:57:53 +0200 Subject: [PATCH 3/3] removed not necessary vscode files, gitignore modified --- .gitignore | 2 ++ .vscode/c_cpp_properties.json | 18 ----------- .vscode/launch.json | 24 -------------- .vscode/settings.json | 59 ----------------------------------- 4 files changed, 2 insertions(+), 101 deletions(-) delete mode 100644 .vscode/c_cpp_properties.json delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 259148f..2cbc7ae 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ *.exe *.out *.app + +.vscode/ \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index 34d5b87..0000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "configurations": [ - { - "name": "windows-cygwin-gcc-x64", - "includePath": [ - "${workspaceFolder}/**" - ], - "compilerPath": "C:/cygwin64/bin/gcc.exe", - "cStandard": "${default}", - "cppStandard": "${default}", - "intelliSenseMode": "linux-gcc-x64", - "compilerArgs": [ - "" - ] - } - ], - "version": 4 -} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 540cd3c..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "C/C++ Runner: Debug Session", - "type": "cppdbg", - "request": "launch", - "args": [], - "stopAtEntry": false, - "externalConsole": true, - "cwd": "d:/Github/EasyNextionLibrary/src", - "program": "d:/Github/EasyNextionLibrary/src/build/Debug/outDebug", - "MIMode": "gdb", - "miDebuggerPath": "C:\\cygwin64\\bin\\gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - } - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index c0b4b55..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "C_Cpp_Runner.cCompilerPath": "C:/cygwin64/bin/gcc", - "C_Cpp_Runner.cppCompilerPath": "C:/cygwin64/bin/g++", - "C_Cpp_Runner.debuggerPath": "C:/cygwin64/bin/gdb", - "C_Cpp_Runner.cStandard": "", - "C_Cpp_Runner.cppStandard": "", - "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", - "C_Cpp_Runner.useMsvc": false, - "C_Cpp_Runner.warnings": [ - "-Wall", - "-Wextra", - "-Wpedantic", - "-Wshadow", - "-Wformat=2", - "-Wcast-align", - "-Wconversion", - "-Wsign-conversion", - "-Wnull-dereference" - ], - "C_Cpp_Runner.msvcWarnings": [ - "/W4", - "/permissive-", - "/w14242", - "/w14287", - "/w14296", - "/w14311", - "/w14826", - "/w44062", - "/w44242", - "/w14905", - "/w14906", - "/w14263", - "/w44265", - "/w14928" - ], - "C_Cpp_Runner.enableWarnings": true, - "C_Cpp_Runner.warningsAsError": false, - "C_Cpp_Runner.compilerArgs": [], - "C_Cpp_Runner.linkerArgs": [], - "C_Cpp_Runner.includePaths": [], - "C_Cpp_Runner.includeSearch": [ - "*", - "**/*" - ], - "C_Cpp_Runner.excludeSearch": [ - "**/build", - "**/build/**", - "**/.*", - "**/.*/**", - "**/.vscode", - "**/.vscode/**" - ], - "C_Cpp_Runner.useAddressSanitizer": false, - "C_Cpp_Runner.useUndefinedSanitizer": false, - "C_Cpp_Runner.useLeakSanitizer": false, - "C_Cpp_Runner.showCompilationTime": false, - "C_Cpp_Runner.useLinkTimeOptimization": false, - "C_Cpp_Runner.msvcSecureNoWarnings": false -} \ No newline at end of file