Add support for generic usb haptic devices
This commit is contained in:
parent
e58e235256
commit
5b17aa3e34
|
|
@ -9,6 +9,8 @@ set(devices_source_files
|
|||
serialdevice.c
|
||||
tachdevice.h
|
||||
tachdevice.c
|
||||
usbhapticdevice.h
|
||||
usbhapticdevice.c
|
||||
sound.h
|
||||
sound.c
|
||||
usb/revburner.h
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds)
|
|||
simdevices[j] = sim->m;
|
||||
simdevices[j].initialized = true;
|
||||
simdevices[j].type = SIMDEV_USB;
|
||||
simdevices[j].tyre = ds[j].tyre;
|
||||
devices++;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -64,7 +64,8 @@ SerialDevice* new_serial_device(DeviceSettings* ds);
|
|||
typedef enum
|
||||
{
|
||||
USBDEV_UNKNOWN = 0,
|
||||
USBDEV_TACHOMETER = 1
|
||||
USBDEV_TACHOMETER = 1,
|
||||
USBDEV_GENERICHAPTIC = 2
|
||||
}
|
||||
USBType;
|
||||
|
||||
|
|
@ -76,6 +77,7 @@ typedef struct
|
|||
union
|
||||
{
|
||||
TachDevice tachdevice;
|
||||
USBGenericHapticDevice hapticdevice;
|
||||
} u;
|
||||
}
|
||||
USBDevice;
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main
|
|||
pa_stream_set_state_callback(stream, stream_state_cb, mainloop);
|
||||
|
||||
|
||||
if (sounddevice->effecttype == SOUNDEFFECT_GEARSHIFT)
|
||||
if (sounddevice->effecttype == EFFECT_GEARSHIFT)
|
||||
{
|
||||
pa_stream_set_write_callback(stream, gear_sound_stream, &sounddevice->sounddata);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int
|
|||
|
||||
const char* streamname= "Engine";
|
||||
switch (sounddevice->effecttype) {
|
||||
case (SOUNDEFFECT_GEARSHIFT):
|
||||
case (EFFECT_GEARSHIFT):
|
||||
|
||||
sounddevice->sounddata.last_gear = 0;
|
||||
//sounddevice->sounddata.pitch = 500;
|
||||
|
|
@ -139,12 +139,12 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int
|
|||
sounddevice->sounddata.curr_duration = duration;
|
||||
streamname = "Gear";
|
||||
break;
|
||||
case (SOUNDEFFECT_TYRESLIP):
|
||||
case (EFFECT_TYRESLIP):
|
||||
sounddevice->sounddata.duration = duration;
|
||||
sounddevice->sounddata.curr_duration = duration;
|
||||
streamname = "TyreSlip";
|
||||
break;
|
||||
case (SOUNDEFFECT_ABSBRAKES):
|
||||
case (EFFECT_ABSBRAKES):
|
||||
sounddevice->sounddata.duration = duration;
|
||||
sounddevice->sounddata.curr_duration = duration;
|
||||
streamname = "ABS";
|
||||
|
|
@ -175,25 +175,25 @@ SoundDevice* new_sound_device(DeviceSettings* ds) {
|
|||
this->m.free = &simdevfree;
|
||||
this->m.derived = this;
|
||||
|
||||
slogt("Attempting to configure sound device with subtype: %i", ds->dev_subtype);
|
||||
switch (ds->dev_subtype) {
|
||||
case (SIMDEVTYPE_ENGINESOUND):
|
||||
this->effecttype = SOUNDEFFECT_ENGINERPM;
|
||||
slogt("Attempting to configure sound device with subtype: %i", ds->effect_type);
|
||||
switch (ds->effect_type) {
|
||||
case (EFFECT_ENGINERPM):
|
||||
this->effecttype = EFFECT_ENGINERPM;
|
||||
this->m.vtable = &engine_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for engine vibrations.");
|
||||
break;
|
||||
case (SIMDEVTYPE_GEARSOUND):
|
||||
this->effecttype = SOUNDEFFECT_GEARSHIFT;
|
||||
case (EFFECT_GEARSHIFT):
|
||||
this->effecttype = EFFECT_GEARSHIFT;
|
||||
this->m.vtable = &gear_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for gear shift vibrations.");
|
||||
break;
|
||||
case (SIMDEVTYPE_TYRESLIP):
|
||||
this->effecttype = SOUNDEFFECT_TYRESLIP;
|
||||
case (EFFECT_TYRESLIP):
|
||||
this->effecttype = EFFECT_TYRESLIP;
|
||||
this->m.vtable = &tyreslip_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for tyre slip vibrations.");
|
||||
break;
|
||||
case (SIMDEVTYPE_ABSBRAKES):
|
||||
this->effecttype = SOUNDEFFECT_ABSBRAKES;
|
||||
case (EFFECT_ABSBRAKES):
|
||||
this->effecttype = EFFECT_ABSBRAKES;
|
||||
this->m.vtable = &absbrakes_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for abs vibrations.");
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -14,15 +14,6 @@ typedef enum
|
|||
}
|
||||
SoundType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SOUNDEFFECT_ENGINERPM = 0,
|
||||
SOUNDEFFECT_GEARSHIFT = 1,
|
||||
SOUNDEFFECT_ABSBRAKES = 2,
|
||||
SOUNDEFFECT_TYRESLIP = 3
|
||||
}
|
||||
VibrationEffectType;
|
||||
|
||||
#define MAX_TABLE_SIZE (6000)
|
||||
typedef struct
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ int usbdev_update(SimDevice* this, SimData* simdata)
|
|||
case USBDEV_TACHOMETER :
|
||||
tachdev_update(&usbdevice->u.tachdevice, simdata);
|
||||
break;
|
||||
case USBDEV_GENERICHAPTIC :
|
||||
usbhapticdev_update(&usbdevice->u.hapticdevice, simdata);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -28,12 +31,16 @@ int usbdev_free(SimDevice* this)
|
|||
{
|
||||
USBDevice* usbdevice = (void *) this->derived;
|
||||
|
||||
slogt("Usb device free");
|
||||
switch ( usbdevice->type )
|
||||
{
|
||||
case USBDEV_UNKNOWN :
|
||||
case USBDEV_TACHOMETER :
|
||||
tachdev_free(&usbdevice->u.tachdevice);
|
||||
break;
|
||||
case USBDEV_GENERICHAPTIC :
|
||||
usbhapticdev_free(&usbdevice->u.hapticdevice);
|
||||
break;
|
||||
}
|
||||
|
||||
free(usbdevice);
|
||||
|
|
@ -46,13 +53,16 @@ int usbdev_init(USBDevice* usbdevice, DeviceSettings* ds)
|
|||
slogi("initializing usb device...");
|
||||
int error = 0;
|
||||
|
||||
usbdevice->type = USBDEV_TACHOMETER;
|
||||
//usbdevice->type = USBDEV_TACHOMETER;
|
||||
switch ( usbdevice->type )
|
||||
{
|
||||
case USBDEV_UNKNOWN :
|
||||
case USBDEV_TACHOMETER :
|
||||
error = tachdev_init(&usbdevice->u.tachdevice, ds);
|
||||
break;
|
||||
case USBDEV_GENERICHAPTIC :
|
||||
error = usbhapticdev_init(&usbdevice->u.hapticdevice, ds);
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
|
|
@ -69,6 +79,12 @@ USBDevice* new_usb_device(DeviceSettings* ds) {
|
|||
this->m.derived = this;
|
||||
this->m.vtable = &usb_simdevice_vtable;
|
||||
|
||||
this->type = USBDEV_TACHOMETER;
|
||||
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC)
|
||||
{
|
||||
this->type = USBDEV_GENERICHAPTIC;
|
||||
}
|
||||
|
||||
int error = usbdev_init(this, ds);
|
||||
|
||||
if (error != 0)
|
||||
|
|
|
|||
|
|
@ -2,5 +2,6 @@
|
|||
#define _USBDEVICE_H
|
||||
|
||||
#include "tachdevice.h"
|
||||
#include "usbhapticdevice.h"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -52,6 +52,31 @@ int strtogame(const char* game, MonocoqueSettings* ms)
|
|||
return MONOCOQUE_ERROR_NONE;
|
||||
}
|
||||
|
||||
int strtoeffecttype(const char* effect, DeviceSettings* ds)
|
||||
{
|
||||
ds->is_valid = false;
|
||||
|
||||
if (strcicmp(effect, "Engine") == 0)
|
||||
{
|
||||
ds->effect_type = EFFECT_ENGINERPM;
|
||||
}
|
||||
if (strcicmp(effect, "Gear") == 0)
|
||||
{
|
||||
ds->effect_type = EFFECT_GEARSHIFT;
|
||||
}
|
||||
if (strcicmp(effect, "ABS") == 0)
|
||||
{
|
||||
ds->effect_type = EFFECT_ABSBRAKES;
|
||||
}
|
||||
if ((strcicmp(effect, "SLIP") == 0) || (strcicmp(effect, "TYRESLIP") == 0) || (strcicmp(effect, "TIRESLIP") == 0))
|
||||
{
|
||||
ds->effect_type = EFFECT_TYRESLIP;
|
||||
}
|
||||
|
||||
ds->is_valid = true;
|
||||
return MONOCOQUE_ERROR_NONE;
|
||||
}
|
||||
|
||||
int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
|
||||
{
|
||||
ds->is_valid = false;
|
||||
|
|
@ -64,6 +89,11 @@ int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
|
|||
ds->dev_subtype = SIMDEVTYPE_TACHOMETER;
|
||||
break;
|
||||
}
|
||||
if (strcicmp(device_subtype, "UsbHaptic") == 0 || strcicmp(device_subtype, "Haptic") == 0)
|
||||
{
|
||||
ds->dev_subtype = SIMDEVTYPE_USBHAPTIC;
|
||||
break;
|
||||
}
|
||||
case SIMDEV_SERIAL:
|
||||
if (strcicmp(device_subtype, "ShiftLights") == 0)
|
||||
{
|
||||
|
|
@ -76,26 +106,8 @@ int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
|
|||
break;
|
||||
}
|
||||
case SIMDEV_SOUND:
|
||||
if (strcicmp(device_subtype, "Engine") == 0)
|
||||
{
|
||||
ds->dev_subtype = SIMDEVTYPE_ENGINESOUND;
|
||||
ds->is_valid = true;
|
||||
break;
|
||||
}
|
||||
if (strcicmp(device_subtype, "Gear") == 0)
|
||||
{
|
||||
ds->dev_subtype = SIMDEVTYPE_GEARSOUND;
|
||||
break;
|
||||
}
|
||||
if (strcicmp(device_subtype, "ABS") == 0)
|
||||
{
|
||||
ds->dev_subtype = SIMDEVTYPE_ABSBRAKES;
|
||||
break;
|
||||
}
|
||||
if ((strcicmp(device_subtype, "SLIP") == 0) || (strcicmp(device_subtype, "TYRESLIP") == 0))
|
||||
{
|
||||
ds->dev_subtype = SIMDEVTYPE_TYRESLIP;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ds->is_valid = false;
|
||||
slogw("%s does not appear to be a valid device sub type, but attempting to continue with other devices", device_subtype);
|
||||
|
|
@ -228,74 +240,10 @@ int loadtachconfig(const char* config_file, DeviceSettings* ds)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int loadconfig(const char* config_file, DeviceSettings* ds)
|
||||
{
|
||||
if (ds->dev_subtype == SIMDEVTYPE_TACHOMETER)
|
||||
{
|
||||
return loadtachconfig(config_file, ds);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int devsetup(const char* device_type, const char* device_subtype, const char* config_file, MonocoqueSettings* ms, DeviceSettings* ds, config_setting_t* device_settings)
|
||||
{
|
||||
int error = MONOCOQUE_ERROR_NONE;
|
||||
//slogt("Called device setup with %s %s %s", device_type, device_subtype, config_file);
|
||||
ds->dev_type = SIMDEV_UNKNOWN;
|
||||
|
||||
error = strtodev(device_type, device_subtype, ds);
|
||||
if (error != MONOCOQUE_ERROR_NONE)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
if (ms->program_action == A_PLAY || ms->program_action == A_TEST)
|
||||
{
|
||||
error = loadconfig(config_file, ds);
|
||||
}
|
||||
if (error != MONOCOQUE_ERROR_NONE)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
if (ds->dev_type == SIMDEV_SOUND)
|
||||
{
|
||||
slogi("reading configured sound device settings");
|
||||
ds->sounddevsettings.frequency = -1;
|
||||
ds->sounddevsettings.volume = -1;
|
||||
ds->sounddevsettings.lowbound_frequency = -1;
|
||||
ds->sounddevsettings.upperbound_frequency = -1;
|
||||
ds->sounddevsettings.pan = 0;
|
||||
ds->sounddevsettings.duration = 2.0;
|
||||
if (ds->dev_subtype == SIMDEVTYPE_GEARSOUND)
|
||||
{
|
||||
ds->sounddevsettings.duration = .125;
|
||||
}
|
||||
if (device_settings != NULL)
|
||||
{
|
||||
|
||||
config_setting_lookup_int(device_settings, "volume", &ds->sounddevsettings.volume);
|
||||
config_setting_lookup_int(device_settings, "frequency", &ds->sounddevsettings.frequency);
|
||||
config_setting_lookup_int(device_settings, "pan", &ds->sounddevsettings.pan);
|
||||
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
|
||||
|
||||
|
||||
int gettyre(config_setting_t* device_settings, DeviceSettings* ds) {
|
||||
|
||||
const char* temp;
|
||||
int found = 0;
|
||||
found = config_setting_lookup_string(device_settings, "devid", &temp);
|
||||
if (found == 0)
|
||||
{
|
||||
ds->sounddevsettings.dev = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ds->sounddevsettings.dev = strdup(temp);
|
||||
}
|
||||
if (ds->dev_subtype == SIMDEVTYPE_TYRESLIP)
|
||||
{
|
||||
|
||||
found = config_setting_lookup_string(device_settings, "tyre", &temp);
|
||||
int found = config_setting_lookup_string(device_settings, "tyre", &temp);
|
||||
|
||||
ds->tyre = ALLFOUR;
|
||||
|
||||
|
|
@ -323,9 +271,41 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
|||
{
|
||||
ds->tyre = REARRIGHT;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int loadconfig(const char* config_file, DeviceSettings* ds)
|
||||
{
|
||||
if (ds->dev_subtype == SIMDEVTYPE_TACHOMETER)
|
||||
{
|
||||
return loadtachconfig(config_file, ds);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int devsetup(const char* device_type, const char* device_subtype, const char* config_file, MonocoqueSettings* ms, DeviceSettings* ds, config_setting_t* device_settings)
|
||||
{
|
||||
int error = MONOCOQUE_ERROR_NONE;
|
||||
//slogt("Called device setup with %s %s %s", device_type, device_subtype, config_file);
|
||||
ds->dev_type = SIMDEV_UNKNOWN;
|
||||
|
||||
error = strtodev(device_type, device_subtype, ds);
|
||||
|
||||
if (error != MONOCOQUE_ERROR_NONE)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
if (ms->program_action == A_PLAY || ms->program_action == A_TEST)
|
||||
{
|
||||
error = loadconfig(config_file, ds);
|
||||
}
|
||||
if (error != MONOCOQUE_ERROR_NONE)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (ds->dev_subtype == SIMDEVTYPE_TACHOMETER)
|
||||
{
|
||||
|
|
@ -346,6 +326,73 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
|||
}
|
||||
}
|
||||
|
||||
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC)
|
||||
{
|
||||
if (device_settings != NULL)
|
||||
{
|
||||
ds->usbdevsettings.value0 = 0;
|
||||
ds->usbdevsettings.value1 = 1;
|
||||
|
||||
const char* temp;
|
||||
int found = config_setting_lookup_string(device_settings, "devpath", &temp);
|
||||
if (found == 0)
|
||||
{
|
||||
ds->usbdevsettings.dev = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ds->usbdevsettings.dev = strdup(temp);
|
||||
}
|
||||
|
||||
config_setting_lookup_int(device_settings, "value0", &ds->usbdevsettings.value0);
|
||||
config_setting_lookup_int(device_settings, "value1", &ds->usbdevsettings.value1);
|
||||
}
|
||||
}
|
||||
|
||||
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_type == SIMDEV_SOUND) {
|
||||
const char* effect;
|
||||
config_setting_lookup_string(device_settings, "effect", &effect);
|
||||
strtoeffecttype(effect, ds);
|
||||
if (ds->effect_type == EFFECT_TYRESLIP || ds->effect_type == EFFECT_WHEELLOCK)
|
||||
{
|
||||
gettyre(device_settings, ds);
|
||||
}
|
||||
|
||||
if (ds->dev_type == SIMDEV_SOUND)
|
||||
{
|
||||
slogi("reading configured sound device settings");
|
||||
ds->sounddevsettings.frequency = -1;
|
||||
ds->sounddevsettings.volume = -1;
|
||||
ds->sounddevsettings.lowbound_frequency = -1;
|
||||
ds->sounddevsettings.upperbound_frequency = -1;
|
||||
ds->sounddevsettings.pan = 0;
|
||||
ds->sounddevsettings.duration = 2.0;
|
||||
if (ds->effect_type == EFFECT_GEARSHIFT)
|
||||
{
|
||||
ds->sounddevsettings.duration = .125;
|
||||
}
|
||||
if (device_settings != NULL)
|
||||
{
|
||||
|
||||
config_setting_lookup_int(device_settings, "volume", &ds->sounddevsettings.volume);
|
||||
config_setting_lookup_int(device_settings, "frequency", &ds->sounddevsettings.frequency);
|
||||
config_setting_lookup_int(device_settings, "pan", &ds->sounddevsettings.pan);
|
||||
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
|
||||
|
||||
const char* temp;
|
||||
int found = 0;
|
||||
found = config_setting_lookup_string(device_settings, "devid", &temp);
|
||||
if (found == 0)
|
||||
{
|
||||
ds->sounddevsettings.dev = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ds->sounddevsettings.dev = strdup(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ds->dev_subtype == SIMDEVTYPE_SIMWIND || ds->dev_subtype == SIMDEVTYPE_SHIFTLIGHTS)
|
||||
{
|
||||
|
|
@ -378,5 +425,13 @@ int settingsfree(DeviceSettings ds)
|
|||
free(ds.sounddevsettings.dev);
|
||||
}
|
||||
}
|
||||
|
||||
if (ds.dev_type == SIMDEV_USB)
|
||||
{
|
||||
if (ds.usbdevsettings.dev != NULL )
|
||||
{
|
||||
free(ds.usbdevsettings.dev);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,12 +22,9 @@ typedef enum
|
|||
{
|
||||
SIMDEVTYPE_UNKNOWN = 0,
|
||||
SIMDEVTYPE_TACHOMETER = 1,
|
||||
SIMDEVTYPE_SHIFTLIGHTS = 2,
|
||||
SIMDEVTYPE_SIMWIND = 3,
|
||||
SIMDEVTYPE_ENGINESOUND = 4,
|
||||
SIMDEVTYPE_GEARSOUND = 5,
|
||||
SIMDEVTYPE_ABSBRAKES = 6,
|
||||
SIMDEVTYPE_TYRESLIP = 7
|
||||
SIMDEVTYPE_USBHAPTIC = 2,
|
||||
SIMDEVTYPE_SHIFTLIGHTS = 3,
|
||||
SIMDEVTYPE_SIMWIND = 4
|
||||
}
|
||||
DeviceSubType;
|
||||
|
||||
|
|
@ -43,6 +40,16 @@ typedef enum
|
|||
}
|
||||
SimulatorUpdate;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
EFFECT_ENGINERPM = 0,
|
||||
EFFECT_GEARSHIFT = 1,
|
||||
EFFECT_ABSBRAKES = 2,
|
||||
EFFECT_TYRESLIP = 3,
|
||||
EFFECT_WHEELLOCK = 4
|
||||
}
|
||||
VibrationEffectType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MONOCOQUE_ERROR_NONE = 0,
|
||||
|
|
@ -101,14 +108,25 @@ typedef struct
|
|||
}
|
||||
SoundDeviceSettings;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int value0;
|
||||
int value1;
|
||||
char* dev;
|
||||
}
|
||||
USBDeviceSettings;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bool is_valid;
|
||||
DeviceType dev_type;
|
||||
DeviceSubType dev_subtype;
|
||||
VibrationEffectType effect_type;
|
||||
// union?
|
||||
TachometerSettings tachsettings;
|
||||
SerialDeviceSettings serialdevsettings;
|
||||
SoundDeviceSettings sounddevsettings;
|
||||
USBDeviceSettings usbdevsettings;
|
||||
MonocoqueTyreIdentifier tyre;
|
||||
}
|
||||
DeviceSettings;
|
||||
|
|
|
|||
Loading…
Reference in New Issue