Make MPU-6050 send data only when it has new data

This commit is contained in:
Eiren Rain
2021-06-26 17:17:42 +03:00
parent 91bf86c60f
commit 6ea4ebd08c
2 changed files with 7 additions and 2 deletions

View File

@@ -57,7 +57,6 @@ bool blinking = false;
unsigned long blinkStart = 0;
unsigned long now_ms, last_ms = 0; //millis() timers
unsigned long last_battery_sample = 0;
unsigned long const start = millis();
bool secondImuActive = false;
void setConfig(DeviceConfig newConfig)

View File

@@ -37,6 +37,8 @@ namespace {
}
}
bool hasNewData = false;
void gatherCalibrationData(MPU9250 &imu);
void MPU6050Sensor::motionSetup(DeviceConfig * config) {
@@ -122,11 +124,15 @@ void MPU6050Sensor::motionLoop() {
q[3] = rawQuat.w;
quaternion.set(-q[1], q[0], q[2], q[3]);
quaternion *= sensorOffset;
hasNewData = true;
}
}
void MPU6050Sensor::sendData() {
sendQuat(&quaternion, PACKET_ROTATION);
if(hasNewData) {
sendQuat(&quaternion, PACKET_ROTATION);
hasNewData = false;
}
}
void MPU6050Sensor::startCalibration(int calibrationType) {