added possibility to save and load the data

from flash for compass calibration
This commit is contained in:
2023-05-24 11:41:07 +02:00
parent 434f5a48c0
commit 1b25f59719
2 changed files with 38 additions and 1 deletions
+34 -1
View File
@@ -61,8 +61,10 @@ void CalibrateCompass::loop() {
if (changed)
this->lastChange = millis();
if (millis() - this->lastChange > this->maxTimeWithoutChange)
if (millis() - this->lastChange > this->maxTimeWithoutChange) {
this->state = State::Finished;
this->newData = true;
}
}
void CalibrateCompass::start() {
@@ -98,6 +100,37 @@ void CalibrateCompass::reset() {
this->state = State::Ready;
}
void CalibrateCompass::saveData() {
if (!this->newData)
return;
Preferences preferences;
preferences.begin("compassCalibration", false);
preferences.putInt("xLow", this->data.data[0][0]);
preferences.putInt("xHigh", this->data.data[0][1]);
preferences.putInt("yLow", this->data.data[1][0]);
preferences.putInt("yHigh", this->data.data[1][1]);
preferences.putInt("zLow", this->data.data[2][0]);
preferences.putInt("zHigh", this->data.data[2][1]);
preferences.end();
}
void CalibrateCompass::loadData() {
Preferences preferences;
preferences.begin("compassCalibration", true);
this->data.data[0][0] = preferences.getInt("xLow", 0);
this->data.data[0][1] = preferences.getInt("xHigh", 0);
this->data.data[1][0] = preferences.getInt("yLow", 0);
this->data.data[1][1] = preferences.getInt("yHigh", 0);
this->data.data[2][0] = preferences.getInt("zLow", 0);
this->data.data[2][1] = preferences.getInt("zHigh", 0);
preferences.end();
}
void CalibrateCompass::clearData() {
for (uint8_t i = 0; i < 3; i++) {
this->data.data[i][0] = 0;