Selaa lähdekoodia

Prevent config saves before GPIO board profile is loaded

SybexXx 3 päivää sitten
vanhempi
sitoutus
e864cad5e5
1 muutettua tiedostoa jossa 11 lisäystä ja 0 poistoa
  1. 11 0
      sd-card/html/edit_config_template.html

+ 11 - 0
sd-card/html/edit_config_template.html

@@ -1793,6 +1793,9 @@ var canvas = document.getElementById('canvas'),
     NUNBERSAkt = -1,
     NUNBERSAkt = -1,
     NUMBERS;
     NUMBERS;
 
 
+// Do not allow config writes until the firmware board GPIO profile was read.
+window.GPIO_PROFILE_LOADED = false;
+
 function cameraParameterChanged() {
 function cameraParameterChanged() {
     changeCamValue = 1;
     changeCamValue = 1;
 
 
@@ -2314,6 +2317,11 @@ function UpdateTooltipModus() {
 }
 }
 
 
 function saveTextAsFile() {
 function saveTextAsFile() {
+    if (window.GPIO_PROFILE_LOADED !== true) {
+        firework.launch("The GPIO board profile is not available. Reload the page before saving configuration.", "danger", 10000);
+        return;
+    }
+
     ReadParameterAll();
     ReadParameterAll();
     if (document.getElementsByClassName("invalid-input").length > 0) {
     if (document.getElementsByClassName("invalid-input").length > 0) {
         firework.launch("Settings cannot be saved. Please check your entries!", 'danger', 30000);
         firework.launch("Settings cannot be saved. Please check your entries!", 'danger', 30000);
@@ -3013,6 +3021,7 @@ window.GPIO_AVAILABLE_PINS = [];
     var CAP_INPUT = 1, CAP_OUTPUT = 2, CAP_PULL_UP = 4, CAP_PULL_DOWN = 8, CAP_INTERRUPT = 16, CAP_PWM = 32;
     var CAP_INPUT = 1, CAP_OUTPUT = 2, CAP_PULL_UP = 4, CAP_PULL_DOWN = 8, CAP_INTERRUPT = 16, CAP_PWM = 32;
 
 
     function unavailable(message) {
     function unavailable(message) {
+        window.GPIO_PROFILE_LOADED = false;
         window.GPIO_AVAILABLE_PINS = [];
         window.GPIO_AVAILABLE_PINS = [];
         if (table) table.innerHTML = "";
         if (table) table.innerHTML = "";
         if (notice) {
         if (notice) {
@@ -3161,6 +3170,8 @@ window.GPIO_AVAILABLE_PINS = [];
                 throw new Error("Invalid board GPIO profile response");
                 throw new Error("Invalid board GPIO profile response");
             }
             }
 
 
+            // A valid empty whitelist is a valid profile (the board may have no safe user pins).
+            window.GPIO_PROFILE_LOADED = true;
             var seen = {};
             var seen = {};
             var pins = profile.pins.filter(function (pin) {
             var pins = profile.pins.filter(function (pin) {
                 if (!pin || !Number.isInteger(pin.gpio) || pin.gpio < 0 ||
                 if (!pin || !Number.isInteger(pin.gpio) || pin.gpio < 0 ||