| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | /** | |||
| 2 | * @file fuel_schedule.h | |||
| 3 | */ | |||
| 4 | ||||
| 5 | #pragma once | |||
| 6 | ||||
| 7 | #include "global.h" | |||
| 8 | #include "efi_gpio.h" | |||
| 9 | #include "scheduler.h" | |||
| 10 | #include "fl_stack.h" | |||
| 11 | #include "trigger_structure.h" | |||
| 12 | #include "wall_fuel.h" | |||
| 13 | ||||
| 14 | #define MAX_WIRES_COUNT 2 | |||
| 15 | ||||
| 16 | class InjectionEvent { | |||
| 17 | public: | |||
| 18 | InjectionEvent() = default; | |||
| 19 | ||||
| 20 | bool update(); | |||
| 21 | ||||
| 22 | // Call this every decoded trigger tooth. It will schedule any relevant events for this injector. | |||
| 23 | void onTriggerTooth(efitick_t nowNt, float currentPhase, float nextPhase); | |||
| 24 | ||||
| 25 | WallFuel& getWallFuel(); | |||
| 26 | ||||
| 27 | 8136 | void setIndex(uint8_t index) { | ||
| 28 | 8136 | ownIndex = index; | ||
| 29 | 8136 | } | ||
| 30 | ||||
| 31 | private: | |||
| 32 | // Update the injection start angle | |||
| 33 | bool updateInjectionAngle(); | |||
| 34 | ||||
| 35 | // Compute the injection start angle, compensating for injection duration and injection phase settings. | |||
| 36 | expected<float> computeInjectionAngle() const; | |||
| 37 | ||||
| 38 | /** | |||
| 39 | * This is a performance optimization for IM_SIMULTANEOUS fuel strategy. | |||
| 40 | * It's more efficient to handle all injectors together if that's the case | |||
| 41 | */ | |||
| 42 | bool isSimultaneous = false; | |||
| 43 | uint8_t ownIndex = 0; | |||
| 44 | uint8_t cylinderNumber = 0; | |||
| 45 | ||||
| 46 | WallFuel wallFuel{}; | |||
| 47 | ||||
| 48 | public: | |||
| 49 | // TODO: this should be private | |||
| 50 | InjectorOutputPin *outputs[MAX_WIRES_COUNT]{}; | |||
| 51 | InjectorOutputPin *outputsStage2[MAX_WIRES_COUNT]{}; | |||
| 52 | float injectionStartAngle = 0; | |||
| 53 | }; | |||
| 54 | ||||
| 55 | void turnInjectionPinHigh(scheduler_arg_t arg); | |||
| 56 | ||||
| 57 | ||||
| 58 | /** | |||
| 59 | * This class knows about when to inject fuel | |||
| 60 | */ | |||
| 61 | class FuelSchedule { | |||
| 62 | public: | |||
| 63 | FuelSchedule(); | |||
| 64 | ||||
| 65 | // Call this function if something happens that requires a rebuild, like a change to the trigger pattern | |||
| 66 | void invalidate(); | |||
| 67 | ||||
| 68 | // Call this every trigger tooth. It will schedule all required injector events. | |||
| 69 | void onTriggerTooth(efitick_t nowNt, float currentPhase, float nextPhase); | |||
| 70 | ||||
| 71 | /** | |||
| 72 | * this method schedules all fuel events for an engine cycle | |||
| 73 | * Calculate injector opening angle, pins, and mode for all injectors | |||
| 74 | */ | |||
| 75 | void addFuelEvents(); | |||
| 76 | ||||
| 77 | static void resetOverlapping(); | |||
| 78 | ||||
| 79 | /** | |||
| 80 | * injection events, per cylinder | |||
| 81 | */ | |||
| 82 | InjectionEvent elements[MAX_CYLINDER_COUNT]; | |||
| 83 | bool isReady = false; | |||
| 84 | }; | |||
| 85 | ||||
| 86 | FuelSchedule * getFuelSchedule(); | |||
| 87 |