Hong.J.Tang
Hong.J.Tang

Reputation: 31

Why my console program can connect the g29 wheel, but can't read the wheel data?

I'm building a driving simulator in VS2017 using the G29. The offcial demo can run correctly. But my code can only make LogiSteeringInitializeWithWindow() and LogiUpdate() return "TRUE". LogiGetState() and LogiGetStateENGINES() can't return any data.

I've read the code of SteeringWheelSDKDemo, but nothing I've find. Googling is so poor for the g29 wheel.

#include <iostream>
#include <stdio.h>
#include "map"
#include "string"
#pragma comment(lib, "LogitechSteeringWheelLib.lib")
#include "LogitechSteeringWheelLib.h"


int main()
{
    DIJOYSTATE2 *controller_state = NULL;
    DIJOYSTATE2ENGINES  *last_state = NULL;
    std::map<std::string, int> current_state_map;
    int controller_idx = 0;
    HWND h_wnd = FindWindow(_T("ConsoleWindowClass"), NULL);
    while (!LogiSteeringInitializeWithWindow(true, h_wnd)) {
        printf("try again.\n");
    }
    while (true) {
        if (!LogiUpdate()) {
            continue;
        }

        while (LogiIsConnected(controller_idx)) {
            std::cout << LOGI_MAX_CONTROLLERS << std::endl;
            wchar_t deviceName[128];
            LogiGetFriendlyProductName(controller_idx, deviceName, 128);
            std::cout << deviceName << std::endl;
            std::cout << "wheel " << LogiIsDeviceConnected(controller_idx, LOGI_DEVICE_TYPE_WHEEL) << std::endl;
            std::cout << "Joystick " << LogiIsDeviceConnected(controller_idx, LOGI_DEVICE_TYPE_JOYSTICK) << std::endl;

            controller_state = LogiGetState(controller_idx);
            last_state = LogiGetStateENGINES(controller_idx);
            std::cout << "-------------" << std::endl;
            std::cout << controller_state->lX << std::endl;
            std::cout << controller_state->lY << std::endl;
            std::cout << controller_state->lRz << std::endl;
            std::cout << "-------------" << std::endl;
            std::cout << last_state->lX << std::endl;
            std::cout << last_state->lY << std::endl;
            std::cout << last_state->lRz << std::endl;
            std::cout << "-------------" << std::endl;
            system("cls");

        }
        std::cout << "unconnected\n";
    }

}

I expect there will the data of wheel, but it's 0.

Upvotes: 3

Views: 579

Answers (1)

Patrick Jordan
Patrick Jordan

Reputation: 33

Ok so I know this is 5 years late but I have a very unsatisfactory answer:

If you simply double click the .exe file to run it, it will work and read your values, if you run it from a powershell or command line or anything else (I guess I haven't tested every way of running a file on windows but a good number), it will not work.

I just had this same problem and was searching everywhere for an answer, and luckily just tried opening the exe another way and got lucky so if you or anyone else has this issue try this.

Upvotes: 0

Related Questions