From acc27cb94b0f90a4b7a9ca443575fbfda7c9103e Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sun, 31 Dec 2023 19:12:19 -0500 Subject: [PATCH] Slowly cookin' --- py/hexagram/cluster.py | 20 ++++++++++++++++---- py/hexagram/dial.py | 12 +++++++----- py/hexagram/speedo.py | 8 ++++++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/py/hexagram/cluster.py b/py/hexagram/cluster.py index 1af04e7..abada9f 100644 --- a/py/hexagram/cluster.py +++ b/py/hexagram/cluster.py @@ -3,9 +3,10 @@ import cairo from typing import Iterable, List +from hexagram.pattern import HexagonPattern from hexagram.gauge import Gauge from hexagram.dial import Dial -from hexagram.pattern import HexagonPattern +from hexagram.speedo import Speedo class ShiftIndicator(Gauge): LIGHT_WIDTH = 48 @@ -62,13 +63,24 @@ class Cluster(): SHIFT_INDICATOR_X = 392 SHIFT_INDICATOR_Y = 24 - __slots__ = 'gauges', + __slots__ = 'gauges', 'speedo', 'tacho', def __init__(self, rpm_redline: float, rpm_max: float): self.gauges: List[Gauge] = list() - for x in (self.HEIGHT / 2, self.WIDTH - self.HEIGHT / 2): - self.gauges.append(Dial(x, self.HEIGHT / 2, self.HEIGHT / 2)) + self.speedo = Speedo(self.HEIGHT / 2, + self.HEIGHT / 2, + self.HEIGHT / 2, + 350.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)) + + self.gauges.append(self.speedo) + self.gauges.append(self.tacho) self.gauges.append(ShiftIndicator(self.SHIFT_INDICATOR_X, self.SHIFT_INDICATOR_Y, diff --git a/py/hexagram/dial.py b/py/hexagram/dial.py index a2f29cf..a80c6c8 100644 --- a/py/hexagram/dial.py +++ b/py/hexagram/dial.py @@ -4,7 +4,7 @@ import cairo from hexagram.gauge import Gauge class Dial(Gauge): - __slots = 'x', 'y', 'radius', + __slots = 'x', 'y', 'radius', 'min_angle', 'max_angle', BEZEL_WIDTH = 16 @@ -13,10 +13,12 @@ class Dial(Gauge): (1, 0.4, 0.0, 0.4, 0.0) ) - def __init__(self, x: float, y: float, radius: float): - self.x = x - self.y = y - self.radius = radius + def __init__(self, x: float, y: float, radius: float, min_angle: float, max_angle: float): + self.x = x + self.y = y + self.radius = radius + self.min_angle = min_angle + self.max_angle = max_angle def _gradient(self): gradient = cairo.LinearGradient(self.x - self.radius, diff --git a/py/hexagram/speedo.py b/py/hexagram/speedo.py index 388da36..5fbb1fc 100644 --- a/py/hexagram/speedo.py +++ b/py/hexagram/speedo.py @@ -1,4 +1,5 @@ import enum +import math from hexagram.cluster import Dial @@ -7,10 +8,13 @@ class SpeedUnits(enum.Enum): MPH = 1 class Speedo(Dial): + MIN_ANGLE = 232.0 * (math.pi / 180.0) + MAX_ANGLE = 488.0 * (math.pi / 180.0) + __slots__ = 'units', 'max_speed', - def __init__(self, x: float, y: float, radius: float, units: SpeedUnits, max_speed: float): - super().__init__(x, y, radius) + 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) self.units = units self.max_speed = max_speed