1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

Add gyro and magnetic custom alignment to MSP (#14019)

* Add magnetic dip and alignment to MSP

* Update PG

* Revert inclination addition

* Revert heading units

* space

* Use MSP_SENSOR_ALIGNMENT

* Missed bracket

* Adjust mag_declination range

* Add gyro custom alignment

* Remove precision from declination

* Revert remove precision from declination
This commit is contained in:
Mark Haslinghuis 2025-01-09 22:41:41 +01:00 committed by GitHub
parent a8d599e187
commit 51c09efe69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 60 additions and 5 deletions

View file

@ -1847,7 +1847,33 @@ case MSP_NAME:
sbufWriteU8(dst, gyroDeviceConfig(0)->alignment);
sbufWriteU8(dst, ALIGN_DEFAULT);
#endif
// Added in MSP API 1.47
switch (gyroConfig()->gyro_to_use) {
#ifdef USE_MULTI_GYRO
case GYRO_CONFIG_USE_GYRO_2:
sbufWriteU16(dst, gyroDeviceConfig(1)->customAlignment.roll);
sbufWriteU16(dst, gyroDeviceConfig(1)->customAlignment.pitch);
sbufWriteU16(dst, gyroDeviceConfig(1)->customAlignment.yaw);
break;
#endif
case GYRO_CONFIG_USE_GYRO_BOTH:
// for dual-gyro in "BOTH" mode we only read/write gyro 0
default:
sbufWriteU16(dst, gyroDeviceConfig(0)->customAlignment.roll);
sbufWriteU16(dst, gyroDeviceConfig(0)->customAlignment.pitch);
sbufWriteU16(dst, gyroDeviceConfig(0)->customAlignment.yaw);
break;
}
#ifdef USE_MAG
sbufWriteU16(dst, compassConfig()->mag_customAlignment.roll);
sbufWriteU16(dst, compassConfig()->mag_customAlignment.pitch);
sbufWriteU16(dst, compassConfig()->mag_customAlignment.yaw);
#else
sbufWriteU16(dst, 0);
sbufWriteU16(dst, 0);
sbufWriteU16(dst, 0);
#endif
break;
}
case MSP_ADVANCED_CONFIG:
@ -3024,7 +3050,36 @@ static mspResult_e mspProcessInCommand(mspDescriptor_t srcDesc, int16_t cmdMSP,
#else
gyroDeviceConfigMutable(0)->alignment = gyroAlignment;
#endif
}
// Added in API 1.47
if (sbufBytesRemaining(src) >= 6) {
switch (gyroConfig()->gyro_to_use) {
#ifdef USE_MULTI_GYRO
case GYRO_CONFIG_USE_GYRO_2:
gyroDeviceConfigMutable(1)->customAlignment.roll = sbufReadU16(src);
gyroDeviceConfigMutable(1)->customAlignment.pitch = sbufReadU16(src);
gyroDeviceConfigMutable(1)->customAlignment.yaw = sbufReadU16(src);
break;
#endif
case GYRO_CONFIG_USE_GYRO_BOTH:
// For dual-gyro in "BOTH" mode we'll only update gyro 0
default:
gyroDeviceConfigMutable(0)->customAlignment.roll = sbufReadU16(src);
gyroDeviceConfigMutable(0)->customAlignment.pitch = sbufReadU16(src);
gyroDeviceConfigMutable(0)->customAlignment.yaw = sbufReadU16(src);
break;
}
}
if (sbufBytesRemaining(src) >= 6) {
#ifdef USE_MAG
compassConfigMutable()->mag_customAlignment.roll = sbufReadU16(src);
compassConfigMutable()->mag_customAlignment.pitch = sbufReadU16(src);
compassConfigMutable()->mag_customAlignment.yaw = sbufReadU16(src);
#else
sbufReadU16(src);
sbufReadU16(src);
sbufReadU16(src);
#endif
}
break;
}