betaflight / betaflight

Open Source Flight Controller Firmware
GNU General Public License v3.0
8.06k stars 2.87k forks source link

Reschedule stats saving on disarm, if quad still moving #13637

Open limonspb opened 2 weeks ago

limonspb commented 2 weeks ago

Situation when stats_min_armed_time_s is set to something else than -1. This activates persistent stats saving upon disarm, like flights counter, total distance, total time in the air.

This can create a problem, when person disarms during crash, it can launch stats saving. And battery might unplug during stats saving, corrupting the configuration.

This change keeps rescheduling writeEEPROM if gyro is still moving. new parameter introduced stats_saving_max_gyro_rate in degrees.

For proper testing need a quad with a beeper. Steps:

  1. Props off.
  2. in CLI set stats_min_armed_time_s = 3, save
  3. Arm quad, wait for 3 seconds, wiggle quad while disarming.

Old behavior: second disarmed tones are heard. New behavior: second disarming tones are heard only after you stop wiggling quad.

possible future improvements:

  1. Take into account gyro moves during the last delay, not just the current state
  2. Take into account accel
github-actions[bot] commented 2 weeks ago

Do you want to test this code? You can flash it directly from Betaflight Configurator:

WARNING: It may be unstable. Use only for testing!