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.

119 lines
3.0KB

  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_PAQUES,
  43. UI_MODE_FACTORY_TESTING
  44. };
  45. struct Settings {
  46. uint8_t mode;
  47. uint8_t range;
  48. uint8_t sync;
  49. uint8_t padding;
  50. };
  51. class Ui {
  52. public:
  53. Ui() { }
  54. ~Ui() { }
  55. void Init(Generator* generator, CvScaler* cv_scaler);
  56. void Poll();
  57. void DoEvents();
  58. void FlushEvents();
  59. void UpdateFactoryTestingFlags(
  60. uint8_t gate_input_flags,
  61. const uint16_t* adc_values);
  62. void set_led_color(uint16_t brightness, bool end_of_attack) {
  63. if (mode_ == UI_MODE_NORMAL) {
  64. if (end_of_attack) {
  65. leds_.set_value(brightness, 0);
  66. } else {
  67. leds_.set_value(0, brightness);
  68. }
  69. }
  70. }
  71. inline UiMode mode() const { return mode_; }
  72. private:
  73. void OnSwitchPressed(const stmlib::Event& e);
  74. void OnSwitchReleased(const stmlib::Event& e);
  75. void UpdateMode();
  76. void UpdateRange();
  77. void SaveState();
  78. stmlib::EventQueue<16> queue_;
  79. bool red_;
  80. bool green_;
  81. bool orange_;
  82. Leds leds_;
  83. Switches switches_;
  84. FactoryTestingSwitch factory_testing_switch_;
  85. uint32_t press_time_[kNumSwitches];
  86. UiMode mode_;
  87. Generator* generator_;
  88. CvScaler* cv_scaler_;
  89. Settings settings_;
  90. uint16_t version_token_;
  91. uint8_t mode_counter_;
  92. uint8_t range_counter_;
  93. uint8_t long_press_counter_;
  94. DISALLOW_COPY_AND_ASSIGN(Ui);
  95. };
  96. } // namespace tides
  97. #endif // TIDES_UI_H_