Refactor tyre effects to take threshold input from config file. Spell threshold correctly.
This commit is contained in:
parent
6c17c56813
commit
b99773a7ee
|
|
@ -42,7 +42,7 @@ void getTyreDiameter(SimData* simdata)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int slipeffect(SimData* simdata, int effecttype, int tyre, double threshhold)
|
int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold)
|
||||||
{
|
{
|
||||||
int play = 0;
|
int play = 0;
|
||||||
double wheelslip[4];
|
double wheelslip[4];
|
||||||
|
|
@ -91,28 +91,28 @@ int slipeffect(SimData* simdata, int effecttype, int tyre, double threshhold)
|
||||||
|
|
||||||
if (tyre == FRONTLEFT || tyre == FRONTS || tyre == ALLFOUR)
|
if (tyre == FRONTLEFT || tyre == FRONTS || tyre == ALLFOUR)
|
||||||
{
|
{
|
||||||
if(wheelslip[0] < -.5)
|
if(wheelslip[0] < -threshold)
|
||||||
{
|
{
|
||||||
play++;
|
play++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tyre == FRONTRIGHT || tyre == FRONTS || tyre == ALLFOUR)
|
if (tyre == FRONTRIGHT || tyre == FRONTS || tyre == ALLFOUR)
|
||||||
{
|
{
|
||||||
if(wheelslip[1] < -.5)
|
if(wheelslip[1] < -threshold)
|
||||||
{
|
{
|
||||||
play++;
|
play++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tyre == REARLEFT || tyre == REARS || tyre == ALLFOUR)
|
if (tyre == REARLEFT || tyre == REARS || tyre == ALLFOUR)
|
||||||
{
|
{
|
||||||
if(wheelslip[2] < -.5)
|
if(wheelslip[2] < -threshold)
|
||||||
{
|
{
|
||||||
play++;
|
play++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tyre == REARRIGHT || tyre == REARS || tyre == ALLFOUR)
|
if (tyre == REARRIGHT || tyre == REARS || tyre == ALLFOUR)
|
||||||
{
|
{
|
||||||
if(wheelslip[3] < -.5)
|
if(wheelslip[3] < -threshold)
|
||||||
{
|
{
|
||||||
play++;
|
play++;
|
||||||
}
|
}
|
||||||
|
|
@ -123,28 +123,28 @@ int slipeffect(SimData* simdata, int effecttype, int tyre, double threshhold)
|
||||||
case (EFFECT_TYRELOCK):
|
case (EFFECT_TYRELOCK):
|
||||||
if (tyre == FRONTLEFT || tyre == FRONTS || tyre == ALLFOUR)
|
if (tyre == FRONTLEFT || tyre == FRONTS || tyre == ALLFOUR)
|
||||||
{
|
{
|
||||||
if(wheelslip[0] > .75)
|
if(wheelslip[0] > threshold)
|
||||||
{
|
{
|
||||||
play++;
|
play++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tyre == FRONTRIGHT || tyre == FRONTS || tyre == ALLFOUR)
|
if (tyre == FRONTRIGHT || tyre == FRONTS || tyre == ALLFOUR)
|
||||||
{
|
{
|
||||||
if(wheelslip[1] > .75)
|
if(wheelslip[1] > threshold)
|
||||||
{
|
{
|
||||||
play++;
|
play++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tyre == REARLEFT || tyre == REARS || tyre == ALLFOUR)
|
if (tyre == REARLEFT || tyre == REARS || tyre == ALLFOUR)
|
||||||
{
|
{
|
||||||
if(wheelslip[2] > .75)
|
if(wheelslip[2] > threshold)
|
||||||
{
|
{
|
||||||
play++;
|
play++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tyre == REARRIGHT || tyre == REARS || tyre == ALLFOUR)
|
if (tyre == REARRIGHT || tyre == REARS || tyre == ALLFOUR)
|
||||||
{
|
{
|
||||||
if(wheelslip[3] > .75)
|
if(wheelslip[3] > threshold)
|
||||||
{
|
{
|
||||||
play++;
|
play++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,6 @@
|
||||||
|
|
||||||
#include "../simulatorapi/simapi/simapi/simdata.h"
|
#include "../simulatorapi/simapi/simapi/simdata.h"
|
||||||
|
|
||||||
int slipeffect(SimData* simdata, int effecttype, int tyre, double threshhold);
|
int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,7 @@ typedef struct
|
||||||
int id;
|
int id;
|
||||||
SoundType type;
|
SoundType type;
|
||||||
VibrationEffectType effecttype;
|
VibrationEffectType effecttype;
|
||||||
|
double slipthreshold;
|
||||||
SoundData sounddata;
|
SoundData sounddata;
|
||||||
#ifdef USE_PULSEAUDIO
|
#ifdef USE_PULSEAUDIO
|
||||||
pa_stream *stream;
|
pa_stream *stream;
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,6 @@
|
||||||
#include "../helper/parameters.h"
|
#include "../helper/parameters.h"
|
||||||
#include "../slog/slog.h"
|
#include "../slog/slog.h"
|
||||||
|
|
||||||
#define slipthreshold 0.75
|
|
||||||
|
|
||||||
int gear_sound_set(SoundDevice* sounddevice, SimData* simdata)
|
int gear_sound_set(SoundDevice* sounddevice, SimData* simdata)
|
||||||
{
|
{
|
||||||
if (sounddevice->sounddata.last_gear != simdata->gear && simdata->gear > 1)
|
if (sounddevice->sounddata.last_gear != simdata->gear && simdata->gear > 1)
|
||||||
|
|
@ -44,7 +42,7 @@ int sounddev_tyreslip_update(SimDevice* this, SimData* simdata)
|
||||||
{
|
{
|
||||||
SoundDevice* sounddevice = (void *) this->derived;
|
SoundDevice* sounddevice = (void *) this->derived;
|
||||||
|
|
||||||
int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, slipthreshold);
|
int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, sounddevice->slipthreshold);
|
||||||
|
|
||||||
if (play > 0)
|
if (play > 0)
|
||||||
{
|
{
|
||||||
|
|
@ -62,7 +60,7 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata)
|
||||||
{
|
{
|
||||||
SoundDevice* sounddevice = (void *) this->derived;
|
SoundDevice* sounddevice = (void *) this->derived;
|
||||||
|
|
||||||
int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, slipthreshold);
|
int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, sounddevice->slipthreshold);
|
||||||
|
|
||||||
if (play > 0)
|
if (play > 0)
|
||||||
{
|
{
|
||||||
|
|
@ -110,7 +108,7 @@ int sounddev_free(SimDevice* this)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int frequency, int pan, double duration)
|
int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int frequency, int pan, double duration, double threshold)
|
||||||
{
|
{
|
||||||
slogi("initializing standalone sound device...");
|
slogi("initializing standalone sound device...");
|
||||||
|
|
||||||
|
|
@ -147,8 +145,15 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int
|
||||||
case (EFFECT_TYRESLIP):
|
case (EFFECT_TYRESLIP):
|
||||||
sounddevice->sounddata.duration = duration;
|
sounddevice->sounddata.duration = duration;
|
||||||
sounddevice->sounddata.curr_duration = duration;
|
sounddevice->sounddata.curr_duration = duration;
|
||||||
|
sounddevice->slipthreshold = threshold;
|
||||||
streamname = "TyreSlip";
|
streamname = "TyreSlip";
|
||||||
break;
|
break;
|
||||||
|
case (EFFECT_TYRELOCK):
|
||||||
|
sounddevice->sounddata.duration = duration;
|
||||||
|
sounddevice->sounddata.curr_duration = duration;
|
||||||
|
sounddevice->slipthreshold = threshold;
|
||||||
|
streamname = "TyreLock";
|
||||||
|
break;
|
||||||
case (EFFECT_ABSBRAKES):
|
case (EFFECT_ABSBRAKES):
|
||||||
sounddevice->sounddata.duration = duration;
|
sounddevice->sounddata.duration = duration;
|
||||||
sounddevice->sounddata.curr_duration = duration;
|
sounddevice->sounddata.curr_duration = duration;
|
||||||
|
|
@ -212,7 +217,7 @@ SoundDevice* new_sound_device(DeviceSettings* ds) {
|
||||||
|
|
||||||
slogt("Attempting to use device %s", ds->sounddevsettings.dev);
|
slogt("Attempting to use device %s", ds->sounddevsettings.dev);
|
||||||
|
|
||||||
int error = sounddev_init(this, ds->sounddevsettings.dev, ds->sounddevsettings.volume, ds->sounddevsettings.frequency, ds->sounddevsettings.pan, ds->sounddevsettings.duration);
|
int error = sounddev_init(this, ds->sounddevsettings.dev, ds->sounddevsettings.volume, ds->sounddevsettings.frequency, ds->sounddevsettings.pan, ds->sounddevsettings.duration, ds->threshold);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
{
|
{
|
||||||
free(this);
|
free(this);
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ typedef struct
|
||||||
int last_gear;
|
int last_gear;
|
||||||
int volume;
|
int volume;
|
||||||
int frequency;
|
int frequency;
|
||||||
|
|
||||||
double duration;
|
double duration;
|
||||||
int curr_frequency;
|
int curr_frequency;
|
||||||
double curr_duration;
|
double curr_duration;
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,11 @@
|
||||||
#include "../../simulatorapi/simapi/simapi/simdata.h"
|
#include "../../simulatorapi/simapi/simapi/simdata.h"
|
||||||
#include "../../slog/slog.h"
|
#include "../../slog/slog.h"
|
||||||
|
|
||||||
#define slipthreshold 0.75
|
|
||||||
|
|
||||||
int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdata)
|
int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdata)
|
||||||
{
|
{
|
||||||
|
|
||||||
int play = slipeffect(simdata, usbhapticdevice->effecttype, usbhapticdevice->tyre, slipthreshold);
|
int play = slipeffect(simdata, usbhapticdevice->effecttype, usbhapticdevice->tyre, usbhapticdevice->threshold);
|
||||||
|
|
||||||
|
|
||||||
if (play != usbhapticdevice->state)
|
if (play != usbhapticdevice->state)
|
||||||
|
|
@ -54,6 +53,7 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
|
||||||
usbhapticdevice->state = usbhapticdevice->value0;
|
usbhapticdevice->state = usbhapticdevice->value0;
|
||||||
usbhapticdevice->tyre = ds->tyre;
|
usbhapticdevice->tyre = ds->tyre;
|
||||||
usbhapticdevice->effecttype = ds->effect_type;
|
usbhapticdevice->effecttype = ds->effect_type;
|
||||||
|
usbhapticdevice->threshold = ds->threshold;
|
||||||
|
|
||||||
usbhapticdevice->handle = fopen(usbhapticdevice->dev, "w");
|
usbhapticdevice->handle = fopen(usbhapticdevice->dev, "w");
|
||||||
if(usbhapticdevice->handle == 0)
|
if(usbhapticdevice->handle == 0)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ typedef struct
|
||||||
int id;
|
int id;
|
||||||
HapticType type;
|
HapticType type;
|
||||||
double state;
|
double state;
|
||||||
|
double threshold;
|
||||||
int value0;
|
int value0;
|
||||||
int value1;
|
int value1;
|
||||||
VibrationEffectType effecttype;
|
VibrationEffectType effecttype;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <dirent.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
@ -357,9 +358,11 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
|
||||||
const char* effect;
|
const char* effect;
|
||||||
config_setting_lookup_string(device_settings, "effect", &effect);
|
config_setting_lookup_string(device_settings, "effect", &effect);
|
||||||
strtoeffecttype(effect, ds);
|
strtoeffecttype(effect, ds);
|
||||||
if (ds->effect_type == EFFECT_TYRESLIP || ds->effect_type == EFFECT_TYRELOCK)
|
if (ds->effect_type == EFFECT_TYRESLIP || ds->effect_type == EFFECT_TYRELOCK || ds->effect_type == EFFECT_ABSBRAKES)
|
||||||
{
|
{
|
||||||
gettyre(device_settings, ds);
|
gettyre(device_settings, ds);
|
||||||
|
ds->threshold = .75;
|
||||||
|
int found = config_setting_lookup_float(device_settings, "threshold", &ds->threshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ds->dev_type == SIMDEV_SOUND)
|
if (ds->dev_type == SIMDEV_SOUND)
|
||||||
|
|
|
||||||
|
|
@ -121,13 +121,17 @@ typedef struct
|
||||||
bool is_valid;
|
bool is_valid;
|
||||||
DeviceType dev_type;
|
DeviceType dev_type;
|
||||||
DeviceSubType dev_subtype;
|
DeviceSubType dev_subtype;
|
||||||
|
// 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;
|
VibrationEffectType effect_type;
|
||||||
|
MonocoqueTyreIdentifier tyre;
|
||||||
|
double threshold;
|
||||||
// union?
|
// union?
|
||||||
TachometerSettings tachsettings;
|
TachometerSettings tachsettings;
|
||||||
SerialDeviceSettings serialdevsettings;
|
SerialDeviceSettings serialdevsettings;
|
||||||
SoundDeviceSettings sounddevsettings;
|
SoundDeviceSettings sounddevsettings;
|
||||||
USBDeviceSettings usbdevsettings;
|
USBDeviceSettings usbdevsettings;
|
||||||
MonocoqueTyreIdentifier tyre;
|
|
||||||
}
|
}
|
||||||
DeviceSettings;
|
DeviceSettings;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue