Make shift indicator addressable and functional

This commit is contained in:
XANTRONIX Development 2024-01-02 17:15:12 -05:00
parent cfe6b75454
commit 1a1a789030

View file

@ -45,9 +45,14 @@ class ShiftIndicator(Gauge):
self.rpm_max = rpm_max
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]
max_level = len(self.LIGHT_LEVELS) - 1
if level < 0:
level = 0
elif level >= max_level:
level = max_level
r, g, b = self.LIGHT_COLORS[level]
if not on:
r *= self.LIGHT_LOW
@ -74,10 +79,12 @@ class ShiftIndicator(Gauge):
if self.value < self.rpm_min:
return
level = math.ceil((self.value - self.rpm_min) / self.rpm_redline)
adj = self.value - self.rpm_min
adj_max = self.rpm_max - self.rpm_min
level = int((adj / adj_max) * len(self.LIGHT_LEVELS))
for l in range(0, len(self.LIGHT_LEVELS)):
self.draw_level(cr, level, l >= level)
self.draw_level(cr, l, level >= l)
class Odometer(TextGauge):
def __init__(self, x: float, y: float, align: Align):
@ -107,7 +114,7 @@ class Clock(TextGauge):
class Cluster():
__slots__ = 'gauges', 'speedo', 'fuel', 'tacho', 'thermo', 'odo', \
'ambient', 'clock'
'ambient', 'clock', 'shift_indicator',
WIDTH = 1280
HEIGHT = 480
@ -140,6 +147,12 @@ class Cluster():
self.clock = Clock(self.WIDTH / 2, self.HEIGHT - 16, Align.MIDDLE)
self.ambient = AmbientTemp(self.WIDTH - 0.8 * self.HEIGHT, self.HEIGHT - 16, Align.RIGHT)
self.shift_indicator = ShiftIndicator(self.SHIFT_INDICATOR_X,
self.SHIFT_INDICATOR_Y,
rpm_min,
rpm_redline,
rpm_max)
self.gauges.append(self.speedo)
self.gauges.append(self.fuel)
self.gauges.append(self.tacho)
@ -147,12 +160,7 @@ class Cluster():
self.gauges.append(self.odo)
self.gauges.append(self.ambient)
self.gauges.append(self.clock)
self.gauges.append(ShiftIndicator(self.SHIFT_INDICATOR_X,
self.SHIFT_INDICATOR_Y,
rpm_min,
rpm_redline,
rpm_max))
self.gauges.append(self.shift_indicator)
def draw_bg(self, cr: cairo.Context):
cr.set_source_rgb(0.1, 0.1, 0.1)