diff --git a/src/monocoque/devices/hapticeffect.c b/src/monocoque/devices/hapticeffect.c index 3aae500..6f32c7a 100644 --- a/src/monocoque/devices/hapticeffect.c +++ b/src/monocoque/devices/hapticeffect.c @@ -228,7 +228,7 @@ int initializeHapticEffect(HapticEffect* h, HapticEffectSettings* hs, MonocoqueS } h->tyre = hs->tyre; - slogt("Haptic effect: %i %i, tyre %i %i", h->effecttype, hs->effect_type, h->tyre, hs->tyre); + slogi("Haptic effect: %i %i, tyre %i %i", h->effecttype, hs->effect_type, h->tyre, hs->tyre); h->threshold = hs->threshold; h->modulationType = hs->modulation; @@ -250,8 +250,11 @@ int initializeHapticEffect(HapticEffect* h, HapticEffectSettings* hs, MonocoqueS } -double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, int useconfig, int* configcheck, char* configfile) +double slipeffect(SimData* simdata, HapticEffect* h, int useconfig, int* configcheck, char* configfile) { + int effecttype = h->effecttype; + int tyre = h->tyre; + double threshold = h->threshold; double play = 0; double wheelslip[4]; wheelslip[0] = 0; @@ -301,7 +304,7 @@ double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, case EFFECT_SUSPENSION: break; default: - slogd("Unknown effect type %i", effecttype); + slogw("Unknown effect type %i", effecttype); } if(simdata->Yvelocity <= 0) { diff --git a/src/monocoque/devices/hapticeffect.h b/src/monocoque/devices/hapticeffect.h index 570c7c3..c5bbfaa 100644 --- a/src/monocoque/devices/hapticeffect.h +++ b/src/monocoque/devices/hapticeffect.h @@ -47,7 +47,7 @@ typedef struct HapticEffect; int initializeHapticEffect(HapticEffect* h, HapticEffectSettings* hs, MonocoqueSettings* ms); -double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, int useconfig, int* configcheck, char* configfile); +double slipeffect(SimData* simdata, HapticEffect* h, int useconfig, int* configcheck, char* configfile); bool hasTyreDiameter(SimData* simdata); int loadtyreconfig(SimData* simdata, char* configfile, bool setDiameters); int savetyreconfig(SimData* simdata, char* configfile); diff --git a/src/monocoque/devices/serialdevice.c b/src/monocoque/devices/serialdevice.c index deadc87..4731ecb 100644 --- a/src/monocoque/devices/serialdevice.c +++ b/src/monocoque/devices/serialdevice.c @@ -145,7 +145,7 @@ int arduino_simhaptic_update(SimDevice* this, SimData* simdata) serialdevice->u.simhapticdata.motor3 = 0; serialdevice->u.simhapticdata.motor4 = 0; - double play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig); + double play = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig); double rplay = play; play = play * serialdevice->ampfactor; diff --git a/src/monocoque/devices/sounddevice.c b/src/monocoque/devices/sounddevice.c index c5d4883..06872da 100644 --- a/src/monocoque/devices/sounddevice.c +++ b/src/monocoque/devices/sounddevice.c @@ -75,7 +75,7 @@ int sounddev_tyreslip_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); + double effect = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig); slogt("Updating sound device frequency from original %i tyre slip effect %f", this->hapticeffect.effecttype, effect); if (effect > 0) @@ -95,7 +95,7 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata) { SoundDevice* sounddevice = (void *) this->derived; - double play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig); + double play = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig); slogt("Updating sound device frequency from original tyre lock effect %f", play); if (play > 0) @@ -113,7 +113,7 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata) int sounddev_absbrakes_update(SimDevice* this, SimData* simdata) { SoundDevice* sounddevice = (void *) this->derived; - double play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig); + double play = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig); slogt("Updating sound device frequency from original abs effect %f", play); if (play > 0) @@ -132,7 +132,7 @@ int sounddev_suspension_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); + double effect = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig); effect = effect * 10; slogt("Updating sound device output from original suspension travel effect %f", effect); diff --git a/src/monocoque/devices/usb/cslelitev3.c b/src/monocoque/devices/usb/cslelitev3.c index 14ea3b8..872477f 100644 --- a/src/monocoque/devices/usb/cslelitev3.c +++ b/src/monocoque/devices/usb/cslelitev3.c @@ -33,7 +33,6 @@ int cslelitev3_update(USBDevice* usbdevice, int effecttype, int play) } } - fprintf(usbdevice->filehandle, "%i\n", value); fflush(usbdevice->filehandle); diff --git a/src/monocoque/devices/usbdevice.c b/src/monocoque/devices/usbdevice.c index cc773ae..bd77869 100644 --- a/src/monocoque/devices/usbdevice.c +++ b/src/monocoque/devices/usbdevice.c @@ -104,6 +104,7 @@ USBDevice* new_usb_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo* si else { int error = 0; + this->type = USBDEV_WHEEL_OR_PEDALS; initializeHapticEffect(&this->m.hapticeffect, &ds->hapticsettings, ms); this->m.vtable = &usb_wheelhaptic_vtable; } diff --git a/src/monocoque/devices/wheeldevice.c b/src/monocoque/devices/wheeldevice.c index 7d4b0e4..3973bfa 100644 --- a/src/monocoque/devices/wheeldevice.c +++ b/src/monocoque/devices/wheeldevice.c @@ -21,8 +21,9 @@ int wheelhapticdev_update(SimDevice* this, SimData* simdata) { USBDevice* usbdevice = (void *) this->derived; + WheelDevice* wheeldevice = &usbdevice->u.wheeldevice; - double play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig); + double play = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig); if (play != usbdevice->hapticstate) { @@ -30,7 +31,7 @@ int wheelhapticdev_update(SimDevice* this, SimData* simdata) if(play > 0) { rplay = 1; - switch ( usbdevice->type ) + switch ( wheeldevice->type ) { case WHEELDEV_CSLELITEV3PEDALS: cslelitev3_update(usbdevice, this->hapticeffect.effecttype, rplay); @@ -45,7 +46,7 @@ int wheelhapticdev_update(SimDevice* this, SimData* simdata) } else { - switch ( usbdevice->type ) + switch ( wheeldevice->type ) { case WHEELDEV_CSLELITEV3PEDALS: cslelitev3_update(usbdevice, this->hapticeffect.effecttype, rplay); @@ -66,8 +67,8 @@ int wheelhapticdev_update(SimDevice* this, SimData* simdata) int wheeldev_update(SimDevice* this, SimData* simdata) { USBDevice* usbdevice = (void *) this->derived; - WheelDevice* wheeldevice = &usbdevice->u.wheeldevice; + switch ( wheeldevice->type ) { case WHEELDEV_UNKNOWN : @@ -142,7 +143,7 @@ int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds) { slogi("initializing wheel or pedals device..."); int error = 0; - + usbdevice->hapticstate = 0; // detection of wheel model WheelDevice* wheeldevice = &usbdevice->u.wheeldevice; switch (ds->dev_subsubtype) { @@ -201,19 +202,20 @@ int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds) } break; case (SIMDEVSUBTYPE_SIMAGICP1000PEDALS): - wheeldevice->type = USBHAPTIC_SIMAGICP1000PEDALS; + wheeldevice->type = WHEELDEV_SIMAGICP1000PEDALS; error = simagicp1000_init(usbdevice); break; case (SIMDEVSUBTYPE_CSLELITEV3PEDALS): - wheeldevice->type = USBHAPTIC_CSLELITEV3PEDALS; + slogi("Attempting to initialize CSL Elite V3 Pedals"); + wheeldevice->type = WHEELDEV_CSLELITEV3PEDALS; error = cslelitev3_init(usbdevice); break; case (SIMDEVSUBTYPE_SIMNETPEDALS): - wheeldevice->type = USBHAPTIC_SIMNETPEDALS; + wheeldevice->type = WHEELDEV_SIMNETPEDALS; error = simnetpedals_init(usbdevice); break; default: - slogw("Possibly unknown device"); + slogw("Possibly unknown wheel device"); } diff --git a/src/monocoque/helper/confighelper.c b/src/monocoque/helper/confighelper.c index 2a815d4..f54eab1 100644 --- a/src/monocoque/helper/confighelper.c +++ b/src/monocoque/helper/confighelper.c @@ -725,8 +725,73 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co } } + if (ds->dev_type == SIMDEV_USB) + { + if (device_settings != NULL) + { + const char* temp; + int found = config_setting_lookup_string(device_settings, "subtype", &temp); + if(temp != NULL && found > 0) + { + strtodevsubsubtype(temp, ds); + } + } + } - if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_type == SIMDEV_SOUND || ds->dev_subtype == SIMDEVTYPE_SERIALHAPTIC) + if (ds->dev_type == SIMDEV_SERIAL) + { + if (device_settings != NULL) + { + const char* temp; + int found = config_setting_lookup_string(device_settings, "subtype", &temp); + if(temp != NULL && found > 0) + { + strtodevsubsubtype(temp, ds); + } + + config_setting_lookup_string(device_settings, "devpath", &temp); + ds->serialdevsettings.portdev = strdup(temp); + + int motorposition = 8; + config_setting_lookup_int(device_settings, "motors", &motorposition); + ds->serialdevsettings.motorsposition = motorposition; + + int numlights = 6; + config_setting_lookup_int(device_settings, "numlights", &numlights); + ds->serialdevsettings.numlights = numlights; + + int numleds = 6; + config_setting_lookup_int(device_settings, "numleds", &numleds); + ds->serialdevsettings.numleds = numleds; + + int startled = 1; + config_setting_lookup_int(device_settings, "startled", &startled); + ds->serialdevsettings.startled = startled; + + int endled = 1; + config_setting_lookup_int(device_settings, "endled", &endled); + ds->serialdevsettings.endled = endled; + + int baud = 9600; + config_setting_lookup_int(device_settings, "baud", &baud); + ds->serialdevsettings.baud = baud; + + double ampfactor = 1.0; + ds->serialdevsettings.ampfactor = 1.0; + found = config_setting_lookup_float(device_settings, "ampfactor", &factor); + ds->serialdevsettings.ampfactor = ampfactor; + + double fanpower = 0.6; + config_setting_lookup_float(device_settings, "fanpower", &fanpower); + ds->serialdevsettings.fanpower = fanpower; + + slogt("set port baud rate to %i, ampfactor %f, fanpower %f", baud, ampfactor, fanpower); + + } + + } + + if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_subtype == SIMDEVTYPE_USBWHEEL || ds->dev_type == SIMDEV_SOUND || ds->dev_subtype == SIMDEVTYPE_SERIALHAPTIC) { slogt("analysing haptic effect settings"); ds->has_haptic_effects = true; @@ -840,58 +905,6 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co } } - } - - if (ds->dev_type == SIMDEV_SERIAL) - { - if (device_settings != NULL) - { - const char* temp; - int found = config_setting_lookup_string(device_settings, "subtype", &temp); - if(temp != NULL && found > 0) - { - strtodevsubsubtype(temp, ds); - } - - config_setting_lookup_string(device_settings, "devpath", &temp); - ds->serialdevsettings.portdev = strdup(temp); - - int motorposition = 8; - config_setting_lookup_int(device_settings, "motors", &motorposition); - ds->serialdevsettings.motorsposition = motorposition; - - int numlights = 6; - config_setting_lookup_int(device_settings, "numlights", &numlights); - ds->serialdevsettings.numlights = numlights; - - int numleds = 6; - config_setting_lookup_int(device_settings, "numleds", &numleds); - ds->serialdevsettings.numleds = numleds; - - int startled = 1; - config_setting_lookup_int(device_settings, "startled", &startled); - ds->serialdevsettings.startled = startled; - - int endled = 1; - config_setting_lookup_int(device_settings, "endled", &endled); - ds->serialdevsettings.endled = endled; - - int baud = 9600; - config_setting_lookup_int(device_settings, "baud", &baud); - ds->serialdevsettings.baud = baud; - - double ampfactor = 1.0; - ds->serialdevsettings.ampfactor = 1.0; - found = config_setting_lookup_float(device_settings, "ampfactor", &factor); - ds->serialdevsettings.ampfactor = ampfactor; - - double fanpower = 0.6; - config_setting_lookup_float(device_settings, "fanpower", &fanpower); - ds->serialdevsettings.fanpower = fanpower; - - slogt("set port baud rate to %i, ampfactor %f, fanpower %f", baud, ampfactor, fanpower); - - } }