From 243f4a8806345c2861ba22dcbbe5a5c74b797fa4 Mon Sep 17 00:00:00 2001 From: Rory Allen <79809962+roryjamesallen@users.noreply.github.com> Date: Mon, 5 Feb 2024 21:17:03 +0000 Subject: [PATCH 1/6] edits to centre_text --- software/firmware/europi.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/software/firmware/europi.py b/software/firmware/europi.py index 81ca7a168..cc6becc0a 100644 --- a/software/firmware/europi.py +++ b/software/firmware/europi.py @@ -535,7 +535,7 @@ def rotate(self, rotate): self.write_cmd(ssd1306.SET_SEG_REMAP | (rotate & 1)) def centre_text(self, text, clear_first=True, auto_show=True): - """Split the provided text across 3 lines of display. + """Display one or more lines of text centred both horizontally and vertically. @param text The text to display, containing at most 3 lines @param clear_first If true, the screen buffer is cleared before rendering the text @@ -551,10 +551,10 @@ def centre_text(self, text, clear_first=True, auto_show=True): maximum_lines = round(self.height / CHAR_HEIGHT) if len(lines) > maximum_lines: raise Exception("Provided text exceeds available space on oled display.") - padding_top = (self.height - (len(lines) * 9)) / 2 + padding_top = (self.height - (len(lines) * (CHAR_HEIGHT + 1))) / 2 for index, content in enumerate(lines): - x_offset = int((self.width - ((len(content) + 1) * 7)) / 2) - 1 - y_offset = int((index * 9) + padding_top) - 1 + x_offset = int((self.width - ((len(content) + 1) * (CHAR_WIDTH- 1))) / 2) - 1 + y_offset = int((index * (CHAR_HEIGHT + 1)) + padding_top) - 1 self.text(content, x_offset, y_offset) if auto_show: From fb7bc859486267325341a59dd2d5d7796e590fb0 Mon Sep 17 00:00:00 2001 From: Rory Allen <79809962+roryjamesallen@users.noreply.github.com> Date: Mon, 5 Feb 2024 21:23:24 +0000 Subject: [PATCH 2/6] Update europi.py --- software/firmware/europi.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/software/firmware/europi.py b/software/firmware/europi.py index cc6becc0a..c468a4def 100644 --- a/software/firmware/europi.py +++ b/software/firmware/europi.py @@ -537,7 +537,7 @@ def rotate(self, rotate): def centre_text(self, text, clear_first=True, auto_show=True): """Display one or more lines of text centred both horizontally and vertically. - @param text The text to display, containing at most 3 lines + @param text The text to display @param clear_first If true, the screen buffer is cleared before rendering the text @param auto_show If true, oled.show() is called after rendering the text. If false, you must call oled.show() yourself @@ -545,8 +545,8 @@ def centre_text(self, text, clear_first=True, auto_show=True): if clear_first: self.fill(0) # Default font is 8x8 pixel monospaced font which can be split to a - # maximum of 4 lines on a 128x32 display, but we limit it to 3 lines - # for readability. + # maximum of 4 lines on a 128x32 display, but the maximum lines is + # rounded for readability lines = str(text).split("\n") maximum_lines = round(self.height / CHAR_HEIGHT) if len(lines) > maximum_lines: From 241d622aa0b37816c39cb33a8a28471f1890fe21 Mon Sep 17 00:00:00 2001 From: Rory Allen <79809962+roryjamesallen@users.noreply.github.com> Date: Mon, 5 Feb 2024 21:25:59 +0000 Subject: [PATCH 3/6] Update europi.py --- software/firmware/europi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/software/firmware/europi.py b/software/firmware/europi.py index c468a4def..9f2b568ca 100644 --- a/software/firmware/europi.py +++ b/software/firmware/europi.py @@ -545,8 +545,8 @@ def centre_text(self, text, clear_first=True, auto_show=True): if clear_first: self.fill(0) # Default font is 8x8 pixel monospaced font which can be split to a - # maximum of 4 lines on a 128x32 display, but the maximum lines is - # rounded for readability + # maximum of 4 lines on a 128x32 display, but the maximum_lines variable + # is rounded down for readability lines = str(text).split("\n") maximum_lines = round(self.height / CHAR_HEIGHT) if len(lines) > maximum_lines: From bc8a32107a8c4136b1b1fcc5d5dd20330b032838 Mon Sep 17 00:00:00 2001 From: Rory Allen <79809962+roryjamesallen@users.noreply.github.com> Date: Tue, 6 Feb 2024 07:39:52 +0000 Subject: [PATCH 4/6] black formatting --- software/firmware/europi.py | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/software/firmware/europi.py b/software/firmware/europi.py index 9f2b568ca..9eae83726 100644 --- a/software/firmware/europi.py +++ b/software/firmware/europi.py @@ -14,7 +14,6 @@ Will set the CV output 3 to a voltage of 4.5V. """ - import ssd1306 import sys import time @@ -231,14 +230,18 @@ class AnalogueInput(AnalogueReader): function of the AnalogueReader and Knob classes """ - def __init__(self, pin, min_voltage=MIN_INPUT_VOLTAGE, max_voltage=MAX_INPUT_VOLTAGE): + def __init__( + self, pin, min_voltage=MIN_INPUT_VOLTAGE, max_voltage=MAX_INPUT_VOLTAGE + ): super().__init__(pin) self.MIN_VOLTAGE = min_voltage self.MAX_VOLTAGE = max_voltage self._gradients = [] for index, value in enumerate(INPUT_CALIBRATION_VALUES[:-1]): try: - self._gradients.append(1 / (INPUT_CALIBRATION_VALUES[index + 1] - value)) + self._gradients.append( + 1 / (INPUT_CALIBRATION_VALUES[index + 1] - value) + ) except ZeroDivisionError: raise Exception( "The input calibration process did not complete properly. Please complete again with rack power turned on" @@ -271,7 +274,9 @@ def read_voltage(self, samples=None): ) else: index = int(percent * (len(INPUT_CALIBRATION_VALUES) - 1)) - cv = index + (self._gradients[index] * (raw_reading - INPUT_CALIBRATION_VALUES[index])) + cv = index + ( + self._gradients[index] * (raw_reading - INPUT_CALIBRATION_VALUES[index]) + ) return clamp(cv, self.MIN_VOLTAGE, self.MAX_VOLTAGE) @@ -354,12 +359,18 @@ def __init__(self, pin, debounce_delay=500): def _bounce_wrapper(self, pin): """IRQ handler wrapper for falling and rising edge callback functions.""" if self.value() == HIGH: - if time.ticks_diff(time.ticks_ms(), self.last_rising_ms) < self.debounce_delay: + if ( + time.ticks_diff(time.ticks_ms(), self.last_rising_ms) + < self.debounce_delay + ): return self.last_rising_ms = time.ticks_ms() return self._rising_handler() else: - if time.ticks_diff(time.ticks_ms(), self.last_falling_ms) < self.debounce_delay: + if ( + time.ticks_diff(time.ticks_ms(), self.last_falling_ms) + < self.debounce_delay + ): return self.last_falling_ms = time.ticks_ms() @@ -553,7 +564,9 @@ def centre_text(self, text, clear_first=True, auto_show=True): raise Exception("Provided text exceeds available space on oled display.") padding_top = (self.height - (len(lines) * (CHAR_HEIGHT + 1))) / 2 for index, content in enumerate(lines): - x_offset = int((self.width - ((len(content) + 1) * (CHAR_WIDTH- 1))) / 2) - 1 + x_offset = ( + int((self.width - ((len(content) + 1) * (CHAR_WIDTH - 1))) / 2) - 1 + ) y_offset = int((index * (CHAR_HEIGHT + 1)) + padding_top) - 1 self.text(content, x_offset, y_offset) @@ -572,7 +585,9 @@ class Output: calibration is important if you want to be able to output precise voltages. """ - def __init__(self, pin, min_voltage=MIN_OUTPUT_VOLTAGE, max_voltage=MAX_OUTPUT_VOLTAGE): + def __init__( + self, pin, min_voltage=MIN_OUTPUT_VOLTAGE, max_voltage=MAX_OUTPUT_VOLTAGE + ): self.pin = PWM(Pin(pin)) self.pin.freq(PWM_FREQ) self._duty = 0 @@ -595,7 +610,9 @@ def voltage(self, voltage=None): return self._duty / MAX_UINT16 voltage = clamp(voltage, self.MIN_VOLTAGE, self.MAX_VOLTAGE) index = int(voltage // 1) - self._set_duty(OUTPUT_CALIBRATION_VALUES[index] + (self._gradients[index] * (voltage % 1))) + self._set_duty( + OUTPUT_CALIBRATION_VALUES[index] + (self._gradients[index] * (voltage % 1)) + ) def on(self): """Set the voltage HIGH at 5 volts.""" From d21d797bb0527ebd436c330d30f6d2d115c56dea Mon Sep 17 00:00:00 2001 From: Rory Allen Date: Tue, 6 Feb 2024 07:46:23 +0000 Subject: [PATCH 5/6] Revert "black formatting" This reverts commit bc8a32107a8c4136b1b1fcc5d5dd20330b032838. --- software/firmware/europi.py | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/software/firmware/europi.py b/software/firmware/europi.py index 9eae83726..9f2b568ca 100644 --- a/software/firmware/europi.py +++ b/software/firmware/europi.py @@ -14,6 +14,7 @@ Will set the CV output 3 to a voltage of 4.5V. """ + import ssd1306 import sys import time @@ -230,18 +231,14 @@ class AnalogueInput(AnalogueReader): function of the AnalogueReader and Knob classes """ - def __init__( - self, pin, min_voltage=MIN_INPUT_VOLTAGE, max_voltage=MAX_INPUT_VOLTAGE - ): + def __init__(self, pin, min_voltage=MIN_INPUT_VOLTAGE, max_voltage=MAX_INPUT_VOLTAGE): super().__init__(pin) self.MIN_VOLTAGE = min_voltage self.MAX_VOLTAGE = max_voltage self._gradients = [] for index, value in enumerate(INPUT_CALIBRATION_VALUES[:-1]): try: - self._gradients.append( - 1 / (INPUT_CALIBRATION_VALUES[index + 1] - value) - ) + self._gradients.append(1 / (INPUT_CALIBRATION_VALUES[index + 1] - value)) except ZeroDivisionError: raise Exception( "The input calibration process did not complete properly. Please complete again with rack power turned on" @@ -274,9 +271,7 @@ def read_voltage(self, samples=None): ) else: index = int(percent * (len(INPUT_CALIBRATION_VALUES) - 1)) - cv = index + ( - self._gradients[index] * (raw_reading - INPUT_CALIBRATION_VALUES[index]) - ) + cv = index + (self._gradients[index] * (raw_reading - INPUT_CALIBRATION_VALUES[index])) return clamp(cv, self.MIN_VOLTAGE, self.MAX_VOLTAGE) @@ -359,18 +354,12 @@ def __init__(self, pin, debounce_delay=500): def _bounce_wrapper(self, pin): """IRQ handler wrapper for falling and rising edge callback functions.""" if self.value() == HIGH: - if ( - time.ticks_diff(time.ticks_ms(), self.last_rising_ms) - < self.debounce_delay - ): + if time.ticks_diff(time.ticks_ms(), self.last_rising_ms) < self.debounce_delay: return self.last_rising_ms = time.ticks_ms() return self._rising_handler() else: - if ( - time.ticks_diff(time.ticks_ms(), self.last_falling_ms) - < self.debounce_delay - ): + if time.ticks_diff(time.ticks_ms(), self.last_falling_ms) < self.debounce_delay: return self.last_falling_ms = time.ticks_ms() @@ -564,9 +553,7 @@ def centre_text(self, text, clear_first=True, auto_show=True): raise Exception("Provided text exceeds available space on oled display.") padding_top = (self.height - (len(lines) * (CHAR_HEIGHT + 1))) / 2 for index, content in enumerate(lines): - x_offset = ( - int((self.width - ((len(content) + 1) * (CHAR_WIDTH - 1))) / 2) - 1 - ) + x_offset = int((self.width - ((len(content) + 1) * (CHAR_WIDTH- 1))) / 2) - 1 y_offset = int((index * (CHAR_HEIGHT + 1)) + padding_top) - 1 self.text(content, x_offset, y_offset) @@ -585,9 +572,7 @@ class Output: calibration is important if you want to be able to output precise voltages. """ - def __init__( - self, pin, min_voltage=MIN_OUTPUT_VOLTAGE, max_voltage=MAX_OUTPUT_VOLTAGE - ): + def __init__(self, pin, min_voltage=MIN_OUTPUT_VOLTAGE, max_voltage=MAX_OUTPUT_VOLTAGE): self.pin = PWM(Pin(pin)) self.pin.freq(PWM_FREQ) self._duty = 0 @@ -610,9 +595,7 @@ def voltage(self, voltage=None): return self._duty / MAX_UINT16 voltage = clamp(voltage, self.MIN_VOLTAGE, self.MAX_VOLTAGE) index = int(voltage // 1) - self._set_duty( - OUTPUT_CALIBRATION_VALUES[index] + (self._gradients[index] * (voltage % 1)) - ) + self._set_duty(OUTPUT_CALIBRATION_VALUES[index] + (self._gradients[index] * (voltage % 1))) def on(self): """Set the voltage HIGH at 5 volts.""" From f2c9037e224a522323c5d35894dbc61df5e5beba Mon Sep 17 00:00:00 2001 From: Rory Allen Date: Tue, 6 Feb 2024 07:49:25 +0000 Subject: [PATCH 6/6] black formatting --- software/firmware/europi.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/software/firmware/europi.py b/software/firmware/europi.py index 9f2b568ca..0850730be 100644 --- a/software/firmware/europi.py +++ b/software/firmware/europi.py @@ -14,7 +14,6 @@ Will set the CV output 3 to a voltage of 4.5V. """ - import ssd1306 import sys import time @@ -553,7 +552,7 @@ def centre_text(self, text, clear_first=True, auto_show=True): raise Exception("Provided text exceeds available space on oled display.") padding_top = (self.height - (len(lines) * (CHAR_HEIGHT + 1))) / 2 for index, content in enumerate(lines): - x_offset = int((self.width - ((len(content) + 1) * (CHAR_WIDTH- 1))) / 2) - 1 + x_offset = int((self.width - ((len(content) + 1) * (CHAR_WIDTH - 1))) / 2) - 1 y_offset = int((index * (CHAR_HEIGHT + 1)) + padding_top) - 1 self.text(content, x_offset, y_offset)