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.

125 lines
3.2KB

  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 RINGS_UI_H_
  29. #define RINGS_UI_H_
  30. #include "stmlib/stmlib.h"
  31. #include "stmlib/ui/event_queue.h"
  32. #include "rings/drivers/leds.h"
  33. #include "rings/drivers/switches.h"
  34. namespace rings {
  35. class Settings;
  36. class CvScaler;
  37. class Part;
  38. class StringSynthPart;
  39. enum UiMode {
  40. UI_MODE_NORMAL,
  41. UI_MODE_CALIBRATION_C1,
  42. UI_MODE_CALIBRATION_C3,
  43. UI_MODE_CALIBRATION_LOW,
  44. UI_MODE_CALIBRATION_HIGH,
  45. UI_MODE_EASTER_EGG_INTRO,
  46. UI_MODE_EASTER_EGG_OUTRO,
  47. UI_MODE_PANIC,
  48. };
  49. enum FactoryTestingCommand {
  50. FACTORY_TESTING_READ_POT,
  51. FACTORY_TESTING_READ_CV,
  52. FACTORY_TESTING_READ_GATE,
  53. FACTORY_TESTING_SET_BYPASS,
  54. FACTORY_TESTING_CALIBRATE,
  55. FACTORY_TESTING_READ_NORMALIZATION,
  56. };
  57. class Ui {
  58. public:
  59. Ui() { }
  60. ~Ui() { }
  61. void Init(
  62. Settings* settings,
  63. CvScaler* cv_scaler,
  64. Part* part,
  65. StringSynthPart* string_synth);
  66. void Poll();
  67. void DoEvents();
  68. void FlushEvents();
  69. void Panic() {
  70. mode_ = UI_MODE_PANIC;
  71. }
  72. void set_strumming_flag(bool flag) {
  73. if (flag) {
  74. // Make sure the LED is off for a short enough time.
  75. strumming_flag_counter_ = std::min(50L, strumming_flag_interval_ >> 2);
  76. strumming_flag_interval_ = 0;
  77. }
  78. }
  79. uint8_t HandleFactoryTestingRequest(uint8_t command);
  80. private:
  81. void OnSwitchPressed(const stmlib::Event& e);
  82. void OnSwitchReleased(const stmlib::Event& e);
  83. void StartCalibration();
  84. void CalibrateC1();
  85. void CalibrateC3();
  86. void StartNormalizationCalibration();
  87. void CalibrateLow();
  88. void CalibrateHigh();
  89. void SaveState();
  90. void AnimateEasterEggLeds();
  91. stmlib::EventQueue<16> queue_;
  92. Leds leds_;
  93. Switches switches_;
  94. uint32_t press_time_[kNumSwitches];
  95. UiMode mode_;
  96. int32_t strumming_flag_counter_;
  97. int32_t strumming_flag_interval_;
  98. Settings* settings_;
  99. CvScaler* cv_scaler_;
  100. Part* part_;
  101. StringSynthPart* string_synth_;
  102. DISALLOW_COPY_AND_ASSIGN(Ui);
  103. };
  104. } // namespace rings
  105. #endif // RINGS_UI_H_