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.

139 lines
3.3KB

  1. // Copyright 2012 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 BRAIDS_UI_H_
  29. #define BRAIDS_UI_H_
  30. #include "stmlib/stmlib.h"
  31. #include "stmlib/ui/event_queue.h"
  32. #include "braids/drivers/display.h"
  33. #include "braids/drivers/encoder.h"
  34. #include "braids/settings.h"
  35. namespace braids {
  36. enum UiMode {
  37. MODE_SPLASH,
  38. MODE_EDIT,
  39. MODE_MENU,
  40. MODE_CALIBRATION_STEP_1,
  41. MODE_CALIBRATION_STEP_2,
  42. MODE_MARQUEE_EDITOR
  43. };
  44. class Ui {
  45. public:
  46. Ui() { }
  47. ~Ui() { }
  48. void Init();
  49. void Poll();
  50. void DoEvents();
  51. void FlushEvents();
  52. void Print(const char* text) {
  53. display_.Print(text);
  54. }
  55. void PrintDebugInteger(uint16_t x) {
  56. char buffer[5];
  57. buffer[4] = '\0';
  58. for (uint16_t i = 0; i < 4; ++i) {
  59. buffer[3 - i] = '0' + (x % 10);
  60. x /= 10;
  61. }
  62. Print(buffer);
  63. }
  64. inline void UpdateCv(
  65. int16_t cv_param,
  66. int16_t cv_color,
  67. int16_t cv_pitch,
  68. int16_t cv_fm) {
  69. cv_[0] = cv_param;
  70. cv_[1] = cv_color;
  71. cv_[2] = cv_pitch;
  72. cv_[3] = cv_fm;
  73. }
  74. inline void StepMarquee() {
  75. marquee_step_++;
  76. blink_ = true;
  77. }
  78. inline bool paques() const {
  79. return mode_ == MODE_MENU && \
  80. setting_ == SETTING_MARQUEE && \
  81. settings.paques();
  82. }
  83. // Overrides oscillator shape display when in meta mode.
  84. inline void set_meta_shape(MacroOscillatorShape shape) {
  85. meta_shape_ = shape;
  86. }
  87. private:
  88. void OnIncrement(const stmlib::Event& event);
  89. void OnClick();
  90. void OnLongClick();
  91. void RefreshDisplay();
  92. stmlib::EventQueue<16> queue_;
  93. uint32_t encoder_press_time_;
  94. bool inhibit_further_switch_events_;
  95. int16_t value_;
  96. uint8_t sub_clock_;
  97. UiMode mode_;
  98. int16_t setting_index_;
  99. Setting setting_;
  100. Display display_;
  101. Encoder encoder_;
  102. int16_t adc_code_c2_;
  103. int16_t adc_code_min_[2];
  104. int16_t cv_[4];
  105. uint8_t splash_frame_;
  106. uint8_t marquee_step_;
  107. uint8_t marquee_character_;
  108. bool marquee_dirty_character_;
  109. bool blink_;
  110. MacroOscillatorShape meta_shape_;
  111. DISALLOW_COPY_AND_ASSIGN(Ui);
  112. };
  113. } // namespace braids
  114. #endif // BRAIDS_UI_H_