Move haptic effect data into it's own structure.
This commit is contained in:
parent
ea100ca2cf
commit
1bde76e3c7
|
|
@ -9,6 +9,10 @@ typedef struct
|
|||
{
|
||||
double threshold;
|
||||
VibrationEffectType effecttype;
|
||||
MonocoqueTyreIdentifier tyre;
|
||||
int useconfig;
|
||||
int* configcheck;
|
||||
char* tyrediameterconfig;
|
||||
}
|
||||
HapticEffect;
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ int arduino_haptic_update(SimDevice* this, SimData* simdata)
|
|||
SerialDevice* serialdevice = (void *) this->derived;
|
||||
int result = 1;
|
||||
|
||||
int play = slipeffect(simdata, serialdevice->hapticeffect.effecttype, this->tyre, serialdevice->hapticeffect.threshold, this->useconfig, this->configcheck, this->tyrediameterconfig);
|
||||
int play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
|
||||
slogt("Updating arduino haptic device");
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ static const vtable arduino_shiftlights_vtable = { &arduino_shiftlights_update,
|
|||
static const vtable arduino_simwind_vtable = { &arduino_simwind_update, &serialdev_free };
|
||||
static const vtable arduino_haptic_vtable = { &arduino_haptic_update, &serialdev_free };
|
||||
|
||||
SerialDevice* new_serial_device(DeviceSettings* ds) {
|
||||
SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||
|
||||
SerialDevice* this = (SerialDevice*) malloc(sizeof(SerialDevice));
|
||||
|
||||
|
|
@ -127,8 +127,12 @@ SerialDevice* new_serial_device(DeviceSettings* ds) {
|
|||
|
||||
if(this->devicetype == ARDUINODEV__HAPTIC)
|
||||
{
|
||||
this->hapticeffect.threshold = ds->threshold;
|
||||
this->hapticeffect.effecttype = ds->effect_type;
|
||||
this->m.hapticeffect.threshold = ds->threshold;
|
||||
this->m.hapticeffect.effecttype = ds->effect_type;
|
||||
this->m.hapticeffect.tyre = ds->tyre;
|
||||
this->m.hapticeffect.useconfig = ms->useconfig;
|
||||
this->m.hapticeffect.configcheck = &ms->configcheck;
|
||||
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
|
||||
}
|
||||
|
||||
int error = serialdev_init(this, ds->serialdevsettings.portdev);
|
||||
|
|
|
|||
|
|
@ -34,16 +34,12 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds, Monocoque
|
|||
simdevices[j].initialized = false;
|
||||
|
||||
if (ds[j].dev_type == SIMDEV_USB) {
|
||||
USBDevice* sim = new_usb_device(&ds[j]);
|
||||
USBDevice* sim = new_usb_device(&ds[j], ms);
|
||||
if (sim != NULL)
|
||||
{
|
||||
simdevices[j] = sim->m;
|
||||
simdevices[j].initialized = true;
|
||||
simdevices[j].type = SIMDEV_USB;
|
||||
simdevices[j].tyre = ds[j].tyre;
|
||||
simdevices[j].useconfig = ms->useconfig;
|
||||
simdevices[j].configcheck = &ms->configcheck;
|
||||
simdevices[j].tyrediameterconfig = ms->tyre_diameter_config;
|
||||
devices++;
|
||||
}
|
||||
else
|
||||
|
|
@ -54,17 +50,13 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds, Monocoque
|
|||
|
||||
if (ds[j].dev_type == SIMDEV_SOUND) {
|
||||
|
||||
SoundDevice* sim = new_sound_device(&ds[j]);
|
||||
SoundDevice* sim = new_sound_device(&ds[j], ms);
|
||||
if (sim != NULL)
|
||||
{
|
||||
|
||||
simdevices[j] = sim->m;
|
||||
simdevices[j].initialized = true;
|
||||
simdevices[j].type = SIMDEV_SOUND;
|
||||
simdevices[j].tyre = ds[j].tyre;
|
||||
simdevices[j].useconfig = ms->useconfig;
|
||||
simdevices[j].configcheck = &ms->configcheck;
|
||||
simdevices[j].tyrediameterconfig = ms->tyre_diameter_config;
|
||||
devices++;
|
||||
}
|
||||
else
|
||||
|
|
@ -75,7 +67,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds, Monocoque
|
|||
|
||||
if (ds[j].dev_type == SIMDEV_SERIAL) {
|
||||
|
||||
SerialDevice* sim = new_serial_device(&ds[j]);
|
||||
SerialDevice* sim = new_serial_device(&ds[j], ms);
|
||||
if (sim != NULL)
|
||||
{
|
||||
simdevices[j] = sim->m;
|
||||
|
|
|
|||
|
|
@ -24,11 +24,7 @@ struct SimDevice
|
|||
int id;
|
||||
bool initialized;
|
||||
DeviceType type;
|
||||
// possibly move these to a haptic effect struct
|
||||
MonocoqueTyreIdentifier tyre;
|
||||
int useconfig;
|
||||
int* configcheck;
|
||||
char* tyrediameterconfig;
|
||||
HapticEffect hapticeffect;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -51,7 +47,6 @@ typedef struct
|
|||
SerialType type;
|
||||
struct sp_port* port;
|
||||
SerialDeviceType devicetype;
|
||||
HapticEffect hapticeffect;
|
||||
union
|
||||
{
|
||||
SimWindData simwinddata;
|
||||
|
|
@ -65,7 +60,7 @@ int arduino_simwind_update(SimDevice* this, SimData* simdata);
|
|||
int arduino_haptic_update(SimDevice* this, SimData* simdata);
|
||||
int serialdev_free(SimDevice* this);
|
||||
|
||||
SerialDevice* new_serial_device(DeviceSettings* ds);
|
||||
SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms);
|
||||
|
||||
/********* USB HID Devices *****/
|
||||
typedef enum
|
||||
|
|
@ -92,7 +87,7 @@ USBDevice;
|
|||
int usbdev_update(SimDevice* this, SimData* simdata);
|
||||
int usbdev_free(SimDevice* this);
|
||||
|
||||
USBDevice* new_usb_device(DeviceSettings* ds);
|
||||
USBDevice* new_usb_device(DeviceSettings* ds, MonocoqueSettings* ms);
|
||||
|
||||
|
||||
/********* Sound Devices *****/
|
||||
|
|
@ -102,8 +97,6 @@ typedef struct
|
|||
int id;
|
||||
SoundType type;
|
||||
int configcheck;
|
||||
VibrationEffectType effecttype;
|
||||
double slipthreshold;
|
||||
SoundData sounddata;
|
||||
#ifdef USE_PULSEAUDIO
|
||||
pa_stream *stream;
|
||||
|
|
@ -119,7 +112,7 @@ int sounddev_gearshift_update(SimDevice* this, SimData* simdata);
|
|||
int sounddev_tyreslip_update(SimDevice* this, SimData* simdata);
|
||||
int sounddev_free(SimDevice* this);
|
||||
|
||||
SoundDevice* new_sound_device(DeviceSettings* ds);
|
||||
SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms);
|
||||
|
||||
/***** Generic Methods *********/
|
||||
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ int usb_generic_shaker_init(SoundDevice* sounddevice)
|
|||
sounddevice->outputParameters.suggestedLatency = Pa_GetDeviceInfo( sounddevice->outputParameters.device )->defaultLowOutputLatency;
|
||||
sounddevice->outputParameters.hostApiSpecificStreamInfo = NULL;
|
||||
|
||||
if (sounddevice->effecttype == EFFECT_GEARSHIFT)
|
||||
if (sounddevice->m.hapticeffect.effecttype == EFFECT_GEARSHIFT)
|
||||
{
|
||||
err = Pa_OpenStream( &sounddevice->stream,
|
||||
NULL, /* No input. */
|
||||
|
|
|
|||
|
|
@ -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 == EFFECT_GEARSHIFT)
|
||||
if (sounddevice->m.hapticeffect.effecttype == EFFECT_GEARSHIFT)
|
||||
{
|
||||
pa_stream_set_write_callback(stream, gear_sound_stream, &sounddevice->sounddata);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ int sounddev_tyreslip_update(SimDevice* this, SimData* simdata)
|
|||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, sounddevice->slipthreshold, this->useconfig, this->configcheck, this->tyrediameterconfig);
|
||||
int play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
|
||||
if (play > 0)
|
||||
{
|
||||
|
|
@ -60,7 +60,7 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata)
|
|||
{
|
||||
SoundDevice* sounddevice = (void *) this->derived;
|
||||
|
||||
int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, sounddevice->slipthreshold, this->useconfig, this->configcheck, this->tyrediameterconfig);
|
||||
int play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
|
||||
if (play > 0)
|
||||
{
|
||||
|
|
@ -131,7 +131,7 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int
|
|||
|
||||
|
||||
const char* streamname= "Engine";
|
||||
switch (sounddevice->effecttype) {
|
||||
switch (sounddevice->m.hapticeffect.effecttype) {
|
||||
case (EFFECT_GEARSHIFT):
|
||||
|
||||
sounddevice->sounddata.last_gear = 0;
|
||||
|
|
@ -146,13 +146,11 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int
|
|||
case (EFFECT_TYRESLIP):
|
||||
sounddevice->sounddata.duration = duration;
|
||||
sounddevice->sounddata.curr_duration = duration;
|
||||
sounddevice->slipthreshold = threshold;
|
||||
streamname = "TyreSlip";
|
||||
break;
|
||||
case (EFFECT_TYRELOCK):
|
||||
sounddevice->sounddata.duration = duration;
|
||||
sounddevice->sounddata.curr_duration = duration;
|
||||
sounddevice->slipthreshold = threshold;
|
||||
streamname = "TyreLock";
|
||||
break;
|
||||
case (EFFECT_ABSBRAKES):
|
||||
|
|
@ -179,7 +177,7 @@ static const vtable tyreslip_sound_simdevice_vtable = { &sounddev_tyreslip_updat
|
|||
static const vtable tyrelock_sound_simdevice_vtable = { &sounddev_tyrelock_update, &sounddev_free };
|
||||
static const vtable absbrakes_sound_simdevice_vtable = { &sounddev_absbrakes_update, &sounddev_free };
|
||||
|
||||
SoundDevice* new_sound_device(DeviceSettings* ds) {
|
||||
SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||
|
||||
SoundDevice* this = (SoundDevice*) malloc(sizeof(SoundDevice));
|
||||
|
||||
|
|
@ -190,27 +188,30 @@ SoundDevice* new_sound_device(DeviceSettings* ds) {
|
|||
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.hapticeffect.effecttype = EFFECT_ENGINERPM;
|
||||
this->m.vtable = &engine_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for engine vibrations.");
|
||||
break;
|
||||
case (EFFECT_GEARSHIFT):
|
||||
this->effecttype = EFFECT_GEARSHIFT;
|
||||
this->m.hapticeffect.effecttype = EFFECT_GEARSHIFT;
|
||||
this->m.vtable = &gear_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for gear shift vibrations.");
|
||||
break;
|
||||
case (EFFECT_TYRESLIP):
|
||||
this->effecttype = EFFECT_TYRESLIP;
|
||||
this->m.hapticeffect.effecttype = EFFECT_TYRESLIP;
|
||||
this->m.hapticeffect.threshold = ds->threshold;
|
||||
this->m.vtable = &tyreslip_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for tyre slip vibrations.");
|
||||
break;
|
||||
case (EFFECT_TYRELOCK):
|
||||
this->effecttype = EFFECT_TYRELOCK;
|
||||
this->m.hapticeffect.effecttype = EFFECT_TYRELOCK;
|
||||
this->m.hapticeffect.threshold = ds->threshold;
|
||||
this->m.vtable = &tyrelock_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for tyre slip vibrations.");
|
||||
break;
|
||||
case (EFFECT_ABSBRAKES):
|
||||
this->effecttype = EFFECT_ABSBRAKES;
|
||||
this->m.hapticeffect.effecttype = EFFECT_ABSBRAKES;
|
||||
this->m.hapticeffect.threshold = ds->threshold;
|
||||
this->m.vtable = &absbrakes_sound_simdevice_vtable;
|
||||
slogi("Initializing sound device for abs vibrations.");
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ int usbdev_update(SimDevice* this, SimData* simdata)
|
|||
tachdev_update(&usbdevice->u.tachdevice, simdata);
|
||||
break;
|
||||
case USBDEV_GENERICHAPTIC :
|
||||
usbhapticdev_update(&usbdevice->u.hapticdevice, simdata, this->tyre, this->useconfig, this->configcheck, this->tyrediameterconfig);
|
||||
usbhapticdev_update(&usbdevice->u.hapticdevice, simdata, this->hapticeffect.tyre, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ int usbdev_init(USBDevice* usbdevice, DeviceSettings* ds)
|
|||
|
||||
static const vtable usb_simdevice_vtable = { &usbdev_update, &usbdev_free };
|
||||
|
||||
USBDevice* new_usb_device(DeviceSettings* ds) {
|
||||
USBDevice* new_usb_device(DeviceSettings* ds, MonocoqueSettings* ms) {
|
||||
|
||||
USBDevice* this = (USBDevice*) malloc(sizeof(USBDevice));
|
||||
|
||||
|
|
@ -79,9 +79,18 @@ 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->m.hapticeffect.threshold = ds->threshold;
|
||||
this->m.hapticeffect.effecttype = ds->effect_type;
|
||||
this->m.hapticeffect.tyre = ds->tyre;
|
||||
this->m.hapticeffect.useconfig = ms->useconfig;
|
||||
this->m.hapticeffect.configcheck = &ms->configcheck;
|
||||
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
|
||||
this->type = USBDEV_GENERICHAPTIC;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue