* @brief Updates gyroscope orientation values. */
| 168 | * @brief Updates gyroscope orientation values. |
| 169 | */ |
| 170 | void Widgets::Gyroscope::updateData() |
| 171 | { |
| 172 | if (!isEnabled()) |
| 173 | return; |
| 174 | |
| 175 | if (!VALIDATE_WIDGET(SerialStudio::DashboardGyroscope, m_index)) |
| 176 | return; |
| 177 | |
| 178 | const auto& gyro = GET_GROUP(SerialStudio::DashboardGyroscope, m_index); |
| 179 | if (gyro.datasets.size() != 3) |
| 180 | return; |
| 181 | |
| 182 | const double previousYaw = m_yaw; |
| 183 | const double previousRoll = m_roll; |
| 184 | const double previousPitch = m_pitch; |
| 185 | |
| 186 | double yawInput = 0; |
| 187 | double rollInput = 0; |
| 188 | double pitchInput = 0; |
| 189 | bool hasYaw = false; |
| 190 | bool hasRoll = false; |
| 191 | bool hasPitch = false; |
| 192 | readAxisInputs(gyro, yawInput, rollInput, pitchInput, hasYaw, hasRoll, hasPitch); |
| 193 | |
| 194 | applyEmaUpdate(yawInput, rollInput, pitchInput, hasYaw, hasRoll, hasPitch); |
| 195 | |
| 196 | auto normalizeAngle = [](double angle) -> double { |
| 197 | angle = std::fmod(angle + 180.0, 360.0); |
| 198 | if (angle < 0) |
| 199 | angle += 360.0; |
| 200 | |
| 201 | return angle - 180.0; |
| 202 | }; |
| 203 | |
| 204 | m_yaw = normalizeAngle(m_yaw); |
| 205 | m_roll = normalizeAngle(m_roll); |
| 206 | m_pitch = normalizeAngle(m_pitch); |
| 207 | |
| 208 | const bool yawChanged = DSP::notEqual(m_yaw, previousYaw); |
| 209 | const bool rollChanged = DSP::notEqual(m_roll, previousRoll); |
| 210 | const bool pitchChanged = DSP::notEqual(m_pitch, previousPitch); |
| 211 | if (yawChanged || rollChanged || pitchChanged) |
| 212 | Q_EMIT updated(); |
| 213 | } |
nothing calls this directly
no test coverage detected