GCC Code Coverage Report


Directory: ./
File: firmware/controllers/tcu/buttonshift.cpp
Date: 2025-11-16 14:52:24
Coverage Exec Excl Total
Lines: 80.7% 46 0 57
Functions: 100.0% 4 0 4
Branches: 75.0% 12 0 16
Decisions: 75.0% 12 - 16

Line Branch Decision Exec Source
1 /**
2 * @file buttonshift.cpp
3 * @brief Polls pins for gear changes
4 *
5 * @date Aug 31, 2020
6 * @author David Holdeman, (c) 2020
7 */
8
9 #include "pch.h"
10
11 #include "buttonshift.h"
12
13 #if EFI_TCU
14 ButtonShiftController buttonShiftController;
15
16 1 ButtonShiftController::ButtonShiftController() :
17 1 debounceUp("gear_up"),
18 1 debounceDown("gear_down")
19 {
20
21 1 }
22
23 1 void ButtonShiftController::init() {
24 // 500 millisecond is maybe a little long?
25 1 debounceUp.init(500, engineConfiguration->tcuUpshiftButtonPin, engineConfiguration->tcuUpshiftButtonPinMode);
26 1 debounceDown.init(500, engineConfiguration->tcuDownshiftButtonPin, engineConfiguration->tcuDownshiftButtonPinMode);
27
28 1 GearControllerBase::init();
29 1 }
30
31 4823 void ButtonShiftController::update() {
32 4823 bool upPinState = false;
33 4823 bool downPinState = false;
34 // Read pins
35 4823 upPinState = debounceUp.readPinEvent();
36 4823 downPinState = debounceDown.readPinEvent();
37 4823 gear_e gear = getDesiredGear();
38 // Select new gear based on current desired gear.
39
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 4813 times.
2/2
✓ Decision 'true' taken 10 times.
✓ Decision 'false' taken 4813 times.
4823 if (upPinState) {
40
5/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 6 times.
10 switch (gear) {
41 case REVERSE:
42 setDesiredGear(NEUTRAL);
43 break;
44
1/1
✓ Decision 'true' taken 1 time.
1 case NEUTRAL:
45 1 setDesiredGear(GEAR_1);
46 1 break;
47
1/1
✓ Decision 'true' taken 1 time.
1 case GEAR_1:
48 1 setDesiredGear(GEAR_2);
49 1 break;
50
1/1
✓ Decision 'true' taken 1 time.
1 case GEAR_2:
51 1 setDesiredGear(GEAR_3);
52 1 break;
53
1/1
✓ Decision 'true' taken 1 time.
1 case GEAR_3:
54 1 setDesiredGear(GEAR_4);
55 1 break;
56
1/1
✓ Decision 'true' taken 6 times.
6 default:
57 6 break;
58 }
59
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4810 times.
2/2
✓ Decision 'true' taken 3 times.
✓ Decision 'false' taken 4810 times.
4813 } else if (downPinState) {
60
3/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
3 switch (gear) {
61 case NEUTRAL:
62 setDesiredGear(REVERSE);
63 break;
64 case GEAR_1:
65 setDesiredGear(NEUTRAL);
66 break;
67
1/1
✓ Decision 'true' taken 1 time.
1 case GEAR_2:
68 1 setDesiredGear(GEAR_1);
69 1 break;
70
1/1
✓ Decision 'true' taken 1 time.
1 case GEAR_3:
71 1 setDesiredGear(GEAR_2);
72 1 break;
73
1/1
✓ Decision 'true' taken 1 time.
1 case GEAR_4:
74 1 setDesiredGear(GEAR_3);
75 1 break;
76 default:
77 break;
78 }
79 }
80
81 4823 GearControllerBase::update();
82 4823 }
83
84 1 ButtonShiftController* getButtonShiftController() {
85 1 return &buttonShiftController;
86 }
87 #endif // EFI_TCU
88