Fix warnings - Add pre-release warning - Abort update on dl fail

This commit is contained in:
Robert Strouse 2023-12-31 12:30:44 -08:00
parent 416443ca1a
commit 58226cc931
6 changed files with 46 additions and 19 deletions

View file

@ -369,6 +369,7 @@ bool GitUpdater::beginUpdate(const char *version) {
this->error = 0;
this->error = this->downloadFile();
if(this->error == 0 && !this->cancelled) {
somfy.commit();
strcpy(this->currentFile, "SomfyController.littlefs.bin");
this->partition = U_SPIFFS;
this->error = this->downloadFile();
@ -442,7 +443,7 @@ int8_t GitUpdater::downloadFile() {
}
delay(1);
if(total >= len) {
if(!Update.end()) {
if(!Update.end(true)) {
Serial.println("Error downloading update...");
Update.printError(Serial);
}
@ -455,6 +456,8 @@ int8_t GitUpdater::downloadFile() {
}
free(buff);
if(len > total) {
Update.abort();
somfy.commit();
Serial.println("Error downloading file!!!");
return -42;
@ -473,6 +476,10 @@ int8_t GitUpdater::downloadFile() {
return httpCode;
}
}
else {
Serial.printf("Invalid HTTP Code: %d\n", httpCode);
}
if(https.connected()) https.end();
Serial.printf("End update %s\n", this->currentFile);

View file

@ -811,8 +811,8 @@ bool SomfyShade::isInGroup() {
void SomfyShade::setGPIOs() {
if(this->proto == radio_proto::GP_Relay) {
// Determine whether the direction needs to be set.
uint8_t p_on = this->gpioFlags & (uint8_t)gpio_flags_t::LowLevelTrigger == 0x00 ? HIGH : LOW;
uint8_t p_off = this->gpioFlags & (uint8_t)gpio_flags_t::LowLevelTrigger == 0x00 ? LOW : HIGH;
uint8_t p_on = (this->gpioFlags & (uint8_t)gpio_flags_t::LowLevelTrigger) == 0x00 ? HIGH : LOW;
uint8_t p_off = (this->gpioFlags & (uint8_t)gpio_flags_t::LowLevelTrigger) == 0x00 ? LOW : HIGH;
int8_t dir = this->direction;
if(dir == 0 && this->tiltType == tilt_types::integrated)
@ -859,8 +859,8 @@ void SomfyShade::setGPIOs() {
}
else if(this->proto == radio_proto::GP_Remote) {
if(millis() > this->gpioRelease) {
uint8_t p_on = this->gpioFlags & (uint8_t)gpio_flags_t::LowLevelTrigger == 0x00 ? HIGH : LOW;
uint8_t p_off = this->gpioFlags & (uint8_t)gpio_flags_t::LowLevelTrigger == 0x00 ? LOW : HIGH;
//uint8_t p_on = (this->gpioFlags & (uint8_t)gpio_flags_t::LowLevelTrigger) == 0x00 ? HIGH : LOW;
uint8_t p_off = (this->gpioFlags & (uint8_t)gpio_flags_t::LowLevelTrigger) == 0x00 ? LOW : HIGH;
digitalWrite(this->gpioUp, p_off);
digitalWrite(this->gpioDown, p_off);
digitalWrite(this->gpioMy, p_off);
@ -871,8 +871,8 @@ void SomfyShade::setGPIOs() {
void SomfyRemote::triggerGPIOs(somfy_frame_t &frame) { }
void SomfyShade::triggerGPIOs(somfy_frame_t &frame) {
if(this->proto == radio_proto::GP_Remote) {
uint8_t p_on = this->gpioFlags & (uint8_t)gpio_flags_t::LowLevelTrigger == 0x00 ? HIGH : LOW;
uint8_t p_off = this->gpioFlags & (uint8_t)gpio_flags_t::LowLevelTrigger == 0x00 ? LOW : HIGH;
uint8_t p_on = (this->gpioFlags & (uint8_t)gpio_flags_t::LowLevelTrigger) == 0x00 ? HIGH : LOW;
uint8_t p_off = (this->gpioFlags & (uint8_t)gpio_flags_t::LowLevelTrigger) == 0x00 ? LOW : HIGH;
int8_t dir = 0;
switch(frame.cmd) {
case somfy_commands::My:
@ -927,6 +927,8 @@ void SomfyShade::triggerGPIOs(somfy_frame_t &frame) {
Serial.printf("UP: true, DOWN: true, MY: true\n");
}
break;
default:
break;
}
this->gpioRelease = millis() + (frame.repeats * 200);
this->gpioDir = dir;
@ -1754,7 +1756,7 @@ void SomfyShade::emitCommand(uint8_t num, somfy_commands cmd, const char *source
e.appendMessage(buf);
snprintf(buf, sizeof(buf), ",\"remoteAddress\":%d", this->getRemoteAddress());
e.appendMessage(buf);
snprintf(buf, sizeof(buf), ",\"cmd\":\"%s\"", translateSomfyCommand(cmd));
snprintf(buf, sizeof(buf), ",\"cmd\":\"%s\"", translateSomfyCommand(cmd).c_str());
e.appendMessage(buf);
snprintf(buf, sizeof(buf), ",\"source\":\"%s\"", source);
e.appendMessage(buf);
@ -2610,6 +2612,8 @@ void SomfyGroup::sendCommand(somfy_commands cmd, uint8_t repeat) {
case somfy_commands::Down:
this->p_direction(1);
break;
default:
break;
}
for(uint8_t i = 0; i < SOMFY_MAX_GROUPED_SHADES; i++) {
if(this->linkedShades[i] != 0) {
@ -2752,8 +2756,9 @@ bool SomfyShade::usesPin(uint8_t pin) {
else if(this->shadeType == shade_types::garage1) {
if(this->proto == radio_proto::GP_Relay && this->gpioUp == pin) return true;
}
else if(this->shadeType == shade_types::drycontact2)
else if(this->shadeType == shade_types::drycontact2) {
if(this->proto == radio_proto::GP_Relay && (this->gpioUp == pin || this->gpioDown == pin)) return true;
}
else {
if(this->gpioUp == pin) return true;
else if(this->proto == radio_proto::GP_Remote && this->gpioMy == pin) return true;
@ -2846,7 +2851,12 @@ int8_t SomfyShade::fromJSON(JsonObject &obj) {
if(obj.containsKey("sunSensor")) this->setSunSensor(obj["sunSensor"]);
if(obj.containsKey("light")) this->setLight(obj["light"]);
if(obj.containsKey("gpioFlags")) this->gpioFlags = obj["gpioFlags"];
if(obj.containsKey("gpioLLTrigger")) this->gpioFlags = obj["gpioLLTrigger"].as<bool>() ? this->gpioFlags |= (uint8_t)gpio_flags_t::LowLevelTrigger : this->gpioFlags &= ~(uint8_t)gpio_flags_t::LowLevelTrigger;
if(obj.containsKey("gpioLLTrigger")) {
if(obj["gpioLLTrigger"].as<bool>())
this->gpioFlags |= (uint8_t)gpio_flags_t::LowLevelTrigger;
else
this->gpioFlags &= ~(uint8_t)gpio_flags_t::LowLevelTrigger;
}
if(obj.containsKey("shadeType")) {
if(obj["shadeType"].is<const char *>()) {
@ -3975,7 +3985,7 @@ void Transceiver::enableReceive(void) {
interruptPin = digitalPinToInterrupt(this->config.RXPin);
ELECHOUSE_cc1101.SetRx();
attachInterrupt(interruptPin, handleReceive, CHANGE);
Serial.printf("Enabled receive on Pin #%d Timing: %d\n", this->config.RXPin, millis() - timing);
Serial.printf("Enabled receive on Pin #%d Timing: %ld\n", this->config.RXPin, millis() - timing);
}
}
void Transceiver::disableReceive(void) {

Binary file not shown.

Binary file not shown.

View file

@ -346,7 +346,6 @@ void Web::handleRepeatCommand(WebServer& server) {
if (method == HTTP_OPTIONS) { server.send(200, "OK"); return; }
uint8_t shadeId = 255;
uint8_t groupId = 255;
uint8_t target = 255;
int8_t repeat = -1;
somfy_commands command = somfy_commands::My;
if (method == HTTP_GET || method == HTTP_PUT || method == HTTP_POST) {
@ -745,7 +744,6 @@ void Web::handleBackup(WebServer &server, bool attach) {
void Web::handleSetPositions(WebServer &server) {
webServer.sendCORSHeaders(server);
if(server.method() == HTTP_OPTIONS) { server.send(200, "OK"); return; }
HTTPMethod method = apiServer.method();
uint8_t shadeId = (server.hasArg("shadeId")) ? atoi(server.arg("shadeId").c_str()) : 255;
int8_t pos = (server.hasArg("position")) ? atoi(server.arg("position").c_str()) : -1;
int8_t tiltPos = (server.hasArg("tiltPosition")) ? atoi(server.arg("tiltPosition").c_str()) : -1;
@ -794,7 +792,6 @@ void Web::handleSetPositions(WebServer &server) {
void Web::handleSetSensor(WebServer &server) {
webServer.sendCORSHeaders(server);
if(server.method() == HTTP_OPTIONS) { server.send(200, "OK"); return; }
HTTPMethod method = apiServer.method();
uint8_t shadeId = (server.hasArg("shadeId")) ? atoi(server.arg("shadeId").c_str()) : 255;
uint8_t groupId = (server.hasArg("groupId")) ? atoi(server.arg("groupId").c_str()) : 255;
int8_t sunny = (server.hasArg("sunny")) ? toBoolean(server.arg("sunny").c_str(), false) ? 1 : 0 : -1;
@ -2020,14 +2017,14 @@ void Web::begin() {
if (method == HTTP_POST || method == HTTP_PUT) {
settings.Security.fromJSON(obj);
settings.Security.save();
DynamicJsonDocument sdoc(512);
JsonObject sobj = sdoc.to<JsonObject>();
char token[65];
webServer.createAPIToken(server.client().remoteIP(), token);
obj["apiKey"] = token;
DynamicJsonDocument sdoc(1024);
JsonObject sobj = sdoc.to<JsonObject>();
settings.Security.toJSON(sobj);
serializeJson(sdoc, g_content);
server.send(200, _encoding_json, g_content);
//server.send(200, "application/json", "{\"status\":\"OK\",\"desc\":\"Successfully saved radio\"}");
}
else {
server.send(201, "application/json", "{\"status\":\"ERROR\",\"desc\":\"Invalid HTTP Method: \"}");

View file

@ -4067,12 +4067,16 @@ class Firmware {
div.setAttribute('class', 'inst-overlay');
div.style.width = '100%';
div.style.alignContent = 'center';
// Sort the releases so that the pre-releases are at the bottom.
rel.releases.sort((a, b) => a.preRelease === b.preRelease && b.draft === a.draft ? 0 : a.preRelease ? 1 : -1);
let html = `<div>Select a version from the repository to install using the dropdown below. Then press the update button to install that version.</div><div style="font-size:.7em;margin-top:4px;">Select Main to install the most recent alpha version from the repository.</div>`;
html += `<div class="field-group" style = "text-align:center;">`;
html += `<div id="divPrereleaseWarning" style="display:none;width:100%;color:red;text-align:center;font-weight:bold;"><span style="margin-top:7px;width:100%;padding:3px;display:inline-block;border-radius:5px;background:white;">WARNING<span><hr style="margin:0px" /><div style="font-size:.7em;padding-left:1em;padding-right:1em;color:black;font-weight:normal;">You have selected a pre-released beta version that has not been fully tested or published for general use.</div></div>`;
html += `<div class="field-group" style="text-align:center;">`;
html += `<select id="selVersion" data-bind="version" style="width:70%;font-size:2em;color:white;text-align-last:center;" onchange="firmware.gitReleaseSelected(document.getElementById('divGitInstall'));">`
for (let i = 0; i < rel.releases.length; i++) {
if (rel.releases[i].hwVersions.length === 0 || rel.releases[i].hwVersions.indexOf(chip) >= 0)
html += `<option style="text-align:left;font-size:.5em;color:black;" value="${rel.releases[i].version.name}">${rel.releases[i].name}${rel.releases[i].preRelease ? ' - Pre' : ''}</option>`
html += `<option style="text-align:left;font-size:.5em;color:black;" data-prerelease="${rel.releases[i].preRelease}" value="${rel.releases[i].version.name}">${rel.releases[i].name}${rel.releases[i].preRelease ? ' - Pre' : ''}</option>`
}
html += `</select><label for="selVersion">Select a version</label></div>`;
html += `<div class="button-container" id="divReleaseNotes" style="text-align:center;margin-top:-20px;display:none;"><button type="button" onclick="firmware.showReleaseNotes(document.getElementById('selVersion').value);" style="display:inline-block;width:auto;padding-left:20px;padding-right:20px;">Release Notes</button></div>`;
@ -4102,6 +4106,15 @@ class Firmware {
gitReleaseSelected(div) {
let obj = ui.fromElement(div);
let divNotes = div.querySelector('#divReleaseNotes');
let divPre = div.querySelector('#divPrereleaseWarning');
let sel = div.querySelector('#selVersion');
if (sel && sel.selectedIndex !== -1 && makeBool(sel.options[sel.selectedIndex].getAttribute('data-prerelease'))) {
if (divPre) divPre.style.display = '';
}
else
if (divPre) divPre.style.display = 'none';
if (divNotes) {
if (!obj.version || obj.version === 'main' || obj.version === '') divNotes.style.display = 'none';
else divNotes.style.display = '';