Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/monocoque/devices/hapticeffect.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,42 @@ double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold,
}
}
break;

case (EFFECT_SUSPENSIONVELOCITY):

if (tyre == FRONTLEFT || tyre == FRONTS || tyre == ALLFOUR)
{
if(simdata->suspvelocity[0] > threshold)
{
play += simdata->suspvelocity[0] - threshold;
slogt("suspension velocity is %f", play);
}
}
if (tyre == FRONTRIGHT || tyre == FRONTS || tyre == ALLFOUR)
{
if(simdata->suspvelocity[1] > threshold)
{
play += simdata->suspvelocity[1] - threshold;
slogt("suspension velocity is %f", play);
}
}
if (tyre == REARLEFT || tyre == REARS || tyre == ALLFOUR)
{
if(simdata->suspvelocity[2] > threshold)
{
play += simdata->suspvelocity[2] - threshold;
slogt("suspension velocity is %f", play);
}
}
if (tyre == REARRIGHT || tyre == REARS || tyre == ALLFOUR)
{
if(simdata->suspvelocity[3] > threshold)
{
play += simdata->suspvelocity[3] - threshold;
slogt("suspension velocity is %f", play);
}
}
break;
}

return play;
Expand Down
34 changes: 34 additions & 0 deletions src/monocoque/devices/sounddevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ int sounddev_suspension_update(SimDevice* this, SimData* simdata)

}

int sounddev_suspensionvelocity_update(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;

double effect = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
slogt("Updating sound device output from suspension velocity effect %f", effect);

if (effect > 0)
{
effect = modulate(sounddevice, effect, sounddevice->modulationType);
}
else
{
sounddevice->sounddata.curr_frequency = 0.0;
sounddevice->sounddata.curr_amplitude = 0;
sounddevice->sounddata.curr_duration = 0;
}
}

int sounddev_gearshift_update(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;
Expand Down Expand Up @@ -213,6 +232,9 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, MonocoqueTyreId
case (EFFECT_SUSPENSION):
streamname = "Suspension";
break;
case (EFFECT_SUSPENSIONVELOCITY):
streamname = "SuspensionVelocity";
break;
case (EFFECT_ENGINERPM):
default:
streamname = "Engine";
Expand All @@ -230,6 +252,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 };
static const vtable suspension_sound_simdevice_vtable = { &sounddev_suspension_update, &sounddev_free };
static const vtable suspensionvelocity_sound_simdevice_vtable = { &sounddev_suspensionvelocity_update, &sounddev_free };

SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo* siminfo) {

Expand All @@ -246,6 +269,7 @@ SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo
case (EFFECT_TYRELOCK):
case (EFFECT_ABSBRAKES):
case (EFFECT_SUSPENSION):
case (EFFECT_SUSPENSIONVELOCITY):
if(siminfo->SimSupportsHapticEffects == false)
{
slogw("Skipping sound effect setup because sim does not support haptic effects");
Expand Down Expand Up @@ -314,6 +338,16 @@ SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo
slogi("Initializing sound device for abs vibrations.");
break;

case (EFFECT_SUSPENSIONVELOCITY):
this->m.hapticeffect.effecttype = EFFECT_SUSPENSIONVELOCITY;
this->m.hapticeffect.threshold = ds->threshold;
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->m.vtable = &suspensionvelocity_sound_simdevice_vtable;
slogi("Initializing sound device for suspension velocity vibrations.");
break;
case (EFFECT_SUSPENSION):
this->m.hapticeffect.effecttype = EFFECT_SUSPENSION;
this->m.hapticeffect.threshold = ds->threshold;
Expand Down
7 changes: 6 additions & 1 deletion src/monocoque/helper/confighelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ int strtoeffecttype(const char* effect, DeviceSettings* ds)
ds->is_valid = true;
ds->effect_type = EFFECT_SUSPENSION;
}
if (strcicmp(effect, "SuspensionVelocity") == 0)
{
ds->is_valid = true;
ds->effect_type = EFFECT_SUSPENSIONVELOCITY;
}
if (strcicmp(effect, "ABS") == 0)
{
ds->is_valid = true;
Expand Down Expand Up @@ -734,7 +739,7 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
const char* effect;
config_setting_lookup_string(device_settings, "effect", &effect);
strtoeffecttype(effect, ds);
if (ds->effect_type == EFFECT_TYRESLIP || ds->effect_type == EFFECT_TYRELOCK || ds->effect_type == EFFECT_ABSBRAKES || ds->effect_type == EFFECT_SUSPENSION )
if (ds->effect_type == EFFECT_TYRESLIP || ds->effect_type == EFFECT_TYRELOCK || ds->effect_type == EFFECT_ABSBRAKES || ds->effect_type == EFFECT_SUSPENSION || ds->effect_type == EFFECT_SUSPENSIONVELOCITY )
{
gettyre(device_settings, ds);
ds->threshold = 0;
Expand Down
13 changes: 7 additions & 6 deletions src/monocoque/helper/confighelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ SimulatorUpdate;

typedef enum
{
EFFECT_ENGINERPM = 0,
EFFECT_GEARSHIFT = 1,
EFFECT_ABSBRAKES = 2,
EFFECT_TYRESLIP = 3,
EFFECT_TYRELOCK = 4,
EFFECT_SUSPENSION = 5
EFFECT_ENGINERPM = 0,
EFFECT_GEARSHIFT = 1,
EFFECT_ABSBRAKES = 2,
EFFECT_TYRESLIP = 3,
EFFECT_TYRELOCK = 4,
EFFECT_SUSPENSION = 5,
EFFECT_SUSPENSIONVELOCITY = 6
}
VibrationEffectType;

Expand Down