You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.7KB

  1. // Copyright 2015 Olivier Gillet.
  2. //
  3. // Author: Olivier Gillet (ol.gillet@gmail.com)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. // See http://creativecommons.org/licenses/MIT/ for more information.
  24. //
  25. // -----------------------------------------------------------------------------
  26. //
  27. // Settings storage.
  28. #include "warps/settings.h"
  29. #include "stmlib/system/storage.h"
  30. namespace warps {
  31. stmlib::Storage<1> storage;
  32. void Settings::Init() {
  33. freshly_baked_ = false;
  34. if (!storage.ParsimoniousLoad(&data_, &version_token_)) {
  35. data_.calibration_data.pitch_offset = 100.00f;
  36. data_.calibration_data.pitch_scale = -110.00f;
  37. data_.calibration_data.offset[0] = 0.909f; // (-10*-36/120.0)/3.3
  38. data_.calibration_data.offset[1] = 0.909f;
  39. data_.calibration_data.offset[2] = 0.495f;
  40. data_.calibration_data.offset[3] = 0.505f;
  41. // normalization probe = LOW ->
  42. // ADC = 1 / 3.3 * (-36/120.0 * -10 + -36/300.0 * 0.0) = 0.91
  43. // normalization probe = HIGH ->
  44. // ADC = 1 / 3.3 * (-36/120.0 * -10 + -36/300.0 * 3.3) = 0.79
  45. data_.calibration_data.normalization_detection_threshold[0] = 0.85f;
  46. data_.calibration_data.normalization_detection_threshold[1] = 0.85f;
  47. data_.state.carrier_shape = 1;
  48. data_.state.boot_in_easter_egg_mode = 0;
  49. freshly_baked_ = true;
  50. Save();
  51. }
  52. for (int i = 0; i < 2; ++i) {
  53. if (data_.calibration_data.normalization_detection_threshold[i] > 0.9f ||
  54. data_.calibration_data.normalization_detection_threshold[i] < 0.8f) {
  55. data_.calibration_data.normalization_detection_threshold[i] = 0.85f;
  56. }
  57. }
  58. }
  59. void Settings::Save() {
  60. storage.ParsimoniousSave(data_, &version_token_);
  61. }
  62. } // namespace warps