Refactor implementation of CSL Elite V3 Pedals
This commit is contained in:
parent
b99773a7ee
commit
77a9368307
|
|
@ -17,6 +17,8 @@ set(devices_source_files
|
||||||
sound.c
|
sound.c
|
||||||
usb/revburner.h
|
usb/revburner.h
|
||||||
usb/revburner.c
|
usb/revburner.c
|
||||||
|
usb/cslelitev3.h
|
||||||
|
usb/cslelitev3.c
|
||||||
sound/usb_generic_shaker.h
|
sound/usb_generic_shaker.h
|
||||||
sound/usb_generic_shaker.c
|
sound/usb_generic_shaker.c
|
||||||
sound/usb_generic_shaker_pulse.c
|
sound/usb_generic_shaker_pulse.c
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <glob.h>
|
||||||
|
|
||||||
|
#include "usbhapticdevice.h"
|
||||||
|
|
||||||
|
#include "../slog/slog.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int cslelitev3_update(USBGenericHapticDevice* usbhapticdevice, int value)
|
||||||
|
{
|
||||||
|
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
fprintf(usbhapticdevice->handle, "%i\n", value);
|
||||||
|
fflush(usbhapticdevice->handle);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cslelitev3_free(USBGenericHapticDevice* usbhapticdevice)
|
||||||
|
{
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
free(usbhapticdevice->dev);
|
||||||
|
|
||||||
|
fflush(usbhapticdevice->handle);
|
||||||
|
fclose(usbhapticdevice->handle);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cslelitev3_init(USBGenericHapticDevice* usbhapticdevice)
|
||||||
|
{
|
||||||
|
slogi("initializing CSL Elite V3 Pedals...");
|
||||||
|
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
|
||||||
|
glob_t globlist;
|
||||||
|
int i = 0;
|
||||||
|
if (glob("/sys/module/hid_fanatec/drivers/hid:fanatec/0003:0EB7:0005.*/rumble", GLOB_PERIOD, NULL, &globlist) == GLOB_NOSPACE || glob("/sys/module/hid_fanatec/drivers/hid:fanatec/0003:0EB7:0005.*/rumble", GLOB_PERIOD, NULL, &globlist) == GLOB_NOMATCH)
|
||||||
|
{
|
||||||
|
res = 1;
|
||||||
|
}
|
||||||
|
if (glob("/sys/module/hid_fanatec/drivers/hid:fanatec/0003:0EB7:0005.*/rumble", GLOB_PERIOD, NULL, &globlist) == GLOB_ABORTED)
|
||||||
|
{
|
||||||
|
res = 2;
|
||||||
|
}
|
||||||
|
if (res == 0)
|
||||||
|
{
|
||||||
|
while (globlist.gl_pathv[i])
|
||||||
|
{
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
usbhapticdevice->dev = strdup(globlist.gl_pathv[i]);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
globfree(&globlist);
|
||||||
|
|
||||||
|
if (res == 1) {
|
||||||
|
sloge("Could not find attach Club Sport Elite V3 Pedals");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
if (res == 2) {
|
||||||
|
sloge("Permissions issue finding Club Sport Elite V3 Pedals");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
usbhapticdevice->handle = fopen(usbhapticdevice->dev, "w");
|
||||||
|
|
||||||
|
if (!usbhapticdevice->handle)
|
||||||
|
{
|
||||||
|
sloge("Could not open pedal device...");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
slogd("CSL Elite V3 Pedals Successfully initialized...");
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef _CSLELITEV3_H
|
||||||
|
#define _CSLELITEV3_H
|
||||||
|
|
||||||
|
int cslelitev3_update(USBGenericHapticDevice* usbhapticdevice, int value);
|
||||||
|
int cslelitev3_init(USBGenericHapticDevice* usbhapticdevice);
|
||||||
|
int cslelitev3_free(USBGenericHapticDevice* usbhapticdevice);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "usbhapticdevice.h"
|
#include "usbhapticdevice.h"
|
||||||
#include "hapticeffect.h"
|
#include "hapticeffect.h"
|
||||||
|
#include "usb/cslelitev3.h"
|
||||||
#include "../../helper/confighelper.h"
|
#include "../../helper/confighelper.h"
|
||||||
#include "../../simulatorapi/simapi/simapi/simdata.h"
|
#include "../../simulatorapi/simapi/simapi/simdata.h"
|
||||||
#include "../../slog/slog.h"
|
#include "../../slog/slog.h"
|
||||||
|
|
@ -14,20 +15,16 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat
|
||||||
{
|
{
|
||||||
|
|
||||||
int play = slipeffect(simdata, usbhapticdevice->effecttype, usbhapticdevice->tyre, usbhapticdevice->threshold);
|
int play = slipeffect(simdata, usbhapticdevice->effecttype, usbhapticdevice->tyre, usbhapticdevice->threshold);
|
||||||
|
|
||||||
|
|
||||||
if (play != usbhapticdevice->state)
|
if (play != usbhapticdevice->state)
|
||||||
{
|
{
|
||||||
if(play > 0)
|
if(play > 0)
|
||||||
{
|
{
|
||||||
fprintf(usbhapticdevice->handle, "%i\n", usbhapticdevice->value1);
|
cslelitev3_update(usbhapticdevice, usbhapticdevice->value1);
|
||||||
fflush(usbhapticdevice->handle);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(usbhapticdevice->handle, "%i\n", usbhapticdevice->value0);
|
cslelitev3_update(usbhapticdevice, usbhapticdevice->value0);
|
||||||
fflush(usbhapticdevice->handle);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
usbhapticdevice->state = play;
|
usbhapticdevice->state = play;
|
||||||
}
|
}
|
||||||
|
|
@ -37,9 +34,7 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat
|
||||||
int usbhapticdev_free(USBGenericHapticDevice* usbhapticdevice)
|
int usbhapticdev_free(USBGenericHapticDevice* usbhapticdevice)
|
||||||
{
|
{
|
||||||
slogt("closing usb haptic device");
|
slogt("closing usb haptic device");
|
||||||
fflush(usbhapticdevice->handle);
|
cslelitev3_free(usbhapticdevice);
|
||||||
fclose(usbhapticdevice->handle);
|
|
||||||
free(usbhapticdevice->dev);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,7 +42,6 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
usbhapticdevice->state = 0;
|
usbhapticdevice->state = 0;
|
||||||
usbhapticdevice->dev = strdup(ds->usbdevsettings.dev);
|
|
||||||
usbhapticdevice->value0 = ds->usbdevsettings.value0;
|
usbhapticdevice->value0 = ds->usbdevsettings.value0;
|
||||||
usbhapticdevice->value1 = ds->usbdevsettings.value1;
|
usbhapticdevice->value1 = ds->usbdevsettings.value1;
|
||||||
usbhapticdevice->state = usbhapticdevice->value0;
|
usbhapticdevice->state = usbhapticdevice->value0;
|
||||||
|
|
@ -55,14 +49,27 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
|
||||||
usbhapticdevice->effecttype = ds->effect_type;
|
usbhapticdevice->effecttype = ds->effect_type;
|
||||||
usbhapticdevice->threshold = ds->threshold;
|
usbhapticdevice->threshold = ds->threshold;
|
||||||
|
|
||||||
usbhapticdevice->handle = fopen(usbhapticdevice->dev, "w");
|
if(ds->effect_type == EFFECT_TYRESLIP)
|
||||||
|
{
|
||||||
|
usbhapticdevice->effecttype = EFFECT_TYRESLIP;
|
||||||
|
}
|
||||||
|
if(ds->effect_type == EFFECT_TYRELOCK)
|
||||||
|
{
|
||||||
|
usbhapticdevice->effecttype = EFFECT_TYRELOCK;
|
||||||
|
}
|
||||||
|
|
||||||
|
slogi("initializing standalone usb haptic device...");
|
||||||
|
// detection of usb device model
|
||||||
|
usbhapticdevice->type = HAPTIC_UNKNOWN;
|
||||||
|
usbhapticdevice->type = HAPTIC_CSLELITEV3;
|
||||||
|
error = cslelitev3_init(usbhapticdevice);
|
||||||
|
|
||||||
if(usbhapticdevice->handle == 0)
|
if(usbhapticdevice->handle == 0)
|
||||||
{
|
{
|
||||||
error = MONOCOQUE_ERROR_INVALID_DEV;
|
error = MONOCOQUE_ERROR_INVALID_DEV;
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
slogt("Initializing standalone usb haptic device");
|
|
||||||
if(ds->effect_type == EFFECT_TYRESLIP)
|
if(ds->effect_type == EFFECT_TYRESLIP)
|
||||||
{
|
{
|
||||||
usbhapticdevice->effecttype = EFFECT_TYRESLIP;
|
usbhapticdevice->effecttype = EFFECT_TYRESLIP;
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
HAPTIC_UNKNOWN = 0,
|
HAPTIC_UNKNOWN = 0,
|
||||||
HAPTIC_GENERIC = 1
|
HAPTIC_CSLELITEV3 = 1
|
||||||
}
|
}
|
||||||
HapticType;
|
HapticType;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue