Refactor implementation and add new settings to save state.
This commit is contained in:
@ -91,18 +91,15 @@ void loop() {
|
||||
// Process change in state of inputs and outputs.
|
||||
gravity.Process();
|
||||
|
||||
// Read CVs and call the update function for each channel.
|
||||
int cv1 = gravity.cv1.Read();
|
||||
int cv2 = gravity.cv2.Read();
|
||||
|
||||
CheckRunReset(cv1, cv2);
|
||||
// Check if cv run or reset is active and read cv.
|
||||
CheckRunReset(gravity.cv1, gravity.cv2);
|
||||
|
||||
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
||||
auto& ch = app.channel[i];
|
||||
// Only apply CV to the channel when the current channel has cv
|
||||
// mod configured.
|
||||
if (ch.isCvModActive()) {
|
||||
ch.applyCvMod(cv1, cv2);
|
||||
ch.applyCvMod(gravity.cv1.Read(), gravity.cv2.Read());
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,21 +170,21 @@ void HandleExtClockTick() {
|
||||
app.refresh_screen = true;
|
||||
}
|
||||
|
||||
void CheckRunReset(int cv1, int cv2) {
|
||||
if (app.cv_run == 1 && cv1 > 255 && !gravity.clock.IsPaused()) {
|
||||
gravity.clock.Stop();
|
||||
} else if (app.cv_run == 1 && cv1 < 255 && gravity.clock.IsPaused()) {
|
||||
void CheckRunReset(AnalogInput& cv1, AnalogInput& cv2) {
|
||||
// Clock Run
|
||||
if (app.cv_run == 1 || app.cv_run == 2) {
|
||||
const int val = (app.cv_run == 1) ? cv1.Read() : cv2.Read();
|
||||
if (val > AnalogInput::GATE_THRESHOLD && gravity.clock.IsPaused()) {
|
||||
gravity.clock.Start();
|
||||
} else if (app.cv_run == 2 && cv2 > 255 && !gravity.clock.IsPaused()) {
|
||||
} else if (val < AnalogInput::GATE_THRESHOLD && !gravity.clock.IsPaused()) {
|
||||
gravity.clock.Stop();
|
||||
} else if (app.cv_run == 2 && cv2 < 255 && gravity.clock.IsPaused()) {
|
||||
gravity.clock.Start();
|
||||
ResetOutputs();
|
||||
}
|
||||
}
|
||||
|
||||
// Clock Reset
|
||||
if (app.cv_reset == 1 && cv1 > 255) {
|
||||
gravity.clock.Reset();
|
||||
} else if (app.cv_reset == 2 && cv2 < 255) {
|
||||
if ((app.cv_reset == 1 && cv1.IsRisingEdge(AnalogInput::GATE_THRESHOLD)) ||
|
||||
(app.cv_reset == 2 && cv2.IsRisingEdge(AnalogInput::GATE_THRESHOLD))) {
|
||||
gravity.clock.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
// Define the constants for the current firmware.
|
||||
const char StateManager::SKETCH_NAME[] = "ALT GRAVITY";
|
||||
const char StateManager::SEMANTIC_VERSION[] = "V2.0.0BETA3"; // NOTE: This should match the version in the library.properties file.
|
||||
const char StateManager::SEMANTIC_VERSION[] = "V2.0.0BETA4"; // NOTE: This should match the version in the library.properties file.
|
||||
|
||||
// Number of available save slots.
|
||||
const byte StateManager::MAX_SAVE_SLOTS = 10;
|
||||
@ -87,6 +87,8 @@ void StateManager::reset(AppState& app) {
|
||||
app.selected_channel = default_app.selected_channel;
|
||||
app.selected_source = default_app.selected_source;
|
||||
app.selected_pulse = default_app.selected_pulse;
|
||||
app.cv_run = default_app.cv_run;
|
||||
app.cv_reset = default_app.cv_reset;
|
||||
|
||||
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
||||
app.channel[i].Init();
|
||||
@ -140,6 +142,8 @@ void StateManager::_saveState(const AppState& app, byte slot_index) {
|
||||
save_data.selected_channel = app.selected_channel;
|
||||
save_data.selected_source = static_cast<byte>(app.selected_source);
|
||||
save_data.selected_pulse = static_cast<byte>(app.selected_pulse);
|
||||
save_data.cv_run = app.cv_run;
|
||||
save_data.cv_reset = app.cv_reset;
|
||||
|
||||
// TODO: break this out into a separate function. Save State should be
|
||||
// broken out into global / per-channel save methods. When saving via
|
||||
@ -179,6 +183,8 @@ void StateManager::_loadState(AppState& app, byte slot_index) {
|
||||
app.selected_channel = load_data.selected_channel;
|
||||
app.selected_source = static_cast<Clock::Source>(load_data.selected_source);
|
||||
app.selected_pulse = static_cast<Clock::Pulse>(load_data.selected_pulse);
|
||||
app.cv_run = load_data.cv_run;
|
||||
app.cv_reset = load_data.cv_reset;
|
||||
|
||||
for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) {
|
||||
auto& ch = app.channel[i];
|
||||
|
||||
@ -76,6 +76,8 @@ class StateManager {
|
||||
byte selected_channel;
|
||||
byte selected_source;
|
||||
byte selected_pulse;
|
||||
byte cv_run;
|
||||
byte cv_reset;
|
||||
ChannelState channel_data[Gravity::OUTPUT_COUNT];
|
||||
};
|
||||
|
||||
|
||||
@ -19,6 +19,8 @@ const int CALIBRATED_HIGH = 512;
|
||||
|
||||
class AnalogInput {
|
||||
public:
|
||||
static const int GATE_THRESHOLD = 0;
|
||||
|
||||
AnalogInput() {}
|
||||
~AnalogInput() {}
|
||||
|
||||
@ -74,6 +76,18 @@ class AnalogInput {
|
||||
*/
|
||||
inline float Voltage() { return ((read_ / 512.0) * 5.0); }
|
||||
|
||||
/**
|
||||
* Checks for a rising edge transition across a threshold.
|
||||
*
|
||||
* @param threshold The value that the input must cross.
|
||||
* @return True if the value just crossed the threshold from below, false otherwise.
|
||||
*/
|
||||
inline bool IsRisingEdge(int16_t threshold) const {
|
||||
bool was_high = old_read_ > threshold;
|
||||
bool is_high = read_ > threshold;
|
||||
return is_high && !was_high;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t pin_;
|
||||
int16_t read_;
|
||||
|
||||
@ -82,7 +82,6 @@ class DigitalOutput {
|
||||
unsigned long last_triggered_;
|
||||
uint8_t trigger_duration_;
|
||||
uint8_t cv_pin_;
|
||||
uint8_t led_pin_;
|
||||
bool on_;
|
||||
|
||||
void update(uint8_t state) {
|
||||
|
||||
Reference in New Issue
Block a user