-
Notifications
You must be signed in to change notification settings - Fork 34
/
config.py
74 lines (55 loc) · 2.62 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from configparser import ConfigParser
import sys
from ant.core import log
from BtAtsPowerCalculator import BtAtsPowerCalculator
from KurtKineticPowerCalculator import KurtKineticPowerCalculator
from TacxBlueMotionPowerCalculator import TacxBlueMotionPowerCalculator
from CycleOpsFluid2PowerCalculator import CycleOpsFluid2PowerCalculator
from EliteNovoForcePowerCalculator import EliteNovoForcePowerCalculator
from LinearInterpolationPowerCalculator import LinearInterpolationPowerCalculator
from constants import *
import hashlib
VPOWER_DEBUG = False
CONFIG = ConfigParser()
_CONFIG_FILENAME = 'vpower.cfg'
# If there's a command-line argument, it's the location of the config file
if len(sys.argv) > 1:
_CONFIG_FILENAME = sys.argv[1]
SECTION = 'vpower'
try:
if VPOWER_DEBUG:
print('Open file ' + _CONFIG_FILENAME)
print('Parse config')
CONFIG.read(_CONFIG_FILENAME)
except Exception as e:
print("Error: "+repr(e.__class__))
if VPOWER_DEBUG: print('Get config items')
# Type of sensor connected to the trainer
SENSOR_TYPE = CONFIG.getint(SECTION, 'speed_sensor_type')
# ANT+ ID of the above sensor
SPEED_SENSOR_ID = CONFIG.getint(SECTION, 'speed_sensor_id')
# Calculator for the model of turbo
pc_class = globals()[CONFIG.get(SECTION, 'power_calculator')]
POWER_CALCULATOR = pc_class()
# For wind/air trainers, current air density in kg/m3 (if not using a BME280 weather sensor)
POWER_CALCULATOR.air_density = CONFIG.getfloat(SECTION, 'air_density')
# For wind/air trainers, how often (secs) to update the air density if there *is* a BME280 present
POWER_CALCULATOR.air_density_update_secs = CONFIG.getfloat(SECTION, 'air_density_update_secs')
# For tyre-driven trainers, the wheel circumference in meters (2.122 for Continental Home trainer tyre)
POWER_CALCULATOR.wheel_circumference = CONFIG.getfloat(SECTION, 'wheel_circumference')
# Overall correction factor, e.g. to match a user's power meter on another bike
POWER_CALCULATOR.set_correction_factor(CONFIG.getfloat(SECTION, 'correction_factor'))
# ANT+ ID of the virtual power sensor
# The expression below will choose a fixed ID based on the CPU's serial number
POWER_SENSOR_ID = int(int(hashlib.md5(getserial().encode()).hexdigest(), 16) & 0xfffe) + 1
# If set to True, the stick's driver will dump everything it reads/writes from/to the stick.
DEBUG = CONFIG.getboolean(SECTION, 'debug')
POWER_CALCULATOR.set_debug(DEBUG or VPOWER_DEBUG)
# Set to None to disable ANT+ message logging
LOG = None
# LOG = log.LogWriter(filename="vpower.log")
# ANT+ network key
NETKEY = b'\xB9\xA5\x21\xFB\xBD\x72\xC3\x45'
if LOG:
print("Using log file:", LOG.filename)
print("")