Add drive modes; move trans modes into trans.py
This commit is contained in:
parent
bbe47fa982
commit
054b61a2c3
1 changed files with 18 additions and 29 deletions
|
@ -2,34 +2,11 @@ import enum
|
||||||
import math
|
import math
|
||||||
import cairo
|
import cairo
|
||||||
|
|
||||||
from hexagram.dial import Dial
|
from hexagram.dial import Dial
|
||||||
|
from hexagram.trans import Gear, ShiftMode
|
||||||
class Gear(enum.Enum):
|
|
||||||
R = -1
|
|
||||||
N = 0
|
|
||||||
GEAR_1 = 1
|
|
||||||
GEAR_2 = 2
|
|
||||||
GEAR_3 = 3
|
|
||||||
GEAR_4 = 4
|
|
||||||
GEAR_5 = 5
|
|
||||||
GEAR_6 = 6
|
|
||||||
GEAR_7 = 7
|
|
||||||
GEAR_8 = 8
|
|
||||||
GEAR_9 = 9
|
|
||||||
GEAR_10 = 10
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
strs = {
|
|
||||||
-1: 'R', 0: 'N', 1: '1',
|
|
||||||
2: '2', 3: '3', 4: '4',
|
|
||||||
5: '5', 6: '6', 7: '7',
|
|
||||||
8: '8', 9: '9', 10: '10'
|
|
||||||
}
|
|
||||||
|
|
||||||
return strs.get(self.value, '?')
|
|
||||||
|
|
||||||
class Tacho(Dial):
|
class Tacho(Dial):
|
||||||
__slots__ = 'gear',
|
__slots__ = 'gear', 'shift_mode',
|
||||||
|
|
||||||
MIN_ANGLE = 232.0 * (math.pi / 180.0)
|
MIN_ANGLE = 232.0 * (math.pi / 180.0)
|
||||||
MAX_ANGLE = 488.0 * (math.pi / 180.0)
|
MAX_ANGLE = 488.0 * (math.pi / 180.0)
|
||||||
|
@ -40,7 +17,8 @@ class Tacho(Dial):
|
||||||
super().__init__(x, y, radius, self.MIN_ANGLE, self.MAX_ANGLE, 0, max_value)
|
super().__init__(x, y, radius, self.MIN_ANGLE, self.MAX_ANGLE, 0, max_value)
|
||||||
|
|
||||||
self.value = 0
|
self.value = 0
|
||||||
self.gear: Gear = Gear.N
|
self.gear: Gear = Gear.N
|
||||||
|
self.shift_mode: ShiftMode = ShiftMode.NORMAL
|
||||||
|
|
||||||
def draw_number(self, cr: cairo.Context, radius: float, value: float, text: str):
|
def draw_number(self, cr: cairo.Context, radius: float, value: float, text: str):
|
||||||
scale = value / self.max_value
|
scale = value / self.max_value
|
||||||
|
@ -79,10 +57,21 @@ class Tacho(Dial):
|
||||||
|
|
||||||
self.draw_number(cr, 0.69, speed, "%d" % int(speed / 1000))
|
self.draw_number(cr, 0.69, speed, "%d" % int(speed / 1000))
|
||||||
|
|
||||||
|
def gear_text(self):
|
||||||
|
text = ''
|
||||||
|
|
||||||
|
if self.shift_mode.value >= ShiftMode.SPORT.value \
|
||||||
|
and self.gear.value >= Gear.GEAR_1.value:
|
||||||
|
text += 'R'
|
||||||
|
|
||||||
|
text += str(self.gear)
|
||||||
|
|
||||||
|
return text
|
||||||
|
|
||||||
def draw_fg(self, cr: cairo.Context):
|
def draw_fg(self, cr: cairo.Context):
|
||||||
super().draw_fg(cr)
|
super().draw_fg(cr)
|
||||||
|
|
||||||
text = str(self.gear)
|
text = self.gear_text()
|
||||||
|
|
||||||
cr.select_font_face("HEX:gon Bold Italic")
|
cr.select_font_face("HEX:gon Bold Italic")
|
||||||
|
|
||||||
|
@ -96,4 +85,4 @@ class Tacho(Dial):
|
||||||
cr.move_to(self.x - width / 2,
|
cr.move_to(self.x - width / 2,
|
||||||
self.y + height / 4)
|
self.y + height / 4)
|
||||||
|
|
||||||
cr.show_text(str(self.gear))
|
cr.show_text(text)
|
||||||
|
|
Loading…
Add table
Reference in a new issue