Skip to content

Commit

Permalink
20240519
Browse files Browse the repository at this point in the history
        Add 12h time format - change by click on clock #7
Reworked Chinese translation by @CXA918 馃殌
Reworked Zigbee flashing code
  • Loading branch information
xyzroe committed May 19, 2024
1 parent 8c36d79 commit f1fcad9
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 8 deletions.
1 change: 1 addition & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*debug*
Binary file removed bin/XZG_20240510.full.bin
Binary file not shown.
Binary file removed bin/XZG_20240510.ota.bin
Binary file not shown.
5 changes: 3 additions & 2 deletions lib/CCTools/src/CCTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,16 +855,17 @@ bool CCTools::beginFlash(uint32_t startAddr, int totalSize)
return _cmdDownload(startAddr, totalSize);
}

void CCTools::processFlash(byte *data, int size)
bool CCTools::processFlash(byte *data, int size)
{
if (memcmp(data, this->emptyPacket, size) != 0)
{
if (!_cmdSendData(data, size))
{
return;
return false;
}
}
this->currentAddr += size;
return true;
}

bool CCTools::checkFirmwareVersion()
Expand Down
2 changes: 1 addition & 1 deletion lib/CCTools/src/CCTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ class CCTools : public CommandInterface
bool detectChipInfo();
bool eraseFlash();
bool beginFlash(uint32_t startAddr, int totalSize);
void processFlash(byte *data, int size);
bool processFlash(byte *data, int size);
bool checkFirmwareVersion();
bool ledToggle();
bool nvram_reset(void (*logFunction)(const String&));
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ lib_deps =
;plerup/EspSoftwareSerial@8.1.0
;marian-craciunescu/ESP32Ping@>=1.7
;me-no-dev/ESPAsyncWebServer@1.2.3
monitor_filters = direct ; log2file ; esp32_exception_decoder, default ;
monitor_filters = direct ; log2file ; esp32_exception_decoder, default ;
monitor_speed = 115200
upload_speed = 460800
;platform_packages =
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// AUTO GENERATED FILE
#ifndef VERSION
#define VERSION "20240510"
#define VERSION "20240519"
#endif
2 changes: 1 addition & 1 deletion src/websrc/html/PAGE_ZIGBEE.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</div>
</div>
<div class="col-12 cardPadding">
<form class="saveParams" method='POST' action="saveParams">
<form class="saveParams" method='POST' action="saveParams" style="margin-block-end: 0em;">
<div class='card'>
<div class="card-header fw-bold">
<svg class="card_icon" fill="currentColor" viewBox="0 0 16 16">
Expand Down
26 changes: 24 additions & 2 deletions src/websrc/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,10 +917,23 @@ function updateTooltips() {

function extractTime(dateStr) {
const date = new Date(dateStr);
let hours = date.getHours().toString().padStart(2, '0');
let hours = date.getHours().toString();
let minutes = date.getMinutes().toString().padStart(2, '0');
let seconds = date.getSeconds().toString().padStart(2, '0');
return `${hours}:${minutes}:${seconds}`;

let pm = "AM";
if (localStorage.getItem('clock_format_12h') == 'true') {
if (hours > 12) {
hours = hours - 12;
pm = "PM";
}
return `${hours}:${minutes}:${seconds} ${pm}`;
}
else {
hours = hours.padStart(2, '0');
return `${hours}:${minutes}:${seconds}`;
}

}

function dataReplace(values, navOnly = false) {
Expand Down Expand Up @@ -2550,6 +2563,15 @@ function handleClicks() {
}
}
});

const clockButton = document.getElementById('clock');

clockButton.addEventListener('click', function () {
const currentFormat = localStorage.getItem('clock_format_12h');
const is12HourFormat = currentFormat === 'true';
localStorage.setItem('clock_format_12h', !is12HourFormat);
console.log('Clock format set to:', !is12HourFormat ? '12-hour' : '24-hour');
});
}

function handleMsg() {
Expand Down
193 changes: 193 additions & 0 deletions src/zb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void flashZbUrl(String url)
// char buffer[100];
// snprintf(buffer, sizeof(buffer), "Flash progress: %.2f%%", percent);
// printLogMsg(String(buffer));
LOGI("%s", String(percent));
sendEvent(tagZB_FW_progress, eventLen, String(percent));
last_percent = percent;
}
Expand Down Expand Up @@ -196,6 +197,7 @@ void printBufferAsHex(const byte *buffer, size_t length)

bool eraseWriteZbUrl(const char *url, std::function<void(float)> progressShow, CCTools &CCTool)
{
/*
HTTPClient http;
WiFiClientSecure client;
client.setInsecure();
Expand Down Expand Up @@ -250,6 +252,197 @@ bool eraseWriteZbUrl(const char *url, std::function<void(float)> progressShow, C
CCTool.restart();
return true;
*/
/*
HTTPClient http;
WiFiClientSecure client;
client.setInsecure();
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
int loadedSize = 0;
int totalSize = 0;
int maxRetries = 10;
int retryCount = 0;
int retryDelay = 500;
bool isSuccess = false;
while (retryCount < maxRetries && !isSuccess)
{
if (loadedSize == 0)
{
CCTool.eraseFlash();
sendEvent("ZB_FW_info", 11, String("erase"));
printLogMsg("Erase completed!");
}
http.begin(client, url);
http.addHeader("Content-Type", "application/octet-stream");
if (loadedSize > 0)
{
http.addHeader("Range", "bytes=" + String(loadedSize) + "-");
}
int httpCode = http.GET();
if (httpCode != HTTP_CODE_OK && httpCode != HTTP_CODE_PARTIAL_CONTENT)
{
char buffer[100];
snprintf(buffer, sizeof(buffer), "Failed to download file, HTTP code: %d\n", httpCode);
printLogMsg(buffer);
http.end();
retryCount++;
delay(retryDelay);
continue;
}
if (totalSize == 0)
{
totalSize = http.getSize();
}
if (loadedSize == 0)
{
if (!CCTool.beginFlash(BEGIN_ZB_ADDR, totalSize))
{
http.end();
LOGI("Error initializing flash process");
continue;
}
printLogMsg("Begin flash");
}
byte buffer[CCTool.TRANSFER_SIZE];
WiFiClient *stream = http.getStreamPtr();
while (http.connected() && loadedSize < totalSize)
{
size_t size = stream->available();
if (size)
{
int c = stream->readBytes(buffer, std::min(size, sizeof(buffer)));
if (!CCTool.processFlash(buffer, c))
{
loadedSize = 0;
// http.end();
retryCount++;
delay(retryDelay);
break;
}
loadedSize += c;
float percent = static_cast<float>(loadedSize) / totalSize * 100.0f;
progressShow(percent);
}
delay(1); // Yield to the WiFi stack
}
http.end();
if (loadedSize >= totalSize)
{
isSuccess = true;
}
}
CCTool.restart();
if (isSuccess)
{
return true;
}
else
{
return false;
}
*/
WiFiClientSecure client;
client.setInsecure();

int loadedSize = 0;
int totalSize = 0;
int maxRetries = 10;
int retryCount = 0;
const int retryDelay = 500;
bool isSuccess = false;

while (retryCount < maxRetries && !isSuccess)
{
HTTPClient http;
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
http.begin(client, url);
http.addHeader("Content-Type", "application/octet-stream");

if (loadedSize > 0)
{
http.addHeader("Range", "bytes=" + String(loadedSize) + "-");
}

int httpCode = http.GET();

if (httpCode != HTTP_CODE_OK && httpCode != HTTP_CODE_PARTIAL_CONTENT)
{
char buffer[100];
snprintf(buffer, sizeof(buffer), "Failed to download file, HTTP code: %d\n", httpCode);
printLogMsg(buffer);

http.end();
retryCount++;
delay(retryDelay);
continue;
}

if (totalSize == 0)
{
totalSize = http.getSize();
}

if (loadedSize == 0)
{
sendEvent("ZB_FW_info", 11, "erase");
printLogMsg("Erase completed!");
CCTool.eraseFlash();

if (!CCTool.beginFlash(BEGIN_ZB_ADDR, totalSize))
{
printLogMsg("Error initializing flash process");
http.end();
continue;
}
}

byte buffer[CCTool.TRANSFER_SIZE];
WiFiClient *stream = http.getStreamPtr();

while (http.connected() && loadedSize < totalSize)
{
size_t size = stream->available();
if (size)
{
int c = stream->readBytes(buffer, std::min(size, sizeof(buffer)));
if (!CCTool.processFlash(buffer, c))
{
loadedSize = 0;
retryCount++;
delay(retryDelay);
break;
}
loadedSize += c;
float percent = static_cast<float>(loadedSize) / totalSize * 100.0f;
progressShow(percent);
}
delay(1); // Yield to the WiFi stack
}

http.end();

if (loadedSize >= totalSize)
{
isSuccess = true;
}
}

CCTool.restart();
return isSuccess;
}

#include <FS.h>
Expand Down
5 changes: 5 additions & 0 deletions tools/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def after_build(source, target, env):
VERSION_NUMBER = extract_version_from_file(VERSION_FILE)

NEW_NAME_BASE = "bin/XZG_" + VERSION_NUMBER

build_env = env['PIOENV']
if "debug" in build_env:
NEW_NAME_BASE += "_" + build_env

NEW_NAME_FULL = NEW_NAME_BASE + ".full.bin"
NEW_NAME_OTA = NEW_NAME_BASE + ".ota.bin"

Expand Down

0 comments on commit f1fcad9

Please sign in to comment.