Start implementing shift indicator properly

This commit is contained in:
XANTRONIX Development 2024-01-01 19:44:25 -05:00
parent 897e1e9661
commit edf639fc56

View file

@ -12,7 +12,7 @@ from hexagram.fuel import FuelGauge
from hexagram.thermo import ThermoGauge
class ShiftIndicator(Gauge):
__slots__ = 'x', 'y', 'rpm_redline', 'rpm_max',
__slots__ = 'x', 'y', 'rpm_min', 'rpm_redline', 'rpm_max',
LIGHT_WIDTH = 48
LIGHT_HEIGHT = 12
@ -35,17 +35,23 @@ class ShiftIndicator(Gauge):
(4,),
)
def __init__(self, x: float, y: float, rpm_redline: float, rpm_max: float):
def __init__(self, x: float, y: float, rpm_min: float, rpm_redline: float, rpm_max: float):
self.value = 0
self.x = x
self.y = y
self.rpm_min = rpm_min
self.rpm_redline = rpm_redline
self.rpm_max = rpm_max
def draw_bg(self, cr: cairo.Context):
for level in range(0, len(self.LIGHT_LEVELS)):
r = self.LIGHT_LOW * self.LIGHT_COLORS[level][0]
g = self.LIGHT_LOW * self.LIGHT_COLORS[level][1]
b = self.LIGHT_LOW * self.LIGHT_COLORS[level][2]
def draw_level(self, cr: cairo.Context, level: int, on: bool=False):
r = self.LIGHT_COLORS[level][0]
g = self.LIGHT_COLORS[level][1]
b = self.LIGHT_COLORS[level][2]
if not on:
r *= self.LIGHT_LOW
g *= self.LIGHT_LOW
b *= self.LIGHT_LOW
cr.set_source_rgb(r, g, b)
@ -59,6 +65,19 @@ class ShiftIndicator(Gauge):
cr.fill()
def draw_bg(self, cr: cairo.Context):
for level in range(0, len(self.LIGHT_LEVELS)):
self.draw_level(cr, level)
def draw_fg(self, cr: cairo.Context):
if self.value < self.rpm_min:
return
level = math.ceil((self.value - self.rpm_min) / self.rpm_redline)
for l in range(0, len(self.LIGHT_LEVELS)):
self.draw_level(cr, level, l >= level)
class Cluster():
WIDTH = 1280
HEIGHT = 480
@ -68,7 +87,7 @@ class Cluster():
__slots__ = 'gauges', 'speedo', 'fuel', 'tacho', 'thermo',
def __init__(self, rpm_redline: float, rpm_max: float):
def __init__(self, rpm_min: float, rpm_redline: float, rpm_max: float):
self.gauges: List[Gauge] = list()
self.speedo = Speedo(self.HEIGHT / 2,
@ -96,6 +115,7 @@ class Cluster():
self.gauges.append(ShiftIndicator(self.SHIFT_INDICATOR_X,
self.SHIFT_INDICATOR_Y,
rpm_min,
rpm_redline,
rpm_max))