-
Notifications
You must be signed in to change notification settings - Fork 70
/
scratchpad.cpp
92 lines (85 loc) · 3.24 KB
/
scratchpad.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//////////////////////////////////////////////////
// MODE CONTROL SECTION //
//////////////////////////////////////////////////
float udc = utils::ProcessUdc(vehicleStartTime, GetInt(Param::speed));
stt |= Param::GetInt(Param::pot) <= Param::GetInt(Param::potmin) ? STAT_NONE : STAT_POTPRESSED;
stt |= udc >= Param::GetFloat(Param::udcsw) ? STAT_NONE : STAT_UDCBELOWUDCSW;
stt |= udc < Param::GetFloat(Param::udclim) ? STAT_NONE : STAT_UDCLIM;
Param::SetInt(Param::status, stt);
switch (opmode)
{
case MOD_OFF:
initbyStart=false;
initbyCharge=false;
DigIo::inv_out.Clear();//inverter power off
DigIo::dcsw_out.Clear();
IOMatrix::GetPin(IOMatrix::NEGCONTACTOR)->Clear();//Negative contactors off if used
IOMatrix::GetPin(IOMatrix::COOLANTPUMP)->Clear();//Coolant pump off if used
DigIo::prec_out.Clear();
Param::SetInt(Param::dir, 0); // shift to park/neutral on shutdown regardless of shifter pos
selectedVehicle->DashOff();
StartSig=false;//reset for next time
if(Param::GetInt(Param::pot) < Param::GetInt(Param::potmin))
{
if ((selectedVehicle->Start() && selectedVehicle->Ready()))
{
StartSig=true;
opmode = MOD_PRECHARGE;//proceed to precharge if 1)throttle not pressed , 2)ign on , 3)start signal rx
vehicleStartTime = rtc_get_counter_val();
initbyStart=true;
}
}
if(chargeMode)
{
opmode = MOD_PRECHARGE;//proceed to precharge if charge requested.
vehicleStartTime = rtc_get_counter_val();
initbyCharge=true;
}
Param::SetInt(Param::opmode, opmode);
break;
case MOD_PECHARGE:
if (!chargeMode)
{
DigIo::inv_out.Set();//inverter power on but not if we are in charge mode!
}
IOMatrix::GetPin(IOMatrix::NEGCONTACTOR)->Set();
IOMatrix::GetPin(IOMatrix::COOLANTPUMP)->Set();
DigIo::prec_out.Set();//commence precharge
if ((stt & (STAT_POTPRESSED | STAT_UDCBELOWUDCSW | STAT_UDCLIM)) == STAT_NONE)
{
if(StartSig)
{
opmode = MOD_RUN;
StartSig=false;//reset for next time
}
else if(chargeMode) opmode = MOD_CHARGE;
}
if(initbyCharge && !chargeMode) opmode = MOD_OFF;// These two statements catch a precharge hang from either start mode or run mode.
if(initbyStart && !selectedVehicle->Ready()) opmode = MOD_OFF;
if (udc < (udcsw) && rtc_get_counter_val() > (vehicleStartTime + PRECHARGE_TIMEOUT))
{
DigIo::prec_out.Clear();
ErrorMessage::Post(ERR_PRECHARGE);
opmode = MOD_PCHFAIL;
}
Param::SetInt(Param::opmode, opmode);
break;
case MOD_PCHFAIL:
StartSig=false
opmode = MOD_OFF;
Param::SetInt(Param::opmode, opmode);
break;
case MOD_CHARGE:
DigIo::dcsw_out.Set();
ErrorMessage::UnpostAll();
if(!chargeMode) opmode = MOD_OFF;
Param::SetInt(Param::opmode, opmode);
break;
case MOD_RUN:
DigIo::dcsw_out.Set();
Param::SetInt(Param::opmode, MOD_RUN);
ErrorMessage::UnpostAll();
if(!selectedVehicle->Ready()) opmode = MOD_OFF;
Param::SetInt(Param::opmode, opmode);
break;
}