From 8d304bf6637a931c53d7ab4feab3d9c0e5703d5a Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sun, 31 Dec 2023 20:31:12 -0500 Subject: [PATCH] idk...This is happening? --- py/hexagram/cluster.py | 5 +++-- py/hexagram/dial.py | 16 +++++++++------- py/hexagram/speedo.py | 19 ++++++++++--------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/py/hexagram/cluster.py b/py/hexagram/cluster.py index abada9f..b09f532 100644 --- a/py/hexagram/cluster.py +++ b/py/hexagram/cluster.py @@ -71,13 +71,14 @@ class Cluster(): self.speedo = Speedo(self.HEIGHT / 2, self.HEIGHT / 2, self.HEIGHT / 2, - 350.0) + 180.0) self.tacho = Dial(self.WIDTH - self.HEIGHT / 2, self.HEIGHT / 2, self.HEIGHT / 2, 232.0 * (math.pi / 180.0), - 488.0 * (math.pi / 180.0)) + 488.0 * (math.pi / 180.0), + 8000) self.gauges.append(self.speedo) self.gauges.append(self.tacho) diff --git a/py/hexagram/dial.py b/py/hexagram/dial.py index 5ae44e2..f37dd69 100644 --- a/py/hexagram/dial.py +++ b/py/hexagram/dial.py @@ -3,8 +3,10 @@ import cairo from hexagram.gauge import Gauge +ANGLE_OFFSET = 1.658 + class Dial(Gauge): - __slots = 'x', 'y', 'radius', 'min_angle', 'max_angle', + __slots = 'x', 'y', 'radius', 'min_angle', 'max_angle', 'max_value', BEZEL_WIDTH = 16 @@ -13,12 +15,13 @@ class Dial(Gauge): (1, 0.4, 0.0, 0.4, 0.0) ) - def __init__(self, x: float, y: float, radius: float, min_angle: float, max_angle: float): + def __init__(self, x: float, y: float, radius: float, min_angle: float, max_angle: float, max_value: float): self.x = x self.y = y self.radius = radius self.min_angle = min_angle self.max_angle = max_angle + self.max_value = max_value def _gradient(self): gradient = cairo.LinearGradient(self.x - self.radius, @@ -32,17 +35,16 @@ class Dial(Gauge): return gradient def draw_number(self, cr: cairo.Context, radius: float, value: float, text: str): - angle = self.min_angle + ((self.max_angle - self.min_angle) * value) - 1.658; + scale = value / self.max_value + angle = self.min_angle + ((self.max_angle - self.min_angle) * scale) - ANGLE_OFFSET cr.set_source_rgb(1, 1, 1) - cr.move_to(self.x + radius * self.radius * math.cos(angle), + cr.move_to(self.x + radius * self.radius * math.cos(angle) - 20, self.y + radius * self.radius * math.sin(angle)) - cr.save() - cr.rotate(angle + 1.658) + #cr.rotate(angle + ANGLE_OFFSET) cr.show_text(text) cr.stroke() - cr.restore() def draw_bg(self, cr: cairo.Context): arc = (self.x, diff --git a/py/hexagram/speedo.py b/py/hexagram/speedo.py index c368dad..4656626 100644 --- a/py/hexagram/speedo.py +++ b/py/hexagram/speedo.py @@ -12,20 +12,21 @@ class Speedo(Dial): MIN_ANGLE = 232.0 * (math.pi / 180.0) MAX_ANGLE = 488.0 * (math.pi / 180.0) - __slots__ = 'units', 'max_speed', + FONT_FACE = "Helvetica" - def __init__(self, x: float, y: float, radius: float, max_speed: float, units: SpeedUnits=SpeedUnits.KPH): - super().__init__(x, y, radius, self.MIN_ANGLE, self.MAX_ANGLE) + __slots__ = 'units', - self.units = units - self.max_speed = max_speed + def __init__(self, x: float, y: float, radius: float, max_value: float, units: SpeedUnits=SpeedUnits.KPH): + super().__init__(x, y, radius, self.MIN_ANGLE, self.MAX_ANGLE, max_value) + + self.units = units def draw_bg(self, cr: cairo.Context): super().draw_bg(cr) - cr.select_font_face("Helvetica") - cr.set_font_size(self.radius * 0.125) + cr.select_font_face(self.FONT_FACE) + cr.set_font_size(self.radius * 0.1) cr.set_source_rgb(1, 1, 1) - for speed in range(0, int(self.max_speed), 50): - self.draw_number(cr, 0.75, speed, str(int(speed))) + for speed in range(0, int(self.max_value)+1, 20): + self.draw_number(cr, 0.75, speed, "%02d" % int(speed))