forked from collin80/GEVCU6
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicleSpecific.cpp
More file actions
153 lines (129 loc) · 5.36 KB
/
VehicleSpecific.cpp
File metadata and controls
153 lines (129 loc) · 5.36 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* VehicleSpecific.h - All code specific to your particular vehicle. This keeps the rest of code generic.
*
Copyright (c) 2016 Collin Kidder, Michael Neuweiler, Charles Galpin
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* The purpose of this file is to create a "device" that is used to interface with all of the other enabled
* devices in order to create a custom control system for your car. Each main device has configuration options
* and is meant for generalized usage. But, what if you want to go further? Perhaps you've got a PowerKeyPro
* keypad and you want to be able to select different regen powers or drive power settings? The default device
* drivers don't support such things because they're not very generic. Or, perhaps you want to allow
* your BMS and motor controller to talk? Maybe the BMS can limit regen or drive power automatically based on battery
* conditions. The code doesn't currently support such things but it would be possible to read the BMS here and then update
* the motor controller. The options are endless. The below code will be updated to show what Collin has done with a reference car
* in order to show what is possible and how it could be coded. Feel free to delete any code not appropriate to your car and/or
* add any extra code you need to make GEVCU do what you want.
*/
#include "VehicleSpecific.h"
/*
* Constructor
*/
VehicleSpecific::VehicleSpecific() : Device() {
prefsHandler = new PrefHandler(VEHICLESPECIFIC);
commonName = "VehicleSpecific";
didInitialSetup = false;
}
/*
* Setup the device.
*/
void VehicleSpecific::setup() {
tickHandler.detach(this); // unregister from TickHandler first
Logger::info("add device: VehicleSpecific (id: %X, %X)", VEHICLESPECIFIC, this);
loadConfiguration();
Device::setup(); //call base class
//Use same tick interval as a pot based pedal would have used.
tickHandler.attach(this, CFG_TICK_INTERVAL_VEHICLE);
}
/*
* Process a timer event. This is where you should be doing checks and updates. By default this
* function is called 10 times per second.
*/
void VehicleSpecific::handleTick() {
Device::handleTick(); // Call parent which controls the workflow
Logger::debug("VS Tick Handler");
if (!didInitialSetup)
{
didInitialSetup = true;
systemIO.setAnalogOut(0, 1); //set first button's LED to RED
systemIO.setAnalogOut(0, 1000); //send batch
}
//button 0 on the pad is neutral
//button 1 is drive
//button 2 is reverse
//button 3
//button 4
//button 5
//button 6
//button 7
if (systemIO.getDigitalIn(4)) //set drive mode neutral
{
Logger::debug("VS Setting gear to neutral");
systemIO.setAnalogOut(0, 1);
systemIO.setAnalogOut(1, 0);
systemIO.setAnalogOut(2, 0);
systemIO.setAnalogOut(0, 1000);
MotorController * motor = deviceManager.getMotorController();
if (motor) motor->setSelectedGear(MotorController::NEUTRAL);
}
if (systemIO.getDigitalIn(5)) //set drive mode to drive
{
Logger::debug("VS Setting gear to drive");
systemIO.setAnalogOut(0, 0);
systemIO.setAnalogOut(1, 1);
systemIO.setAnalogOut(2, 0);
systemIO.setAnalogOut(0, 1000);
MotorController * motor = deviceManager.getMotorController();
if (motor) motor->setSelectedGear(MotorController::DRIVE);
}
if (systemIO.getDigitalIn(6)) //set drive mode to reverse
{
Logger::debug("VS Setting gear to reverse");
systemIO.setAnalogOut(0, 0);
systemIO.setAnalogOut(1, 0);
systemIO.setAnalogOut(2, 1);
systemIO.setAnalogOut(0, 1000);
MotorController * motor = deviceManager.getMotorController();
if (motor) motor->setSelectedGear(MotorController::REVERSE);
}
}
/*
* Return the device ID
*/
DeviceId VehicleSpecific::getId() {
return (VEHICLESPECIFIC);
}
DeviceType VehicleSpecific::getType()
{
return DEVICE_MISC;
}
/*
* Load the device configuration.
* If possible values are read from EEPROM. If not, reasonable default values
* are chosen and the configuration is overwritten in the EEPROM.
*/
void VehicleSpecific::loadConfiguration() {
Device::loadConfiguration(); // call parent
}
/*
* Store the current configuration to EEPROM
*/
void VehicleSpecific::saveConfiguration() {
Device::saveConfiguration(); // call parent
}