Прошивка ардуино не определяется как игровое устройство.

Izbt
Offline
Зарегистрирован: 26.08.2021

После прошивки ардуины она должна определятся как игровое устройство, но у меня почему то она определяется просто как устройство которое не настроить как игровое устройство.

Посмотрите и исправьте прошивку если кто может.

 

#include <Joystick.h>
#include "confOptions.h"
#define Throttle          A0
#define Brake             A1
#define Clutch            A2

#define Throttle_I2       A5 //second input line (brown wire)
#define Brake_I2          A6 //second input line (brown wire)
#define Clutch_I2         A8 //second input line (brown wire)

#define BrakeResistance   A3
#define VibrationMotor    3

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
                   JOYSTICK_TYPE_MULTI_AXIS, 0, 0,
                   false, false, false, true, false, false,
                   false, true, false, true, false);

const int MaxRange = 1023;
const int MinRange = 0;

const int AxisMax = 1024;

int blBrk = 0;
int blThr = 0;
int blCth = 0;
int maxBrk = 0; //max value for Brake
int maxThr = 0; //max value for Throttle
int maxCth = 0; //max value for Clutch
bool aveBrkSet = false;
bool aveThrSet = false;
bool aveCthSet = false;

bool debug = false;
bool dbg_PrintThr = false;
bool dbg_PrintBrk = false;
bool dbg_PrintCTH = false;

void setup() {
  delay(2000); //set a delay for everything to settle
      
  debug = Enable_Debug;
  dbg_PrintThr = Debug_Thr;
  dbg_PrintBrk = Debug_Brk;
  dbg_PrintCTH = Debug_Cth;

  //setting ranges
  Joystick.setRxAxisRange(MinRange, MaxRange);
  Joystick.setThrottleRange(MinRange, MaxRange);
  Joystick.setBrakeRange(MinRange, MaxRange);

  Joystick.begin(true);

  // Setting Pin Modes
  pinMode(Throttle, INPUT); //Throttle  
  pinMode(Brake, INPUT); //Brake
  pinMode(Clutch, INPUT); //Clutch
  
  //Setting optional pins states
  if (use_Dual_Thr) pinMode(Throttle_I2, INPUT); //Throttle input 2
  if (use_Dual_Cl) pinMode(Clutch_I2, INPUT); //Clutch input 2
  if (use_Dual_Brk) pinMode(Brake_I2, INPUT); //Brake input 2
  
  pinMode(BrakeResistance, INPUT); //BrakeResistance;
  pinMode(VibrationMotor, OUTPUT); // Vibration Motor Control this is paired with a transistor to control the motor
  pinMode(13, OUTPUT); // LED output
  digitalWrite(VibrationMotor, HIGH); // set the pin as High, Low will result in the motor spinning

  // get the baseline registering values
  blBrk = get_baseline(Brake, 25);
  blThr = get_baseline(Throttle, 25);
  blCth = get_baseline(Clutch, 25);
}

void loop() {
  //reading the relevant values from the pedals
  int valThr = 0;
  int valBrk = 0;
  int valCth = 0;
  
  if (use_Dual_Thr) valThr = abs((analogRead(Throttle)+analogRead(Throttle_I2))/2);
  else valThr = analogRead(Throttle);
  
  if (use_Dual_Cl) valCth = abs((analogRead(Clutch)+analogRead(Clutch_I2))/2);
  else valCth = analogRead(Clutch);
  
  if (use_Dual_Brk) valBrk = abs((analogRead(Brake)+analogRead(Brake_I2))/2);
  else valBrk = analogRead(Brake);
  
  /* Original read statements
  int valThr = analogRead(Throttle);
  int valBrk = analogRead(Brake);
  int valCth = analogRead(Clutch); */
  
  int valRestBrk = analogRead(BrakeResistance);
  double pers = get_Persentage(BrakeResistance); //get the resistance persentage to apply against the brake pedal which then halved

  //All values below are normalised and converted to absolute to ensure a positive value
  int actCthVal = abs(valCth - blCth);//normalised clutch value 
  int actThrVal = abs(valThr - blThr);//normalised Throttle value
  int actBrkVal = abs(valBrk - blBrk);//normalised brake value
  int PersBrkVal = int(((valBrk - blBrk) * pers)) ; //normalised brake value with the resistance added

  // set/update the max value based on pedal progressions
  if (maxCth < actCthVal) maxCth = actCthVal;
  if (maxThr < actThrVal) maxThr = actThrVal;  
  if (maxBrk < actBrkVal) maxBrk = actBrkVal;

  if (debug) {
    if(dbg_PrintThr){      
      String values = "Throttle - Baseline: " + String(blThr) + ", Actual Value: " + String(valThr) + ", Normalised Value: " + String(actThrVal) + ", max value: " + String(maxThr);
      Serial.println(values);
      delay(100);}
 
    if(dbg_PrintBrk){
       String values = "Brakes - Baseline: " + String(blBrk) + ", Actual Value: " + String(valBrk) + ", Normalised Value: " + String(actBrkVal) + ", Normalised With Resistance:" + String(PersBrkVal) + ", Pers:" + String(pers) + ", Resistance: " + String(valRestBrk) + ", max value: " + String(maxBrk);
       Serial.println(values);
       delay(100);}
    
    if(dbg_PrintCTH){
      String values = "Clutch - Baseline: " + String(blCth) + ", Actual Value: " + String(valCth) + ", Normalised Value: " + String(actCthVal) + ", Max Value: " + String(maxCth);                      
      Serial.println(values);
      delay(100);}  
    Serial.println("");//create an empty line   
  }

  if (actBrkVal > (maxBrk * 0.80)) digitalWrite(VibrationMotor, LOW); //enable the motor to spin when the pedal reaches 80% of the pedal pressure
  else digitalWrite(VibrationMotor, HIGH); //stop the motor when it falls below 80%

  //Limit upperbound Noise
  if (actCthVal  > (maxCth - clutch_U_DZ)  ) {actCthVal  = (maxCth - clutch_U_DZ);}
  if (actThrVal  > (maxThr - throttle_U_DZ)) {actThrVal  = (maxThr - throttle_U_DZ);}
  if (PersBrkVal > (maxBrk - brake_U_DZ)   ) {PersBrkVal = (maxBrk - brake_U_DZ);}
 
  //set the values applying base deadzone
  if (valCth >0) 
  {
    if (actCthVal > clutch_L_DZ) Joystick.setRxAxis(actCthVal);
    else Joystick.setRxAxis(0);
  }
  if (valThr >0) 
  {
    if (actThrVal > throttle_L_DZ) Joystick.setThrottle(actThrVal);
    else Joystick.setThrottle(0);
  }
  if (valBrk >0) 
  {
    if (actBrkVal > brake_L_DZ) Joystick.setBrake(PersBrkVal);
    else Joystick.setBrake(0);
  }
}

int get_baseline(int pin, int count) { //get the pedal baseline
  int maxVal = 0;
  int newVal = 0;
  for (int i = 0; i < count; i++) {
    newVal = analogRead(pin);
    if (maxVal < newVal) maxVal = newVal;
  }
  return maxVal;
}

double get_Persentage(int pinToRead) {
  return (1 - (double(analogRead(pinToRead)) / AxisMax)); //1024 is the maximum
}

Второй компонент кода

/*
  Joystick.h
  Copyright (c) 2015-2017, Matthew Heironimus
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef JOYSTICK_h
#define JOYSTICK_h

#include <DynamicHID/DynamicHID.h>

#if ARDUINO < 10606
#error The Joystick library requires Arduino IDE 1.6.6 or greater. Please update your IDE.
#endif // ARDUINO < 10606

#if ARDUINO > 10606
#if !defined(USBCON)
#error The Joystick library can only be used with a USB MCU (e.g. Arduino Leonardo, Arduino Micro, etc.).
#endif // !defined(USBCON)
#endif // ARDUINO > 10606

#if !defined(_USING_DYNAMIC_HID)

#warning "Using legacy HID core (non pluggable)"

#else // !defined(_USING_DYNAMIC_HID)

//================================================================================
//  Joystick (Gamepad)

#define JOYSTICK_DEFAULT_REPORT_ID         0x03
#define JOYSTICK_DEFAULT_BUTTON_COUNT        32
#define JOYSTICK_DEFAULT_AXIS_MINIMUM         0
#define JOYSTICK_DEFAULT_AXIS_MAXIMUM      1023
#define JOYSTICK_DEFAULT_SIMULATOR_MINIMUM    0
#define JOYSTICK_DEFAULT_SIMULATOR_MAXIMUM 1023
#define JOYSTICK_DEFAULT_HATSWITCH_COUNT      2
#define JOYSTICK_HATSWITCH_COUNT_MAXIMUM      2
#define JOYSTICK_HATSWITCH_RELEASE           -1
#define JOYSTICK_TYPE_JOYSTICK             0x04
#define JOYSTICK_TYPE_GAMEPAD              0x05
#define JOYSTICK_TYPE_MULTI_AXIS           0x08

class Joystick_
{
private:

    // Joystick State
	int16_t	                 _xAxis;
	int16_t	                 _yAxis;
	int16_t	                 _zAxis;
	int16_t	                 _xAxisRotation;
	int16_t	                 _yAxisRotation;
	int16_t	                 _zAxisRotation;
	int16_t                  _throttle;
	int16_t                  _rudder;
	int16_t					 _accelerator;
	int16_t					 _brake;
	int16_t					 _steering;
	int16_t	                 _hatSwitchValues[JOYSTICK_HATSWITCH_COUNT_MAXIMUM];
    uint8_t                 *_buttonValues = NULL;

    // Joystick Settings
    bool                     _autoSendState;
    uint8_t                  _buttonCount;
    uint8_t                  _buttonValuesArraySize = 0;
	uint8_t					 _hatSwitchCount;
	uint8_t					 _includeAxisFlags;
	uint8_t					 _includeSimulatorFlags;
	int16_t                  _xAxisMinimum = JOYSTICK_DEFAULT_AXIS_MINIMUM;
	int16_t                  _xAxisMaximum = JOYSTICK_DEFAULT_AXIS_MAXIMUM;
	int16_t                  _yAxisMinimum = JOYSTICK_DEFAULT_AXIS_MINIMUM;
	int16_t                  _yAxisMaximum = JOYSTICK_DEFAULT_AXIS_MAXIMUM;
	int16_t                  _zAxisMinimum = JOYSTICK_DEFAULT_AXIS_MINIMUM;
	int16_t                  _zAxisMaximum = JOYSTICK_DEFAULT_AXIS_MAXIMUM;
	int16_t                  _rxAxisMinimum = JOYSTICK_DEFAULT_AXIS_MINIMUM;
	int16_t                  _rxAxisMaximum = JOYSTICK_DEFAULT_AXIS_MAXIMUM;
	int16_t                  _ryAxisMinimum = JOYSTICK_DEFAULT_AXIS_MINIMUM;
	int16_t                  _ryAxisMaximum = JOYSTICK_DEFAULT_AXIS_MAXIMUM;
	int16_t                  _rzAxisMinimum = JOYSTICK_DEFAULT_AXIS_MINIMUM;
	int16_t                  _rzAxisMaximum = JOYSTICK_DEFAULT_AXIS_MAXIMUM;
	int16_t                  _rudderMinimum = JOYSTICK_DEFAULT_SIMULATOR_MINIMUM;
	int16_t                  _rudderMaximum = JOYSTICK_DEFAULT_SIMULATOR_MAXIMUM;
	int16_t                  _throttleMinimum = JOYSTICK_DEFAULT_SIMULATOR_MINIMUM;
	int16_t                  _throttleMaximum = JOYSTICK_DEFAULT_SIMULATOR_MAXIMUM;
	int16_t                  _acceleratorMinimum = JOYSTICK_DEFAULT_SIMULATOR_MINIMUM;
	int16_t                  _acceleratorMaximum = JOYSTICK_DEFAULT_SIMULATOR_MAXIMUM;
	int16_t                  _brakeMinimum = JOYSTICK_DEFAULT_SIMULATOR_MINIMUM;
	int16_t                  _brakeMaximum = JOYSTICK_DEFAULT_SIMULATOR_MAXIMUM;
	int16_t                  _steeringMinimum = JOYSTICK_DEFAULT_SIMULATOR_MINIMUM;
	int16_t                  _steeringMaximum = JOYSTICK_DEFAULT_SIMULATOR_MAXIMUM;

	uint8_t                  _hidReportId;
	uint8_t                  _hidReportSize; 

protected:
	int buildAndSet16BitValue(bool includeValue, int16_t value, int16_t valueMinimum, int16_t valueMaximum, int16_t actualMinimum, int16_t actualMaximum, uint8_t dataLocation[]);
	int buildAndSetAxisValue(bool includeAxis, int16_t axisValue, int16_t axisMinimum, int16_t axisMaximum, uint8_t dataLocation[]);
	int buildAndSetSimulationValue(bool includeValue, int16_t value, int16_t valueMinimum, int16_t valueMaximum, uint8_t dataLocation[]);

public:
	Joystick_(
		uint8_t hidReportId = JOYSTICK_DEFAULT_REPORT_ID,
		uint8_t joystickType = JOYSTICK_TYPE_JOYSTICK,
        uint8_t buttonCount = JOYSTICK_DEFAULT_BUTTON_COUNT,
		uint8_t hatSwitchCount = JOYSTICK_DEFAULT_HATSWITCH_COUNT,
		bool includeXAxis = true,
		bool includeYAxis = true,
		bool includeZAxis = true,
		bool includeRxAxis = true,
		bool includeRyAxis = true,
		bool includeRzAxis = true,
		bool includeRudder = true,
		bool includeThrottle = true,
		bool includeAccelerator = true,
		bool includeBrake = true,
		bool includeSteering = true);

	void begin(bool initAutoSendState = true);
	void end();
	
	// Set Range Functions
	inline void setXAxisRange(int16_t minimum, int16_t maximum)
	{
		_xAxisMinimum = minimum;
		_xAxisMaximum = maximum;
	}
	inline void setYAxisRange(int16_t minimum, int16_t maximum)
	{
		_yAxisMinimum = minimum;
		_yAxisMaximum = maximum;
	}
	inline void setZAxisRange(int16_t minimum, int16_t maximum)
	{
		_zAxisMinimum = minimum;
		_zAxisMaximum = maximum;
	}
	inline void setRxAxisRange(int16_t minimum, int16_t maximum)
	{
		_rxAxisMinimum = minimum;
		_rxAxisMaximum = maximum;
	}
	inline void setRyAxisRange(int16_t minimum, int16_t maximum)
	{
		_ryAxisMinimum = minimum;
		_ryAxisMaximum = maximum;
	}
	inline void setRzAxisRange(int16_t minimum, int16_t maximum)
	{
		_rzAxisMinimum = minimum;
		_rzAxisMaximum = maximum;
	}
	inline void setRudderRange(int16_t minimum, int16_t maximum)
	{
		_rudderMinimum = minimum;
		_rudderMaximum = maximum;
	}
	inline void setThrottleRange(int16_t minimum, int16_t maximum)
	{
		_throttleMinimum = minimum;
		_throttleMaximum = maximum;
	}
	inline void setAcceleratorRange(int16_t minimum, int16_t maximum)
	{
		_acceleratorMinimum = minimum;
		_acceleratorMaximum = maximum;
	}
	inline void setBrakeRange(int16_t minimum, int16_t maximum)
	{
		_brakeMinimum = minimum;
		_brakeMaximum = maximum;
	}
	inline void setSteeringRange(int16_t minimum, int16_t maximum)
	{
		_steeringMinimum = minimum;
		_steeringMaximum = maximum;
	}

	// Set Axis Values
	void setXAxis(int16_t value);
	void setYAxis(int16_t value);
	void setZAxis(int16_t value);
	void setRxAxis(int16_t value);
	void setRyAxis(int16_t value);
	void setRzAxis(int16_t value);

	// Set Simuation Values
	void setRudder(int16_t value);
	void setThrottle(int16_t value);
	void setAccelerator(int16_t value);
	void setBrake(int16_t value);
	void setSteering(int16_t value);

	void setButton(uint8_t button, uint8_t value);
	void pressButton(uint8_t button);
	void releaseButton(uint8_t button);

	void setHatSwitch(int8_t hatSwitch, int16_t value);

	void sendState();
};

#endif // !defined(_USING_DYNAMIC_HID)
#endif // JOYSTICK_h

Третий код

//confOptions.h
//debug options
#define Enable_Debug false
#define Debug_Thr true
#define Debug_Cth false
#define Debug_Brk false

// Input Precision
#define use_Dual_Thr false
#define use_Dual_Cl  false
#define use_Dual_Brk false

// initial Deadzone
#define brake_L_DZ 5
#define throttle_L_DZ 5
#define clutch_L_DZ 5

// maximum Deadzone
#define brake_U_DZ 5
#define throttle_U_DZ 5
#define clutch_U_DZ 5

 

Izbt
Offline
Зарегистрирован: 26.08.2021
kalapanga
Offline
Зарегистрирован: 23.10.2016

Issues по Вашей ссылке смотрели? Не Ваш случай?