Support for cammus c12
This commit is contained in:
parent
910e225a9a
commit
a81004418d
|
|
@ -23,6 +23,8 @@ set(devices_source_files
|
|||
usb/cslelitev3.c
|
||||
usb/wheels/cammusc5.h
|
||||
usb/wheels/cammusc5.c
|
||||
usb/wheels/cammusc12.h
|
||||
usb/wheels/cammusc12.c
|
||||
sound/usb_generic_shaker.h
|
||||
sound/usb_generic_shaker.c
|
||||
sound/usb_generic_shaker_pulse.c
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#include "cammusc12.h"
|
||||
#include "../../../slog/slog.h"
|
||||
|
||||
const int cammusc12_hidupdate_buf_size = 16;
|
||||
|
||||
int cammusc12_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity)
|
||||
{
|
||||
|
||||
int res = 0;
|
||||
|
||||
unsigned char bytes[cammusc12_hidupdate_buf_size];
|
||||
|
||||
for (int x = 0; x < cammusc12_hidupdate_buf_size; x++)
|
||||
{
|
||||
bytes[x] = 0x00;
|
||||
}
|
||||
// byte 1 must be fc it seems
|
||||
bytes[0] = 0xFA;
|
||||
bytes[1] = 0xFB;
|
||||
bytes[2] = 0xD4;
|
||||
|
||||
int perct = 0;
|
||||
if(rpm > 0 && maxrpm > 0)
|
||||
{
|
||||
double rpmperct = (double) rpm / (double) maxrpm;
|
||||
perct = trunc(nearbyint( rpmperct * 100 ));
|
||||
}
|
||||
bytes[3] = perct;
|
||||
|
||||
// bytes 2 and 3 are a 16 bit velocity
|
||||
if ( velocity > 0 )
|
||||
{
|
||||
bytes[4] = (velocity >> 8) & 0xFF;
|
||||
bytes[5] = velocity & 0xFF;
|
||||
}
|
||||
|
||||
// byte 4 is gear
|
||||
bytes[6] = gear-1;
|
||||
|
||||
slogt("writing bytes x%02xx%02xx%02xx%02xx%02x%02x%02x from rpm %i velocity %i gear %i", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], rpm, velocity, gear);
|
||||
if (wheeldevice->handle)
|
||||
{
|
||||
res = hid_write(wheeldevice->handle, bytes, cammusc12_hidupdate_buf_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
slogd("no handle");
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int cammusc12_free(WheelDevice* wheeldevice)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
hid_close(wheeldevice->handle);
|
||||
res = hid_exit();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int cammusc12_init(WheelDevice* wheeldevice)
|
||||
{
|
||||
slogi("initializing cammus c12 wheel...");
|
||||
|
||||
int res = 0;
|
||||
|
||||
res = hid_init();
|
||||
|
||||
wheeldevice->handle = hid_open(0x3416, 0x1023, NULL);
|
||||
|
||||
if (!wheeldevice->handle)
|
||||
{
|
||||
sloge("Could not find attached Cammus C12 Wheel");
|
||||
res = hid_exit();
|
||||
return 1;
|
||||
}
|
||||
slogd("Found Cammus C12 Wheel...");
|
||||
return res;
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef _CAMMUSC12_H
|
||||
#define _CAMMUSC12_H
|
||||
|
||||
#include "../../wheeldevice.h"
|
||||
|
||||
int cammusc12_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity);
|
||||
int cammusc12_init(WheelDevice* wheeldevice);
|
||||
int cammusc12_free(WheelDevice* wheeldevice);
|
||||
|
||||
#endif
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "usb/wheels/cammusc5.h"
|
||||
#include "usb/wheels/cammusc12.h"
|
||||
#include "wheeldevice.h"
|
||||
#include "../helper/confighelper.h"
|
||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||
|
|
@ -16,6 +17,9 @@ int wheeldev_update(WheelDevice* wheeldevice, SimData* simdata)
|
|||
case WHEELDEV_CAMMUSC5 :
|
||||
cammusc5_update(wheeldevice, simdata->maxrpm, simdata->rpms, simdata->gear, simdata->velocity);
|
||||
break;
|
||||
case WHEELDEV_CAMMUSC12 :
|
||||
cammusc12_update(wheeldevice, simdata->maxrpm, simdata->rpms, simdata->gear, simdata->velocity);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -31,6 +35,10 @@ int wheeldev_free(WheelDevice* wheeldevice)
|
|||
cammusc5_update(wheeldevice, 0, 0, 0, 0);
|
||||
cammusc5_free(wheeldevice);
|
||||
break;
|
||||
case WHEELDEV_CAMMUSC12 :
|
||||
cammusc12_update(wheeldevice, 0, 0, 0, 0);
|
||||
cammusc12_free(wheeldevice);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -41,11 +49,25 @@ int wheeldev_init(WheelDevice* wheeldevice, DeviceSettings* ds)
|
|||
slogi("initializing wheel device...");
|
||||
int error = 0;
|
||||
// detection of wheel model
|
||||
wheeldevice->type = WHEELDEV_UNKNOWN;
|
||||
|
||||
switch (ds->dev_subsubtype) {
|
||||
|
||||
case SIMDEVSUBTYPE_CAMMUSC5:
|
||||
wheeldevice->type = WHEELDEV_CAMMUSC5;
|
||||
|
||||
|
||||
slogi("Attempting to initialize cammus C5");
|
||||
error = cammusc5_init(wheeldevice);
|
||||
break;
|
||||
case SIMDEVSUBTYPE_CAMMUSC12:
|
||||
wheeldevice->type = WHEELDEV_CAMMUSC12;
|
||||
slogi("Attempting to initialize cammus C12");
|
||||
error = cammusc12_init(wheeldevice);
|
||||
break;
|
||||
default:
|
||||
wheeldevice->type = WHEELDEV_UNKNOWN;
|
||||
slogw("Unknown cammus wheel detected, trying C5");
|
||||
error = cammusc5_init(wheeldevice);
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@
|
|||
typedef enum
|
||||
{
|
||||
WHEELDEV_UNKNOWN = 0,
|
||||
WHEELDEV_CAMMUSC5 = 1
|
||||
WHEELDEV_CAMMUSC5 = 1,
|
||||
WHEELDEV_CAMMUSC12 = 2
|
||||
}
|
||||
WheelType;
|
||||
|
||||
|
|
|
|||
|
|
@ -95,6 +95,21 @@ int strtoeffecttype(const char* effect, DeviceSettings* ds)
|
|||
return MONOCOQUE_ERROR_NONE;
|
||||
}
|
||||
|
||||
int strtodevsubsubtype(const char* device_subsubtype, DeviceSettings* ds)
|
||||
{
|
||||
ds->dev_subsubtype = SIMDEVSUBTYPE_UNKNOWN;
|
||||
|
||||
if (strcicmp(device_subsubtype, "CammusC5") == 0)
|
||||
{
|
||||
ds->dev_subsubtype = SIMDEVSUBTYPE_CAMMUSC5;
|
||||
}
|
||||
if (strcicmp(device_subsubtype, "CammusC12") == 0)
|
||||
{
|
||||
ds->dev_subsubtype = SIMDEVSUBTYPE_CAMMUSC12;
|
||||
}
|
||||
return MONOCOQUE_ERROR_NONE;
|
||||
}
|
||||
|
||||
int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
|
||||
{
|
||||
ds->is_valid = false;
|
||||
|
|
@ -463,6 +478,19 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
|||
// logic for different devices
|
||||
}
|
||||
|
||||
if (ds->dev_subtype == SIMDEVTYPE_USBWHEEL)
|
||||
{
|
||||
// logic for different devices
|
||||
int b = 0;
|
||||
|
||||
const char* temp;
|
||||
int found = config_setting_lookup_string(device_settings, "subtype", &temp);
|
||||
if(temp != NULL && found > 0)
|
||||
{
|
||||
b = strtodevsubsubtype(temp, ds);
|
||||
}
|
||||
}
|
||||
|
||||
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_type == SIMDEV_SOUND || ds->dev_subtype == SIMDEVTYPE_SERIALHAPTIC)
|
||||
{
|
||||
slogt("analysing haptic effect settings");
|
||||
|
|
|
|||
|
|
@ -30,6 +30,14 @@ typedef enum
|
|||
}
|
||||
DeviceSubType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SIMDEVSUBTYPE_UNKNOWN = 0,
|
||||
SIMDEVSUBTYPE_CAMMUSC5 = 1,
|
||||
SIMDEVSUBTYPE_CAMMUSC12 = 2,
|
||||
}
|
||||
DeviceSubSubType;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
|
@ -169,6 +177,7 @@ typedef struct
|
|||
bool is_valid;
|
||||
DeviceType dev_type;
|
||||
DeviceSubType dev_subtype;
|
||||
DeviceSubSubType dev_subsubtype;
|
||||
// to get really fancy move the effect information to it's own structure that would be a member of
|
||||
// any device settings member structure that can carry an effect
|
||||
VibrationEffectType effect_type;
|
||||
|
|
|
|||
Loading…
Reference in New Issue