Start implementing shift indicator properly
This commit is contained in:
parent
897e1e9661
commit
edf639fc56
1 changed files with 35 additions and 15 deletions
|
@ -12,7 +12,7 @@ from hexagram.fuel import FuelGauge
|
||||||
from hexagram.thermo import ThermoGauge
|
from hexagram.thermo import ThermoGauge
|
||||||
|
|
||||||
class ShiftIndicator(Gauge):
|
class ShiftIndicator(Gauge):
|
||||||
__slots__ = 'x', 'y', 'rpm_redline', 'rpm_max',
|
__slots__ = 'x', 'y', 'rpm_min', 'rpm_redline', 'rpm_max',
|
||||||
|
|
||||||
LIGHT_WIDTH = 48
|
LIGHT_WIDTH = 48
|
||||||
LIGHT_HEIGHT = 12
|
LIGHT_HEIGHT = 12
|
||||||
|
@ -35,29 +35,48 @@ class ShiftIndicator(Gauge):
|
||||||
(4,),
|
(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.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
|
self.rpm_min = rpm_min
|
||||||
self.rpm_redline = rpm_redline
|
self.rpm_redline = rpm_redline
|
||||||
self.rpm_max = rpm_max
|
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]
|
||||||
|
|
||||||
|
if not on:
|
||||||
|
r *= self.LIGHT_LOW
|
||||||
|
g *= self.LIGHT_LOW
|
||||||
|
b *= self.LIGHT_LOW
|
||||||
|
|
||||||
|
cr.set_source_rgb(r, g, b)
|
||||||
|
|
||||||
|
for i in self.LIGHT_LEVELS[level]:
|
||||||
|
x = i * (self.LIGHT_WIDTH + self.LIGHT_SPACING)
|
||||||
|
|
||||||
|
cr.rectangle(self.x + x,
|
||||||
|
self.y,
|
||||||
|
self.LIGHT_WIDTH,
|
||||||
|
self.LIGHT_HEIGHT)
|
||||||
|
|
||||||
|
cr.fill()
|
||||||
|
|
||||||
def draw_bg(self, cr: cairo.Context):
|
def draw_bg(self, cr: cairo.Context):
|
||||||
for level in range(0, len(self.LIGHT_LEVELS)):
|
for level in range(0, len(self.LIGHT_LEVELS)):
|
||||||
r = self.LIGHT_LOW * self.LIGHT_COLORS[level][0]
|
self.draw_level(cr, level)
|
||||||
g = self.LIGHT_LOW * self.LIGHT_COLORS[level][1]
|
|
||||||
b = self.LIGHT_LOW * self.LIGHT_COLORS[level][2]
|
|
||||||
|
|
||||||
cr.set_source_rgb(r, g, b)
|
def draw_fg(self, cr: cairo.Context):
|
||||||
|
if self.value < self.rpm_min:
|
||||||
|
return
|
||||||
|
|
||||||
for i in self.LIGHT_LEVELS[level]:
|
level = math.ceil((self.value - self.rpm_min) / self.rpm_redline)
|
||||||
x = i * (self.LIGHT_WIDTH + self.LIGHT_SPACING)
|
|
||||||
|
|
||||||
cr.rectangle(self.x + x,
|
for l in range(0, len(self.LIGHT_LEVELS)):
|
||||||
self.y,
|
self.draw_level(cr, level, l >= level)
|
||||||
self.LIGHT_WIDTH,
|
|
||||||
self.LIGHT_HEIGHT)
|
|
||||||
|
|
||||||
cr.fill()
|
|
||||||
|
|
||||||
class Cluster():
|
class Cluster():
|
||||||
WIDTH = 1280
|
WIDTH = 1280
|
||||||
|
@ -68,7 +87,7 @@ class Cluster():
|
||||||
|
|
||||||
__slots__ = 'gauges', 'speedo', 'fuel', 'tacho', 'thermo',
|
__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.gauges: List[Gauge] = list()
|
||||||
|
|
||||||
self.speedo = Speedo(self.HEIGHT / 2,
|
self.speedo = Speedo(self.HEIGHT / 2,
|
||||||
|
@ -96,6 +115,7 @@ class Cluster():
|
||||||
|
|
||||||
self.gauges.append(ShiftIndicator(self.SHIFT_INDICATOR_X,
|
self.gauges.append(ShiftIndicator(self.SHIFT_INDICATOR_X,
|
||||||
self.SHIFT_INDICATOR_Y,
|
self.SHIFT_INDICATOR_Y,
|
||||||
|
rpm_min,
|
||||||
rpm_redline,
|
rpm_redline,
|
||||||
rpm_max))
|
rpm_max))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue