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.

117 lines
3.0KB

  1. // Copyright 2014 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 WARPS_UI_H_
  29. #define WARPS_UI_H_
  30. #include "stmlib/stmlib.h"
  31. #include "stmlib/ui/event_queue.h"
  32. #include "warps/drivers/leds.h"
  33. #include "warps/drivers/switches.h"
  34. #include "warps/dsp/modulator.h"
  35. namespace warps {
  36. class CvScaler;
  37. class Settings;
  38. enum UiMode {
  39. UI_MODE_NORMAL,
  40. UI_MODE_CALIBRATION_C1,
  41. UI_MODE_CALIBRATION_C3,
  42. UI_MODE_CALIBRATION_LOW,
  43. UI_MODE_CALIBRATION_HIGH,
  44. UI_MODE_CALIBRATION_ERROR,
  45. UI_MODE_PANIC,
  46. UI_MODE_EASTER_EGG_DANCE
  47. };
  48. enum FactoryTestingCommand {
  49. FACTORY_TESTING_READ_POT,
  50. FACTORY_TESTING_READ_CV,
  51. FACTORY_TESTING_READ_GATE,
  52. FACTORY_TESTING_SET_BYPASS,
  53. FACTORY_TESTING_CALIBRATE,
  54. FACTORY_TESTING_READ_NORMALIZATION
  55. };
  56. class Ui {
  57. public:
  58. Ui() { }
  59. ~Ui() { }
  60. void Init(Settings* settings, CvScaler* cv_scaler, Modulator* modulator);
  61. void Poll();
  62. void DoEvents();
  63. void Panic() {
  64. mode_ = UI_MODE_PANIC;
  65. }
  66. uint8_t HandleFactoryTestingRequest(uint8_t command);
  67. private:
  68. void OnSwitchPressed(const stmlib::Event& e);
  69. void OnSwitchReleased(const stmlib::Event& e);
  70. void StartCalibration();
  71. void CalibrateC1();
  72. void CalibrateC3();
  73. void StartNormalizationCalibration();
  74. void CalibrateLow();
  75. void CalibrateHigh();
  76. void UpdateCarrierShape();
  77. bool DetectSecretHandshake();
  78. stmlib::EventQueue<16> queue_;
  79. Leds leds_;
  80. Switches switches_;
  81. Settings* settings_;
  82. CvScaler* cv_scaler_;
  83. Modulator* modulator_;
  84. UiMode mode_;
  85. uint32_t press_time_;
  86. uint8_t carrier_shape_;
  87. uint8_t secret_handshake_[6];
  88. static const uint8_t palette_[10][3];
  89. static const uint8_t easter_egg_palette_[10][3];
  90. DISALLOW_COPY_AND_ASSIGN(Ui);
  91. };
  92. } // namespace warps
  93. #endif // WARPS_UI_H_