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.

106 lines
2.8KB

  1. // Copyright 2016 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. #ifndef PLAITS_SETTINGS_H_
  29. #define PLAITS_SETTINGS_H_
  30. #include "stmlib/stmlib.h"
  31. #include "stmlib/system/storage.h"
  32. #include "plaits/drivers/cv_adc.h"
  33. namespace plaits {
  34. struct ChannelCalibrationData {
  35. float offset;
  36. float scale;
  37. int16_t normalization_detection_threshold;
  38. inline float Transform(float x) const {
  39. return x * scale + offset;
  40. }
  41. };
  42. struct PersistentData {
  43. ChannelCalibrationData channel_calibration_data[CV_ADC_CHANNEL_LAST];
  44. uint8_t padding[16];
  45. enum { tag = 0x494C4143 }; // CALI
  46. };
  47. struct State {
  48. uint8_t engine;
  49. uint8_t lpg_colour;
  50. uint8_t decay;
  51. uint8_t octave;
  52. uint8_t color_blind;
  53. uint8_t padding[3];
  54. enum { tag = 0x54415453 }; // STAT
  55. };
  56. class Settings {
  57. public:
  58. Settings() { }
  59. ~Settings() { }
  60. bool Init();
  61. void SavePersistentData();
  62. void SaveState();
  63. inline const ChannelCalibrationData& calibration_data(int channel) const {
  64. return persistent_data_.channel_calibration_data[channel];
  65. }
  66. inline ChannelCalibrationData* mutable_calibration_data(int channel) {
  67. return &persistent_data_.channel_calibration_data[channel];
  68. }
  69. inline const State& state() const {
  70. return state_;
  71. }
  72. inline State* mutable_state() {
  73. return &state_;
  74. }
  75. private:
  76. PersistentData persistent_data_;
  77. State state_;
  78. stmlib::ChunkStorage<
  79. 0x08004000,
  80. 0x08008000,
  81. PersistentData,
  82. State> chunk_storage_;
  83. DISALLOW_COPY_AND_ASSIGN(Settings);
  84. };
  85. } // namespace plaits
  86. #endif // PLAITS_SETTINGS_H_