Skip to content

Commit

Permalink
getVVTPosition returns expected<>
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Sep 13, 2024
1 parent a76268c commit a0bd4e5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
8 changes: 4 additions & 4 deletions firmware/console/status_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,10 @@ static void updateFuelSensors() {
static void updateVvtSensors() {
#if EFI_SHAFT_POSITION_INPUT
// 248
engine->outputChannels.vvtPositionB1I = engine->triggerCentral.getVVTPosition(/*bankIndex*/0, /*camIndex*/0);
engine->outputChannels.vvtPositionB1E = engine->triggerCentral.getVVTPosition(/*bankIndex*/0, /*camIndex*/1);
engine->outputChannels.vvtPositionB2I = engine->triggerCentral.getVVTPosition(/*bankIndex*/1, /*camIndex*/0);
engine->outputChannels.vvtPositionB2E = engine->triggerCentral.getVVTPosition(/*bankIndex*/1, /*camIndex*/1);
engine->outputChannels.vvtPositionB1I = engine->triggerCentral.getVVTPosition(/*bankIndex*/0, /*camIndex*/0).value_or(0);
engine->outputChannels.vvtPositionB1E = engine->triggerCentral.getVVTPosition(/*bankIndex*/0, /*camIndex*/1).value_or(0);
engine->outputChannels.vvtPositionB2I = engine->triggerCentral.getVVTPosition(/*bankIndex*/1, /*camIndex*/0).value_or(0);
engine->outputChannels.vvtPositionB2E = engine->triggerCentral.getVVTPosition(/*bankIndex*/1, /*camIndex*/1).value_or(0);
#endif
}

Expand Down
8 changes: 4 additions & 4 deletions firmware/controllers/can/can_verbose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ struct Cams {

static void populateFrame(Cams& msg) {
#if EFI_SHAFT_POSITION_INPUT
msg.Bank1IntakeActual = engine->triggerCentral.getVVTPosition(0, 0);
msg.Bank1ExhaustActual = engine->triggerCentral.getVVTPosition(0, 1);
msg.Bank2IntakeActual = engine->triggerCentral.getVVTPosition(1, 0);
msg.Bank2ExhaustActual = engine->triggerCentral.getVVTPosition(1, 1);
msg.Bank1IntakeActual = engine->triggerCentral.getVVTPosition(0, 0).value_or(0);
msg.Bank1ExhaustActual = engine->triggerCentral.getVVTPosition(0, 1).value_or(0);
msg.Bank2IntakeActual = engine->triggerCentral.getVVTPosition(1, 0).value_or(0);
msg.Bank2ExhaustActual = engine->triggerCentral.getVVTPosition(1, 1).value_or(0);
#endif // EFI_SHAFT_POSITION_INPUT

// TODO: maybe don't rely on outputChannels here
Expand Down
7 changes: 5 additions & 2 deletions firmware/controllers/trigger/trigger_central.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ int TriggerCentral::getHwEventCounter(int index) const {
}


angle_t TriggerCentral::getVVTPosition(uint8_t bankIndex, uint8_t camIndex) {
expected<angle_t> TriggerCentral::getVVTPosition(uint8_t bankIndex, uint8_t camIndex) {
if (bankIndex >= BANKS_COUNT || camIndex >= CAMS_PER_BANK) {
return NAN;
return unexpected;
}

// TODO: return unexpected if timed out

return vvtPosition[bankIndex][camIndex];
}

Expand Down
2 changes: 1 addition & 1 deletion firmware/controllers/trigger/trigger_central.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class TriggerCentral final : public trigger_central_s {
int vvtEventRiseCounter[CAM_INPUTS_COUNT];
int vvtEventFallCounter[CAM_INPUTS_COUNT];

angle_t getVVTPosition(uint8_t bankIndex, uint8_t camIndex);
expected<angle_t> getVVTPosition(uint8_t bankIndex, uint8_t camIndex);

#if EFI_UNIT_TEST
// latest VVT event position (could be not synchronization event)
Expand Down

0 comments on commit a0bd4e5

Please sign in to comment.