16 {
21
23
26
32
33
34#if HW_PROTEUS
36
37 setPPSInputs(PROTEUS_IN_ANALOG_VOLT_2, PROTEUS_IN_ANALOG_VOLT_11);
38 setTPS1Inputs(PROTEUS_IN_ANALOG_VOLT_4, PROTEUS_IN_ANALOG_VOLT_3);
39
40
41#endif
42
43#if defined(HW_HELLEN_8CHAN)
52
59#endif
60
61#ifdef HW_HELLEN_UAEFI
64
66
68
74
76
78
79
82
85
86#endif
87
91
99
105
108
109
111
112function getBitRange(data, bitIndex, bitWidth)
113 byteIndex = bitIndex >> 3
114 shift = bitIndex - byteIndex * 8
115 value = data[1 + byteIndex]
116 if (shift + bitWidth > 8) then
117 value = value + data[2 + byteIndex] * 256
118 end
119 mask = (1 << bitWidth) - 1
120 return (value >> shift) & mask
121end
122
123hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
124
125function toHexString(num)
126 if num == 0 then
127 return '0'
128 end
129
130 local result = ""
131 while num > 0 do
132 local n = num % 16
133 result = hexstr[n + 1] ..result
134 num = math.floor(num / 16)
135 end
136 return result
137end
138
139function arrayToString(arr)
140 local str = ""
141 local index = 1
142 while arr[index] ~= nil do
143 str = str.." "..toHexString(arr[index])
144 index = index + 1
145 end
146 return str
147end
148
149STARTER_OUTPUT_INDEX = 0
150startPwm(STARTER_OUTPUT_INDEX, 100, 0)
151
152-- 201
153ECMEngineStatus = 0xC9
154IGN_STATUS = 0x1f1
155-- 0x514
156VIN_Part1 = 1300
157-- 04E1
158VIN_Part2 = 1249
159
160setTickRate(100)
161
162function canIgnStatus(bus, id, dlc, data)
163 crankingBits = getBitRange(data, 2, 2)
164 isCranking = (crankingBits == 2)
165-- need special considerations to append boolean print('crankingBits ' .. crankingBits .. ', isCranking ' .. isCranking)
166 print('crankingBits ' .. crankingBits)
167end
168
169function printAny(bus, id, dlc, data)
170 print('packet ' .. id)
171end
172
173canRxAdd(IGN_STATUS, canIgnStatus)
174-- canRxAddMask(0, 0xFFFFFFF, printAny)
175
176-- todo: take VIN from configuration? encode VIN?
177canVin1 = { 0x47, 0x4E, 0x4C, 0x43, 0x32, 0x45, 0x30, 0x34 }
178canVin2 = { 0x42, 0x52, 0x32, 0x31, 0x36, 0x33, 0x36, 0x36 }
179dataECMEngineStatus = { 0x84, 0x09, 0x99, 0x0A, 0x00, 0x40, 0x08, 0x00 }
180
181-- todo: smarter loop code :)
182canVin1[1] = vin(1)
183canVin1[2] = vin(2)
184canVin1[3] = vin(3)
185canVin1[4] = vin(4)
186canVin1[5] = vin(5)
187canVin1[6] = vin(6)
188canVin1[7] = vin(7)
189canVin1[8] = vin(8)
190
191canVin2[1] = vin(9)
192canVin2[2] = vin(10)
193canVin2[3] = vin(11)
194canVin2[4] = vin(12)
195canVin2[5] = vin(13)
196canVin2[6] = vin(14)
197canVin2[7] = vin(15)
198canVin2[8] = vin(16)
199
200function onTick()
201 txCan(1, VIN_Part1, 0, canVin1)
202 txCan(1, VIN_Part2, 0, canVin2)
203
204 -- good enough for fuel module!
205 txCan(1, ECMEngineStatus, 0, dataECMEngineStatus)
206
207 if isCranking then
208 setPwmDuty(STARTER_OUTPUT_INDEX, 1)
209 else
210 setPwmDuty(STARTER_OUTPUT_INDEX, 0)
211 end
212end
213
214 )");
215
218}
void setTPS1Calibration(uint16_t tpsMin, uint16_t tpsMax)
void setPPSInputs(adc_channel_e pps1, adc_channel_e pps2)
void setTPS1Inputs(adc_channel_e tps1, adc_channel_e tps2)
void setPPSCalibration(float primaryUp, float primaryDown, float secondaryUp, float secondaryDown)
void setLeftRightBanksNeedBetterName()
static constexpr engine_configuration_s * engineConfiguration
void setLuaScript(const char *luaScript)