Skip to content

Commit

Permalink
Implement display class
Browse files Browse the repository at this point in the history
  • Loading branch information
brickbots committed Mar 2, 2024
1 parent ef1a2ad commit 2556c70
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 19 deletions.
17 changes: 16 additions & 1 deletion python/PiFinder/displays.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions python/PiFinder/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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),
Expand Down
17 changes: 11 additions & 6 deletions python/PiFinder/ui/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ class UIModule:
__button_hints__ = {}
__uuid__ = str(uuid.uuid1()).split("-")[0]
_config_options = None
_title_bar_y = 16
_CAM_ICON = ""
_IMU_ICON = ""
_GPS_ICON = "󰤉"
_unmoved = False # has the telescope moved since the last cam solve?

def __init__(
self,
display: Type[DisplayBase],
display_class: Type[DisplayBase],
camera_image,
shared_state,
command_queues,
Expand All @@ -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__}"
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 15 additions & 8 deletions python/PiFinder/ui/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand All @@ -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))
Expand Down Expand Up @@ -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)
)
Expand Down
3 changes: 2 additions & 1 deletion python/PiFinder/ui/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion python/PiFinder/ui/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2556c70

Please sign in to comment.