clangtidy corrections part 1
This commit is contained in:
@@ -1,68 +1,79 @@
|
||||
/**
|
||||
* @file calibrateCompass.cpp
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2023-05-23
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "calibrateCompass.h"
|
||||
|
||||
CalibrateCompass::CalibrateCompass(QMC5883LCompass* compass) {
|
||||
CalibrateCompass::CalibrateCompass(QMC5883LCompass *compass)
|
||||
{
|
||||
this->compass = compass;
|
||||
this->state = State::Ready;
|
||||
this->clearData();
|
||||
this->activateOnlyChilds();
|
||||
}
|
||||
|
||||
void CalibrateCompass::runAsChild() {
|
||||
void CalibrateCompass::runAsChild()
|
||||
{
|
||||
if (this->state != State::Calibrating)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool changed = false;
|
||||
|
||||
this->compass->read();
|
||||
int x = this->compass->getX();
|
||||
int y = this->compass->getY();
|
||||
int z = this->compass->getZ();
|
||||
int xAxis = this->compass->getX();
|
||||
int yAxis = this->compass->getY();
|
||||
int zAxis = this->compass->getZ();
|
||||
|
||||
if(x < this->data.data[0][0]) {
|
||||
this->data.data[0][0] = x;
|
||||
if (xAxis < this->data.data[0][0])
|
||||
{
|
||||
this->data.data[0][0] = xAxis;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if(x > this->data.data[0][1]) {
|
||||
this->data.data[0][1] = x;
|
||||
if (xAxis > this->data.data[0][1])
|
||||
{
|
||||
this->data.data[0][1] = xAxis;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if(y < this->data.data[1][0]) {
|
||||
this->data.data[1][0] = y;
|
||||
if (yAxis < this->data.data[1][0])
|
||||
{
|
||||
this->data.data[1][0] = yAxis;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if(y > this->data.data[1][1]) {
|
||||
this->data.data[1][1] = y;
|
||||
if (yAxis > this->data.data[1][1])
|
||||
{
|
||||
this->data.data[1][1] = yAxis;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if(z < this->data.data[2][0]) {
|
||||
this->data.data[2][0] = z;
|
||||
if (zAxis < this->data.data[2][0])
|
||||
{
|
||||
this->data.data[2][0] = zAxis;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if(z > this->data.data[2][1]) {
|
||||
this->data.data[2][1] = z;
|
||||
if (zAxis > this->data.data[2][1])
|
||||
{
|
||||
this->data.data[2][1] = zAxis;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
this->lastChange = millis();
|
||||
|
||||
if (millis() - this->lastChange > this->maxTimeWithoutChange) {
|
||||
if (millis() - this->lastChange > this->maxTimeWithoutChange)
|
||||
{
|
||||
this->state = State::Finished;
|
||||
this->checkDataValidity();
|
||||
}
|
||||
@@ -70,9 +81,12 @@ void CalibrateCompass::runAsChild() {
|
||||
|
||||
void CalibrateCompass::run() {}
|
||||
|
||||
void CalibrateCompass::start() {
|
||||
void CalibrateCompass::start()
|
||||
{
|
||||
if (this->state != State::Ready)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->clearData();
|
||||
this->state = State::Calibrating;
|
||||
@@ -80,39 +94,45 @@ void CalibrateCompass::start() {
|
||||
this->lastChange = millis();
|
||||
}
|
||||
|
||||
void CalibrateCompass::useData() {
|
||||
if (!this->dataValid) {
|
||||
void CalibrateCompass::useData()
|
||||
{
|
||||
if (!this->dataValid)
|
||||
{
|
||||
std::cout << "CalibrateCompass::useData - Data not valid" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
this->compass->setCalibration( this->data.data[0][0],
|
||||
this->data.data[0][1],
|
||||
this->data.data[1][0],
|
||||
this->data.data[1][1],
|
||||
this->data.data[2][0],
|
||||
this->data.data[2][1]
|
||||
);
|
||||
this->compass->setCalibration(this->data.data[0][0],
|
||||
this->data.data[0][1],
|
||||
this->data.data[1][0],
|
||||
this->data.data[1][1],
|
||||
this->data.data[2][0],
|
||||
this->data.data[2][1]);
|
||||
|
||||
std::cout << "CalibrateCompass::useData " << *this << std::endl;
|
||||
std::cout << "CalibrateCompass::useData " << *this << std::endl;
|
||||
}
|
||||
|
||||
void CalibrateCompass::removeCalibration() {
|
||||
void CalibrateCompass::removeCalibration()
|
||||
{
|
||||
this->compass->clearCalibration();
|
||||
}
|
||||
|
||||
void CalibrateCompass::reset() {
|
||||
void CalibrateCompass::reset()
|
||||
{
|
||||
this->clearData();
|
||||
this->state = State::Ready;
|
||||
}
|
||||
|
||||
void CalibrateCompass::saveData() {
|
||||
void CalibrateCompass::saveData()
|
||||
{
|
||||
if (!this->dataValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Preferences preferences;
|
||||
preferences.begin("compass", 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]);
|
||||
@@ -123,7 +143,8 @@ void CalibrateCompass::saveData() {
|
||||
preferences.end();
|
||||
}
|
||||
|
||||
void CalibrateCompass::loadData() {
|
||||
void CalibrateCompass::loadData()
|
||||
{
|
||||
Preferences preferences;
|
||||
preferences.begin("compass", true);
|
||||
|
||||
@@ -138,20 +159,23 @@ void CalibrateCompass::loadData() {
|
||||
this->checkDataValidity();
|
||||
}
|
||||
|
||||
void CalibrateCompass::clearData() {
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
void CalibrateCompass::clearData()
|
||||
{
|
||||
for (uint8_t i = 0; i < 3; i++)
|
||||
{
|
||||
this->data.data[i][0] = 0;
|
||||
this->data.data[i][1] = 0;
|
||||
}
|
||||
this->dataValid = false;
|
||||
}
|
||||
|
||||
void CalibrateCompass::checkDataValidity() {
|
||||
void CalibrateCompass::checkDataValidity()
|
||||
{
|
||||
int sum = 0;
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
if (this->data.data[i][0] > INT16_MAX || this->data.data[i][0] < INT16_MIN
|
||||
|| this->data.data[i][1] > INT16_MAX || this->data.data[i][1] < INT16_MIN)
|
||||
{
|
||||
for (uint8_t i = 0; i < 3; i++)
|
||||
{
|
||||
if (this->data.data[i][0] > INT16_MAX || this->data.data[i][0] < INT16_MIN || this->data.data[i][1] > INT16_MAX || this->data.data[i][1] < INT16_MIN)
|
||||
{
|
||||
this->dataValid = false;
|
||||
return;
|
||||
}
|
||||
@@ -161,7 +185,8 @@ void CalibrateCompass::checkDataValidity() {
|
||||
this->dataValid = sum;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const CalibrateCompass& caliComp) {
|
||||
std::ostream &operator<<(std::ostream &os, const CalibrateCompass &caliComp)
|
||||
{
|
||||
os << "(";
|
||||
os << caliComp.data.data[0][0];
|
||||
os << ", ";
|
||||
|
||||
Reference in New Issue
Block a user