16 {
24 }
25
32
33
36
37
40
50
52
55
57
58#if HW_PROTEUS && EFI_PROD_CODE
61
63
64#if EFI_PROD_CODE
66#else
68#endif
69
71
73
74 setPPSInputs(PROTEUS_IN_ANALOG_VOLT_4, PROTEUS_IN_ANALOG_VOLT_5);
75
76
78--outputIndex = 0
79--startPwm(outputIndex, 100, 0)
80
81rpmLimitSetting = findSetting("compReleaseRpm", 300)
82compReleaseDulationLimit = findSetting("compReleaseDur", 6000)
83
84every200msTimer = Timer.new();
85everySecondTimer = Timer.new();
86every50msTimer = Timer.new();
87offCounter = 0
88-- cranking!
89packet542 = {0x20, 0x82, 0x81, 0xd9, 0x00, 0x00, 0x00, 0x00}
90packet543 = {0x13, 0x57, 0x13, 0x45, 0x00, 0xe8, 0x00, 0x00}
91packet541 = {0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x00, 0xFF}
92
93-- every 200ms
94packet540 = {0x00, 0x00, 0x5a, 0x4c, 0xff, 0x00, 0x00, 0x00}
95
96-- every 1000ms
97packet502 = {0x01}
98packet546 = {0x35, 0x48, 0x44, 0x31, 0x46, 0x48}
99packet547 = {0x50, 0x41, 0x31, 0x4b, 0x42, 0x36}
100packet548 = {0x33, 0x34, 0x38, 0x32, 0x32, 0x00}
101
102counter543 = 0;
103setTickRate(66);
104
105canRxAdd(0x570)
106canRxAdd(0x500)
107
108function onCanRx(bus, id, dlc, data)
109 --print('got CAN id=' .. id .. ' dlc=' .. dlc)
110
111 if id == 0x500 then --Check can state of BCM
112 canState = data[1]
113 if canState == 01 then
114 packet502[1] = 0x01
115 else
116 packet502[1] = 0x00
117 end
118 if id == 0x570 then
119 curState = data[1]
120 if curState == 06 then -- Cranking TODO: MUST ONLY DO THIS ON RPM TILL STARt
121 packet542[2] = 0x82
122 end
123 if curState == 04 then -- Kill off
124 packet542[2] = 0x82
125 end
126 if curState == 01 then -- Kill
127 packet542[2] = 0xA2
128 end
129 end
130 end
131end
132
133
134function onTick()
135
136 if packet502[1] == 01 then
137 offCounter = 0
138 counter543 = (counter543 + 1) % 64
139 packet543[7] = 64 + counter543
140 packet543[8] = crc8_j1850(packet543, 7)
141 APP = getSensor("AcceleratorPedal")
142 if APP == nil then
143 packet543[5] = 0
144 else
145 packet543[5] = APP *2
146 end
147
148 txCan(1, 0x543, 0, packet543)
149 txCan(1, 0x541, 0, packet541)
150
151 if every200msTimer:getElapsedSeconds() > 0.2 then
152 every200msTimer:reset();
153 txCan(1, 0x540, 0, packet540)
154 end
155
156 if every50msTimer:getElapsedSeconds() > 0.05 then
157 every50msTimer:reset();
158 txCan(1, 0x542, 0, packet542)
159 end
160
161 if everySecondTimer:getElapsedSeconds() > 1 then
162 everySecondTimer:reset();
163 txCan(1, 0x502, 0, packet502)
164 txCan(1, 0x546, 0, packet546)
165 txCan(1, 0x547, 0, packet547)
166 txCan(1, 0x548, 0, packet548)
167 end
168
169
170 rpm = getSensor("RPM")
171-- handle nil RPM, todo: change firmware to avoid nil RPM
172 rpm = (rpm == nil and 0 or rpm)
173 --print('Rpm ' .. rpm)
174 --print('getTimeSinceTriggerEventMs ' .. getTimeSinceTriggerEventMs())
175 enableCompressionReleaseSolenoid = getTimeSinceTriggerEventMs() < compReleaseDulationLimit and rpm < rpmLimitSetting
176 duty = enableCompressionReleaseSolenoid and 1 or 0
177-- print("Compression release solenoid " .. duty)
178-- setPwmDuty(outputIndex, duty)
179 else
180 if offCounter == 0 then --goodbye sweet love
181 txCan(1, 0x502, 0, packet502) --goodbye
182 offCounter = 1 --One shot
183 end
184 end
185end
187#endif
188}
void setCustomMap(float lowValue, float mapLowValueVoltage, float highValue, float mapHighValueVoltage)
void setPPSInputs(adc_channel_e pps1, adc_channel_e pps2)
void setTPS1Inputs(adc_channel_e tps1, adc_channel_e tps2)
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
static void harleyEngine()
angle_t timing_offset_cylinder[MAX_CYLINDER_COUNT]
gppwm_note_t scriptSettingName[SCRIPT_SETTING_COUNT]
ignition_mode_e ignitionMode
int8_t gapTrackingLengthOverride
output_pin_e mainRelayPin
vvt_mode_e vvtMode[CAMS_PER_BANK]
output_pin_e injectionPins[MAX_CYLINDER_COUNT]
int8_t maximumIgnitionTiming
int8_t minimumIgnitionTiming
brain_input_pin_e triggerInputPins[TRIGGER_INPUT_PIN_COUNT]
script_setting_t scriptSetting[SCRIPT_SETTING_COUNT]
float triggerGapOverrideFrom[GAP_TRACKING_LENGTH]
injection_mode_e injectionMode
brain_input_pin_e camInputs[CAM_INPUTS_COUNT]
float mapCamDetectionAnglePosition
output_pin_e ignitionPins[MAX_CYLINDER_COUNT]
output_pin_e luaOutputPins[LUA_PWM_COUNT]
float triggerGapOverrideTo[GAP_TRACKING_LENGTH]