feat: implement scale calibration checks and update start_scale function to return calibration status
This commit is contained in:
parent
c6da28ad6f
commit
37717392d0
45
src/main.cpp
45
src/main.cpp
@ -58,7 +58,22 @@ void setup() {
|
|||||||
|
|
||||||
startNfc();
|
startNfc();
|
||||||
|
|
||||||
start_scale();
|
uint8_t scaleCalibrated = start_scale();
|
||||||
|
if (scaleCalibrated == 3) {
|
||||||
|
oledShowMessage("Scale not calibrated!");
|
||||||
|
for (uint16_t i = 0; i < 50000; i++) {
|
||||||
|
yield();
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1));
|
||||||
|
esp_task_wdt_reset();
|
||||||
|
}
|
||||||
|
} else if (scaleCalibrated == 0) {
|
||||||
|
oledShowMessage("HX711 not found");
|
||||||
|
for (uint16_t i = 0; i < 50000; i++) {
|
||||||
|
yield();
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1));
|
||||||
|
esp_task_wdt_reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WDT initialisieren mit 10 Sekunden Timeout
|
// WDT initialisieren mit 10 Sekunden Timeout
|
||||||
bool panic = true; // Wenn true, löst ein WDT-Timeout einen System-Panik aus
|
bool panic = true; // Wenn true, löst ein WDT-Timeout einen System-Panik aus
|
||||||
@ -84,33 +99,33 @@ uint8_t wifiErrorCounter = 0;
|
|||||||
|
|
||||||
// ##### PROGRAM START #####
|
// ##### PROGRAM START #####
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
/*
|
|
||||||
// Überprüfe den WLAN-Status
|
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
|
||||||
wifiErrorCounter++;
|
|
||||||
wifiOn = false;
|
|
||||||
} else {
|
|
||||||
wifiErrorCounter = 0;
|
|
||||||
wifiOn = true;
|
|
||||||
}
|
|
||||||
if (wifiErrorCounter > 20) ESP.restart();
|
|
||||||
*/
|
|
||||||
|
|
||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
|
|
||||||
// Send AMS Data min every Minute
|
// Send AMS Data min every Minute
|
||||||
if (currentMillis - lastAmsSendTime >= amsSendInterval) {
|
if (currentMillis - lastAmsSendTime >= amsSendInterval)
|
||||||
|
{
|
||||||
lastAmsSendTime = currentMillis;
|
lastAmsSendTime = currentMillis;
|
||||||
sendAmsData(nullptr);
|
sendAmsData(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wenn Waage nicht Kalibriert
|
||||||
|
if (scaleCalibrated == 3)
|
||||||
|
{
|
||||||
|
oledShowMessage("Scale not calibrated!");
|
||||||
|
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||||
|
yield();
|
||||||
|
esp_task_wdt_reset();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Ausgabe der Waage auf Display
|
// Ausgabe der Waage auf Display
|
||||||
if (pauseMainTask == 0 && weight != lastWeight && hasReadRfidTag == 0)
|
if (pauseMainTask == 0 && weight != lastWeight && hasReadRfidTag == 0)
|
||||||
{
|
{
|
||||||
(weight < 0) ? oledShowMessage("!! -1") : oledShowWeight(weight);
|
(weight < 0) ? oledShowMessage("!! -1") : oledShowWeight(weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Wenn Timer abgelaufen und nicht gerade ein RFID-Tag geschrieben wird
|
// Wenn Timer abgelaufen und nicht gerade ein RFID-Tag geschrieben wird
|
||||||
if (currentMillis - lastWeightReadTime >= weightReadInterval && hasReadRfidTag < 3)
|
if (currentMillis - lastWeightReadTime >= weightReadInterval && hasReadRfidTag < 3)
|
||||||
{
|
{
|
||||||
|
@ -16,6 +16,7 @@ int16_t weight = 0;
|
|||||||
uint8_t weigthCouterToApi = 0;
|
uint8_t weigthCouterToApi = 0;
|
||||||
uint8_t scale_tare_counter = 0;
|
uint8_t scale_tare_counter = 0;
|
||||||
uint8_t pauseMainTask = 0;
|
uint8_t pauseMainTask = 0;
|
||||||
|
uint8_t scaleCalibrated = 1;
|
||||||
|
|
||||||
Preferences preferences;
|
Preferences preferences;
|
||||||
const char* NVS_NAMESPACE = "scale";
|
const char* NVS_NAMESPACE = "scale";
|
||||||
@ -50,7 +51,7 @@ void scale_loop(void * parameter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_scale() {
|
uint8_t start_scale() {
|
||||||
Serial.println("Prüfe Calibration Value");
|
Serial.println("Prüfe Calibration Value");
|
||||||
long calibrationValue;
|
long calibrationValue;
|
||||||
|
|
||||||
@ -64,7 +65,10 @@ void start_scale() {
|
|||||||
|
|
||||||
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
|
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
|
||||||
|
|
||||||
if (isnan(calibrationValue) || calibrationValue < 1) calibrationValue = defaultScaleCalibrationValue;
|
if (isnan(calibrationValue) || calibrationValue < 1) {
|
||||||
|
calibrationValue = defaultScaleCalibrationValue;
|
||||||
|
scaleCalibrated = 0;
|
||||||
|
}
|
||||||
|
|
||||||
oledShowMessage("Scale Tare Please remove all");
|
oledShowMessage("Scale Tare Please remove all");
|
||||||
for (uint16_t i = 0; i < 2000; i++) {
|
for (uint16_t i = 0; i < 2000; i++) {
|
||||||
@ -97,6 +101,8 @@ void start_scale() {
|
|||||||
} else {
|
} else {
|
||||||
Serial.println("ScaleLoop-Task erfolgreich erstellt");
|
Serial.println("ScaleLoop-Task erfolgreich erstellt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (scaleCalibrated == 1) ? 1 : 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t calibrate_scale() {
|
uint8_t calibrate_scale() {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "HX711.h"
|
#include "HX711.h"
|
||||||
|
|
||||||
|
|
||||||
void start_scale();
|
uint8_t start_scale();
|
||||||
uint8_t calibrate_scale();
|
uint8_t calibrate_scale();
|
||||||
uint8_t tareScale();
|
uint8_t tareScale();
|
||||||
|
|
||||||
@ -14,6 +14,7 @@ extern int16_t weight;
|
|||||||
extern uint8_t weigthCouterToApi;
|
extern uint8_t weigthCouterToApi;
|
||||||
extern uint8_t scale_tare_counter;
|
extern uint8_t scale_tare_counter;
|
||||||
extern uint8_t pauseMainTask;
|
extern uint8_t pauseMainTask;
|
||||||
|
extern uint8_t scaleCalibrated;
|
||||||
|
|
||||||
extern TaskHandle_t ScaleTask;
|
extern TaskHandle_t ScaleTask;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user