feat: Add CV input indicators to the display, optimize redraws based on CV value changes, and disable outputs when entering calibration mode.

This commit is contained in:
2026-03-09 19:49:49 -07:00
parent dc1a6ff5c3
commit a2ad5d244e

View File

@ -41,6 +41,8 @@ bool prev_gate1 = false;
bool prev_gate2 = false; bool prev_gate2 = false;
bool ff_state = false; bool ff_state = false;
bool needs_redraw = true; bool needs_redraw = true;
int last_cv1_draw = -1000;
int last_cv2_draw = -1000;
unsigned long last_redraw = 0; unsigned long last_redraw = 0;
bool prev_both_buttons = false; bool prev_both_buttons = false;
@ -220,18 +222,35 @@ void UpdateCalibrationDisplay() {
DisplayCalibrationPoint(&gravity.cv2, "CV2: ", 1); DisplayCalibrationPoint(&gravity.cv2, "CV2: ", 1);
} }
void UpdateDisplay() { // UpdateDisplay
void UpdateDisplay(int cv1_val, int cv2_val) {
// Comp 1 graphics (Left) // Comp 1 graphics (Left)
int c1_h = max((comp1_size * 3) / 64, 1); int c1_h = max((comp1_size * 3) / 64, 1);
int c1_center = 26 - ((comp1_shift * 3) / 64); int c1_center = 26 - ((comp1_shift * 3) / 64);
int c1_y = c1_center - (c1_h / 2); int c1_y = c1_center - (c1_h / 2);
gravity.display.drawBox(20, c1_y, 44, c1_h); gravity.display.drawFrame(20, c1_y, 44, c1_h);
// CV 1 Indicator (Filled Box, 50% width, from 0V center)
int cv1_y = constrain(26 - ((cv1_val * 3) / 64), 2, 50);
if (cv1_val >= 0) {
gravity.display.drawBox(31, cv1_y, 22, 26 - cv1_y);
} else {
gravity.display.drawBox(31, 26, 22, cv1_y - 26);
}
// Comp 2 graphics (Right) // Comp 2 graphics (Right)
int c2_h = max((comp2_size * 3) / 64, 1); int c2_h = max((comp2_size * 3) / 64, 1);
int c2_center = 26 - ((comp2_shift * 3) / 64); int c2_center = 26 - ((comp2_shift * 3) / 64);
int c2_y = c2_center - (c2_h / 2); int c2_y = c2_center - (c2_h / 2);
gravity.display.drawBox(74, c2_y, 44, c2_h); gravity.display.drawFrame(74, c2_y, 44, c2_h);
// CV 2 Indicator (Filled Box, 50% width, from 0V center)
int cv2_y = constrain(26 - ((cv2_val * 3) / 64), 2, 50);
if (cv2_val >= 0) {
gravity.display.drawBox(85, cv2_y, 22, 26 - cv2_y);
} else {
gravity.display.drawBox(85, 26, 22, cv2_y - 26);
}
// Restore solid drawing for labels // Restore solid drawing for labels
gravity.display.setDrawColor(1); gravity.display.setDrawColor(1);
@ -306,6 +325,11 @@ void loop() {
if (current_mode == MODE_COMPARATOR) { if (current_mode == MODE_COMPARATOR) {
current_mode = MODE_CALIBRATION; current_mode = MODE_CALIBRATION;
cal_selected_param = 0; cal_selected_param = 0;
// Turn off all outputs to prevent phantom gates while tuning
for (int i = 0; i < 6; i++) {
gravity.outputs[i].Update(LOW);
}
} else { } else {
SaveCalibration(); SaveCalibration();
current_mode = MODE_COMPARATOR; current_mode = MODE_COMPARATOR;
@ -374,18 +398,27 @@ void loop() {
eeprom_needs_save = false; eeprom_needs_save = false;
} }
// Force frequent redraws in calibration mode for immediate feedback if (current_mode == MODE_COMPARATOR) {
if (current_mode == MODE_CALIBRATION && (millis() - last_redraw >= 30)) { if (abs(cv1_val - last_cv1_draw) > 12 || abs(cv2_val - last_cv2_draw) > 12) {
needs_redraw = true; needs_redraw = true;
last_redraw = millis(); }
} else if (current_mode == MODE_CALIBRATION) {
// Need frequent redraws in calibration to see the live target input
if (abs(cv1_val - last_cv1_draw) >= 2 || abs(cv2_val - last_cv2_draw) >= 2) {
needs_redraw = true;
}
} }
if (needs_redraw) { // Cap framerate so display I2C calls do not block gate loop
if (needs_redraw && (millis() - last_redraw >= 30)) {
needs_redraw = false; needs_redraw = false;
last_redraw = millis();
gravity.display.firstPage(); gravity.display.firstPage();
do { do {
if (current_mode == MODE_COMPARATOR) { if (current_mode == MODE_COMPARATOR) {
UpdateDisplay(); last_cv1_draw = cv1_val;
last_cv2_draw = cv2_val;
UpdateDisplay(cv1_val, cv2_val);
} else { } else {
UpdateCalibrationDisplay(); UpdateCalibrationDisplay();
} }