Files
-
blinds / hardware_design / pcb / blinds_v60.brd
-
blinds / hardware_design / pcb / blinds_v60.sch
-
braids / hardware_design / pcb / braids_v50.brd
-
braids / hardware_design / pcb / braids_v50.sch
-
branches / hardware_design / pcb / branches_v40.brd
-
branches / hardware_design / pcb / branches_v40.sch
-
clouds / hardware_design / pcb / clouds_v30.brd
-
clouds / hardware_design / pcb / clouds_v30.sch
-
ears / hardware_design / panel / ears_panel_v30.brd
-
ears / hardware_design / panel / ears_panel_v30.sch
-
ears / hardware_design / pcb / ears_v40.brd
-
ears / hardware_design / pcb / ears_v40.sch
-
edges / hardware_design / pcb / edges_expander_v01.brd
-
edges / hardware_design / pcb / edges_expander_v01.sch
-
edges / hardware_design / pcb / edges_v20.brd
-
edges / hardware_design / pcb / edges_v20.sch
-
elements / hardware_design / pcb / elements_v02.brd
-
elements / hardware_design / pcb / elements_v02.sch
-
frames / hardware_design / pcb / frames_v03.brd
-
frames / hardware_design / pcb / frames_v03.sch
-
grids / hardware_design / pcb / grids_v02.brd
-
grids / hardware_design / pcb / grids_v02.sch
-
kinks / hardware_design / pcb / kinks_v41.brd
-
kinks / hardware_design / pcb / kinks_v41.sch
-
links / hardware_design / pcb / links_v40.brd
-
links / hardware_design / pcb / links_v40.sch
-
marbles / hardware_design / pcb / marbles_v70.brd
-
marbles / hardware_design / pcb / marbles_v70.sch
-
peaks / hardware_design / pcb / peaks_v30.brd
-
peaks / hardware_design / pcb / peaks_v30.sch
-
plaits / hardware_design / pcb / plaits_v50.brd
-
plaits / hardware_design / pcb / plaits_v50.sch
-
rings / hardware_design / pcb / rings_v30.brd
-
rings / hardware_design / pcb / rings_v30.sch
-
ripples / hardware_design / pcb / ripples_v40.brd
-
ripples / hardware_design / pcb / ripples_v40.sch
-
shades / hardware_design / pcb / shades_v30.brd
-
shades / hardware_design / pcb / shades_v30.sch
-
shelves / hardware_design / pcb / shelves_expander_v10.brd
-
shelves / hardware_design / pcb / shelves_expander_v10.sch
-
shelves / hardware_design / pcb / shelves_v05.brd
-
shelves / hardware_design / pcb / shelves_v05.sch
-
stages / hardware_design / pcb / stages_v70.brd
-
stages / hardware_design / pcb / stages_v70.sch
-
streams / hardware_design / pcb / streams_v02_bargraph.brd
-
streams / hardware_design / pcb / streams_v02_bargraph.sch
-
streams / hardware_design / pcb / streams_v05.brd
-
streams / hardware_design / pcb / streams_v05.sch
-
tides / hardware_design / pcb / tides_v40.brd
-
tides / hardware_design / pcb / tides_v40.sch
-
veils / hardware_design / pcb / veils_v40.brd
-
veils / hardware_design / pcb / veils_v40.sch
-
volts / hardware_design / pcb / volts_v01.brd
-
volts / hardware_design / pcb / volts_v01.sch
-
warps / hardware_design / pcb / warps_v30.brd
-
warps / hardware_design / pcb / warps_v30.sch
-
yarns / hardware_design / pcb / yarns_v03.brd
-
yarns / hardware_design / pcb / yarns_v03.sch
Last update 6 years 1 month
by
Olivier Gillet
Fileselements | |
---|---|
.. | |
bootloader | |
drivers | |
dsp | |
hardware_design | |
resources | |
samples | |
test | |
__init__.py | |
cv_scaler.cc | |
cv_scaler.h | |
elements.cc | |
makefile | |
meter.h | |
resources.cc | |
resources.h | |
ui.cc | |
ui.h |
ui.cc// Copyright 2014 Olivier Gillet. // // Author: Olivier Gillet (ol.gillet@gmail.com) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // // See http://creativecommons.org/licenses/MIT/ for more information. // // ----------------------------------------------------------------------------- // // User interface. #include "elements/ui.h" #include <algorithm> #include "stmlib/system/system_clock.h" #include "elements/cv_scaler.h" #include "elements/dsp/part.h" namespace elements { using namespace std; using namespace stmlib; void Ui::Init(Part* part, CvScaler* cv_scaler) { leds_.Init(); switch_.Init(); mode_ = UI_MODE_NORMAL; // UI_MODE_DISPLAY_MODEL; part_ = part; cv_scaler_ = cv_scaler; part_->set_easter_egg(cv_scaler_->boot_in_easter_egg_mode()); part_->set_resonator_model(ResonatorModel(cv_scaler_->resonator_model())); } void Ui::Poll() { // 1kHz. system_clock.Tick(); switch_.Debounce(); if (switch_.just_pressed()) { queue_.AddEvent(CONTROL_SWITCH, 0, 0); press_time_ = system_clock.milliseconds(); } if (switch_.pressed() && \ press_time_ && (system_clock.milliseconds() - press_time_) >= 3000) { if (cv_scaler_->ready_for_calibration()) { queue_.AddEvent(CONTROL_SWITCH, 1, 0); press_time_ = 0; } else if (cv_scaler_->resonator_high()) { if (cv_scaler_->exciter_low()) { queue_.AddEvent(CONTROL_SWITCH, 2, 0); } else { queue_.AddEvent(CONTROL_SWITCH, 3, 0); } press_time_ = 0; } } if (switch_.released() && press_time_) { queue_.AddEvent( CONTROL_SWITCH, 0, system_clock.milliseconds() - press_time_ + 1); } bool blink = (system_clock.milliseconds() & 127) > 64; switch (mode_) { case UI_MODE_NORMAL: leds_.set_gate(part_->gate()); leds_.set_exciter( lut_db_led_brightness[int32_t(part_->exciter_level() * 512.0f)]); leds_.set_resonator( lut_db_led_brightness[int32_t(part_->resonator_level() * 512.0f)]); break; case UI_MODE_CALIBRATION_1: leds_.set_gate(!blink); leds_.set_exciter(blink ? 255 : 0); leds_.set_resonator(0); break; case UI_MODE_CALIBRATION_2: leds_.set_gate(!blink); leds_.set_exciter(0); leds_.set_resonator(blink ? 255 : 0); break; case UI_MODE_PANIC: leds_.set_gate(blink); leds_.set_exciter(blink ? 255 : 0); leds_.set_resonator(blink ? 0 : 255); break; case UI_MODE_DISPLAY_MODEL: { bool blink = (system_clock.milliseconds() & 255) > 128; uint8_t count = ((system_clock.milliseconds()) >> 8) & 3; bool pulse = (count <= part_->resonator_model()) && blink; leds_.set_gate(pulse); leds_.set_exciter(pulse ? 255 : 0); leds_.set_resonator(pulse ? 255 : 0); } break; } if (part_->bypass()) { leds_.set_gate(true); leds_.set_exciter(255); leds_.set_resonator(255); } leds_.Write(); } void Ui::FlushEvents() { queue_.Flush(); } void Ui::OnSwitchPressed(const Event& e) { switch (e.control_id) { case 0: if (mode_ == UI_MODE_CALIBRATION_1) { CalibrateC1(); } else if (mode_ == UI_MODE_CALIBRATION_2) { CalibrateC3(); } else { gate_ = true; } break; case 1: mode_ = UI_MODE_CALIBRATION_1; break; case 2: part_->set_easter_egg(!part_->easter_egg()); cv_scaler_->set_boot_in_easter_egg_mode(part_->easter_egg()); cv_scaler_->SaveCalibration(); gate_ = false; break; case 3: part_->set_resonator_model( ResonatorModel((part_->resonator_model() + 1) % 3)); cv_scaler_->set_resonator_model(part_->resonator_model()); cv_scaler_->SaveCalibration(); gate_ = false; mode_ = UI_MODE_DISPLAY_MODEL; break; default: break; } } void Ui::OnSwitchReleased(const Event& e) { gate_ = false; } void Ui::CalibrateC1() { cv_scaler_->CalibrateC1(); cv_scaler_->CalibrateOffsets(); mode_ = UI_MODE_CALIBRATION_2; } void Ui::CalibrateC3() { bool success = cv_scaler_->CalibrateC3(); if (success) { cv_scaler_->SaveCalibration(); mode_ = UI_MODE_NORMAL; } else { mode_ = UI_MODE_PANIC; } } void Ui::DoEvents() { while (queue_.available()) { Event e = queue_.PullEvent(); if (e.control_type == CONTROL_SWITCH) { if (e.data == 0) { OnSwitchPressed(e); } else { OnSwitchReleased(e); } } } if (mode_ == UI_MODE_DISPLAY_MODEL) { if (queue_.idle_time() > 4000) { mode_ = UI_MODE_NORMAL; queue_.Touch(); } } else { if (queue_.idle_time() > 800 && mode_ == UI_MODE_PANIC) { mode_ = UI_MODE_NORMAL; } if (queue_.idle_time() > 1000) { queue_.Touch(); } } } uint8_t Ui::HandleFactoryTestingRequest(uint8_t command) { uint8_t argument = command & 0x1f; command = command >> 5; uint8_t reply = 0; switch (command) { case FACTORY_TESTING_READ_POT: reply = cv_scaler_->pot_value(argument); break; case FACTORY_TESTING_READ_CV: reply = cv_scaler_->cv_value(argument); break; case FACTORY_TESTING_READ_GATE: if (argument == 0x00) { return gate_; } else { return cv_scaler_->gate(); } break; case FACTORY_TESTING_SET_BYPASS: part_->set_bypass(argument); break; case FACTORY_TESTING_CALIBRATE: if (argument == 0) { mode_ = UI_MODE_CALIBRATION_1; } else if (argument == 1) { CalibrateC1(); } else { CalibrateC3(); } break; } return reply; } } // namespace elements