diff --git a/src/monocoque/devices/hapticeffect.c b/src/monocoque/devices/hapticeffect.c index 72db458..919e95e 100644 --- a/src/monocoque/devices/hapticeffect.c +++ b/src/monocoque/devices/hapticeffect.c @@ -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; double wheelslip[4]; @@ -60,7 +60,12 @@ int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold) 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); + *configcheck = 1; } if(hasTyreDiameter(simdata)==true) { @@ -152,6 +157,39 @@ int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold) break; 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; } diff --git a/src/monocoque/devices/hapticeffect.h b/src/monocoque/devices/hapticeffect.h index 2f7150e..ea66c38 100644 --- a/src/monocoque/devices/hapticeffect.h +++ b/src/monocoque/devices/hapticeffect.h @@ -3,6 +3,6 @@ #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 diff --git a/src/monocoque/devices/simdevice.c b/src/monocoque/devices/simdevice.c index a4d57e7..cc37dff 100644 --- a/src/monocoque/devices/simdevice.c +++ b/src/monocoque/devices/simdevice.c @@ -41,6 +41,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds) //simdevices[j].initialized = true; simdevices[j].type = SIMDEV_USB; simdevices[j].tyre = ds[j].tyre; + simdevices[j].configcheck = 0; devices++; } else @@ -59,6 +60,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds) simdevices[j].initialized = true; simdevices[j].type = SIMDEV_SOUND; simdevices[j].tyre = ds[j].tyre; + simdevices[j].configcheck = 0; devices++; } else diff --git a/src/monocoque/devices/simdevice.h b/src/monocoque/devices/simdevice.h index 1b1ca63..dacc634 100644 --- a/src/monocoque/devices/simdevice.h +++ b/src/monocoque/devices/simdevice.h @@ -23,7 +23,9 @@ struct SimDevice int id; bool initialized; DeviceType type; + // possibly move these to a haptic effect struct MonocoqueTyreIdentifier tyre; + int configcheck; }; typedef struct { @@ -94,6 +96,7 @@ typedef struct SimDevice m; int id; SoundType type; + int configcheck; VibrationEffectType effecttype; double slipthreshold; SoundData sounddata; diff --git a/src/monocoque/devices/sounddevice.c b/src/monocoque/devices/sounddevice.c index a132c7e..2febd7b 100644 --- a/src/monocoque/devices/sounddevice.c +++ b/src/monocoque/devices/sounddevice.c @@ -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); + int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, sounddevice->slipthreshold, &this->configcheck); 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); + int play = slipeffect(simdata, sounddevice->effecttype, this->tyre, sounddevice->slipthreshold, &this->configcheck); if (play > 0) { diff --git a/src/monocoque/devices/sounddevice.h b/src/monocoque/devices/sounddevice.h index 0f28aff..00eb949 100644 --- a/src/monocoque/devices/sounddevice.h +++ b/src/monocoque/devices/sounddevice.h @@ -20,7 +20,6 @@ typedef struct int last_gear; int volume; int frequency; - double duration; int curr_frequency; double curr_duration; diff --git a/src/monocoque/devices/usbdevice.c b/src/monocoque/devices/usbdevice.c index 5b285f3..14ddcbd 100644 --- a/src/monocoque/devices/usbdevice.c +++ b/src/monocoque/devices/usbdevice.c @@ -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); + usbhapticdev_update(&usbdevice->u.hapticdevice, simdata, this->tyre, &this->configcheck); break; } diff --git a/src/monocoque/devices/usbhapticdevice.c b/src/monocoque/devices/usbhapticdevice.c index d368a48..62640a2 100644 --- a/src/monocoque/devices/usbhapticdevice.c +++ b/src/monocoque/devices/usbhapticdevice.c @@ -11,10 +11,10 @@ #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) { @@ -45,7 +45,6 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d usbhapticdevice->value0 = ds->usbdevsettings.value0; usbhapticdevice->value1 = ds->usbdevsettings.value1; usbhapticdevice->state = usbhapticdevice->value0; - usbhapticdevice->tyre = ds->tyre; usbhapticdevice->effecttype = ds->effect_type; usbhapticdevice->threshold = ds->threshold; @@ -57,6 +56,10 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d { usbhapticdevice->effecttype = EFFECT_TYRELOCK; } + if(ds->effect_type == EFFECT_ABSBRAKES) + { + usbhapticdevice->effecttype = EFFECT_ABSBRAKES; + } slogi("initializing standalone usb haptic device..."); // detection of usb device model @@ -70,14 +73,5 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d return error; } - if(ds->effect_type == EFFECT_TYRESLIP) - { - usbhapticdevice->effecttype = EFFECT_TYRESLIP; - } - if(ds->effect_type == EFFECT_TYRELOCK) - { - usbhapticdevice->effecttype = EFFECT_TYRELOCK; - } - return error; } diff --git a/src/monocoque/devices/usbhapticdevice.h b/src/monocoque/devices/usbhapticdevice.h index eb2cfc8..a11e785 100644 --- a/src/monocoque/devices/usbhapticdevice.h +++ b/src/monocoque/devices/usbhapticdevice.h @@ -22,14 +22,13 @@ typedef struct int value0; int value1; VibrationEffectType effecttype; - MonocoqueTyreIdentifier tyre; FILE* handle; char* dev; } 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_free(USBGenericHapticDevice* hapticdevice);