Fix issue with new haptic code on usb devices and consolidate some function calls

This commit is contained in:
Paul Dino Jones
2026-06-23 20:07:53 -04:00
parent 8eb433f01e
commit 78cc80064a
8 changed files with 90 additions and 72 deletions
+6 -3
View File
@@ -228,7 +228,7 @@ int initializeHapticEffect(HapticEffect* h, HapticEffectSettings* hs, MonocoqueS
} }
h->tyre = hs->tyre; 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->threshold = hs->threshold;
h->modulationType = hs->modulation; 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 play = 0;
double wheelslip[4]; double wheelslip[4];
wheelslip[0] = 0; wheelslip[0] = 0;
@@ -301,7 +304,7 @@ double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold,
case EFFECT_SUSPENSION: case EFFECT_SUSPENSION:
break; break;
default: default:
slogd("Unknown effect type %i", effecttype); slogw("Unknown effect type %i", effecttype);
} }
if(simdata->Yvelocity <= 0) if(simdata->Yvelocity <= 0)
{ {
+1 -1
View File
@@ -47,7 +47,7 @@ typedef struct
HapticEffect; HapticEffect;
int initializeHapticEffect(HapticEffect* h, HapticEffectSettings* hs, MonocoqueSettings* ms); 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); bool hasTyreDiameter(SimData* simdata);
int loadtyreconfig(SimData* simdata, char* configfile, bool setDiameters); int loadtyreconfig(SimData* simdata, char* configfile, bool setDiameters);
int savetyreconfig(SimData* simdata, char* configfile); int savetyreconfig(SimData* simdata, char* configfile);
+1 -1
View File
@@ -145,7 +145,7 @@ int arduino_simhaptic_update(SimDevice* this, SimData* simdata)
serialdevice->u.simhapticdata.motor3 = 0; serialdevice->u.simhapticdata.motor3 = 0;
serialdevice->u.simhapticdata.motor4 = 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; double rplay = play;
play = play * serialdevice->ampfactor; play = play * serialdevice->ampfactor;
+4 -4
View File
@@ -75,7 +75,7 @@ int sounddev_tyreslip_update(SimDevice* this, SimData* simdata)
{ {
SoundDevice* sounddevice = (void *) this->derived; 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); slogt("Updating sound device frequency from original %i tyre slip effect %f", this->hapticeffect.effecttype, effect);
if (effect > 0) if (effect > 0)
@@ -95,7 +95,7 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata)
{ {
SoundDevice* sounddevice = (void *) this->derived; 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); slogt("Updating sound device frequency from original tyre lock effect %f", play);
if (play > 0) if (play > 0)
@@ -113,7 +113,7 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata)
int sounddev_absbrakes_update(SimDevice* this, SimData* simdata) int sounddev_absbrakes_update(SimDevice* this, SimData* simdata)
{ {
SoundDevice* sounddevice = (void *) this->derived; 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); slogt("Updating sound device frequency from original abs effect %f", play);
if (play > 0) if (play > 0)
@@ -132,7 +132,7 @@ int sounddev_suspension_update(SimDevice* this, SimData* simdata)
{ {
SoundDevice* sounddevice = (void *) this->derived; 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; effect = effect * 10;
slogt("Updating sound device output from original suspension travel effect %f", effect); slogt("Updating sound device output from original suspension travel effect %f", effect);
-1
View File
@@ -33,7 +33,6 @@ int cslelitev3_update(USBDevice* usbdevice, int effecttype, int play)
} }
} }
fprintf(usbdevice->filehandle, "%i\n", value); fprintf(usbdevice->filehandle, "%i\n", value);
fflush(usbdevice->filehandle); fflush(usbdevice->filehandle);
+1
View File
@@ -104,6 +104,7 @@ USBDevice* new_usb_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo* si
else else
{ {
int error = 0; int error = 0;
this->type = USBDEV_WHEEL_OR_PEDALS;
initializeHapticEffect(&this->m.hapticeffect, &ds->hapticsettings, ms); initializeHapticEffect(&this->m.hapticeffect, &ds->hapticsettings, ms);
this->m.vtable = &usb_wheelhaptic_vtable; this->m.vtable = &usb_wheelhaptic_vtable;
} }
+11 -9
View File
@@ -21,8 +21,9 @@
int wheelhapticdev_update(SimDevice* this, SimData* simdata) int wheelhapticdev_update(SimDevice* this, SimData* simdata)
{ {
USBDevice* usbdevice = (void *) this->derived; 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) if (play != usbdevice->hapticstate)
{ {
@@ -30,7 +31,7 @@ int wheelhapticdev_update(SimDevice* this, SimData* simdata)
if(play > 0) if(play > 0)
{ {
rplay = 1; rplay = 1;
switch ( usbdevice->type ) switch ( wheeldevice->type )
{ {
case WHEELDEV_CSLELITEV3PEDALS: case WHEELDEV_CSLELITEV3PEDALS:
cslelitev3_update(usbdevice, this->hapticeffect.effecttype, rplay); cslelitev3_update(usbdevice, this->hapticeffect.effecttype, rplay);
@@ -45,7 +46,7 @@ int wheelhapticdev_update(SimDevice* this, SimData* simdata)
} }
else else
{ {
switch ( usbdevice->type ) switch ( wheeldevice->type )
{ {
case WHEELDEV_CSLELITEV3PEDALS: case WHEELDEV_CSLELITEV3PEDALS:
cslelitev3_update(usbdevice, this->hapticeffect.effecttype, rplay); 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) int wheeldev_update(SimDevice* this, SimData* simdata)
{ {
USBDevice* usbdevice = (void *) this->derived; USBDevice* usbdevice = (void *) this->derived;
WheelDevice* wheeldevice = &usbdevice->u.wheeldevice; WheelDevice* wheeldevice = &usbdevice->u.wheeldevice;
switch ( wheeldevice->type ) switch ( wheeldevice->type )
{ {
case WHEELDEV_UNKNOWN : case WHEELDEV_UNKNOWN :
@@ -142,7 +143,7 @@ int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds)
{ {
slogi("initializing wheel or pedals device..."); slogi("initializing wheel or pedals device...");
int error = 0; int error = 0;
usbdevice->hapticstate = 0;
// detection of wheel model // detection of wheel model
WheelDevice* wheeldevice = &usbdevice->u.wheeldevice; WheelDevice* wheeldevice = &usbdevice->u.wheeldevice;
switch (ds->dev_subsubtype) { switch (ds->dev_subsubtype) {
@@ -201,19 +202,20 @@ int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds)
} }
break; break;
case (SIMDEVSUBTYPE_SIMAGICP1000PEDALS): case (SIMDEVSUBTYPE_SIMAGICP1000PEDALS):
wheeldevice->type = USBHAPTIC_SIMAGICP1000PEDALS; wheeldevice->type = WHEELDEV_SIMAGICP1000PEDALS;
error = simagicp1000_init(usbdevice); error = simagicp1000_init(usbdevice);
break; break;
case (SIMDEVSUBTYPE_CSLELITEV3PEDALS): case (SIMDEVSUBTYPE_CSLELITEV3PEDALS):
wheeldevice->type = USBHAPTIC_CSLELITEV3PEDALS; slogi("Attempting to initialize CSL Elite V3 Pedals");
wheeldevice->type = WHEELDEV_CSLELITEV3PEDALS;
error = cslelitev3_init(usbdevice); error = cslelitev3_init(usbdevice);
break; break;
case (SIMDEVSUBTYPE_SIMNETPEDALS): case (SIMDEVSUBTYPE_SIMNETPEDALS):
wheeldevice->type = USBHAPTIC_SIMNETPEDALS; wheeldevice->type = WHEELDEV_SIMNETPEDALS;
error = simnetpedals_init(usbdevice); error = simnetpedals_init(usbdevice);
break; break;
default: default:
slogw("Possibly unknown device"); slogw("Possibly unknown wheel device");
} }
+66 -53
View File
@@ -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", &ampfactor);
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"); slogt("analysing haptic effect settings");
ds->has_haptic_effects = true; 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", &ampfactor);
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);
}
} }