Version initiale
This commit is contained in:
BIN
Notice d'utilisation.docx
Normal file
BIN
Notice d'utilisation.docx
Normal file
Binary file not shown.
BIN
Shifter STL/Assy.STL
Normal file
BIN
Shifter STL/Assy.STL
Normal file
Binary file not shown.
BIN
Shifter STL/Center.STL
Normal file
BIN
Shifter STL/Center.STL
Normal file
Binary file not shown.
BIN
Shifter STL/Center_top.STL
Normal file
BIN
Shifter STL/Center_top.STL
Normal file
Binary file not shown.
BIN
Shifter STL/Lower_frame.STL
Normal file
BIN
Shifter STL/Lower_frame.STL
Normal file
Binary file not shown.
BIN
Shifter STL/Lower_ring.STL
Normal file
BIN
Shifter STL/Lower_ring.STL
Normal file
Binary file not shown.
BIN
Shifter STL/Switch_mount.STL
Normal file
BIN
Shifter STL/Switch_mount.STL
Normal file
Binary file not shown.
BIN
Shifter STL/Upper_frame.STL
Normal file
BIN
Shifter STL/Upper_frame.STL
Normal file
Binary file not shown.
BIN
Shifter STL/clamp.STL
Normal file
BIN
Shifter STL/clamp.STL
Normal file
Binary file not shown.
70
SimulatorDescriptor.h
Normal file
70
SimulatorDescriptor.h
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
// D:\Documents\Simulator project\SimulatorDescriptor.h
|
||||||
|
|
||||||
|
|
||||||
|
char ReportDescriptor[125] = {
|
||||||
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
|
0x09, 0x04, // USAGE (Joystick)
|
||||||
|
0xa1, 0x01, // COLLECTION (Application)
|
||||||
|
0x85, 0x03, // REPORT_ID (3)
|
||||||
|
0x05, 0x09, // USAGE_PAGE (Button)
|
||||||
|
0x19, 0x01, // USAGE_MINIMUM (Button 1)
|
||||||
|
0x29, 0x08, // USAGE_MAXIMUM (Button 8)
|
||||||
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||||
|
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
||||||
|
0x95, 0x08, // REPORT_COUNT (8)
|
||||||
|
0x75, 0x01, // REPORT_SIZE (1)
|
||||||
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||||
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||||
|
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
|
||||||
|
0xa1, 0x00, // COLLECTION (Physical)
|
||||||
|
0x09, 0x32, // USAGE (Z)
|
||||||
|
0x75, 0x08, // REPORT_SIZE (8)
|
||||||
|
0x95, 0x01, // REPORT_COUNT (1)
|
||||||
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||||
|
0xc0, // END_COLLECTION
|
||||||
|
0xc0, // END_COLLECTION
|
||||||
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
|
0x09, 0x04, // USAGE (Joystick)
|
||||||
|
0xa1, 0x01, // COLLECTION (Application)
|
||||||
|
0x85, 0x04, // REPORT_ID (4)
|
||||||
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||||
|
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
|
||||||
|
0xa1, 0x00, // COLLECTION (Physical)
|
||||||
|
0x09, 0x33, // USAGE (Rx)
|
||||||
|
0x09, 0x34, // USAGE (Ry)
|
||||||
|
0x09, 0x35, // USAGE (Rz)
|
||||||
|
0x75, 0x08, // REPORT_SIZE (8)
|
||||||
|
0x95, 0x03, // REPORT_COUNT (3)
|
||||||
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||||
|
0xc0, // END_COLLECTION
|
||||||
|
0xc0, // END_COLLECTION
|
||||||
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
|
0x09, 0x04, // USAGE (Joystick)
|
||||||
|
0xa1, 0x01, // COLLECTION (Application)
|
||||||
|
0x85, 0x05, // REPORT_ID (5)
|
||||||
|
0x05, 0x09, // USAGE_PAGE (Button)
|
||||||
|
0x19, 0x01, // USAGE_MINIMUM (Button 1)
|
||||||
|
0x29, 0x0b, // USAGE_MAXIMUM (Button 11)
|
||||||
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||||
|
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
||||||
|
0x75, 0x01, // REPORT_SIZE (1)
|
||||||
|
0x95, 0x0b, // REPORT_COUNT (11)
|
||||||
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||||
|
0x95, 0x01, // REPORT_COUNT (1)
|
||||||
|
0x75, 0x05, // REPORT_SIZE (5)
|
||||||
|
0x81, 0x03, // INPUT (Cnst,Var,Abs)
|
||||||
|
0x05, 0x02, // USAGE_PAGE (Simulation Controls)
|
||||||
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||||
|
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
|
||||||
|
0xa1, 0x00, // COLLECTION (Physical)
|
||||||
|
0x09, 0xc8, // USAGE (Steering)
|
||||||
|
0x75, 0x08, // REPORT_SIZE (8)
|
||||||
|
0x95, 0x01, // REPORT_COUNT (1)
|
||||||
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||||
|
0xc0, // END_COLLECTION
|
||||||
|
0xc0, // END_COLLECTION
|
||||||
|
0x05, 0x01 // USAGE_PAGE (Generic Desktop)
|
||||||
|
};
|
||||||
|
|
||||||
BIN
SimulatorDescriptor.hid
Normal file
BIN
SimulatorDescriptor.hid
Normal file
Binary file not shown.
137
ZenDrive Simulator/ZenDrive Simulator.ino
Normal file
137
ZenDrive Simulator/ZenDrive Simulator.ino
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
// ZenDrive Simulator firmware
|
||||||
|
// Copyright (c) 2021 - Valentin Boulanger
|
||||||
|
// Version : 1.0.0
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "ZenDrive.h"
|
||||||
|
|
||||||
|
// Pins declaration
|
||||||
|
const int SPEEDS_PIN = A0;
|
||||||
|
const int HANDBRAKE_PIN = A5;
|
||||||
|
const int CLUTCH_PIN = A2;
|
||||||
|
const int BRAKE_PIN = A3;
|
||||||
|
const int ACCELERATOR_PIN = A4;
|
||||||
|
const int DIRECTION_PIN = A1;
|
||||||
|
const int LEFT_BLINKER_PIN = 2;
|
||||||
|
const int RIGHT_BLINKER_PIN = 3;
|
||||||
|
const int WARNING_PIN = 4;
|
||||||
|
const int CRUISE_PIN = 5;
|
||||||
|
const int CRUISE_UP_PIN = 6;
|
||||||
|
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;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Initialize sensors
|
||||||
|
pinMode(SPEEDS_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(HANDBRAKE_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(CLUTCH_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(BRAKE_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(ACCELERATOR_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(DIRECTION_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(LEFT_BLINKER_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(RIGHT_BLINKER_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(WARNING_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(CRUISE_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(CRUISE_UP_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(CRUISE_DOWN_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(STARTER_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(HORN_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(LIGHTS_ON_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(ROAD_LIGHTS_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(HEAD_LIGHTS_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(FOG_LIGHTS_PIN, INPUT_PULLUP);
|
||||||
|
|
||||||
|
// Initialize ZenDrive Library
|
||||||
|
ZenDrive.begin(true);
|
||||||
|
|
||||||
|
//Button shared margin
|
||||||
|
int btnMargin = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Set refresh to false
|
||||||
|
ZenDrive.gearshiftNeedRefresh = false;
|
||||||
|
ZenDrive.pedalsNeedRefresh = false;
|
||||||
|
ZenDrive.wheelNeedRefresh = false;
|
||||||
|
|
||||||
|
/* 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();
|
||||||
|
else ZenDrive.switchNeutral();
|
||||||
|
//Read handbrake
|
||||||
|
ZenDrive.setHandbrake(map(analogRead(HANDBRAKE_PIN), 0, 1023, 0, 255));
|
||||||
|
// Send gearshift states if there are changes
|
||||||
|
if(ZenDrive.gearshiftNeedRefresh) 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));
|
||||||
|
// Send pedals states if they are changes
|
||||||
|
if(ZenDrive.pedalsNeedRefresh) 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));
|
||||||
|
// Horn
|
||||||
|
ZenDrive.setHorn(digitalRead(HORN_PIN));
|
||||||
|
// Cruise on
|
||||||
|
if(digitalRead(CRUISE_PIN)) ZenDrive.activeCruise();
|
||||||
|
// Cruise up
|
||||||
|
if(digitalRead(CRUISE_UP_PIN)) ZenDrive.increaseCruise();
|
||||||
|
// Cruise down
|
||||||
|
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);
|
||||||
|
}
|
||||||
504
ZenDrive Simulator/ZenDrive.cpp
Normal file
504
ZenDrive Simulator/ZenDrive.cpp
Normal file
@@ -0,0 +1,504 @@
|
|||||||
|
/*
|
||||||
|
ZenDrive.cpp
|
||||||
|
|
||||||
|
Copyright (c) 2021, Valentin Boulanger
|
||||||
|
|
||||||
|
This library is a part of the ZenDrive simulator firmware.
|
||||||
|
Version : 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ZenDrive.h"
|
||||||
|
|
||||||
|
#if defined(_USING_HID)
|
||||||
|
|
||||||
|
#define GEARSHIFT_REPORT_ID 0x03
|
||||||
|
#define GEARSHIFT_STATE_SIZE 2
|
||||||
|
|
||||||
|
#define PEDALS_REPORT_ID 0x04
|
||||||
|
#define PEDALS_STATE_SIZE 3
|
||||||
|
|
||||||
|
#define WHEEL_REPORT_ID 0x05
|
||||||
|
#define WHEEL_STATE_SIZE 3
|
||||||
|
|
||||||
|
static const uint8_t _hidReportDescriptor[] PROGMEM = {
|
||||||
|
|
||||||
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
|
0x09, 0x04, // USAGE (Joystick)
|
||||||
|
0xa1, 0x01, // COLLECTION (Application)
|
||||||
|
0x85, GEARSHIFT_REPORT_ID, // REPORT_ID (3)
|
||||||
|
0x05, 0x09, // USAGE_PAGE (Button)
|
||||||
|
0x19, 0x01, // USAGE_MINIMUM (Button 1)
|
||||||
|
0x29, 0x08, // USAGE_MAXIMUM (Button 8)
|
||||||
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||||
|
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
||||||
|
0x95, 0x08, // REPORT_COUNT (8)
|
||||||
|
0x75, 0x01, // REPORT_SIZE (1)
|
||||||
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||||
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||||
|
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
|
||||||
|
0xa1, 0x00, // COLLECTION (Physical)
|
||||||
|
0x09, 0x32, // USAGE (Z)
|
||||||
|
0x75, 0x08, // REPORT_SIZE (8)
|
||||||
|
0x95, 0x01, // REPORT_COUNT (1)
|
||||||
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||||
|
0xc0, // END_COLLECTION
|
||||||
|
0xc0, // END_COLLECTION
|
||||||
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
|
0x09, 0x04, // USAGE (Joystick)
|
||||||
|
0xa1, 0x01, // COLLECTION (Application)
|
||||||
|
0x85, PEDALS_REPORT_ID, // REPORT_ID (4)
|
||||||
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||||
|
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
|
||||||
|
0xa1, 0x00, // COLLECTION (Physical)
|
||||||
|
0x09, 0x33, // USAGE (Rx)
|
||||||
|
0x09, 0x34, // USAGE (Ry)
|
||||||
|
0x09, 0x35, // USAGE (Rz)
|
||||||
|
0x75, 0x08, // REPORT_SIZE (8)
|
||||||
|
0x95, 0x03, // REPORT_COUNT (3)
|
||||||
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||||
|
0xc0, // END_COLLECTION
|
||||||
|
0xc0, // END_COLLECTION
|
||||||
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||||
|
0x09, 0x04, // USAGE (Joystick)
|
||||||
|
0xa1, 0x01, // COLLECTION (Application)
|
||||||
|
0x85, WHEEL_REPORT_ID, // REPORT_ID (5)
|
||||||
|
0x05, 0x09, // USAGE_PAGE (Button)
|
||||||
|
0x19, 0x01, // USAGE_MINIMUM (Button 1)
|
||||||
|
0x29, 0x0b, // USAGE_MAXIMUM (Button 11)
|
||||||
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||||
|
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
||||||
|
0x75, 0x01, // REPORT_SIZE (1)
|
||||||
|
0x95, 0x0b, // REPORT_COUNT (11)
|
||||||
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||||
|
0x95, 0x01, // REPORT_COUNT (1)
|
||||||
|
0x75, 0x05, // REPORT_SIZE (5)
|
||||||
|
0x81, 0x03, // INPUT (Cnst,Var,Abs)
|
||||||
|
0x05, 0x02, // USAGE_PAGE (Simulation Controls)
|
||||||
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||||
|
0x26, 0xff, 0x00, // LOGICAL_MAXIMUM (255)
|
||||||
|
0xa1, 0x00, // COLLECTION (Physical)
|
||||||
|
0x09, 0xc8, // USAGE (Steering)
|
||||||
|
0x75, 0x08, // REPORT_SIZE (8)
|
||||||
|
0x95, 0x01, // REPORT_COUNT (1)
|
||||||
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||||
|
0xc0, // END_COLLECTION
|
||||||
|
0xc0 // END_COLLECTION
|
||||||
|
};
|
||||||
|
|
||||||
|
ZenDrive_::ZenDrive_()
|
||||||
|
{
|
||||||
|
// Setup HID report structure
|
||||||
|
static HIDSubDescriptor node(_hidReportDescriptor, sizeof(_hidReportDescriptor));
|
||||||
|
HID().AppendDescriptor(&node);
|
||||||
|
|
||||||
|
// Initalize state for each module
|
||||||
|
// Gearshift module
|
||||||
|
speeds = B00000001; // (NEUTRAL;SPEED1;SPEED2;SPEED3;SPEED4;SPEED5;SPEED6;SPEEDR)
|
||||||
|
handbrake = 255;
|
||||||
|
|
||||||
|
//Pedals module
|
||||||
|
clutch = 0;
|
||||||
|
brake = 0;
|
||||||
|
accelerator = 0;
|
||||||
|
|
||||||
|
//Steering wheel module
|
||||||
|
wheelCommands = 0; // (BLINKER LEFT;BLINKER RIGHT;WARNING;LIGHTS;HEADLIGHTS;FOGLIGHTS;STARTER;HORN;CRUISE;CRUISE +;CRUISE -;NOT USED;NOT USED;NOT USED;NOT USED;NOT USED)
|
||||||
|
steering = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::begin(bool initAutoSendState)
|
||||||
|
{
|
||||||
|
// Sending initial states
|
||||||
|
sendGearshiftStates();
|
||||||
|
sendPedalsStates();
|
||||||
|
sendWheelStates();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::end()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gearshift module
|
||||||
|
void ZenDrive_::switchNeutral()
|
||||||
|
{
|
||||||
|
if(currentSpeed != 0){
|
||||||
|
bitSet(speeds, 0);
|
||||||
|
bitClear(speeds, 1);
|
||||||
|
bitClear(speeds, 2);
|
||||||
|
bitClear(speeds, 3);
|
||||||
|
bitClear(speeds, 4);
|
||||||
|
bitClear(speeds, 5);
|
||||||
|
bitClear(speeds, 6);
|
||||||
|
bitClear(speeds, 7);
|
||||||
|
currentSpeed = 0;
|
||||||
|
gearshiftNeedRefresh = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ZenDrive_::switchSpeed1()
|
||||||
|
{
|
||||||
|
if(currentSpeed != 1){
|
||||||
|
bitClear(speeds, 0);
|
||||||
|
bitSet(speeds, 1);
|
||||||
|
bitClear(speeds, 2);
|
||||||
|
bitClear(speeds, 3);
|
||||||
|
bitClear(speeds, 4);
|
||||||
|
bitClear(speeds, 5);
|
||||||
|
bitClear(speeds, 6);
|
||||||
|
bitClear(speeds, 7);
|
||||||
|
currentSpeed = 1;
|
||||||
|
gearshiftNeedRefresh = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ZenDrive_::switchSpeed2()
|
||||||
|
{
|
||||||
|
if(currentSpeed != 2)
|
||||||
|
{
|
||||||
|
bitClear(speeds, 0);
|
||||||
|
bitClear(speeds, 1);
|
||||||
|
bitSet(speeds, 2);
|
||||||
|
bitClear(speeds, 3);
|
||||||
|
bitClear(speeds, 4);
|
||||||
|
bitClear(speeds, 5);
|
||||||
|
bitClear(speeds, 6);
|
||||||
|
bitClear(speeds, 7);
|
||||||
|
currentSpeed = 2;
|
||||||
|
gearshiftNeedRefresh = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ZenDrive_::switchSpeed3()
|
||||||
|
{
|
||||||
|
if(currentSpeed != 3)
|
||||||
|
{
|
||||||
|
bitClear(speeds, 0);
|
||||||
|
bitClear(speeds, 1);
|
||||||
|
bitClear(speeds, 2);
|
||||||
|
bitSet(speeds, 3);
|
||||||
|
bitClear(speeds, 4);
|
||||||
|
bitClear(speeds, 5);
|
||||||
|
bitClear(speeds, 6);
|
||||||
|
bitClear(speeds, 7);
|
||||||
|
currentSpeed = 3;
|
||||||
|
gearshiftNeedRefresh = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ZenDrive_::switchSpeed4()
|
||||||
|
{
|
||||||
|
if(currentSpeed != 4)
|
||||||
|
{
|
||||||
|
bitClear(speeds, 0);
|
||||||
|
bitClear(speeds, 1);
|
||||||
|
bitClear(speeds, 2);
|
||||||
|
bitClear(speeds, 3);
|
||||||
|
bitSet(speeds, 4);
|
||||||
|
bitClear(speeds, 5);
|
||||||
|
bitClear(speeds, 6);
|
||||||
|
bitClear(speeds, 7);
|
||||||
|
currentSpeed = 4;
|
||||||
|
gearshiftNeedRefresh = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ZenDrive_::switchSpeed5()
|
||||||
|
{
|
||||||
|
if(currentSpeed != 5)
|
||||||
|
{
|
||||||
|
bitClear(speeds, 0);
|
||||||
|
bitClear(speeds, 1);
|
||||||
|
bitClear(speeds, 2);
|
||||||
|
bitClear(speeds, 3);
|
||||||
|
bitClear(speeds, 4);
|
||||||
|
bitSet(speeds, 5);
|
||||||
|
bitClear(speeds, 6);
|
||||||
|
bitClear(speeds, 7);
|
||||||
|
currentSpeed = 5;
|
||||||
|
gearshiftNeedRefresh = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ZenDrive_::switchSpeed6()
|
||||||
|
{
|
||||||
|
if(currentSpeed != 6)
|
||||||
|
{
|
||||||
|
bitClear(speeds, 0);
|
||||||
|
bitClear(speeds, 1);
|
||||||
|
bitClear(speeds, 2);
|
||||||
|
bitClear(speeds, 3);
|
||||||
|
bitClear(speeds, 4);
|
||||||
|
bitClear(speeds, 5);
|
||||||
|
bitSet(speeds, 6);
|
||||||
|
bitClear(speeds, 7);
|
||||||
|
currentSpeed = 6;
|
||||||
|
gearshiftNeedRefresh = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ZenDrive_::switchSpeedR()
|
||||||
|
{
|
||||||
|
if(currentSpeed != 7)
|
||||||
|
{
|
||||||
|
bitClear(speeds, 0);
|
||||||
|
bitClear(speeds, 1);
|
||||||
|
bitClear(speeds, 2);
|
||||||
|
bitClear(speeds, 3);
|
||||||
|
bitClear(speeds, 4);
|
||||||
|
bitClear(speeds, 5);
|
||||||
|
bitClear(speeds, 6);
|
||||||
|
bitSet(speeds, 7);
|
||||||
|
currentSpeed = 7;
|
||||||
|
gearshiftNeedRefresh = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::setHandbrake(int8_t value)
|
||||||
|
{
|
||||||
|
if(value < handbrake - 5 || value > handbrake + 5)
|
||||||
|
{
|
||||||
|
handbrake = value;
|
||||||
|
gearshiftNeedRefresh = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pedals module
|
||||||
|
void ZenDrive_::setClutch(int8_t value)
|
||||||
|
{
|
||||||
|
if(value < clutch - 5 || value > clutch + 5)
|
||||||
|
{
|
||||||
|
clutch = value;
|
||||||
|
pedalsNeedRefresh = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::setBrake(int8_t value)
|
||||||
|
{
|
||||||
|
if(value < brake - 5 || value > brake + 5)
|
||||||
|
{
|
||||||
|
brake = value;
|
||||||
|
pedalsNeedRefresh = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::setAccelerator(int8_t value)
|
||||||
|
{
|
||||||
|
if(value < accelerator - 5 || value > accelerator + 5)
|
||||||
|
{
|
||||||
|
accelerator = value;
|
||||||
|
pedalsNeedRefresh = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Steering wheel module
|
||||||
|
void ZenDrive_::setBlinkerLeft(bool value)
|
||||||
|
{
|
||||||
|
if(value != isBlinkerLeft)
|
||||||
|
{
|
||||||
|
bitSet(wheelCommands, 0);
|
||||||
|
sendWheelStates();
|
||||||
|
bitClear(wheelCommands, 0);
|
||||||
|
sendWheelStates();
|
||||||
|
isBlinkerLeft = !isBlinkerLeft;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::setBlinkerRight(bool value)
|
||||||
|
{
|
||||||
|
if(value != isBlinkerRight)
|
||||||
|
{
|
||||||
|
bitSet(wheelCommands, 1);
|
||||||
|
sendWheelStates();
|
||||||
|
bitClear(wheelCommands, 1);
|
||||||
|
sendWheelStates();
|
||||||
|
isBlinkerRight = !isBlinkerRight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::setWarning(bool value)
|
||||||
|
{
|
||||||
|
if(value != isWarning)
|
||||||
|
{
|
||||||
|
bitSet(wheelCommands, 2);
|
||||||
|
sendWheelStates();
|
||||||
|
bitClear(wheelCommands, 2);
|
||||||
|
sendWheelStates();
|
||||||
|
isWarning = !isWarning;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::switchLightsOn()
|
||||||
|
{
|
||||||
|
int steps = 0;
|
||||||
|
if(isRoadLights) steps = 2;
|
||||||
|
else if(!isLights) steps = 1;
|
||||||
|
if(steps != 0){
|
||||||
|
for(int i = 0; i < steps; i++){
|
||||||
|
bitSet(wheelCommands, 3);
|
||||||
|
sendWheelStates();
|
||||||
|
bitClear(wheelCommands, 3);
|
||||||
|
sendWheelStates();
|
||||||
|
isLights = true;
|
||||||
|
isRoadLights = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::switchRoadLights()
|
||||||
|
{
|
||||||
|
int steps = 0;
|
||||||
|
if(isLights) steps = 1;
|
||||||
|
else if(!isRoadLights) steps = 2;
|
||||||
|
if(steps != 0){
|
||||||
|
for(int i = 0; i < steps; i++){
|
||||||
|
bitSet(wheelCommands, 3);
|
||||||
|
sendWheelStates();
|
||||||
|
bitClear(wheelCommands, 3);
|
||||||
|
sendWheelStates();
|
||||||
|
isLights = false;
|
||||||
|
isRoadLights = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::switchLightsOff()
|
||||||
|
{
|
||||||
|
int steps = 0;
|
||||||
|
if(isLights) steps = 2;
|
||||||
|
else if(isRoadLights) steps = 1;
|
||||||
|
if(steps != 0){
|
||||||
|
for(int i = 0; i < steps; i++){
|
||||||
|
bitSet(wheelCommands, 3);
|
||||||
|
sendWheelStates();
|
||||||
|
bitClear(wheelCommands, 3);
|
||||||
|
sendWheelStates();
|
||||||
|
isLights = false;
|
||||||
|
isRoadLights = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::setHeadLights(bool value)
|
||||||
|
{
|
||||||
|
if(value != isHeadLights)
|
||||||
|
{
|
||||||
|
bitSet(wheelCommands, 4);
|
||||||
|
sendWheelStates();
|
||||||
|
bitClear(wheelCommands, 4);
|
||||||
|
sendWheelStates();
|
||||||
|
isHeadLights = !isHeadLights;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::setFogLights(bool value)
|
||||||
|
{
|
||||||
|
if(value != isFogLights)
|
||||||
|
{
|
||||||
|
bitSet(wheelCommands, 5);
|
||||||
|
sendWheelStates();
|
||||||
|
bitClear(wheelCommands, 5);
|
||||||
|
sendWheelStates();
|
||||||
|
isFogLights = !isFogLights;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::setStarter(bool value)
|
||||||
|
{
|
||||||
|
if(value != isStarter)
|
||||||
|
{
|
||||||
|
bitSet(wheelCommands, 6);
|
||||||
|
sendWheelStates();
|
||||||
|
bitClear(wheelCommands, 6);
|
||||||
|
sendWheelStates();
|
||||||
|
isStarter = !isStarter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::setHorn(bool value)
|
||||||
|
{
|
||||||
|
if(value != isHorn)
|
||||||
|
{
|
||||||
|
if(value) bitSet(wheelCommands, 7);
|
||||||
|
else bitClear(wheelCommands, 7);
|
||||||
|
wheelNeedRefresh = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::activeCruise()
|
||||||
|
{
|
||||||
|
bitSet(wheelCommands, 8);
|
||||||
|
sendWheelStates();
|
||||||
|
bitClear(wheelCommands, 8);
|
||||||
|
sendWheelStates();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::increaseCruise()
|
||||||
|
{
|
||||||
|
bitSet(wheelCommands, 9);
|
||||||
|
sendWheelStates();
|
||||||
|
bitClear(wheelCommands, 9);
|
||||||
|
sendWheelStates();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::decreaseCruise()
|
||||||
|
{
|
||||||
|
bitSet(wheelCommands, 10);
|
||||||
|
sendWheelStates();
|
||||||
|
bitClear(wheelCommands, 10);
|
||||||
|
sendWheelStates();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::setDirection(uint8_t value)
|
||||||
|
{
|
||||||
|
if(value < steering - 5 || value > steering + 5)
|
||||||
|
{
|
||||||
|
steering = value;
|
||||||
|
wheelNeedRefresh = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send states to the PC
|
||||||
|
void ZenDrive_::sendGearshiftStates()
|
||||||
|
{
|
||||||
|
// Gearshift module
|
||||||
|
uint8_t dataGearshift[GEARSHIFT_STATE_SIZE];
|
||||||
|
uint8_t speedTmp = speeds;
|
||||||
|
dataGearshift[0] = speedTmp & 0xFF;
|
||||||
|
dataGearshift[1] = handbrake;
|
||||||
|
|
||||||
|
HID().SendReport(GEARSHIFT_REPORT_ID, dataGearshift, GEARSHIFT_STATE_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::sendPedalsStates()
|
||||||
|
{
|
||||||
|
// Pedals module
|
||||||
|
uint8_t dataPedals[PEDALS_STATE_SIZE];
|
||||||
|
dataPedals[0] = clutch;
|
||||||
|
dataPedals[1] = brake;
|
||||||
|
dataPedals[2] = accelerator;
|
||||||
|
|
||||||
|
HID().SendReport(PEDALS_REPORT_ID, dataPedals, PEDALS_STATE_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZenDrive_::sendWheelStates()
|
||||||
|
{
|
||||||
|
// Steering wheel module
|
||||||
|
uint8_t dataWheel[WHEEL_STATE_SIZE];
|
||||||
|
uint16_t commandTmp = wheelCommands;
|
||||||
|
|
||||||
|
// Split 16 bit button-state into 2 bytes
|
||||||
|
dataWheel[0] = commandTmp & 0xFF;
|
||||||
|
commandTmp >>= 8;
|
||||||
|
dataWheel[1] = commandTmp & 0xFF;
|
||||||
|
dataWheel[2] = steering;
|
||||||
|
|
||||||
|
HID().SendReport(WHEEL_REPORT_ID, dataWheel, WHEEL_STATE_SIZE);
|
||||||
|
|
||||||
|
/*data[7] = xAxis + 127;
|
||||||
|
data[8] = yAxis + 127;
|
||||||
|
data[9] = zAxis + 127;
|
||||||
|
|
||||||
|
data[10] = (xAxisRotation % 360) * 0.708;
|
||||||
|
data[11] = (yAxisRotation % 360) * 0.708;
|
||||||
|
data[12] = (zAxisRotation % 360) * 0.708;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
ZenDrive_ ZenDrive;
|
||||||
|
|
||||||
|
#endif
|
||||||
111
ZenDrive Simulator/ZenDrive.h
Normal file
111
ZenDrive Simulator/ZenDrive.h
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
/*
|
||||||
|
ZenDrive.h
|
||||||
|
|
||||||
|
Copyright (c) 2021, Valentin Boulanger
|
||||||
|
|
||||||
|
This library is a part of the ZenDrive simulator firmware.
|
||||||
|
Version : 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ZENDRIVE_h
|
||||||
|
#define ZENDRIVE_h
|
||||||
|
|
||||||
|
#include "HID.h"
|
||||||
|
|
||||||
|
#if ARDUINO < 10606
|
||||||
|
#error The ZenDrive library requires Arduino IDE 1.6.6 or greater. Please update your IDE.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ARDUINO > 10606
|
||||||
|
#if !defined(USBCON)
|
||||||
|
#error The ZenDrive library can only be used with a USB MCU (e.g. Arduino Leonardo, Arduino Micro, etc.).
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(_USING_HID)
|
||||||
|
|
||||||
|
#warning "Using legacy HID core (non pluggable)"
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
//================================================================================
|
||||||
|
//================================================================================
|
||||||
|
// ZenDrive Simulator (Gamepad)
|
||||||
|
|
||||||
|
class ZenDrive_
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
// Gearshift module
|
||||||
|
uint8_t speeds; // (NEUTRAL;SPEED1;SPEED2;SPEED3;SPEED4;SPEED5;SPEED6;SPEEDR)
|
||||||
|
uint8_t handbrake;
|
||||||
|
|
||||||
|
//Pedals module
|
||||||
|
uint8_t clutch;
|
||||||
|
uint8_t brake;
|
||||||
|
uint8_t accelerator;
|
||||||
|
|
||||||
|
//Steering wheel module
|
||||||
|
uint16_t wheelCommands; // (BLINKER LEFT;BLINKER RIGHT;WARNING;LIGHTS;HEAD LIGHTS;FOGLIGHTS;STARTER;HORN;CRUISE;CRUISE +;CRUISE -;NOT USED;NOT USED;NOT USED;NOT USED;NOT USED)
|
||||||
|
int8_t steering;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ZenDrive_();
|
||||||
|
|
||||||
|
void begin(bool initAutoSendState = true);
|
||||||
|
void end();
|
||||||
|
|
||||||
|
// Gearshift module
|
||||||
|
bool gearshiftNeedRefresh = false;
|
||||||
|
int currentSpeed = 0;
|
||||||
|
void switchNeutral();
|
||||||
|
void switchSpeed1();
|
||||||
|
void switchSpeed2();
|
||||||
|
void switchSpeed3();
|
||||||
|
void switchSpeed4();
|
||||||
|
void switchSpeed5();
|
||||||
|
void switchSpeed6();
|
||||||
|
void switchSpeedR();
|
||||||
|
int currentHandbrake = 0;
|
||||||
|
void setHandbrake(int8_t value);
|
||||||
|
|
||||||
|
// Pedals module
|
||||||
|
bool pedalsNeedRefresh = false;
|
||||||
|
void setClutch(int8_t value);
|
||||||
|
void setBrake(int8_t value);
|
||||||
|
void setAccelerator(int8_t value);
|
||||||
|
|
||||||
|
// Steering wheel module
|
||||||
|
bool wheelNeedRefresh = false;
|
||||||
|
bool isBlinkerLeft = false;
|
||||||
|
void setBlinkerLeft(bool value);
|
||||||
|
bool isBlinkerRight = false;
|
||||||
|
void setBlinkerRight(bool value);
|
||||||
|
bool isWarning = false;
|
||||||
|
void setWarning(bool value);
|
||||||
|
bool isLights = false;
|
||||||
|
bool isRoadLights = false;
|
||||||
|
void switchLightsOn();
|
||||||
|
void switchRoadLights();
|
||||||
|
void switchLightsOff();
|
||||||
|
bool isHeadLights = false;
|
||||||
|
void setHeadLights(bool value);
|
||||||
|
bool isFogLights = false;
|
||||||
|
void setFogLights(bool value);
|
||||||
|
bool isStarter = false;
|
||||||
|
void setStarter(bool value);
|
||||||
|
bool isHorn = false;
|
||||||
|
void setHorn(bool value);
|
||||||
|
void activeCruise();
|
||||||
|
void increaseCruise();
|
||||||
|
void decreaseCruise();
|
||||||
|
void setDirection(uint8_t value);
|
||||||
|
|
||||||
|
void sendGearshiftStates();
|
||||||
|
void sendPedalsStates();
|
||||||
|
void sendWheelStates();
|
||||||
|
};
|
||||||
|
extern ZenDrive_ ZenDrive;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
13
sharedButtons/sharedButtons.ino
Normal file
13
sharedButtons/sharedButtons.ino
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
const int SHARED_BUTTONS = A1;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
pinMode(SHARED_BUTTONS, INPUT_PULLUP);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
Serial.println(analogRead(SHARED_BUTTONS));
|
||||||
|
delay(50);
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user