Rev 5 | Rev 7 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5 | Rev 6 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | namespace |
5 | namespace |
6 | { |
6 | { |
7 | 7 | ||
8 | unsigned constexpr INTERP_SCALE = 256; |
8 | unsigned constexpr INTERP_SCALE = 256; |
9 | 9 | ||
10 | unsigned constexpr MAX_TIMING_POINTS = 10; |
- | |
11 | unsigned constexpr MAX_VACUUM_POINTS = 10; |
- | |
12 | int constexpr TimingScale = TIMING_SCALE; |
10 | int constexpr TimingScale = TIMING_SCALE; |
13 | int16_t constexpr NO_DATA = -1; |
11 | int16_t constexpr NO_DATA = -1; |
14 | 12 | ||
15 | static int8_t const timingAdjust __attribute((section(".nvram"))) = 0; // in TIMING_SCALE |
13 | int8_t timingAdjust = 0; // in TIMING_SCALE |
16 | int16_t const rpmMap[MAX_TIMING_POINTS] __attribute__((section(".nvram"))) = {400, 750, 1000, 1500, 2500, 3500, 4500, 6000, NO_DATA, NO_DATA}; |
14 | int16_t rpmMap[MAX_TIMING_POINTS] = {400, 750, 1000, 1500, 2500, 3500, 4500, 6000}; |
17 | int16_t const vacuumMap[MAX_VACUUM_POINTS] __attribute__((section(".nvram"))) = {0, 166, 225, 300, 700, NO_DATA, NO_DATA, NO_DATA, NO_DATA, NO_DATA}; |
15 | int16_t vacuumMap[MAX_VACUUM_POINTS] = {0, 166, 225, 300, 700, NO_DATA, NO_DATA, NO_DATA}; |
18 | uint8_t const mapping[MAX_VACUUM_POINTS][MAX_TIMING_POINTS] __attribute__((section(".nvram"))) = { |
16 | uint8_t mapping[MAX_VACUUM_POINTS][MAX_TIMING_POINTS] = { |
19 | /* Table in degrees. */ |
17 | /* Table in degrees. */ |
20 | /* row for 0mb = centrifugal only */ |
18 | /* row for 0mb = centrifugal only */ |
21 | {12, 7, 7, 19, 25, 29, 29, 22, 22, 22}, |
19 | {12, 7, 7, 19, 25, 29, 29, 22}, |
22 | /* row for 166 mB*/ |
20 | /* row for 166 mB*/ |
23 | {12, 7, 7, 21, 27, 31, 31, 24, 24, 22}, |
21 | {12, 7, 7, 21, 27, 31, 31, 24}, |
24 | /* row for 225 mB */ |
22 | /* row for 225 mB */ |
25 | {12, 7, 7, 25, 31, 35, 35, 28, 24, 22}, |
23 | {12, 7, 7, 25, 31, 35, 35, 28}, |
26 | /* row for 300 mB*/ |
24 | /* row for 300 mB*/ |
27 | {12, 7, 7, 29, 35, 39, 39, 33, 28, 22}, |
25 | {12, 7, 7, 29, 35, 39, 39, 33}, |
28 | /* row for 700 mB*/ |
26 | /* row for 700 mB*/ |
29 | {12, 7, 7, 29, 35, 39, 39, 33, 28, 22}, |
27 | {12, 7, 7, 29, 35, 39, 39, 33}, |
30 | /* unused */ |
28 | /* unused */ |
31 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, |
29 | {0, 0, 0, 0, 0, 0, 0, 0}, |
32 | /* unused */ |
30 | /* unused */ |
33 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, |
31 | {0, 0, 0, 0, 0, 0, 0, 0}, |
34 | /* unused */ |
32 | /* unused */ |
35 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, |
33 | {0, 0, 0, 0, 0, 0, 0, 0}, |
36 | /* unused */ |
34 | /* unused */ |
37 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, |
- | |
38 | /* unused */ |
- | |
39 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, |
- | |
- | 35 | ||
40 | }; |
36 | }; |
41 | 37 | ||
42 | } |
38 | } |
43 | /// @brief Lookup a point using linear interpolation |
- | |
44 | /// @param point value to lookup |
- | |
45 | /// @param curve data point list |
- | |
46 | /// @param size number of data points in list |
- | |
47 | /// @param [out] frac fraction of distance between points |
- | |
48 | /// @return index of first point |
- | |
49 | int lookup(int point, int16_t const curve[], int size, int16_t *frac) |
- | |
50 | 39 | ||
- | 40 | uint8_t getTimingAdjust() { return timingAdjust; }; |
|
- | 41 | ||
- | 42 | void setTimingAdjust(int8_t adjust) { timingAdjust = adjust; } |
|
- | 43 | ||
- | 44 | int16_t getRpmMap(int i) |
|
- | 45 | { |
|
- | 46 | if (i >= 0 && i < MAX_TIMING_POINTS) |
|
- | 47 | return rpmMap[i]; |
|
- | 48 | else |
|
- | 49 | return 0; |
|
- | 50 | } |
|
- | 51 | ||
- | 52 | void setRpmMap(int i, int16_t val) |
|
- | 53 | { |
|
- | 54 | if (i >= 0 && i < MAX_TIMING_POINTS) |
|
- | 55 | rpmMap[i] = val; |
|
- | 56 | } |
|
- | 57 | ||
- | 58 | int16_t getVacuumMap(int i) |
|
- | 59 | { |
|
- | 60 | if (i >= 0 && i < MAX_VACUUM_POINTS) |
|
- | 61 | return vacuumMap[i]; |
|
- | 62 | else |
|
- | 63 | return 0; |
|
- | 64 | } |
|
- | 65 | ||
- | 66 | void setVacuumMap(int i, int16_t val) |
|
- | 67 | { |
|
- | 68 | if (i >= 0 && i < MAX_VACUUM_POINTS) |
|
- | 69 | vacuumMap[i] = val; |
|
- | 70 | } |
|
- | 71 | ||
- | 72 | void setTiming(int vacuumIndex, int rpmIndex, uint8_t value) |
|
- | 73 | { |
|
- | 74 | if (vacuumIndex < 0 && vacuumIndex >= MAX_VACUUM_POINTS) |
|
- | 75 | return; |
|
- | 76 | if (rpmIndex < 0 && rpmIndex >= MAX_VACUUM_POINTS) |
|
- | 77 | return; |
|
- | 78 | mapping[vacuumIndex][rpmIndex] = value; |
|
- | 79 | } |
|
- | 80 | ||
- | 81 | uint8_t getTiming(int vacuumIndex, int rpmIndex) |
|
- | 82 | { |
|
- | 83 | if (vacuumIndex < 0 && vacuumIndex >= MAX_VACUUM_POINTS) |
|
- | 84 | return 0; |
|
- | 85 | if (rpmIndex < 0 && rpmIndex >= MAX_VACUUM_POINTS) |
|
- | 86 | return 0; |
|
- | 87 | return mapping[vacuumIndex][rpmIndex]; |
|
- | 88 | } |
|
- | 89 | ||
- | 90 | int lookup(int point, int16_t const curve[], int size, int16_t *frac) |
|
51 | { |
91 | { |
52 | // check lower bounds |
92 | // check lower bounds |
53 | if (point < curve[0]) |
93 | if (point < curve[0]) |
54 | { |
94 | { |
55 | *frac = 0; |
95 | *frac = 0; |