From a2ad5d244e78a026f7c9097c67cc40a9ae5136e9 Mon Sep 17 00:00:00 2001 From: Adam Wonak Date: Mon, 9 Mar 2026 19:49:49 -0700 Subject: [PATCH] feat: Add CV input indicators to the display, optimize redraws based on CV value changes, and disable outputs when entering calibration mode. --- firmware/Comparator/Comparator.ino | 51 ++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/firmware/Comparator/Comparator.ino b/firmware/Comparator/Comparator.ino index 3d3cf0e..84ff261 100644 --- a/firmware/Comparator/Comparator.ino +++ b/firmware/Comparator/Comparator.ino @@ -41,6 +41,8 @@ bool prev_gate1 = false; bool prev_gate2 = false; bool ff_state = false; bool needs_redraw = true; +int last_cv1_draw = -1000; +int last_cv2_draw = -1000; unsigned long last_redraw = 0; bool prev_both_buttons = false; @@ -220,18 +222,35 @@ void UpdateCalibrationDisplay() { DisplayCalibrationPoint(&gravity.cv2, "CV2: ", 1); } -void UpdateDisplay() { +// UpdateDisplay +void UpdateDisplay(int cv1_val, int cv2_val) { // Comp 1 graphics (Left) int c1_h = max((comp1_size * 3) / 64, 1); int c1_center = 26 - ((comp1_shift * 3) / 64); 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) int c2_h = max((comp2_size * 3) / 64, 1); int c2_center = 26 - ((comp2_shift * 3) / 64); 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 gravity.display.setDrawColor(1); @@ -306,6 +325,11 @@ void loop() { if (current_mode == MODE_COMPARATOR) { current_mode = MODE_CALIBRATION; 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 { SaveCalibration(); current_mode = MODE_COMPARATOR; @@ -374,18 +398,27 @@ void loop() { eeprom_needs_save = false; } - // Force frequent redraws in calibration mode for immediate feedback - if (current_mode == MODE_CALIBRATION && (millis() - last_redraw >= 30)) { - needs_redraw = true; - last_redraw = millis(); + if (current_mode == MODE_COMPARATOR) { + if (abs(cv1_val - last_cv1_draw) > 12 || abs(cv2_val - last_cv2_draw) > 12) { + needs_redraw = true; + } + } 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; + last_redraw = millis(); gravity.display.firstPage(); do { if (current_mode == MODE_COMPARATOR) { - UpdateDisplay(); + last_cv1_draw = cv1_val; + last_cv2_draw = cv2_val; + UpdateDisplay(cv1_val, cv2_val); } else { UpdateCalibrationDisplay(); }