Add attempt at ABS effect. Small refactorings

This commit is contained in:
Paul Dino Jones 2024-06-07 04:21:08 +00:00
parent 4530627fc2
commit 8cbc21b1a0
9 changed files with 55 additions and 20 deletions

View File

@ -42,7 +42,7 @@ void getTyreDiameter(SimData* simdata)
} }
int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold) int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, int* configcheck)
{ {
int play = 0; int play = 0;
double wheelslip[4]; double wheelslip[4];
@ -60,7 +60,12 @@ int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold)
if(hasTyreDiameter(simdata)==false) if(hasTyreDiameter(simdata)==false)
{ {
// check for saved tyre diameter in config file
// if not saved version exists get tyre diameter and save it
// use config check variable to track if the config check has been performed
// avoid many opens of the same file
getTyreDiameter(simdata); getTyreDiameter(simdata);
*configcheck = 1;
} }
if(hasTyreDiameter(simdata)==true) if(hasTyreDiameter(simdata)==true)
{ {
@ -152,6 +157,39 @@ int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold)
break; break;
case (EFFECT_ABSBRAKES): case (EFFECT_ABSBRAKES):
threshold = simdata->abs + threshold;
if (tyre == FRONTLEFT || tyre == FRONTS || tyre == ALLFOUR)
{
if(wheelslip[0] > threshold)
{
play++;
}
}
if (tyre == FRONTRIGHT || tyre == FRONTS || tyre == ALLFOUR)
{
if(wheelslip[1] > threshold)
{
play++;
}
}
if (tyre == REARLEFT || tyre == REARS || tyre == ALLFOUR)
{
if(wheelslip[2] > threshold)
{
play++;
}
}
if (tyre == REARRIGHT || tyre == REARS || tyre == ALLFOUR)
{
if(wheelslip[3] > threshold)
{
play++;
}
}
if(simdata->abs <= 0)
{
play = 0;
}
break; break;
} }

View File

@ -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 threshold); int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, int* configcheck);
#endif #endif

View File

@ -41,6 +41,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds)
//simdevices[j].initialized = true; //simdevices[j].initialized = true;
simdevices[j].type = SIMDEV_USB; simdevices[j].type = SIMDEV_USB;
simdevices[j].tyre = ds[j].tyre; simdevices[j].tyre = ds[j].tyre;
simdevices[j].configcheck = 0;
devices++; devices++;
} }
else else
@ -59,6 +60,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds)
simdevices[j].initialized = true; simdevices[j].initialized = true;
simdevices[j].type = SIMDEV_SOUND; simdevices[j].type = SIMDEV_SOUND;
simdevices[j].tyre = ds[j].tyre; simdevices[j].tyre = ds[j].tyre;
simdevices[j].configcheck = 0;
devices++; devices++;
} }
else else

View File

@ -23,7 +23,9 @@ struct SimDevice
int id; int id;
bool initialized; bool initialized;
DeviceType type; DeviceType type;
// possibly move these to a haptic effect struct
MonocoqueTyreIdentifier tyre; MonocoqueTyreIdentifier tyre;
int configcheck;
}; };
typedef struct { typedef struct {
@ -94,6 +96,7 @@ typedef struct
SimDevice m; SimDevice m;
int id; int id;
SoundType type; SoundType type;
int configcheck;
VibrationEffectType effecttype; VibrationEffectType effecttype;
double slipthreshold; double slipthreshold;
SoundData sounddata; SoundData sounddata;

View File

@ -42,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, sounddevice->slipthreshold); int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, sounddevice->slipthreshold, &this->configcheck);
if (play > 0) if (play > 0)
{ {
@ -60,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, sounddevice->slipthreshold); int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, sounddevice->slipthreshold, &this->configcheck);
if (play > 0) if (play > 0)
{ {

View File

@ -20,7 +20,6 @@ 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;

View File

@ -20,7 +20,7 @@ int usbdev_update(SimDevice* this, SimData* simdata)
tachdev_update(&usbdevice->u.tachdevice, simdata); tachdev_update(&usbdevice->u.tachdevice, simdata);
break; break;
case USBDEV_GENERICHAPTIC : case USBDEV_GENERICHAPTIC :
usbhapticdev_update(&usbdevice->u.hapticdevice, simdata); usbhapticdev_update(&usbdevice->u.hapticdevice, simdata, this->tyre, &this->configcheck);
break; break;
} }

View File

@ -11,10 +11,10 @@
#include "../../slog/slog.h" #include "../../slog/slog.h"
int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdata) int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdata, int tyre, int* configcheck)
{ {
int play = slipeffect(simdata, usbhapticdevice->effecttype, usbhapticdevice->tyre, usbhapticdevice->threshold); int play = slipeffect(simdata, usbhapticdevice->effecttype, tyre, usbhapticdevice->threshold, configcheck);
if (play != usbhapticdevice->state) if (play != usbhapticdevice->state)
{ {
@ -45,7 +45,6 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
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;
usbhapticdevice->tyre = ds->tyre;
usbhapticdevice->effecttype = ds->effect_type; usbhapticdevice->effecttype = ds->effect_type;
usbhapticdevice->threshold = ds->threshold; usbhapticdevice->threshold = ds->threshold;
@ -57,6 +56,10 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
{ {
usbhapticdevice->effecttype = EFFECT_TYRELOCK; usbhapticdevice->effecttype = EFFECT_TYRELOCK;
} }
if(ds->effect_type == EFFECT_ABSBRAKES)
{
usbhapticdevice->effecttype = EFFECT_ABSBRAKES;
}
slogi("initializing standalone usb haptic device..."); slogi("initializing standalone usb haptic device...");
// detection of usb device model // detection of usb device model
@ -70,14 +73,5 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
return error; return error;
} }
if(ds->effect_type == EFFECT_TYRESLIP)
{
usbhapticdevice->effecttype = EFFECT_TYRESLIP;
}
if(ds->effect_type == EFFECT_TYRELOCK)
{
usbhapticdevice->effecttype = EFFECT_TYRELOCK;
}
return error; return error;
} }

View File

@ -22,14 +22,13 @@ typedef struct
int value0; int value0;
int value1; int value1;
VibrationEffectType effecttype; VibrationEffectType effecttype;
MonocoqueTyreIdentifier tyre;
FILE* handle; FILE* handle;
char* dev; char* dev;
} }
USBGenericHapticDevice; USBGenericHapticDevice;
int usbhapticdev_update(USBGenericHapticDevice* hapticdevice, SimData* simdata); int usbhapticdev_update(USBGenericHapticDevice* hapticdevice, SimData* simdata, int tyre, int* configcheck);
int usbhapticdev_init(USBGenericHapticDevice* hapticdevice, DeviceSettings* ds); int usbhapticdev_init(USBGenericHapticDevice* hapticdevice, DeviceSettings* ds);
int usbhapticdev_free(USBGenericHapticDevice* hapticdevice); int usbhapticdev_free(USBGenericHapticDevice* hapticdevice);