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.

124 lines
3.1KB

  1. // Copyright 2013 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
  28. #ifndef TIDES_UI_H_
  29. #define TIDES_UI_H_
  30. #include "stmlib/stmlib.h"
  31. #include "stmlib/ui/event_queue.h"
  32. #include "tides/drivers/factory_testing_switch.h"
  33. #include "tides/drivers/leds.h"
  34. #include "tides/drivers/switches.h"
  35. namespace tides {
  36. class Generator;
  37. class CvScaler;
  38. enum UiMode {
  39. UI_MODE_NORMAL,
  40. UI_MODE_CALIBRATION_C2,
  41. UI_MODE_CALIBRATION_C4,
  42. UI_MODE_FACTORY_TESTING,
  43. UI_MODE_FEATURE_SWITCH,
  44. UI_MODE_QUANTIZE,
  45. };
  46. struct Settings {
  47. uint8_t mode;
  48. uint8_t range;
  49. uint8_t sync;
  50. uint8_t magic_number; /* don't move that line around! */
  51. uint8_t quantize;
  52. uint8_t feature_mode;
  53. uint8_t padding[2];
  54. };
  55. class Ui {
  56. public:
  57. Ui() { }
  58. ~Ui() { }
  59. void Init(Generator* generator, CvScaler* cv_scaler);
  60. void Poll();
  61. void DoEvents();
  62. void FlushEvents();
  63. void UpdateFactoryTestingFlags(
  64. uint8_t gate_input_flags,
  65. const uint16_t* adc_values);
  66. void set_led_color(uint16_t brightness, bool end_of_attack) {
  67. if (mode_ == UI_MODE_NORMAL) {
  68. if (end_of_attack) {
  69. leds_.set_value(brightness, 0);
  70. } else {
  71. leds_.set_value(0, brightness);
  72. }
  73. }
  74. }
  75. inline UiMode mode() const { return mode_; }
  76. private:
  77. void OnSwitchPressed(const stmlib::Event& e);
  78. void OnSwitchReleased(const stmlib::Event& e);
  79. void UpdateMode();
  80. void UpdateRange();
  81. void SaveState();
  82. stmlib::EventQueue<16> queue_;
  83. bool red_;
  84. bool green_;
  85. bool orange_;
  86. Leds leds_;
  87. Switches switches_;
  88. FactoryTestingSwitch factory_testing_switch_;
  89. uint32_t press_time_[kNumSwitches];
  90. UiMode mode_;
  91. Generator* generator_;
  92. CvScaler* cv_scaler_;
  93. Settings settings_;
  94. uint16_t version_token_;
  95. uint8_t mode_counter_;
  96. uint8_t range_counter_;
  97. uint8_t long_press_counter_;
  98. uint8_t ignore_releases_;
  99. DISALLOW_COPY_AND_ASSIGN(Ui);
  100. };
  101. } // namespace tides
  102. #endif // TIDES_UI_H_