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