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.

147 lines
3.8KB

  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. // User interface.
  28. #ifndef MARBLES_UI_H_
  29. #define MARBLES_UI_H_
  30. #include "stmlib/stmlib.h"
  31. #include "stmlib/ui/event_queue.h"
  32. #include "marbles/drivers/adc.h"
  33. #include "marbles/drivers/leds.h"
  34. #include "marbles/drivers/switches.h"
  35. namespace marbles {
  36. class ClockInputs;
  37. class CvReader;
  38. class ScaleRecorder;
  39. class Settings;
  40. enum UiMode {
  41. UI_MODE_NORMAL,
  42. UI_MODE_SELECT_SCALE,
  43. UI_MODE_RECORD_SCALE,
  44. UI_MODE_CALIBRATION_1,
  45. UI_MODE_CALIBRATION_2,
  46. UI_MODE_CALIBRATION_3,
  47. UI_MODE_CALIBRATION_4,
  48. UI_MODE_PANIC,
  49. };
  50. enum FactoryTestingCommand {
  51. FACTORY_TESTING_READ_POT,
  52. FACTORY_TESTING_READ_CV,
  53. FACTORY_TESTING_READ_GATE,
  54. FACTORY_TESTING_GENERATE_TEST_SIGNALS,
  55. FACTORY_TESTING_CALIBRATE,
  56. FACTORY_TESTING_READ_NORMALIZATION,
  57. FACTORY_TESTING_FORCE_DAC_CODE,
  58. FACTORY_TESTING_WRITE_CALIBRATION_DATA_NIBBLE,
  59. };
  60. struct AlternateKnobMapping {
  61. Switch unlock_switch;
  62. uint8_t* destination;
  63. };
  64. class Ui {
  65. public:
  66. Ui() { }
  67. ~Ui() { }
  68. void Init(
  69. Settings* settings,
  70. CvReader* cv_reader,
  71. ScaleRecorder* scale_recorder,
  72. ClockInputs* clock_inputs);
  73. void Poll();
  74. void DoEvents();
  75. void FlushEvents();
  76. uint8_t HandleFactoryTestingRequest(uint8_t command);
  77. bool recording_scale() const {
  78. return mode_ == UI_MODE_RECORD_SCALE;
  79. }
  80. bool output_test_mode() const {
  81. return output_test_mode_;
  82. }
  83. uint16_t output_test_forced_dac_code(int i) const {
  84. return output_test_forced_dac_code_[i];
  85. }
  86. void set_deja_vu_lock(bool deja_vu_lock) {
  87. deja_vu_lock_ = deja_vu_lock;
  88. }
  89. private:
  90. void UpdateLEDs();
  91. void OnSwitchPressed(const stmlib::Event& e);
  92. void OnSwitchReleased(const stmlib::Event& e);
  93. void NextCalibrationStep();
  94. void SaveState();
  95. void UpdateHiddenParameters();
  96. void TerminateScaleRecording();
  97. static LedColor MakeColor(uint8_t value, bool color_blind);
  98. stmlib::EventQueue<16> queue_;
  99. Leds leds_;
  100. Switches switches_;
  101. uint32_t press_time_[SWITCH_LAST];
  102. bool ignore_release_[SWITCH_LAST];
  103. UiMode mode_;
  104. Settings* settings_;
  105. CvReader* cv_reader_;
  106. ScaleRecorder* scale_recorder_;
  107. ClockInputs* clock_inputs_;
  108. static const LedColor palette_[4];
  109. static AlternateKnobMapping alternate_knob_mappings_[ADC_CHANNEL_LAST];
  110. float pot_value_[ADC_CHANNEL_LAST];
  111. bool setting_modification_flag_;
  112. bool deja_vu_lock_;
  113. bool output_test_mode_;
  114. uint16_t output_test_forced_dac_code_[4];
  115. uint32_t calibration_data_;
  116. DISALLOW_COPY_AND_ASSIGN(Ui);
  117. };
  118. } // namespace marbles
  119. #endif // MARBLES_UI_H_