Hallo zusammen,
in meinem Sketch setze ich Variablen, wenn Fehler auftauchen.
Was wäre die beste Variante?
-
typedef struct {
bool Wifi = false;
bool Eeprom = false;
bool Bme280 = false;
bool Bh1750 = false;
bool Moisture = false;
bool Relay = false;
bool Mqtt = false;
bool Upgrade = false;
} Errors;
Errors errors[1];
2.
bool ErrorWifi = false;
bool ErrorEeprom = false;
bool ErrorBme280 = false;
bool ErrorBh1750 = false;
bool ErrorMoisture = false;
bool ErrorRelay = false;
bool ErrorMqtt = false;
bool ErrorUpgrade = false;
-
bool errors[8] = {false, false, false, false, false, false, false, false};
Variante 3 ist zu unübersichtlich, da nach Monaten bestimmt keiner mehr weiß, welcher Fehler in error[3] steht.
Wie machen das die hier anwesenden Profis?
wno158
2
Keine Ahnung wie die Profis das machen
EDIT (Forum-Blues):
Ich hatte mehr geschrieben und mich für Lösung 1 ausgesprochen, allerdings ohne den Array mit einem Element.
Die Forensoftware hats versaut.
combie
3
Wie machen das die hier anwesenden Profis?
Wie Profihaft ich bin, kann ich dir nicht sagen....
Aber eine mögliche Alternative bieten:
struct Error{
bool Wifi:1 = false;
bool Eeprom:1 = false;
bool Bme280:1 = false;
bool Bh1750:1 = false;
bool Moisture:1 = false;
bool Relay:1 = false;
bool Mqtt:1 = false;
bool Upgrade:1 = false;
};
Error error;
typedef struct {
bool Wifi = false;
bool Eeprom = false;
bool Bme280 = false;
bool Bh1750 = false;
bool Moisture = false;
bool Relay = false;
bool Mqtt = false;
bool Upgrade = false;
} Errors;
Errors errors[1];
Der Unterschied:
sizeof(Errors) : 8
sizeof(Error) : 1
Und dann noch ein union drum rum, mit Type pruning, würde sowas erlauben:
if(error.alle) // ausgabe: "es ist irgendein Error aufgetreten"
Hallo
probier mal diese Formulierung aus:
enum Geraete {Eeprom,Bme280,Bh1750, Moisture,Relay,Mqtt,Upgrade, maxGeraete};
typedef struct {
bool status;
} Error;
Error error[maxGeraete];
error[Eeprom].status= false;
error[Bme280].status= false;
error[Bh1750].status= false;
error[Moisture].status= false;
.
.
.
.
system
Closed
5
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.