From 3d938b4eb41ee82709b13d4f8b8fc7260ddd1a8d Mon Sep 17 00:00:00 2001 From: Florian Date: Tue, 10 Oct 2023 22:34:13 +0200 Subject: [PATCH 1/4] Improve version comparison --- src/PixelIt.ino | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/PixelIt.ino b/src/PixelIt.ino index e379963..b127822 100644 --- a/src/PixelIt.ino +++ b/src/PixelIt.ino @@ -336,6 +336,13 @@ unsigned long checkUpdateScreenPrevMillis = 0; unsigned long checkUpdatePrevMillis = 0; String lastReleaseVersion = VERSION; +typedef struct { + int major; + int minor; + int patch; + char prerelease[16]; +} Version; + // MP3Player Vars String OldGetMP3PlayerInfo; @@ -375,6 +382,37 @@ String ResetReason() #endif } +Version parseVersion(const char* versionStr) { + Version version; + int x = sscanf(versionStr, "%d.%d.%d-%s", &version.major, &version.minor, &version.patch, version.prerelease); + return version; +} + +int compareVersions(const char* version1, const char* version2) { + Version v1 = parseVersion(version1); + Version v2 = parseVersion(version2); + + if (v1.major != v2.major) { + return v1.major - v2.major; + } + if (v1.minor != v2.minor) { + return v1.minor - v2.minor; + } + if (v1.patch != v2.patch) { + return v1.patch - v2.patch; + } + + if (strlen(v1.prerelease) == 0 && strlen(v2.prerelease) == 0) { + return 0; // Versions are equal + } else if (strlen(v1.prerelease) == 0) { + return 1; // v1 is greater (no prerelease for v1, but prerelease for v2) + } else if (strlen(v2.prerelease) == 0) { + return -1; // v2 is greater (no prerelease for v2, but prerelease for v1) + } else { + return strcmp(v1.prerelease, v2.prerelease); // Compare prerelease strings + } +} + void getBatteryVoltage() { uint16_t value = 0; @@ -3689,9 +3727,12 @@ void checkUpdate() if (root.containsKey("version")) { lastReleaseVersion = root["version"].as(); - if (!lastReleaseVersion.equals(VERSION)) + + int result = compareVersions(lastReleaseVersion.c_str(), VERSION); + + if (result > 0) { - Log(F("CheckUpdate"), F("New FW available")); + Log(F("CheckUpdate"), "New FW available -> " + lastReleaseVersion); } else { @@ -3748,7 +3789,9 @@ void loop() if (millis() - checkUpdateScreenPrevMillis >= CHECKUPDATESCREEN_INTERVAL) { checkUpdateScreenPrevMillis = millis(); - if (!lastReleaseVersion.equals(VERSION)) + + int result = compareVersions(lastReleaseVersion.c_str(), VERSION); + if (result > 0) { if (!sleepMode) { From 5fe764fc317c6de2f3f20de2f8c349b4217817e5 Mon Sep 17 00:00:00 2001 From: Florian Date: Tue, 10 Oct 2023 23:09:39 +0200 Subject: [PATCH 2/4] Log versions and fix prerelease char-array recycling --- src/PixelIt.ino | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/PixelIt.ino b/src/PixelIt.ino index b127822..62ed6c3 100644 --- a/src/PixelIt.ino +++ b/src/PixelIt.ino @@ -57,7 +57,7 @@ #define CHECKUPDATESCREEN_DURATION 1000 * 5 // 5 Seconds #define SEND_LIVEVIEW_INTERVAL 250 // 0.5 Seconds, 0 to disable -#define VERSION "0.0.0-beta" // will be replaced by build piple with Git-Tag! +#define VERSION "2.3.2-beta" // will be replaced by build piple with Git-Tag! #define XSTR(x) #x #define STR(x) XSTR(x) @@ -384,6 +384,9 @@ String ResetReason() Version parseVersion(const char* versionStr) { Version version; + + memset(version.prerelease, 0, sizeof(version.prerelease)); + int x = sscanf(versionStr, "%d.%d.%d-%s", &version.major, &version.minor, &version.patch, version.prerelease); return version; } @@ -3732,11 +3735,11 @@ void checkUpdate() if (result > 0) { - Log(F("CheckUpdate"), "New FW available -> " + lastReleaseVersion); + Log(F("CheckUpdate"), "New FW available " + String(VERSION) + " -> " + lastReleaseVersion); } else { - Log(F("CheckUpdate"), F("No new FW available")); + Log(F("CheckUpdate"), "No new FW available " + String(VERSION) + " -> " + lastReleaseVersion); } } } From 575257dbd940db065c260d300488105d16b2dd8a Mon Sep 17 00:00:00 2001 From: Florian Date: Tue, 10 Oct 2023 23:35:13 +0200 Subject: [PATCH 3/4] Handle versions if strings are empty eg no connection --- src/PixelIt.ino | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/PixelIt.ino b/src/PixelIt.ino index 62ed6c3..9ccf02c 100644 --- a/src/PixelIt.ino +++ b/src/PixelIt.ino @@ -57,7 +57,7 @@ #define CHECKUPDATESCREEN_DURATION 1000 * 5 // 5 Seconds #define SEND_LIVEVIEW_INTERVAL 250 // 0.5 Seconds, 0 to disable -#define VERSION "2.3.2-beta" // will be replaced by build piple with Git-Tag! +#define VERSION "0.0.0-beta" // will be replaced by build piple with Git-Tag! #define XSTR(x) #x #define STR(x) XSTR(x) @@ -392,6 +392,11 @@ Version parseVersion(const char* versionStr) { } int compareVersions(const char* version1, const char* version2) { + if (strlen(version1) == 0 || strlen(version2) == 0) + { + return 0; + } + Version v1 = parseVersion(version1); Version v2 = parseVersion(version2); From 8dae0562042c35cb3130f25dbb20a3cef6828ac1 Mon Sep 17 00:00:00 2001 From: Fab!an Date: Wed, 11 Oct 2023 23:08:52 +0200 Subject: [PATCH 4/4] Updated readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f834c4..303e456 100644 --- a/README.md +++ b/README.md @@ -109,11 +109,12 @@ Thanks to these great people for supporting this project. -### 2.4.0 **WORK IN PROGRESS** +### 2.4.x **WORK IN PROGRESS** - (foorschtbar) Native support for [Ulanzi TC001 Pixel Clock](https://www.ulanzi.com/products/ulanzi-pixel-smart-clock-2882?aff=1181)\* (**Beta**, see [Releases](https://github.com/pixelit-project/PixelIt/releases)) :tada: - (foorschtbar) Display `zZz` on the matrix when the device going to sleep - (foorschtbar) Fixed issue with flickering icons, wenn device wake from sleep mode +- (Metaln00b) Improved new firmware check by doing real version compare (major, minor, patch and prerelease) ### 2.3.2 (2023-09-16)