Bläddra i källkod

add g29 in windows.

yuchuli 2 år sedan
förälder
incheckning
ac88ae0493

+ 58 - 3
src/test/testg29_win/mainwindow.cpp

@@ -30,6 +30,8 @@ void MainWindow::LoadAPI()
     LogiIsConnected =(LogiIsConnectedFunction)xlib.resolve("LogiIsConnected");
     LogiGetState =(LogiGetStateFunction)xlib.resolve("LogiGetState");
     LogiSteeringShutdown =(LogiSteeringShutdownFunction)xlib.resolve("LogiSteeringShutdown");
+    LogiPlayConstantForce =(LogiPlayConstantForceFunction)xlib.resolve("LogiPlayConstantForce");
+    LogiStopConstantForce =(LogiStopConstantForceFunction)xlib.resolve("LogiStopConstantForce");
 
     if((LogiSteeringInitialize == NULL)||(LogiIsConnected == NULL)||(LogiGetState == NULL)||(LogiSteeringShutdown == NULL))
     {
@@ -43,14 +45,50 @@ void MainWindow::LoadAPI()
 
 int MainWindow::GetWheelAccBrake(double & angle,double & acc, double & brake)
 {
-    if((LogiUpdate())&&(LogiIsConnected(1)))
+//    if(LogiIsConnected(0))
+//    {
+//        std::cout<<"connected. "<<std::endl;
+//    }
+//    if(LogiUpdate())
+//    {
+//        std::cout<<" update. "<<std::endl;
+//    }
+    if((LogiUpdate())&&(LogiIsConnected(0)))
     {
-        DIJOYSTATE2* wheel = LogiGetState(1);
+        DIJOYSTATE2* wheel = LogiGetState(0);
         angle = wheel->lX;
         acc = wheel->lY;
         brake = wheel->lRz;
+        if(angle>100)
+        {
+            int force;
+            if(angle>3000)force = 30;
+            else
+            {
+                force = angle*30/3000;
+            }
+            LogiPlayConstantForce(0,force);
+        }
+        else
+        {
+            if(angle<-100)
+            {
+                int force;
+                if(angle<-3000)force = -30;
+                else
+                {
+                    force = angle*30/3000;
+                }
+               LogiPlayConstantForce(0,force);
+            }
+            else
+            {
+                LogiStopConstantForce(0);
+            }
+        }
         return 0;
     }
+
     return -1;
 }
 
@@ -62,7 +100,12 @@ MainWindow::MainWindow(QWidget *parent)
 
     LoadAPI();
 
-    LogiSteeringInitialize(true);
+    bool bStart = LogiSteeringInitialize(false);
+    std::cout<<" init. "<<bStart<<std::endl;
+
+    QTimer * timer = new QTimer(this);
+    connect(timer,SIGNAL(timeout()),this,SLOT(onTimer()));
+    timer->start(100);
 }
 
 MainWindow::~MainWindow()
@@ -70,3 +113,15 @@ MainWindow::~MainWindow()
     delete ui;
 }
 
+void MainWindow::onTimer()
+{
+    double angle,acc,brake;
+    if(GetWheelAccBrake(angle,acc,brake) == 0)
+    {
+        char strout[1000];
+        snprintf(strout,1000,"angle:%f\nacc:%f\nbrake:%f",angle,acc,brake);
+        ui->plainTextEdit->setPlainText(strout);
+//        std::cout<<" angle: "<<angle<<" acc: "<<acc<<" brake:"<<brake<<std::endl;
+    }
+
+}

+ 14 - 0
src/test/testg29_win/mainwindow.h

@@ -5,6 +5,8 @@
 
 #include <dinput.h>
 
+#include <QTimer>
+
 QT_BEGIN_NAMESPACE
 namespace Ui { class MainWindow; }
 QT_END_NAMESPACE
@@ -21,6 +23,13 @@ typedef   DIJOYSTATE2* (*LogiGetStateFunction)(const int index);
 //Call this function to shutdown the SDK and destroy the controller and wheel objects
 typedef void (*LogiSteeringShutdownFunction)();
 
+//Play the constant force on the controller at index with the specified parameter
+typedef bool (*LogiPlayConstantForceFunction)(const int index, const int magnitudePercentage);
+
+//Stop the constant force on the controller at index
+typedef bool (*LogiStopConstantForceFunction)(const int index);
+
+
 
 class MainWindow : public QMainWindow
 {
@@ -40,6 +49,11 @@ private:
     LogiIsConnectedFunction LogiIsConnected;
     LogiGetStateFunction LogiGetState;
     LogiSteeringShutdownFunction LogiSteeringShutdown;
+    LogiPlayConstantForceFunction LogiPlayConstantForce;
+    LogiStopConstantForceFunction LogiStopConstantForce;
+
+private slots:
+    void onTimer();
 
 
 private:

+ 22 - 2
src/test/testg29_win/mainwindow.ui

@@ -13,8 +13,28 @@
   <property name="windowTitle">
    <string>MainWindow</string>
   </property>
-  <widget class="QWidget" name="centralwidget"/>
-  <widget class="QMenuBar" name="menubar"/>
+  <widget class="QWidget" name="centralwidget">
+   <widget class="QPlainTextEdit" name="plainTextEdit">
+    <property name="geometry">
+     <rect>
+      <x>90</x>
+      <y>50</y>
+      <width>281</width>
+      <height>161</height>
+     </rect>
+    </property>
+   </widget>
+  </widget>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>800</width>
+     <height>23</height>
+    </rect>
+   </property>
+  </widget>
   <widget class="QStatusBar" name="statusbar"/>
  </widget>
  <resources/>

+ 157 - 1
src/tool/RemoteCtrl_Wide/joyreadthread.cpp

@@ -1,6 +1,13 @@
-#include "joyreadthread.h"
+
+
+#include <QThread>
+
+#include <QFile>
+
 
 #ifndef Q_OS_WIN
+
+#include "joyreadthread.h"
 #include <assert.h>
 #include <math.h>
 #include <algorithm>
@@ -162,4 +169,153 @@ int JoyReadThread::GetShift()
 }
 
 
+#else
+
+#include <QFile>
+#include <QLibrary>
+#include <iostream>
+#include "dinput.h"
+#include "joyreadthread.h"
+
+void JoyReadThread::LoadAPI()
+{
+    mbJoyOK = false;
+    std::cout<<"Load Logi g29 API"<<std::endl;
+    QLibrary xlib("./LogitechSteeringWheelEnginesWrapper.dll");
+    if(!xlib.load())
+    {
+        std::cout<<" load LogitechSteeringWheelEnginesWrapper fail."<<xlib.errorString().toStdString()<< std::endl;
+        return ;
+    }
+
+    LogiUpdate =(LogiUpdateFunction)xlib.resolve("LogiUpdate");
+
+    if(LogiUpdate == NULL)
+    {
+        std::cout<<" no this api."<<std::endl;
+        return;
+    }
+    else
+    {
+        std::cout<<" Load API Successfully. "<<std::endl;
+    }
+
+    LogiSteeringInitialize =(LogiSteeringInitializeFunction)xlib.resolve("LogiSteeringInitialize");
+    LogiIsConnected =(LogiIsConnectedFunction)xlib.resolve("LogiIsConnected");
+    LogiGetState =(LogiGetStateFunction)xlib.resolve("LogiGetState");
+    LogiSteeringShutdown =(LogiSteeringShutdownFunction)xlib.resolve("LogiSteeringShutdown");
+    LogiPlayConstantForce =(LogiPlayConstantForceFunction)xlib.resolve("LogiPlayConstantForce");
+    LogiStopConstantForce =(LogiStopConstantForceFunction)xlib.resolve("LogiStopConstantForce");
+
+    if((LogiSteeringInitialize == NULL)||(LogiIsConnected == NULL)||(LogiGetState == NULL)||(LogiSteeringShutdown == NULL))
+    {
+        std::cout<<" no this apiS."<<std::endl;
+        return;
+    }
+    else
+    {
+        std::cout<<" Load All API Successfully. "<<std::endl;
+    }
+
+    mbJoyOK = true;
+}
+
+JoyReadThread::JoyReadThread()
+{
+
+    LoadAPI();
+}
+
+void JoyReadThread::run()
+{
+    if(mbJoyOK == false)return;
+
+    bool bStart = LogiSteeringInitialize(false);
+    std::cout<<" init. "<<bStart<<std::endl;
+
+    int nFail = 0;
+    while(!QThread::isInterruptionRequested())
+    {
+
+        double angle,acc,brake;
+        if((LogiUpdate())&&(LogiIsConnected(0)))
+        {
+            DIJOYSTATE2* wheel = LogiGetState(0);
+            angle = wheel->lX;
+            acc = wheel->lY;
+            brake = wheel->lRz;
+            if(angle>100)
+            {
+                int force;
+                if(angle>3000)force = 30;
+                else
+                {
+                    force = angle*30/3000;
+                }
+                LogiPlayConstantForce(0,force);
+            }
+            else
+            {
+                if(angle<-100)
+                {
+                    int force;
+                    if(angle<-3000)force = -30;
+                    else
+                    {
+                        force = angle*30/3000;
+                    }
+                   LogiPlayConstantForce(0,force);
+                }
+                else
+                {
+                    LogiStopConstantForce(0);
+                }
+            }
+
+            mfWheel = angle;
+            mfAcc = acc;
+            mfBrake = brake;
+            nFail = 0;
+        }
+        else
+        {
+            nFail++;
+        }
+        if(nFail>10)
+        {
+            mbJoyOK = false;
+        }
+        msleep(20);
+
+    }
+
+    LogiSteeringShutdown();
+    mbJoyOK = false;
+}
+
+bool JoyReadThread::isOK()
+{
+    return mbJoyOK;
+}
+
+double JoyReadThread::GetAcc()
+{
+    return mfAcc;
+}
+
+double JoyReadThread::GetBrake()
+{
+    return mfBrake;
+}
+
+double JoyReadThread::GetWheel()
+{
+    return mfWheel;
+}
+
+int JoyReadThread::GetShift()
+{
+    return mnShift;
+}
+
 #endif

+ 39 - 2
src/tool/RemoteCtrl_Wide/joyreadthread.h

@@ -1,11 +1,33 @@
 #ifndef JOYREADTHREAD_H
 #define JOYREADTHREAD_H
 
-#ifndef Q_OS_WIN
+
+
 #include <QThread>
 
 #include <QFile>
 
+#ifdef Q_OS_WIN
+ #include "dinput.h"
+
+typedef bool (*LogiSteeringInitializeFunction)(bool ignoreXInputControllers);
+typedef bool  (*LogiUpdateFunction)();
+//Check if a generic device at index is connected
+typedef  bool (*LogiIsConnectedFunction)(const int index);
+
+
+//Get the state of the controller in the standard way.
+typedef   DIJOYSTATE2* (*LogiGetStateFunction)(const int index);
+//Call this function to shutdown the SDK and destroy the controller and wheel objects
+typedef void (*LogiSteeringShutdownFunction)();
+
+//Play the constant force on the controller at index with the specified parameter
+typedef bool (*LogiPlayConstantForceFunction)(const int index, const int magnitudePercentage);
+
+//Stop the constant force on the controller at index
+typedef bool (*LogiStopConstantForceFunction)(const int index);
+#endif
+
 class JoyReadThread : public QThread
 {
 public:
@@ -35,8 +57,23 @@ private:
     double mfBrake = 32767;
 
     int mnShift = 0; //0 N >0 D -1 R
-};
 
+private:
+#ifdef Q_OS_WIN
+
+
+
+
+    LogiUpdateFunction LogiUpdate;
+    LogiSteeringInitializeFunction LogiSteeringInitialize;
+    LogiIsConnectedFunction LogiIsConnected;
+    LogiGetStateFunction LogiGetState;
+    LogiSteeringShutdownFunction LogiSteeringShutdown;
+    LogiPlayConstantForceFunction LogiPlayConstantForce;
+    LogiStopConstantForceFunction LogiStopConstantForce;
+    void LoadAPI();
 #endif
+};
+
 
 #endif // JOYREADTHREAD_H

+ 3 - 4
src/tool/RemoteCtrl_Wide/mainwindow.cpp

@@ -96,10 +96,9 @@ MainWindow::MainWindow(QWidget *parent)
     mstrqueryMD5 = ServiceRCIni.GetQueryMD5();
     mstrctrlMD5 = ServiceRCIni.GetCtrlMD5();
 
-#ifndef Q_OS_WIN
+
     mpJRT = new JoyReadThread();
     mpJRT->start();
-#endif
 
     int i;
 
@@ -615,7 +614,7 @@ void MainWindow::onTimerManual()
 
     int nOldShift = mnShift;
 
-#ifndef Q_OS_WIN
+
     if(mpJRT->isOK())
     {
         mfWheel = mpJRT->GetWheel() * (-100.0)/32768.0;
@@ -647,7 +646,7 @@ void MainWindow::onTimerManual()
         }
         return;
     }
-#endif
+
 
     if(mPressKeys.contains(Qt::Key_C)||(mPressKeys.contains(Qt::Key_A))||(mPressKeys.contains(Qt::Key_D))||(mPressKeys.contains(Qt::Key_W))||(mPressKeys.contains(Qt::Key_S)))
     {

+ 0 - 2
src/tool/RemoteCtrl_Wide/mainwindow.h

@@ -174,9 +174,7 @@ private:
 
      QString mstrVIN;
 
-#ifndef Q_OS_WIN
      JoyReadThread * mpJRT;
-#endif
 
      int mnShift = 0;