Correctifs de bugs

This commit is contained in:
=
2021-01-27 14:19:36 +01:00
parent 561a727a0a
commit 058362a533
6 changed files with 105 additions and 63 deletions

View File

@@ -7,11 +7,11 @@
// Pins declaration
const int SPEEDS_PIN = A0;
const int HANDBRAKE_PIN = A5;
const int HANDBRAKE_PIN = A1;
const int CLUTCH_PIN = A2;
const int BRAKE_PIN = A3;
const int ACCELERATOR_PIN = A4;
const int DIRECTION_PIN = A1;
const int DIRECTION_PIN = A5;
const int LEFT_BLINKER_PIN = 2;
const int RIGHT_BLINKER_PIN = 3;
const int WARNING_PIN = 4;
@@ -21,13 +21,15 @@ const int CRUISE_DOWN_PIN = 7;
const int STARTER_PIN = 8;
const int HORN_PIN = 9;
const int LIGHTS_ON_PIN = 10;
const int ROAD_LIGHTS_PIN = 11;
const int HEAD_LIGHTS_PIN = 12;
const int FOG_LIGHTS_PIN = 13;
const int ROAD_LIGHTS_PIN = 16;
const int HEAD_LIGHTS_PIN = 14;
const int FOG_LIGHTS_PIN = 15;
const int INTERVAL = 15;
void setup() {
// Initialize sensors
pinMode(SPEEDS_PIN, INPUT_PULLUP);
pinMode(SPEEDS_PIN, INPUT);
pinMode(HANDBRAKE_PIN, INPUT_PULLUP);
pinMode(CLUTCH_PIN, INPUT_PULLUP);
pinMode(BRAKE_PIN, INPUT_PULLUP);
@@ -47,10 +49,52 @@ void setup() {
pinMode(FOG_LIGHTS_PIN, INPUT_PULLUP);
// Initialize ZenDrive Library
ZenDrive.begin(true);
ZenDrive.begin();
//Button shared margin
int btnMargin = 5;
// Send current states
/* Gearshift */
int value = analogRead(SPEEDS_PIN);
if(value < 200) ZenDrive.switchSpeed1();
else if(value < 326) ZenDrive.switchSpeed2();
else if(value < 421) ZenDrive.switchSpeed3();
else if(value < 493) ZenDrive.switchSpeed4();
else if(value < 551) ZenDrive.switchSpeed5();
else if(value < 596) ZenDrive.switchSpeed6();
else if(value < 634) ZenDrive.switchSpeedR();
else ZenDrive.switchNeutral();
//Read handbrake
ZenDrive.setHandbrake(map(analogRead(HANDBRAKE_PIN), 0, 1023, 0, 255));
ZenDrive.sendGearshiftStates();
/* Pedals module */
// Read clutch
ZenDrive.setClutch(map(analogRead(CLUTCH_PIN), 0, 1023, 0, 255));
// Read brake
ZenDrive.setBrake(map(analogRead(BRAKE_PIN), 0, 1023, 0, 255));
// Read accelerator
ZenDrive.setAccelerator(map(analogRead(ACCELERATOR_PIN), 0, 1023, 0, 255));
ZenDrive.sendPedalsStates();
/* Steering wheel module */
// Left blinker
ZenDrive.setBlinkerLeft(digitalRead(LEFT_BLINKER_PIN));
// Right blinker
ZenDrive.setBlinkerRight(digitalRead(RIGHT_BLINKER_PIN));
// Warning
ZenDrive.setWarning(digitalRead(WARNING_PIN));
// Lights
if (!digitalRead(LIGHTS_ON_PIN)) ZenDrive.switchLightsOn();
else if(!digitalRead(ROAD_LIGHTS_PIN)) ZenDrive.switchRoadLights();
else ZenDrive.switchLightsOff();
// Head lights
ZenDrive.setHeadLights(digitalRead(HEAD_LIGHTS_PIN));
// Fog lights
ZenDrive.setFogLights(digitalRead(FOG_LIGHTS_PIN));
// Starter
ZenDrive.setStarter(digitalRead(STARTER_PIN));
// Read direction
ZenDrive.setDirection(map(analogRead(DIRECTION_PIN), 0, 1023, -127, 127));
ZenDrive.sendWheelStates();
}
void loop() {
@@ -61,14 +105,14 @@ void loop() {
/* Gearshift module */
//Read speed states on the analog shared pin
int value = analogRead(A0);
if(value > 900) ZenDrive.switchSpeedR();
else if(value > 800) ZenDrive.switchSpeed6();
else if(value > 700) ZenDrive.switchSpeed5();
else if(value > 600) ZenDrive.switchSpeed4();
else if(value > 500) ZenDrive.switchSpeed3();
else if(value > 400) ZenDrive.switchSpeed2();
else if(value > 300) ZenDrive.switchSpeed1();
int value = analogRead(SPEEDS_PIN);
if(value < 200) ZenDrive.switchSpeed1();
else if(value < 326) ZenDrive.switchSpeed2();
else if(value < 421) ZenDrive.switchSpeed3();
else if(value < 493) ZenDrive.switchSpeed4();
else if(value < 551) ZenDrive.switchSpeed5();
else if(value < 596) ZenDrive.switchSpeed6();
else if(value < 634) ZenDrive.switchSpeedR();
else ZenDrive.switchNeutral();
//Read handbrake
ZenDrive.setHandbrake(map(analogRead(HANDBRAKE_PIN), 0, 1023, 0, 255));
@@ -93,8 +137,8 @@ void loop() {
// Warning
ZenDrive.setWarning(digitalRead(WARNING_PIN));
// Lights
if (digitalRead(LIGHTS_ON_PIN)) ZenDrive.switchLightsOn();
else if(digitalRead(ROAD_LIGHTS_PIN)) ZenDrive.switchRoadLights();
if (!digitalRead(LIGHTS_ON_PIN)) ZenDrive.switchLightsOn();
else if(!digitalRead(ROAD_LIGHTS_PIN)) ZenDrive.switchRoadLights();
else ZenDrive.switchLightsOff();
// Head lights
ZenDrive.setHeadLights(digitalRead(HEAD_LIGHTS_PIN));
@@ -103,35 +147,16 @@ void loop() {
// Starter
ZenDrive.setStarter(digitalRead(STARTER_PIN));
// Horn
ZenDrive.setHorn(digitalRead(HORN_PIN));
ZenDrive.setHorn(!digitalRead(HORN_PIN));
// Cruise on
if(digitalRead(CRUISE_PIN)) ZenDrive.activeCruise();
if(!digitalRead(CRUISE_PIN)) ZenDrive.activeCruise();
// Cruise up
if(digitalRead(CRUISE_UP_PIN)) ZenDrive.increaseCruise();
if(!digitalRead(CRUISE_UP_PIN)) ZenDrive.increaseCruise();
// Cruise down
if(digitalRead(CRUISE_DOWN_PIN)) ZenDrive.decreaseCruise();
if(!digitalRead(CRUISE_DOWN_PIN)) ZenDrive.decreaseCruise();
// Read direction
ZenDrive.setDirection(map(analogRead(DIRECTION_PIN), 0, 1023, -127, 127));
// Send steering wheel states if they are changes
if(ZenDrive.wheelNeedRefresh) ZenDrive.sendWheelStates();
// Read pin value
/*int clutchValue = map(analogRead(clutchPin), 0, 1023, 0, 255);
if(clutchValue < lastClutchState - 5 || clutchValue > lastClutchState + 5){
//Serial.println(clutchValue);
ZenDrive.setHandbrake(clutchValue);
lastClutchState = clutchValue;
}*/
/*for (int index = 0; index < 4; index++)
{
int currentButtonState = !digitalRead(index + pinToButtonMap);
if (currentButtonState != lastButtonState[index])
{
Joystick.setButton(index, currentButtonState);
lastButtonState[index] = currentButtonState;
}
}*/
delay(50);
}