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.

100 lines
2.4KB

  1. // Copyright 2012 Olivier Gillet.
  2. //
  3. // Author: Olivier Gillet (olivier@mutable-instruments.net)
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. //
  16. // User interface handling.
  17. #ifndef EDGES_UI_H_
  18. #define EDGES_UI_H_
  19. #include "avrlibx/avrlibx.h"
  20. #include "edges/hardware_config.h"
  21. namespace edges {
  22. enum Mode {
  23. MODE_NORMAL,
  24. MODE_MENU,
  25. MODE_CALIBRATE_1,
  26. MODE_CALIBRATE_2,
  27. MODE_RECORDING,
  28. MODE_LEARNING_MIDI_CHANNEL
  29. };
  30. static const uint8_t kNumSwitches = 6;
  31. class Ui {
  32. public:
  33. Ui() { }
  34. ~Ui() { }
  35. void Init();
  36. static void set_gate(uint8_t gate) { gate_ = gate; }
  37. static void set_cv(uint8_t channel, uint16_t cv) {
  38. if (mode_ >= MODE_CALIBRATE_1 &&
  39. mode_ <= MODE_CALIBRATE_2 &&
  40. channel == edited_channel_) {
  41. calibration_cv_[mode_ - MODE_CALIBRATE_1] = cv;
  42. }
  43. cv_[channel] = cv;
  44. }
  45. static uint16_t cv(uint8_t channel) {
  46. if (mode_ == MODE_RECORDING && channel == edited_channel_) {
  47. return root_cv_;
  48. } else {
  49. return cv_[channel];
  50. }
  51. }
  52. static void Poll();
  53. static uint8_t gate() { return gate_; }
  54. static Mode mode() { return mode_; }
  55. private:
  56. static void OnSwitchHeld(uint8_t index);
  57. static void OnSwitchReleased(uint8_t index);
  58. static uint8_t edited_channel_;
  59. static Mode mode_;
  60. static uint8_t gate_;
  61. // Used for dimming LEDs.
  62. static uint16_t leds_pwm_counter_;
  63. // Used for detecting long switch pressed.
  64. static uint16_t switch_time_counter_;
  65. static uint16_t calibration_cv_[2];
  66. static uint16_t root_cv_;
  67. static uint16_t cv_[2 * kNumChannels];
  68. static Leds leds_;
  69. static Switches switches_;
  70. static Gpio<PortC, 1> midi_learn_switch_;
  71. static Gpio<PortC, 3> midi_mode_switch_;
  72. static uint8_t debounce_history_[kNumSwitches];
  73. DISALLOW_COPY_AND_ASSIGN(Ui);
  74. };
  75. extern Ui ui;
  76. } // namespace edges
  77. #endif // EDGES_UI_H_