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
|
@ -3,33 +3,10 @@ import math
|
|||
import cairo
|
||||
|
||||
from hexagram.dial import Dial
|
||||
|
||||
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, '?')
|
||||
from hexagram.trans import Gear, ShiftMode
|
||||
|
||||
class Tacho(Dial):
|
||||
__slots__ = 'gear',
|
||||
__slots__ = 'gear', 'shift_mode',
|
||||
|
||||
MIN_ANGLE = 232.0 * (math.pi / 180.0)
|
||||
MAX_ANGLE = 488.0 * (math.pi / 180.0)
|
||||
|
@ -41,6 +18,7 @@ class Tacho(Dial):
|
|||
|
||||
self.value = 0
|
||||
self.gear: Gear = Gear.N
|
||||
self.shift_mode: ShiftMode = ShiftMode.NORMAL
|
||||
|
||||
def draw_number(self, cr: cairo.Context, radius: float, value: float, text: str):
|
||||
scale = value / self.max_value
|
||||
|
@ -79,10 +57,21 @@ class Tacho(Dial):
|
|||
|
||||
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):
|
||||
super().draw_fg(cr)
|
||||
|
||||
text = str(self.gear)
|
||||
text = self.gear_text()
|
||||
|
||||
cr.select_font_face("HEX:gon Bold Italic")
|
||||
|
||||
|
@ -96,4 +85,4 @@ class Tacho(Dial):
|
|||
cr.move_to(self.x - width / 2,
|
||||
self.y + height / 4)
|
||||
|
||||
cr.show_text(str(self.gear))
|
||||
cr.show_text(text)
|
||||
|
|
Loading…
Add table
Reference in a new issue