rusefi/firmware/controllers/engine_cycle/fuel_schedule.h

87 lines
1.9 KiB
C++

/**
* @file fuel_schedule.h
*/
#pragma once
#include "global.h"
#include "efi_gpio.h"
#include "scheduler.h"
#include "fl_stack.h"
#include "trigger_structure.h"
#include "wall_fuel.h"
#define MAX_WIRES_COUNT 2
class InjectionEvent {
public:
InjectionEvent();
bool update();
// Call this every decoded trigger tooth. It will schedule any relevant events for this injector.
void onTriggerTooth(efitick_t nowNt, float currentPhase, float nextPhase);
WallFuel& getWallFuel();
void setIndex(uint8_t index) {
ownIndex = index;
}
private:
// Update the injection start angle
bool updateInjectionAngle();
// Compute the injection start angle, compensating for injection duration and injection phase settings.
expected<float> computeInjectionAngle() const;
/**
* This is a performance optimization for IM_SIMULTANEOUS fuel strategy.
* It's more efficient to handle all injectors together if that's the case
*/
bool isSimultaneous = false;
uint8_t ownIndex = 0;
uint8_t cylinderNumber = 0;
WallFuel wallFuel;
public:
// TODO: this should be private
InjectorOutputPin *outputs[MAX_WIRES_COUNT];
InjectorOutputPin *outputsStage2[MAX_WIRES_COUNT];
float injectionStartAngle = 0;
};
void turnInjectionPinHigh(uintptr_t arg);
/**
* This class knows about when to inject fuel
*/
class FuelSchedule {
public:
FuelSchedule();
// Call this function if something happens that requires a rebuild, like a change to the trigger pattern
void invalidate();
// Call this every trigger tooth. It will schedule all required injector events.
void onTriggerTooth(efitick_t nowNt, float currentPhase, float nextPhase);
/**
* this method schedules all fuel events for an engine cycle
* Calculate injector opening angle, pins, and mode for all injectors
*/
void addFuelEvents();
void resetOverlapping();
/**
* injection events, per cylinder
*/
InjectionEvent elements[MAX_CYLINDER_COUNT];
bool isReady = false;
};
FuelSchedule * getFuelSchedule();