diff --git a/python/PiFinder/displays.py b/python/PiFinder/displays.py index cab8ce0c..376a14c6 100644 --- a/python/PiFinder/displays.py +++ b/python/PiFinder/displays.py @@ -32,13 +32,27 @@ def get(self, color_intensity): class DisplayBase: resolution = (128, 128) color_mask = RED_RGB + titlebar_height = 16 def __init__(self): self.colors = Colors(self.color_mask, self.resolution) + # calculated display params + self.centerX = int(self.resolution[0] / 2) + self.centerY = int(self.resolution[1] / 2) + self.fov_res = min(self.resolution[0], self.resolution[1]) + def set_brightness(self, brightness: int) -> None: return None + @property + def resX(self) -> int: + return self.resolution[0] + + @property + def resY(self) -> int: + return self.resolution[1] + class DisplayPygame(DisplayBase): resolution = (128, 128) @@ -83,10 +97,11 @@ def set_brightness(self, level): class DisplayST7789(DisplayBase): resolution = (320, 240) + titlebar_height = 20 def __init__(self): # init display (SPI hardware) - serial = spi(device=0, port=0) + serial = spi(device=0, port=0, bus_speed_hz=52000000) device_serial = st7789(serial, bgr=True) device_serial.capabilities( diff --git a/python/PiFinder/plot.py b/python/PiFinder/plot.py index 03e9e0b7..7f5af5ca 100644 --- a/python/PiFinder/plot.py +++ b/python/PiFinder/plot.py @@ -27,8 +27,9 @@ class Starfield: specified RA/DEC + roll """ - def __init__(self, colors, mag_limit=7, fov=10.2): + def __init__(self, colors, resolution, mag_limit=7, fov=10.2): self.colors = colors + self.resolution = resolution utctime = datetime.datetime(2023, 1, 1, 2, 0, 0).replace(tzinfo=utc) ts = sf_utils.ts self.t = ts.from_datetime(utctime) @@ -42,7 +43,7 @@ def __init__(self, colors, mag_limit=7, fov=10.2): self.raw_stars = hipparcos.load_dataframe(f) # Image size stuff - self.target_size = 128 + self.target_size = max(self.resolution) self.diag_mult = 1.422 self.render_size = ( int(self.target_size * self.diag_mult), diff --git a/python/PiFinder/ui/base.py b/python/PiFinder/ui/base.py index 749c0838..40d430bb 100644 --- a/python/PiFinder/ui/base.py +++ b/python/PiFinder/ui/base.py @@ -21,7 +21,6 @@ class UIModule: __button_hints__ = {} __uuid__ = str(uuid.uuid1()).split("-")[0] _config_options = None - _title_bar_y = 16 _CAM_ICON = "" _IMU_ICON = "" _GPS_ICON = "󰤉" @@ -29,7 +28,7 @@ class UIModule: def __init__( self, - display: Type[DisplayBase], + display_class: Type[DisplayBase], camera_image, shared_state, command_queues, @@ -40,19 +39,22 @@ def __init__( self.button_hints = self.__button_hints__ self.button_hints_timer = time.time() self.switch_to = None - self.display = display.device - self.colors = display.colors + self.display_class = display_class + self.display = display_class.device + self.colors = display_class.colors self.shared_state = shared_state self.ui_state = shared_state.ui_state() self.camera_image = camera_image self.command_queues = command_queues - self.screen = Image.new("RGB", display.resolution) + self.screen = Image.new("RGB", display_class.resolution) self.draw = ImageDraw.Draw(self.screen) self.font_base = fonts.base self.font_bold = fonts.bold self.font_large = fonts.large self.font_small = fonts.small + # Display resolution stuff + # screenshot stuff root_dir = str(utils.data_dir) prefix = f"{self.__uuid__}_{self.__title__}" @@ -201,7 +203,10 @@ def screen_update(self, title_bar=True, button_hints=True): if title_bar: fg = self.colors.get(0) bg = self.colors.get(64) - self.draw.rectangle([0, 0, 128, self._title_bar_y], fill=bg) + self.draw.rectangle( + [0, 0, self.display_class.resX, self.display_class.titlebar_height], + fill=bg, + ) if self.ui_state.show_fps(): self.draw.text((6, 1), str(self.fps), font=self.font_bold, fill=fg) else: diff --git a/python/PiFinder/ui/chart.py b/python/PiFinder/ui/chart.py index 21a20b82..6b1dde99 100644 --- a/python/PiFinder/ui/chart.py +++ b/python/PiFinder/ui/chart.py @@ -43,7 +43,7 @@ class UIChart(UIModule): def __init__(self, *args): super().__init__(*args) self.last_update = time.time() - self.starfield = plot.Starfield(self.colors) + self.starfield = plot.Starfield(self.colors, self.display_class.resolution) self.solution = None self.fov_list = [5, 10.2, 20, 30, 60] self.fov_index = 1 @@ -94,7 +94,11 @@ def plot_markers(self): marker_image = ImageChops.multiply( marker_image, - Image.new("RGB", (128, 128), self.colors.get(marker_brightness)), + Image.new( + "RGB", + self.display_class.resolution, + self.colors.get(marker_brightness), + ), ) self.screen.paste(ImageChops.add(self.screen, marker_image)) @@ -115,12 +119,12 @@ def draw_reticle(self): fov = self.fov for circ_deg in [4, 2, 0.5]: - circ_rad = ((circ_deg / fov) * 128) / 2 + circ_rad = ((circ_deg / fov) * self.display_class.fov_res) / 2 bbox = [ - 64 - circ_rad, - 64 - circ_rad, - 64 + circ_rad, - 64 + circ_rad, + self.display_class.centerX - circ_rad, + self.display_class.centerY - circ_rad, + self.display_class.centerX + circ_rad, + self.display_class.centerY + circ_rad, ] self.draw.arc(bbox, 20, 70, fill=self.colors.get(brightness)) self.draw.arc(bbox, 110, 160, fill=self.colors.get(brightness)) @@ -184,7 +188,10 @@ def update(self, force=False): self.last_update = last_solve_time else: - self.draw.rectangle([0, 0, 128, 128], fill=self.colors.get(0)) + self.draw.rectangle( + [0, 0, self.display_class.resX, self.display_class.resY], + fill=self.colors.get(0), + ) self.draw.text( (18, 20), "Can't plot", font=self.font_large, fill=self.colors.get(255) ) diff --git a/python/PiFinder/ui/console.py b/python/PiFinder/ui/console.py index 71603642..552e57b0 100644 --- a/python/PiFinder/ui/console.py +++ b/python/PiFinder/ui/console.py @@ -82,7 +82,8 @@ def update(self, force=False): if self.welcome: # Clear / write just top line self.draw.rectangle( - [0, 0, 128, self._title_bar_y], fill=self.colors.get(0) + [0, 0, 128, self.display_class.titlebar_height], + fill=self.colors.get(0), ) self.draw.text( (0, 1), diff --git a/python/PiFinder/ui/status.py b/python/PiFinder/ui/status.py index aa08518d..ee547739 100644 --- a/python/PiFinder/ui/status.py +++ b/python/PiFinder/ui/status.py @@ -88,7 +88,7 @@ def __init__(self, *args): super().__init__(*args) self.version_txt = f"{utils.pifinder_dir}/version.txt" self.wifi_txt = f"{utils.pifinder_dir}/wifi_status.txt" - self._draw_pos = (0, self._title_bar_y) + self._draw_pos = (0, self.display_class.titlebar_height) with open(self.wifi_txt, "r") as wfs: self._config_options["WiFi Mode"]["value"] = wfs.read() with open(self.version_txt, "r") as ver: