MCPcopy Create free account
hub / github.com/ManuelW77/Filaman / start_scale

Function start_scale

src/scale.cpp:217–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215}
216
217void start_scale(bool touchSensorConnected) {
218 Serial.println("Prüfe Calibration Value");
219 float calibrationValue;
220
221 // NVS lesen
222 Preferences preferences;
223 preferences.begin(NVS_NAMESPACE_SCALE, true); // true = readonly
224 if(preferences.isKey(NVS_KEY_CALIBRATION)){
225 calibrationValue = preferences.getFloat(NVS_KEY_CALIBRATION);
226 scaleCalibrated = true;
227 }else{
228 calibrationValue = SCALE_DEFAULT_CALIBRATION_VALUE;
229 scaleCalibrated = false;
230 }
231
232 // auto Tare
233 // Wenn Touch Sensor verbunden, dann autoTare auf false setzen
234 // Danach prüfen was in NVS gespeichert ist
235 autoTare = (touchSensorConnected) ? false : true;
236 autoTare = preferences.getBool(NVS_KEY_AUTOTARE, autoTare);
237
238 preferences.end();
239
240 Serial.print("Read Scale Calibration Value ");
241 Serial.println(calibrationValue);
242
243 scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
244
245 oledShowProgressBar(6, 7, DISPLAY_BOOT_TEXT, "Serching scale");
246 for (uint16_t i = 0; i < 3000; i++) {
247 yield();
248 vTaskDelay(pdMS_TO_TICKS(1));
249 esp_task_wdt_reset();
250 }
251
252 while(!scale.is_ready()) {
253 vTaskDelay(pdMS_TO_TICKS(5000));
254 }
255
256 scale.set_scale(calibrationValue);
257 //vTaskDelay(pdMS_TO_TICKS(5000));
258
259 // Initialize weight stabilization filter
260 resetWeightFilter();
261
262 // Display Gewicht
263 oledShowWeight(0);
264
265 Serial.println("starte Scale Task");
266 BaseType_t result = xTaskCreatePinnedToCore(
267 scale_loop, /* Function to implement the task */
268 "ScaleLoop", /* Name of the task */
269 2048, /* Stack size in words */
270 NULL, /* Task input parameter */
271 scaleTaskPrio, /* Priority of the task */
272 &ScaleTask, /* Task handle. */
273 scaleTaskCore); /* Core where the task should run */
274

Callers 1

setupFunction · 0.85

Calls 3

oledShowProgressBarFunction · 0.85
resetWeightFilterFunction · 0.85
oledShowWeightFunction · 0.85

Tested by

no test coverage detected