Refactor haptic code and devices that rely on it, to more easily allow devices to use the haptic attributes

This commit is contained in:
Paul Dino Jones
2026-06-23 13:29:49 -04:00
parent c4fa9e4138
commit 8eb433f01e
21 changed files with 431 additions and 343 deletions
-2
View File
@@ -13,8 +13,6 @@ set(devices_source_files
tachdevice.c tachdevice.c
wheeldevice.h wheeldevice.h
wheeldevice.c wheeldevice.c
usbhapticdevice.h
usbhapticdevice.c
hapticeffect.h hapticeffect.h
hapticeffect.c hapticeffect.c
sound.h sound.h
+57 -2
View File
@@ -6,6 +6,7 @@
#include <math.h> #include <math.h>
#include "usbhapticdevice.h" #include "usbhapticdevice.h"
#include "simdevice.h"
#include "../../helper/confighelper.h" #include "../../helper/confighelper.h"
#include "../../simulatorapi/simapi/simapi/simdata.h" #include "../../simulatorapi/simapi/simapi/simdata.h"
#include "../../simulatorapi/simapi/simapi/simmapper.h" #include "../../simulatorapi/simapi/simapi/simmapper.h"
@@ -194,6 +195,60 @@ void getTyreDiameter(SimData* simdata)
} }
} }
int initializeHapticEffect(HapticEffect* h, HapticEffectSettings* hs, MonocoqueSettings* ms)
{
switch (hs->effect_type)
{
case (EFFECT_ENGINERPM):
h->effecttype = EFFECT_ENGINERPM;
slogi("Initializing haptic effect for engine vibrations.");
break;
case (EFFECT_GEARSHIFT):
h->effecttype = EFFECT_GEARSHIFT;
slogi("Initializing haptic effect for gear shift vibrations.");
break;
case (EFFECT_TYRESLIP):
h->effecttype = EFFECT_TYRESLIP;
slogi("Initializing haptic effect for tyre slip vibrations.");
break;
case (EFFECT_TYRELOCK):
h->effecttype = EFFECT_TYRELOCK;
slogi("Initializing haptic effect for tyre lock vibrations.");
break;
case (EFFECT_ABSBRAKES):
h->effecttype = EFFECT_ABSBRAKES;
slogi("Initializing haptic effect for abs vibrations.");
break;
case (EFFECT_SUSPENSION):
h->effecttype = EFFECT_SUSPENSION;
slogi("Initializing haptic effect for suspension vibrations.");
break;
}
h->tyre = hs->tyre;
slogt("Haptic effect: %i %i, tyre %i %i", h->effecttype, hs->effect_type, h->tyre, hs->tyre);
h->threshold = hs->threshold;
h->modulationType = hs->modulation;
h->basefrequency = hs->frequency;
h->frequencyMax = hs->frequencyMax;
h->baseamplitude = hs->amplitude;
h->amplitudeMax = hs->amplitudeMax;
h->motorposition = hs->motorposition;
h->duration = hs->duration;
slogt("haptic duration: %f", h->duration);
slogt("haptic base frequency: %i", h->basefrequency);
slogt("haptic base amplitude: %i", h->baseamplitude);
slogt("haptic motorposition: %i", h->motorposition);
h->useconfig = ms->useconfig;
h->configcheck = &ms->configcheck;
h->tyrediameterconfig = ms->tyre_diameter_config;
}
double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, int useconfig, int* configcheck, char* configfile) double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, int useconfig, int* configcheck, char* configfile)
{ {
@@ -212,7 +267,7 @@ double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold,
if(sim_slip_ratio == 0) if(sim_slip_ratio == 0)
{ {
slogt("wheel vibration calculation with wheel config set to %i configchecked %i configfile %s car %s sim %i", useconfig, *configcheck, configfile, simdata->car, simdata->simexe); //slogt("wheel vibration calculation with wheel config set to %i configchecked %i configfile %s car %s sim %i", useconfig, *configcheck, configfile, simdata->car, simdata->simexe);
switch (effecttype) switch (effecttype)
{ {
@@ -246,7 +301,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"); slogd("Unknown effect type %i", effecttype);
} }
if(simdata->Yvelocity <= 0) if(simdata->Yvelocity <= 0)
{ {
+33 -2
View File
@@ -2,20 +2,51 @@
#define _HAPTICEFFECT_H #define _HAPTICEFFECT_H
#include <stdio.h> #include <stdio.h>
#include "../helper/confighelper.h"
#include "../simulatorapi/simapi/simapi/simdata.h" #include "../simulatorapi/simapi/simapi/simdata.h"
typedef enum
{
HAPTIC_EFFECT_MODULATION_NONE = 0,
HAPTIC_EFFECT_MODULATION_FREQUENCY = 1,
HAPTIC_EFFECT_MODULATION_AMPLIFY = 2,
}
HapticEffectModulationType;
typedef struct
{
uint32_t curr_frequency;
uint32_t curr_amplitude;
double curr_duration;
uint32_t last_gear;
}
CurrentEffectData;
typedef struct typedef struct
{ {
double threshold;
VibrationEffectType effecttype; VibrationEffectType effecttype;
MonocoqueTyreIdentifier tyre; MonocoqueTyreIdentifier tyre;
HapticEffectModulationType modulationType;
uint32_t volume;
double duration;
double threshold;
uint32_t motorposition;
uint32_t basefrequency;
uint32_t frequencyMax;
uint32_t baseamplitude;
uint32_t amplitudeMax;
CurrentEffectData live_effect;
int useconfig; int useconfig;
int* configcheck; int* configcheck;
char* tyrediameterconfig; char* tyrediameterconfig;
} }
HapticEffect; 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, int effecttype, int tyre, double threshold, 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);
+9 -9
View File
@@ -155,9 +155,9 @@ int arduino_simhaptic_update(SimDevice* this, SimData* simdata)
} }
uint8_t effectspeed = ceil(255 * play); uint8_t effectspeed = ceil(255 * play);
uint8_t motor = serialdevice->motorsposition; uint8_t motor = this->hapticeffect.motorposition;
if (play != serialdevice->state) if (play != serialdevice->hapticstate)
{ {
// motor 1 // motor 1
if (motor == 0 || motor == 4 || motor == 7 || motor == 8 || motor == 10 || motor == 11 || motor == 13 || motor == 14) if (motor == 0 || motor == 4 || motor == 7 || motor == 8 || motor == 10 || motor == 11 || motor == 13 || motor == 14)
@@ -173,7 +173,7 @@ int arduino_simhaptic_update(SimDevice* this, SimData* simdata)
serialdevice->u.simhapticdata.motor3 = 1; serialdevice->u.simhapticdata.motor3 = 1;
slogt("Updating arduino haptic device with effect type %i speed motor speed %i on motor %i from original effect %f with ampfactor %f", this->hapticeffect.effecttype, serialdevice->u.simhapticdata.effect3, 3, rplay, serialdevice->ampfactor); slogt("Updating arduino haptic device with effect type %i speed motor speed %i on motor %i from original effect %f with ampfactor %f", this->hapticeffect.effecttype, serialdevice->u.simhapticdata.effect3, 3, rplay, serialdevice->ampfactor);
} }
serialdevice->state = play; serialdevice->hapticstate = play;
} }
size_t size = sizeof(SimHapticData); size_t size = sizeof(SimHapticData);
@@ -197,7 +197,7 @@ int serialdev_free(SimDevice* this)
serialdevice->u.simhapticdata.motor3 = 1; serialdevice->u.simhapticdata.motor3 = 1;
serialdevice->u.simhapticdata.effect4 = 0; serialdevice->u.simhapticdata.effect4 = 0;
serialdevice->u.simhapticdata.motor4 = 1; serialdevice->u.simhapticdata.motor4 = 1;
serialdevice->state = 0; serialdevice->hapticstate = 0;
size_t size = sizeof(SimHapticData); size_t size = sizeof(SimHapticData);
monocoque_serial_write_block(serialdevice->id, &serialdevice->u.simhapticdata, size, 9000); monocoque_serial_write_block(serialdevice->id, &serialdevice->u.simhapticdata, size, 9000);
@@ -356,7 +356,7 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms, SimIn
this->u.simhapticdata.effect2 = 0; this->u.simhapticdata.effect2 = 0;
this->u.simhapticdata.effect3 = 0; this->u.simhapticdata.effect3 = 0;
this->u.simhapticdata.effect4 = 0; this->u.simhapticdata.effect4 = 0;
this->state = 0; this->hapticstate = 0;
this->ampfactor = ds->serialdevsettings.ampfactor; this->ampfactor = ds->serialdevsettings.ampfactor;
this->fanpower = ds->serialdevsettings.fanpower; this->fanpower = ds->serialdevsettings.fanpower;
slogi("Initializing arduino device for haptic effects."); slogi("Initializing arduino device for haptic effects.");
@@ -388,10 +388,10 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms, SimIn
if(this->devicetype == ARDUINODEV__HAPTIC && error == 0) if(this->devicetype == ARDUINODEV__HAPTIC && error == 0)
{ {
this->m.hapticeffect.threshold = ds->threshold; this->m.hapticeffect.threshold = ds->hapticsettings.threshold;
this->m.hapticeffect.effecttype = ds->effect_type; this->m.hapticeffect.effecttype = ds->hapticsettings.effect_type;
slogt("Haptic effect: %i %i", this->m.hapticeffect.effecttype, ds->effect_type); slogt("Haptic effect: %i %i", this->m.hapticeffect.effecttype, ds->hapticsettings.effect_type);
this->m.hapticeffect.tyre = ds->tyre; this->m.hapticeffect.tyre = ds->hapticsettings.tyre;
this->m.hapticeffect.useconfig = ms->useconfig; this->m.hapticeffect.useconfig = ms->useconfig;
this->m.hapticeffect.configcheck = &ms->configcheck; this->m.hapticeffect.configcheck = &ms->configcheck;
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config; this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
+10 -8
View File
@@ -67,7 +67,7 @@ typedef struct
int baudrate; int baudrate;
double ampfactor; double ampfactor;
double fanpower; double fanpower;
double state; double hapticstate;
union union
{ {
SimWindData simwinddata; SimWindData simwinddata;
@@ -88,10 +88,10 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms, SimIn
/********* USB HID Devices *****/ /********* USB HID Devices *****/
typedef enum typedef enum
{ {
USBDEV_UNKNOWN = 0, USBDEV_UNKNOWN = 0,
USBDEV_TACHOMETER = 1, USBDEV_TACHOMETER = 1,
USBDEV_GENERICHAPTIC = 2, USBDEV_GENERICHAPTIC = 2,
USBDEV_WHEEL = 3 USBDEV_WHEEL_OR_PEDALS = 3
} }
USBType; USBType;
@@ -100,12 +100,14 @@ typedef struct
SimDevice m; SimDevice m;
int id; int id;
hid_device* handle; hid_device* handle;
FILE* filehandle;
char* dev;
double hapticstate;
USBType type; USBType type;
union union
{ {
TachDevice tachdevice; TachDevice tachdevice;
WheelDevice wheeldevice; WheelDevice wheeldevice;
USBGenericHapticDevice hapticdevice;
} u; } u;
} }
USBDevice; USBDevice;
@@ -122,7 +124,6 @@ typedef struct
SimDevice m; SimDevice m;
int id; int id;
int configcheck; int configcheck;
SoundEffectModulationType modulationType;
SoundData sounddata; SoundData sounddata;
//#ifdef USE_PULSEAUDIO //#ifdef USE_PULSEAUDIO
pa_stream *stream; pa_stream *stream;
@@ -154,7 +155,8 @@ int simdevfree(SimDevice* this);
/****** USB SubTypes ****************/ /****** USB SubTypes ****************/
int wheeldev_update(USBDevice* usbdevice, SimData* simdata); int wheelhapticdev_update(SimDevice* this, SimData* simdata);
int wheeldev_update(SimDevice* this, SimData* simdata);
int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds); int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds);
int wheeldev_free(USBDevice* usbdevice); int wheeldev_free(USBDevice* usbdevice);
+33 -83
View File
@@ -15,13 +15,15 @@
#include "../helper/parameters.h" #include "../helper/parameters.h"
#include "../slog/slog.h" #include "../slog/slog.h"
int gear_sound_set(SoundDevice* sounddevice, SimData* simdata) int gear_sound_set(SimDevice* this, SimData* simdata)
{ {
SoundDevice* sounddevice = (void *) this->derived;
if (sounddevice->sounddata.last_gear != simdata->gear && simdata->gear > 1) if (sounddevice->sounddata.last_gear != simdata->gear && simdata->gear > 1)
{ {
//sounddevice->sounddata.gear_sound_data = 3.14; //sounddevice->sounddata.gear_sound_data = 3.14;
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency; sounddevice->sounddata.curr_frequency = this->hapticeffect.basefrequency;
sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude; sounddevice->sounddata.curr_amplitude = this->hapticeffect.baseamplitude;
sounddevice->sounddata.curr_duration = 0; sounddevice->sounddata.curr_duration = 0;
} }
sounddevice->sounddata.last_gear = simdata->gear; sounddevice->sounddata.last_gear = simdata->gear;
@@ -30,27 +32,29 @@ int gear_sound_set(SoundDevice* sounddevice, SimData* simdata)
} }
double modulate(SoundDevice* sounddevice, double raw_effect, SoundEffectModulationType modulation) double modulate(SimDevice* this, double raw_effect, HapticEffectModulationType modulation)
{ {
SoundDevice* sounddevice = (void *) this->derived;
double modulated_effect = raw_effect; double modulated_effect = raw_effect;
switch (modulation) switch (modulation)
{ {
case SOUND_EFFECT_MODULATION_FREQUENCY: case HAPTIC_EFFECT_MODULATION_FREQUENCY:
modulated_effect = ((sounddevice->sounddata.frequencyMax - sounddevice->sounddata.frequency) * raw_effect) + sounddevice->sounddata.frequency; modulated_effect = ((this->hapticeffect.frequencyMax - this->hapticeffect.basefrequency) * raw_effect) + this->hapticeffect.basefrequency;
sounddevice->sounddata.curr_frequency = modulated_effect; sounddevice->sounddata.curr_frequency = modulated_effect;
sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude; sounddevice->sounddata.curr_amplitude = this->hapticeffect.baseamplitude;
slogt("set curr frequency to %f from raw effect %f and base frequency %i", sounddevice->sounddata.curr_frequency, raw_effect, sounddevice->sounddata.frequency); slogt("set curr frequency to %f from raw effect %f and base frequency %i", sounddevice->sounddata.curr_frequency, raw_effect, this->hapticeffect.basefrequency);
break; break;
case SOUND_EFFECT_MODULATION_AMPLIFY: case HAPTIC_EFFECT_MODULATION_AMPLIFY:
modulated_effect = ((sounddevice->sounddata.amplitudeMax - sounddevice->sounddata.amplitude) * raw_effect) + sounddevice->sounddata.amplitude; modulated_effect = ((this->hapticeffect.amplitudeMax - this->hapticeffect.baseamplitude) * raw_effect) + this->hapticeffect.baseamplitude;
sounddevice->sounddata.curr_amplitude = modulated_effect; sounddevice->sounddata.curr_amplitude = modulated_effect;
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency; sounddevice->sounddata.curr_frequency = this->hapticeffect.basefrequency;
slogt("set curr amplitude to %i from raw effect %f and base amplitude %i", sounddevice->sounddata.curr_amplitude, raw_effect, sounddevice->sounddata.amplitude); slogt("set curr amplitude to %i from raw effect %f and base amplitude %i", sounddevice->sounddata.curr_amplitude, raw_effect, this->hapticeffect.baseamplitude);
break; break;
case SOUND_EFFECT_MODULATION_NONE: case HAPTIC_EFFECT_MODULATION_NONE:
default: default:
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency; sounddevice->sounddata.curr_frequency = this->hapticeffect.basefrequency;
sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude; sounddevice->sounddata.curr_amplitude = this->hapticeffect.baseamplitude;
break; break;
} }
@@ -64,7 +68,7 @@ int sounddev_engine_update(SimDevice* this, SimData* simdata)
double effect = ((double)simdata->rpms/60)/((double)simdata->maxrpm/60); double effect = ((double)simdata->rpms/60)/((double)simdata->maxrpm/60);
slogt("Set base effect of %f from rpms of %i", effect, simdata->rpms); slogt("Set base effect of %f from rpms of %i", effect, simdata->rpms);
modulate(sounddevice, effect, sounddevice->modulationType); modulate(this, effect, this->hapticeffect.modulationType);
} }
int sounddev_tyreslip_update(SimDevice* this, SimData* simdata) int sounddev_tyreslip_update(SimDevice* this, SimData* simdata)
@@ -72,11 +76,11 @@ 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.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
slogt("Updating sound device frequency from original tyre slip effect %f", effect); slogt("Updating sound device frequency from original %i tyre slip effect %f", this->hapticeffect.effecttype, effect);
if (effect > 0) if (effect > 0)
{ {
modulate(sounddevice, effect, sounddevice->modulationType); modulate(this, effect, this->hapticeffect.modulationType);
} }
else else
{ {
@@ -96,7 +100,7 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata)
if (play > 0) if (play > 0)
{ {
modulate(sounddevice, play, sounddevice->modulationType); modulate(this, play, this->hapticeffect.modulationType);
} }
else else
{ {
@@ -114,7 +118,7 @@ int sounddev_absbrakes_update(SimDevice* this, SimData* simdata)
if (play > 0) if (play > 0)
{ {
modulate(sounddevice, play, sounddevice->modulationType); modulate(this, play, this->hapticeffect.modulationType);
} }
else else
{ {
@@ -134,7 +138,7 @@ int sounddev_suspension_update(SimDevice* this, SimData* simdata)
if (effect > 0) if (effect > 0)
{ {
effect = modulate(sounddevice, effect, sounddevice->modulationType); effect = modulate(this, effect, this->hapticeffect.modulationType);
} }
else else
{ {
@@ -147,9 +151,7 @@ int sounddev_suspension_update(SimDevice* this, SimData* simdata)
int sounddev_gearshift_update(SimDevice* this, SimData* simdata) int sounddev_gearshift_update(SimDevice* this, SimData* simdata)
{ {
SoundDevice* sounddevice = (void *) this->derived; gear_sound_set(this, simdata);
gear_sound_set(sounddevice, simdata);
} }
@@ -163,28 +165,17 @@ int sounddev_free(SimDevice* this)
return 0; return 0;
} }
int sounddev_init(SoundDevice* sounddevice, const char* devname, MonocoqueTyreIdentifier tyre, SoundDeviceSettings sds) int sounddev_init(SoundDevice* sounddevice, const char* devname, SoundDeviceSettings sds)
{ {
slogi("initializing standalone sound device..."); slogi("initializing standalone sound device...");
slogi("volume is: %i", sds.volume); slogi("volume is: %i", sds.volume);
slogi("Modulation type: %i", sds.modulation);
slogi("frequency is: %i", sds.frequency);
slogi("frequency Max is: %i", sds.frequencyMax);
slogi("amplitude is: %i", sds.amplitude);
slogi("amplitude Max is: %i", sds.amplitudeMax);
slogi("pan is: %i", sds.pan); slogi("pan is: %i", sds.pan);
slogi("channels is: %i", sds.channels); slogi("channels is: %i", sds.channels);
slogi("duration is: %f", sds.duration);
slogi("noise is: %i", sds.noise); slogi("noise is: %i", sds.noise);
sounddevice->modulationType = sds.modulation;
sounddevice->sounddata.frequency = sds.frequency;
sounddevice->sounddata.frequencyMax = sds.frequencyMax;
sounddevice->sounddata.amplitude = sds.amplitude;
sounddevice->sounddata.amplitudeMax = sds.amplitudeMax;
sounddevice->sounddata.noise = (double)sds.noise; sounddevice->sounddata.noise = (double)sds.noise;
sounddevice->sounddata.curr_duration = 0; sounddevice->sounddata.curr_duration = 0;
@@ -240,7 +231,7 @@ SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo
this->m.derived = this; this->m.derived = this;
int error = 0; int error = 0;
switch (ds->effect_type) switch (ds->hapticsettings.effect_type)
{ {
case (EFFECT_TYRESLIP): case (EFFECT_TYRESLIP):
case (EFFECT_TYRELOCK): case (EFFECT_TYRELOCK):
@@ -258,73 +249,32 @@ SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo
if(error == 0) if(error == 0)
{ {
slogt("Attempting to configure sound device with subtype: %i", ds->effect_type); initializeHapticEffect(&this->m.hapticeffect, &ds->hapticsettings, ms);
switch (ds->effect_type) slogt("Attempting to configure sound device with subtype: %i", ds->hapticsettings.effect_type);
switch (ds->hapticsettings.effect_type)
{ {
case (EFFECT_ENGINERPM): case (EFFECT_ENGINERPM):
this->m.hapticeffect.effecttype = EFFECT_ENGINERPM;
this->m.vtable = &engine_sound_simdevice_vtable; this->m.vtable = &engine_sound_simdevice_vtable;
slogi("Initializing sound device for engine vibrations."); slogi("Initializing sound device for engine vibrations.");
break; break;
case (EFFECT_GEARSHIFT): case (EFFECT_GEARSHIFT):
this->m.hapticeffect.effecttype = EFFECT_GEARSHIFT;
this->m.vtable = &gear_sound_simdevice_vtable; this->m.vtable = &gear_sound_simdevice_vtable;
slogi("Initializing sound device for gear shift vibrations."); slogi("Initializing sound device for gear shift vibrations.");
break; break;
case (EFFECT_TYRESLIP): case (EFFECT_TYRESLIP):
this->m.hapticeffect.effecttype = EFFECT_TYRESLIP;
this->m.hapticeffect.threshold = ds->threshold;
this->m.hapticeffect.threshold = ds->threshold;
slogt("Haptic effect: %i %i", this->m.hapticeffect.effecttype, ds->effect_type);
this->m.hapticeffect.tyre = ds->tyre;
this->m.hapticeffect.useconfig = ms->useconfig;
this->m.hapticeffect.configcheck = &ms->configcheck;
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
this->m.vtable = &tyreslip_sound_simdevice_vtable; this->m.vtable = &tyreslip_sound_simdevice_vtable;
slogi("Initializing sound device for tyre slip vibrations."); slogi("Initializing sound device for tyre slip vibrations.");
break; break;
case (EFFECT_TYRELOCK): case (EFFECT_TYRELOCK):
this->m.hapticeffect.effecttype = EFFECT_TYRELOCK;
this->m.hapticeffect.threshold = ds->threshold;
this->m.hapticeffect.threshold = ds->threshold;
slogt("Haptic effect: %i %i", this->m.hapticeffect.effecttype, ds->effect_type);
this->m.hapticeffect.tyre = ds->tyre;
this->m.hapticeffect.useconfig = ms->useconfig;
this->m.hapticeffect.configcheck = &ms->configcheck;
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
this->m.vtable = &tyrelock_sound_simdevice_vtable; this->m.vtable = &tyrelock_sound_simdevice_vtable;
slogi("Initializing sound device for tyre slip vibrations."); slogi("Initializing sound device for tyre lock vibrations.");
break; break;
case (EFFECT_ABSBRAKES): case (EFFECT_ABSBRAKES):
this->m.hapticeffect.effecttype = EFFECT_ABSBRAKES;
this->m.hapticeffect.threshold = ds->threshold;
this->m.hapticeffect.threshold = ds->threshold;
slogt("Haptic effect: %i %i", this->m.hapticeffect.effecttype, ds->effect_type);
this->m.hapticeffect.tyre = ds->tyre;
this->m.hapticeffect.useconfig = ms->useconfig;
this->m.hapticeffect.configcheck = &ms->configcheck;
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
this->m.vtable = &absbrakes_sound_simdevice_vtable; this->m.vtable = &absbrakes_sound_simdevice_vtable;
slogi("Initializing sound device for abs vibrations."); slogi("Initializing sound device for abs vibrations.");
break; break;
case (EFFECT_SUSPENSION): case (EFFECT_SUSPENSION):
this->m.hapticeffect.effecttype = EFFECT_SUSPENSION;
this->m.hapticeffect.threshold = ds->threshold;
this->m.hapticeffect.threshold = ds->threshold;
slogt("Haptic effect: %i %i on tyre %i", this->m.hapticeffect.effecttype, ds->effect_type, ds->tyre);
this->m.hapticeffect.tyre = ds->tyre;
this->m.hapticeffect.useconfig = ms->useconfig;
this->m.hapticeffect.configcheck = &ms->configcheck;
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
this->m.vtable = &suspension_sound_simdevice_vtable; this->m.vtable = &suspension_sound_simdevice_vtable;
slogi("Initializing sound device for suspension vibrations."); slogi("Initializing sound device for suspension vibrations.");
break; break;
@@ -334,7 +284,7 @@ SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo
if(error == 0) if(error == 0)
{ {
slogt("Attempting to use sound device %s", ds->sounddevsettings.dev); slogt("Attempting to use sound device %s", ds->sounddevsettings.dev);
error = sounddev_init(this, ds->sounddevsettings.dev, ds->tyre, ds->sounddevsettings); error = sounddev_init(this, ds->sounddevsettings.dev, ds->sounddevsettings);
} }
if (error != 0) if (error != 0)
-12
View File
@@ -8,23 +8,11 @@
//#endif //#endif
typedef enum
{
SOUND_EFFECT_MODULATION_NONE = 0,
SOUND_EFFECT_MODULATION_FREQUENCY = 1,
SOUND_EFFECT_MODULATION_AMPLIFY = 2,
}
SoundEffectModulationType;
#define MAX_TABLE_SIZE (6000) #define MAX_TABLE_SIZE (6000)
typedef struct typedef struct
{ {
uint8_t last_gear; uint8_t last_gear;
int volume; int volume;
uint32_t frequency;
uint32_t frequencyMax;
uint32_t amplitude;
uint32_t amplitudeMax;
double duration; double duration;
double curr_frequency; double curr_frequency;
uint32_t curr_amplitude; uint32_t curr_amplitude;
+12 -12
View File
@@ -3,7 +3,7 @@
#include <string.h> #include <string.h>
#include <glob.h> #include <glob.h>
#include "usbhapticdevice.h" #include "cslelitev3.h"
#include "../../helper/confighelper.h" #include "../../helper/confighelper.h"
#include "../slog/slog.h" #include "../slog/slog.h"
@@ -11,7 +11,7 @@
const char* SYSFSRUMBLEPATH = "/sys/module/hid_fanatec/drivers/hid:f*/0003:0EB7:183B.*/rumble"; const char* SYSFSRUMBLEPATH = "/sys/module/hid_fanatec/drivers/hid:f*/0003:0EB7:183B.*/rumble";
int cslelitev3_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play) int cslelitev3_update(USBDevice* usbdevice, int effecttype, int play)
{ {
int res = 0; int res = 0;
@@ -34,25 +34,25 @@ int cslelitev3_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, i
} }
fprintf(usbhapticdevice->filehandle, "%i\n", value); fprintf(usbdevice->filehandle, "%i\n", value);
fflush(usbhapticdevice->filehandle); fflush(usbdevice->filehandle);
return res; return res;
} }
int cslelitev3_free(USBGenericHapticDevice* usbhapticdevice) int cslelitev3_free(USBDevice* usbdevice)
{ {
int res = 0; int res = 0;
free(usbhapticdevice->dev); free(usbdevice->dev);
fflush(usbhapticdevice->filehandle); fflush(usbdevice->filehandle);
fclose(usbhapticdevice->filehandle); fclose(usbdevice->filehandle);
return res; return res;
} }
int cslelitev3_init(USBGenericHapticDevice* usbhapticdevice) int cslelitev3_init(USBDevice* usbdevice)
{ {
slogi("initializing CSL Elite V3 Pedals..."); slogi("initializing CSL Elite V3 Pedals...");
@@ -75,7 +75,7 @@ int cslelitev3_init(USBGenericHapticDevice* usbhapticdevice)
{ {
if (i == 0) if (i == 0)
{ {
usbhapticdevice->dev = strdup(globlist.gl_pathv[i]); usbdevice->dev = strdup(globlist.gl_pathv[i]);
} }
i++; i++;
} }
@@ -91,9 +91,9 @@ int cslelitev3_init(USBGenericHapticDevice* usbhapticdevice)
return res; return res;
} }
usbhapticdevice->filehandle = fopen(usbhapticdevice->dev, "w"); usbdevice->filehandle = fopen(usbdevice->dev, "w");
if (!usbhapticdevice->filehandle) if (!usbdevice->filehandle)
{ {
sloge("Could not open pedal device..."); sloge("Could not open pedal device...");
return res; return res;
+6 -3
View File
@@ -1,8 +1,11 @@
#ifndef _CSLELITEV3_H #ifndef _CSLELITEV3_H
#define _CSLELITEV3_H #define _CSLELITEV3_H
int cslelitev3_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play); #include "../wheeldevice.h"
int cslelitev3_init(USBGenericHapticDevice* usbhapticdevice); #include "../simdevice.h"
int cslelitev3_free(USBGenericHapticDevice* usbhapticdevice);
int cslelitev3_update(USBDevice* usbdevice, int effecttype, int play);
int cslelitev3_init(USBDevice* usbdevice);
int cslelitev3_free(USBDevice* usbdevice);
#endif #endif
+17 -17
View File
@@ -3,7 +3,7 @@
#include <string.h> #include <string.h>
#include <hidapi/hidapi.h> #include <hidapi/hidapi.h>
#include "usbhapticdevice.h" #include "simagicp1000.h"
#include "../../helper/confighelper.h" #include "../../helper/confighelper.h"
#include "../slog/slog.h" #include "../slog/slog.h"
@@ -14,12 +14,12 @@
const size_t SIMAGIC_P1000_BUFSIZE = 49; const size_t SIMAGIC_P1000_BUFSIZE = 49;
const char* SIMAGICP1000DEVSTRING = "SIMAGIC P1000 Pedals"; const char* SIMAGICP1000DEVSTRING = "SIMAGIC P1000 Pedals";
int senddevreport(USBGenericHapticDevice* usbhapticdevice, unsigned char* buf, size_t bufsize) int senddevreport(USBDevice* usbdevice, unsigned char* buf, size_t bufsize)
{ {
int res = 0; int res = 0;
if (usbhapticdevice->handle) if (usbdevice->handle)
{ {
res = hid_send_feature_report(usbhapticdevice->handle, buf, SIMAGIC_P1000_BUFSIZE); res = hid_send_feature_report(usbdevice->handle, buf, SIMAGIC_P1000_BUFSIZE);
slogd("sent %i bytes to %s", bufsize, SIMAGICP1000DEVSTRING); slogd("sent %i bytes to %s", bufsize, SIMAGICP1000DEVSTRING);
slogt("sent bytes %02x %02x %02x %02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]); slogt("sent bytes %02x %02x %02x %02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
} }
@@ -30,7 +30,7 @@ int senddevreport(USBGenericHapticDevice* usbhapticdevice, unsigned char* buf, s
return res != bufsize; return res != bufsize;
} }
int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play) int simagicp1000_update(USBDevice* usbdevice, int effecttype, int play)
{ {
int res = 0; int res = 0;
@@ -54,17 +54,17 @@ int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype,
{ {
case (EFFECT_TYRESLIP): case (EFFECT_TYRESLIP):
bytes[2] = 0x02; bytes[2] = 0x02;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE); senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
break; break;
case (EFFECT_TYRELOCK): case (EFFECT_TYRELOCK):
bytes[2] = 0x01; bytes[2] = 0x01;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE); senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
break; break;
case (EFFECT_ABSBRAKES): case (EFFECT_ABSBRAKES):
bytes[2] = 0x02; bytes[2] = 0x02;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE); senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
bytes[2] = 0x01; bytes[2] = 0x01;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE); senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
break; break;
} }
} }
@@ -72,19 +72,19 @@ int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype,
{ {
bytes[0] = 241; bytes[0] = 241;
bytes[2] = 0x01; bytes[2] = 0x01;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE); senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
bytes[2] = 0x02; bytes[2] = 0x02;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE); senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
} }
return res; return res;
} }
int simagicp1000_free(USBGenericHapticDevice* usbhapticdevice) int simagicp1000_free(USBDevice* usbdevice)
{ {
int res = 0; int res = 0;
hid_close(usbhapticdevice->handle); hid_close(usbdevice->handle);
res = hid_exit(); res = hid_exit();
return res; return res;
@@ -92,7 +92,7 @@ int simagicp1000_free(USBGenericHapticDevice* usbhapticdevice)
return res; return res;
} }
int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice) int simagicp1000_init(USBDevice* usbdevice)
{ {
slogi("initializing %s...", SIMAGICP1000DEVSTRING); slogi("initializing %s...", SIMAGICP1000DEVSTRING);
@@ -100,9 +100,9 @@ int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice)
res = hid_init(); res = hid_init();
usbhapticdevice->handle = hid_open(SIMAGIC_VENDOR_ID, SIMAGIC_PRODUCT_ID_P1000, NULL); usbdevice->handle = hid_open(SIMAGIC_VENDOR_ID, SIMAGIC_PRODUCT_ID_P1000, NULL);
if (!usbhapticdevice->handle) if (!usbdevice->handle)
{ {
sloge("Could not find attached %s", SIMAGICP1000DEVSTRING); sloge("Could not find attached %s", SIMAGICP1000DEVSTRING);
res = hid_exit(); res = hid_exit();
@@ -123,7 +123,7 @@ int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice)
bytes[5] = 0x00; bytes[5] = 0x00;
bytes[6] = 0x01; bytes[6] = 0x01;
bytes[7] = 0x02; bytes[7] = 0x02;
res = senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE); res = senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
slogd("Initialization returned %i", res); slogd("Initialization returned %i", res);
if(res != 0) if(res != 0)
{ {
+6 -3
View File
@@ -1,8 +1,11 @@
#ifndef _SIMAGICP1000_H #ifndef _SIMAGICP1000_H
#define _SIMAGICP1000_H #define _SIMAGICP1000_H
int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play); #include "../wheeldevice.h"
int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice); #include "../simdevice.h"
int simagicp1000_free(USBGenericHapticDevice* usbhapticdevice);
int simagicp1000_update(USBDevice* usbdevice, int effecttype, int play);
int simagicp1000_init(USBDevice* usbdevice);
int simagicp1000_free(USBDevice* usbdevice);
#endif #endif
+15 -15
View File
@@ -3,7 +3,7 @@
#include <string.h> #include <string.h>
#include <glob.h> #include <glob.h>
#include "usbhapticdevice.h" #include "simnetpedals.h"
#include "../../helper/confighelper.h" #include "../../helper/confighelper.h"
#include "../slog/slog.h" #include "../slog/slog.h"
@@ -21,7 +21,7 @@
//Byte[8]: motor 3 amplitude (0 to 100%) //Byte[8]: motor 3 amplitude (0 to 100%)
int simnetpedals_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play) int simnetpedals_update(USBDevice* usbdevice, int effecttype, int play, int motorposition, int frequency, int amplitude)
{ {
int res = 0; int res = 0;
@@ -33,23 +33,23 @@ int simnetpedals_update(USBGenericHapticDevice* usbhapticdevice, int effecttype,
} }
bytes[0] = 0x01; bytes[0] = 0x01;
bytes[1] = 0x00; bytes[1] = 0x00;
bytes[2] = usbhapticdevice->motorposition; bytes[2] = motorposition;
uint8_t motormultiple = usbhapticdevice->motorposition - 1; uint8_t motormultiple = motorposition - 1;
if(usbhapticdevice->motorposition == 0x04) if(motorposition == 0x04)
{ {
motormultiple = 2; motormultiple = 2;
} }
if(play > 0) if(play > 0)
{ {
bytes[3 + (motormultiple * 2)] = usbhapticdevice->frequency; bytes[3 + (motormultiple * 2)] = frequency;
bytes[4 + (motormultiple * 2)] = usbhapticdevice->amplitude; bytes[4 + (motormultiple * 2)] = amplitude;
} }
if (usbhapticdevice->handle) if (usbdevice->handle)
{ {
slogt("writing bytes x%02xx%02xx%02xx%02xx%02xx%02xx%02xx%02xx%02x", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], bytes[8]); slogt("writing bytes x%02xx%02xx%02xx%02xx%02xx%02xx%02xx%02xx%02x", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], bytes[8]);
res = hid_write(usbhapticdevice->handle, bytes, SIMNETPEDALS_BUFSIZE); res = hid_write(usbdevice->handle, bytes, SIMNETPEDALS_BUFSIZE);
} }
else else
{ {
@@ -59,17 +59,17 @@ int simnetpedals_update(USBGenericHapticDevice* usbhapticdevice, int effecttype,
return res; return res;
} }
int simnetpedals_free(USBGenericHapticDevice* usbhapticdevice) int simnetpedals_free(USBDevice* usbdevice)
{ {
int res = 0; int res = 0;
hid_close(usbhapticdevice->handle); hid_close(usbdevice->handle);
res = hid_exit(); res = hid_exit();
return res; return res;
} }
int simnetpedals_init(USBGenericHapticDevice* usbhapticdevice) int simnetpedals_init(USBDevice* usbdevice)
{ {
slogi("initializing simnet pedals..."); slogi("initializing simnet pedals...");
@@ -77,14 +77,14 @@ int simnetpedals_init(USBGenericHapticDevice* usbhapticdevice)
res = hid_init(); res = hid_init();
usbhapticdevice->handle = hid_open(0xcafe, 0xa301, NULL); usbdevice->handle = hid_open(0xcafe, 0xa301, NULL);
if (!usbhapticdevice->handle) if (!usbdevice->handle)
{ {
sloge("Could not find attached Simnet Pedals"); sloge("Could not find attached Simnet Pedals");
res = hid_exit(); res = hid_exit();
return 1; return 1;
} }
slogd("Found Simnet Pedals handle %i...", usbhapticdevice->handle); slogd("Found Simnet Pedals handle %i...", usbdevice->handle);
return res; return res;
} }
+6 -3
View File
@@ -1,8 +1,11 @@
#ifndef _SIMNETPEDALS_H #ifndef _SIMNETPEDALS_H
#define _SIMNETPEDALS_H #define _SIMNETPEDALS_H
int simnetpedals_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play); #include "../wheeldevice.h"
int simnetpedals_init(USBGenericHapticDevice* usbhapticdevice); #include "../simdevice.h"
int simnetpedals_free(USBGenericHapticDevice* usbhapticdevice);
int simnetpedals_update(USBDevice* usbdevice, int effecttype, int play, int motorposition, int frequency, int amplitude);
int simnetpedals_init(USBDevice* usbdevice);
int simnetpedals_free(USBDevice* usbdevice);
#endif #endif
@@ -2,7 +2,6 @@
#define _CAMMUSC12_H #define _CAMMUSC12_H
#include "../../wheeldevice.h" #include "../../wheeldevice.h"
#include "../../simdevice.h" #include "../../simdevice.h"
int cammusc12_update(USBDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity); int cammusc12_update(USBDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity);
+26 -29
View File
@@ -19,11 +19,9 @@ int usbdev_update(SimDevice* this, SimData* simdata)
case USBDEV_TACHOMETER : case USBDEV_TACHOMETER :
tachdev_update(usbdevice, simdata); tachdev_update(usbdevice, simdata);
break; break;
case USBDEV_WHEEL : case USBDEV_WHEEL_OR_PEDALS :
wheeldev_update(usbdevice, simdata); // this should be directed via vtable to wheeldevice.c
break; //wheeldev_update(usbdevice, simdata);
case USBDEV_GENERICHAPTIC :
usbhapticdev_update(&usbdevice->u.hapticdevice, simdata, this->hapticeffect.tyre, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
break; break;
} }
@@ -41,12 +39,9 @@ int usbdev_free(SimDevice* this)
case USBDEV_TACHOMETER : case USBDEV_TACHOMETER :
tachdev_free(usbdevice); tachdev_free(usbdevice);
break; break;
case USBDEV_WHEEL : case USBDEV_WHEEL_OR_PEDALS :
wheeldev_free(usbdevice); wheeldev_free(usbdevice);
break; break;
case USBDEV_GENERICHAPTIC :
usbhapticdev_free(&usbdevice->u.hapticdevice);
break;
} }
free(usbdevice); free(usbdevice);
@@ -66,53 +61,55 @@ int usbdev_init(USBDevice* usbdevice, DeviceSettings* ds, SimInfo* siminfo)
case USBDEV_TACHOMETER : case USBDEV_TACHOMETER :
error = tachdev_init(usbdevice, ds); error = tachdev_init(usbdevice, ds);
break; break;
case USBDEV_WHEEL : case USBDEV_WHEEL_OR_PEDALS :
error = wheeldev_init(usbdevice, ds); error = wheeldev_init(usbdevice, ds);
break; break;
case USBDEV_GENERICHAPTIC :
error = usbhapticdev_init(&usbdevice->u.hapticdevice, ds, siminfo);
break;
} }
return error; return error;
} }
static const vtable usb_simdevice_vtable = { &usbdev_update, &usbdev_free }; static const vtable usb_simdevice_vtable = { &usbdev_update, &usbdev_free };
static const vtable usb_wheeldevice_vtable = { &wheeldev_update, &usbdev_free };
static const vtable usb_wheelhaptic_vtable = { &wheelhapticdev_update, &usbdev_free };
USBDevice* new_usb_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo* siminfo) { USBDevice* new_usb_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo* siminfo) {
USBDevice* this = (USBDevice*) malloc(sizeof(USBDevice)); USBDevice* this = (USBDevice*) malloc(sizeof(USBDevice));
int error = 0;
this->m.update = &update; this->m.update = &update;
this->m.free = &simdevfree; this->m.free = &simdevfree;
this->m.derived = this; this->m.derived = this;
this->m.vtable = &usb_simdevice_vtable; this->m.vtable = &usb_simdevice_vtable;
// TODO: turn this into a switch when we get more devices // TODO: turn this into a switch when we get more devices
this->type = USBDEV_TACHOMETER; this->type = USBDEV_TACHOMETER;
if(ds->dev_subtype == SIMDEVTYPE_USBWHEEL) if(ds->dev_subtype == SIMDEVTYPE_USBWHEEL)
{ {
this->type = USBDEV_WHEEL; this->type = USBDEV_WHEEL_OR_PEDALS;
this->m.vtable = &usb_wheeldevice_vtable;
} }
if(ds->has_haptic_effects == true)
// really generic haptic isn't and shouldn't be it's own type
// it's an attribute that is added to a device via composition
// same if that haptic device is a serial device
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC)
{ {
this->m.hapticeffect.threshold = ds->threshold; if(siminfo->SimSupportsHapticEffects == false)
this->m.hapticeffect.effecttype = ds->effect_type; {
this->m.hapticeffect.tyre = ds->tyre; // if the user added haptic effects to the config and the sim does not support it, but still wishes to use features
this->m.hapticeffect.useconfig = ms->useconfig; // just remove the haptic effect from the config?
this->m.hapticeffect.configcheck = &ms->configcheck; slogi("This sim does not support haptic effects");
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config; error = MONOCOQUE_ERROR_UNSUPPORTED_SIM_FEATURE;
this->type = USBDEV_GENERICHAPTIC; }
else
{
int error = 0;
initializeHapticEffect(&this->m.hapticeffect, &ds->hapticsettings, ms);
this->m.vtable = &usb_wheelhaptic_vtable;
}
} }
int error = usbdev_init(this, ds, siminfo); error = usbdev_init(this, ds, siminfo);
if (error != 0) if (error != 0)
{ {
+8 -29
View File
@@ -17,7 +17,7 @@
int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdata, int tyre, int useconfig, int* configcheck, char* configfile) int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdata, int tyre, int useconfig, int* configcheck, char* configfile)
{ {
double play = slipeffect(simdata, usbhapticdevice->effecttype, tyre, usbhapticdevice->threshold, useconfig, configcheck, configfile); double play = slipeffect(simdata, this->hapticeffect.effecttype, tyre, this->hapticeffect.threshold, useconfig, configcheck, configfile);
if (play != usbhapticdevice->state) if (play != usbhapticdevice->state)
{ {
@@ -28,13 +28,13 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat
switch ( usbhapticdevice->type ) switch ( usbhapticdevice->type )
{ {
case USBHAPTIC_CSLELITEV3PEDALS: case USBHAPTIC_CSLELITEV3PEDALS:
cslelitev3_update(usbhapticdevice, usbhapticdevice->effecttype, rplay); cslelitev3_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
break; break;
case USBHAPTIC_SIMAGICP1000PEDALS: case USBHAPTIC_SIMAGICP1000PEDALS:
simagicp1000_update(usbhapticdevice, usbhapticdevice->effecttype, rplay); simagicp1000_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
break; break;
case USBHAPTIC_SIMNETPEDALS: case USBHAPTIC_SIMNETPEDALS:
simnetpedals_update(usbhapticdevice, usbhapticdevice->effecttype, rplay); simnetpedals_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
break; break;
} }
} }
@@ -43,13 +43,13 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat
switch ( usbhapticdevice->type ) switch ( usbhapticdevice->type )
{ {
case USBHAPTIC_CSLELITEV3PEDALS: case USBHAPTIC_CSLELITEV3PEDALS:
cslelitev3_update(usbhapticdevice, usbhapticdevice->effecttype, rplay); cslelitev3_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
break; break;
case USBHAPTIC_SIMAGICP1000PEDALS: case USBHAPTIC_SIMAGICP1000PEDALS:
simagicp1000_update(usbhapticdevice, usbhapticdevice->effecttype, rplay); simagicp1000_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
break; break;
case USBHAPTIC_SIMNETPEDALS: case USBHAPTIC_SIMNETPEDALS:
simnetpedals_update(usbhapticdevice, usbhapticdevice->effecttype, rplay); simnetpedals_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
break; break;
} }
} }
@@ -86,25 +86,7 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
} }
int error = 0; int error = 0;
usbhapticdevice->state = 0; initializeHapticEffect(&this->m.hapticeffect, &ds->hapticsettings, ms);
usbhapticdevice->value0 = ds->usbdevsettings.value0;
usbhapticdevice->value1 = ds->usbdevsettings.value1;
usbhapticdevice->state = usbhapticdevice->value0;
usbhapticdevice->effecttype = ds->effect_type;
usbhapticdevice->threshold = ds->threshold;
if(ds->effect_type == EFFECT_TYRESLIP)
{
usbhapticdevice->effecttype = EFFECT_TYRESLIP;
}
if(ds->effect_type == 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
@@ -119,9 +101,6 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
break; break;
case (SIMDEVSUBTYPE_SIMNETPEDALS): case (SIMDEVSUBTYPE_SIMNETPEDALS):
usbhapticdevice->type = USBHAPTIC_SIMNETPEDALS; usbhapticdevice->type = USBHAPTIC_SIMNETPEDALS;
usbhapticdevice->motorposition = ds->usbdevsettings.motorsposition;
usbhapticdevice->frequency = ds->usbdevsettings.frequency;
usbhapticdevice->amplitude = ds->usbdevsettings.amplitude;
error = simnetpedals_init(usbhapticdevice); error = simnetpedals_init(usbhapticdevice);
break; break;
default: default:
-9
View File
@@ -18,15 +18,6 @@ HapticType;
typedef struct typedef struct
{ {
int id; int id;
HapticType type;
double state;
double threshold;
int value0;
int value1;
uint32_t frequency;
uint32_t amplitude;
uint32_t motorposition;
VibrationEffectType effecttype;
FILE* filehandle; FILE* filehandle;
hid_device* handle; hid_device* handle;
char* dev; char* dev;
+78 -7
View File
@@ -2,19 +2,71 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "usb/wheels/logitechg29.h" #include "usb/wheels/logitechg29.h"
#include "usb/wheels/cammusc5.h" #include "usb/wheels/cammusc5.h"
#include "usb/wheels/cammusc12.h" #include "usb/wheels/cammusc12.h"
#include "usb/wheels/gtneo.h" #include "usb/wheels/gtneo.h"
#include "serial/moza.h" #include "serial/moza.h"
#include "usb/cslelitev3.h"
#include "usb/simagicp1000.h"
#include "usb/simnetpedals.h"
#include "simdevice.h" #include "simdevice.h"
#include "../helper/confighelper.h"
#include "../simulatorapi/simapi/simapi/simdata.h" #include "../simulatorapi/simapi/simapi/simdata.h"
#include "../slog/slog.h" #include "../slog/slog.h"
int wheeldev_update(USBDevice* usbdevice, SimData* simdata) int wheelhapticdev_update(SimDevice* this, SimData* simdata)
{ {
USBDevice* usbdevice = (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);
if (play != usbdevice->hapticstate)
{
int rplay = 0;
if(play > 0)
{
rplay = 1;
switch ( usbdevice->type )
{
case WHEELDEV_CSLELITEV3PEDALS:
cslelitev3_update(usbdevice, this->hapticeffect.effecttype, rplay);
break;
case WHEELDEV_SIMAGICP1000PEDALS:
simagicp1000_update(usbdevice, this->hapticeffect.effecttype, rplay);
break;
case WHEELDEV_SIMNETPEDALS:
simnetpedals_update(usbdevice, this->hapticeffect.effecttype, rplay, this->hapticeffect.motorposition, this->hapticeffect.basefrequency, this->hapticeffect.baseamplitude);
break;
}
}
else
{
switch ( usbdevice->type )
{
case WHEELDEV_CSLELITEV3PEDALS:
cslelitev3_update(usbdevice, this->hapticeffect.effecttype, rplay);
break;
case WHEELDEV_SIMAGICP1000PEDALS:
simagicp1000_update(usbdevice, this->hapticeffect.effecttype, rplay);
break;
case WHEELDEV_SIMNETPEDALS:
simnetpedals_update(usbdevice, this->hapticeffect.effecttype, rplay, this->hapticeffect.motorposition, 0, 0);
break;
}
}
usbdevice->hapticstate = play;
}
return 0;
}
int wheeldev_update(SimDevice* this, SimData* simdata)
{
USBDevice* usbdevice = (void *) this->derived;
WheelDevice* wheeldevice = &usbdevice->u.wheeldevice; WheelDevice* wheeldevice = &usbdevice->u.wheeldevice;
switch ( wheeldevice->type ) switch ( wheeldevice->type )
{ {
@@ -72,6 +124,15 @@ int wheeldev_free(USBDevice* usbdevice)
free(usbdevice->m.device_specific_config_file); free(usbdevice->m.device_specific_config_file);
} }
break; break;
case WHEELDEV_CSLELITEV3PEDALS:
cslelitev3_free(usbdevice);
break;
case WHEELDEV_SIMAGICP1000PEDALS:
simagicp1000_free(usbdevice);
break;
case WHEELDEV_SIMNETPEDALS:
simnetpedals_free(usbdevice);
break;
} }
return 0; return 0;
@@ -79,8 +140,9 @@ int wheeldev_free(USBDevice* usbdevice)
int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds) int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds)
{ {
slogi("initializing wheel device..."); slogi("initializing wheel or pedals device...");
int error = 0; int error = 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) {
@@ -138,11 +200,20 @@ int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds)
error = -1; error = -1;
} }
break; break;
default: case (SIMDEVSUBTYPE_SIMAGICP1000PEDALS):
wheeldevice->type = WHEELDEV_UNKNOWN; wheeldevice->type = USBHAPTIC_SIMAGICP1000PEDALS;
slogw("Unknown cammus wheel detected, trying C5"); error = simagicp1000_init(usbdevice);
error = cammusc5_init(usbdevice);
break; break;
case (SIMDEVSUBTYPE_CSLELITEV3PEDALS):
wheeldevice->type = USBHAPTIC_CSLELITEV3PEDALS;
error = cslelitev3_init(usbdevice);
break;
case (SIMDEVSUBTYPE_SIMNETPEDALS):
wheeldevice->type = USBHAPTIC_SIMNETPEDALS;
error = simnetpedals_init(usbdevice);
break;
default:
slogw("Possibly unknown device");
} }
+9 -6
View File
@@ -8,12 +8,15 @@
typedef enum typedef enum
{ {
WHEELDEV_UNKNOWN = 0, WHEELDEV_UNKNOWN = 0,
WHEELDEV_CAMMUSC5 = 1, WHEELDEV_CAMMUSC5 = 1,
WHEELDEV_CAMMUSC12 = 2, WHEELDEV_CAMMUSC12 = 2,
WHEELDEV_MOZAR5 = 3, WHEELDEV_MOZAR5 = 3,
WHEELDEV_SIMAGICGTNEO = 4, WHEELDEV_SIMAGICGTNEO = 4,
WHEELDEV_LOGITECHG29 = 5 WHEELDEV_LOGITECHG29 = 5,
WHEELDEV_CSLELITEV3PEDALS = 6,
WHEELDEV_SIMAGICP1000PEDALS = 7,
WHEELDEV_SIMNETPEDALS = 8
} }
WheelType; WheelType;
+79 -79
View File
@@ -37,35 +37,35 @@ int strtoeffecttype(const char* effect, DeviceSettings* ds)
if (strcicmp(effect, "Engine") == 0) if (strcicmp(effect, "Engine") == 0)
{ {
ds->is_valid = true; ds->is_valid = true;
ds->effect_type = EFFECT_ENGINERPM; ds->hapticsettings.effect_type = EFFECT_ENGINERPM;
} }
if (strcicmp(effect, "Gear") == 0) if (strcicmp(effect, "Gear") == 0)
{ {
ds->is_valid = true; ds->is_valid = true;
ds->effect_type = EFFECT_GEARSHIFT; ds->hapticsettings.effect_type = EFFECT_GEARSHIFT;
} }
if (strcicmp(effect, "Suspension") == 0) if (strcicmp(effect, "Suspension") == 0)
{ {
ds->is_valid = true; ds->is_valid = true;
ds->effect_type = EFFECT_SUSPENSION; ds->hapticsettings.effect_type = EFFECT_SUSPENSION;
} }
if (strcicmp(effect, "ABS") == 0) if (strcicmp(effect, "ABS") == 0)
{ {
ds->is_valid = true; ds->is_valid = true;
slogt("found abas effect set"); slogt("found abas effect set");
ds->effect_type = EFFECT_ABSBRAKES; ds->hapticsettings.effect_type = EFFECT_ABSBRAKES;
} }
if ((strcicmp(effect, "SLIP") == 0) || (strcicmp(effect, "TYRESLIP") == 0) || (strcicmp(effect, "TIRESLIP") == 0)) if ((strcicmp(effect, "SLIP") == 0) || (strcicmp(effect, "TYRESLIP") == 0) || (strcicmp(effect, "TIRESLIP") == 0))
{ {
ds->is_valid = true; ds->is_valid = true;
slogt("found tyreslip effect set"); slogt("found tyreslip effect set");
ds->effect_type = EFFECT_TYRESLIP; ds->hapticsettings.effect_type = EFFECT_TYRESLIP;
} }
if ((strcicmp(effect, "LOCK") == 0) || (strcicmp(effect, "TYRELOCK") == 0) || (strcicmp(effect, "TIRELOCK") == 0)) if ((strcicmp(effect, "LOCK") == 0) || (strcicmp(effect, "TYRELOCK") == 0) || (strcicmp(effect, "TIRELOCK") == 0))
{ {
ds->is_valid = true; ds->is_valid = true;
slogt("found tyreslock effect set"); slogt("found tyreslock effect set");
ds->effect_type = EFFECT_TYRELOCK; ds->hapticsettings.effect_type = EFFECT_TYRELOCK;
} }
if (ds->is_valid == false) if (ds->is_valid == false)
@@ -591,31 +591,31 @@ int gettyre(config_setting_t* device_settings, DeviceSettings* ds) {
const char* temp; const char* temp;
int found = config_setting_lookup_string(device_settings, "tyre", &temp); int found = config_setting_lookup_string(device_settings, "tyre", &temp);
ds->tyre = ALLFOUR; ds->hapticsettings.tyre = ALLFOUR;
if (strcicmp(temp, "FRONTS") == 0) if (strcicmp(temp, "FRONTS") == 0)
{ {
ds->tyre = FRONTS; ds->hapticsettings.tyre = FRONTS;
} }
if (strcicmp(temp, "REARS") == 0) if (strcicmp(temp, "REARS") == 0)
{ {
ds->tyre = REARS; ds->hapticsettings.tyre = REARS;
} }
if (strcicmp(temp, "FRONTLEFT") == 0) if (strcicmp(temp, "FRONTLEFT") == 0)
{ {
ds->tyre = FRONTLEFT; ds->hapticsettings.tyre = FRONTLEFT;
} }
if (strcicmp(temp, "FRONTRIGHT") == 0) if (strcicmp(temp, "FRONTRIGHT") == 0)
{ {
ds->tyre = FRONTRIGHT; ds->hapticsettings.tyre = FRONTRIGHT;
} }
if (strcicmp(temp, "REARLEFT") == 0) if (strcicmp(temp, "REARLEFT") == 0)
{ {
ds->tyre = REARLEFT; ds->hapticsettings.tyre = REARLEFT;
} }
if (strcicmp(temp, "REARRIGHT") == 0) if (strcicmp(temp, "REARRIGHT") == 0)
{ {
ds->tyre = REARRIGHT; ds->hapticsettings.tyre = REARRIGHT;
} }
} }
@@ -725,54 +725,91 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
} }
} }
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_subtype == SIMDEVTYPE_USBWHEEL || ds->dev_subtype == SIMDEVTYPE_SERIALWHEEL)
{
// logic for different devices
int b = 0;
const char* temp;
int found = config_setting_lookup_string(device_settings, "subtype", &temp);
if(temp != NULL && found > 0)
{
b = strtodevsubsubtype(temp, ds);
}
ds->usbdevsettings.frequency = 0;
ds->usbdevsettings.amplitude = 0;
ds->usbdevsettings.motorsposition = 0;
config_setting_lookup_int(device_settings, "frequency", &ds->usbdevsettings.frequency);
config_setting_lookup_int(device_settings, "amplitude", &ds->usbdevsettings.amplitude);
int motorposition = 1;
config_setting_lookup_int(device_settings, "motors", &motorposition);
ds->usbdevsettings.motorsposition = motorposition;
}
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_type == SIMDEV_SOUND || ds->dev_subtype == SIMDEVTYPE_SERIALHAPTIC) if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || 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;
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 || ds->effect_type == EFFECT_ABSBRAKES || ds->effect_type == EFFECT_SUSPENSION ) if (ds->hapticsettings.effect_type == EFFECT_TYRESLIP || ds->hapticsettings.effect_type == EFFECT_TYRELOCK || ds->hapticsettings.effect_type == EFFECT_ABSBRAKES || ds->hapticsettings.effect_type == EFFECT_SUSPENSION )
{ {
gettyre(device_settings, ds); gettyre(device_settings, ds);
ds->threshold = 0; ds->threshold = 0;
int found = config_setting_lookup_float(device_settings, "threshold", &ds->threshold); int found = config_setting_lookup_float(device_settings, "threshold", &ds->threshold);
} }
slogi("reading configured haptic effect settings");
ds->hapticsettings.frequency = 0;
ds->hapticsettings.frequencyMax = 0;
ds->hapticsettings.amplitude = 50;
ds->hapticsettings.amplitudeMax = 50;
ds->hapticsettings.volume = 0;
if (ds->hapticsettings.effect_type == EFFECT_GEARSHIFT)
{
ds->hapticsettings.duration = .125;
}
if (device_settings != NULL)
{
config_setting_lookup_int(device_settings, "volume", &ds->hapticsettings.volume);
config_setting_lookup_int(device_settings, "frequency", &ds->hapticsettings.frequency);
config_setting_lookup_int(device_settings, "frequencyMax", &ds->hapticsettings.frequencyMax);
config_setting_lookup_int(device_settings, "amplitude", &ds->hapticsettings.amplitude);
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
config_setting_lookup_int(device_settings, "amplitudeMax", &ds->hapticsettings.amplitudeMax);
const char* temp = NULL;
int found = 0;
found = config_setting_lookup_string(device_settings, "modulation", &temp);
ds->hapticsettings.modulation = EFFECT_MODULATION_NONE;
if (found == 0)
{
ds->hapticsettings.modulation = EFFECT_MODULATION_NONE;
slogd("Effect modulation not found, set to none");
}
else
{
if(strcicmp(temp, "FREQUENCY") == 0)
{
ds->hapticsettings.modulation = EFFECT_MODULATION_FREQUENCY;
if(ds->hapticsettings.frequencyMax == 0 || ds->hapticsettings.frequencyMax < ds->hapticsettings.frequency)
{
ds->hapticsettings.modulation = EFFECT_MODULATION_NONE;
slogw("Falling back to no frequency modulation since frequencyMax is either not set or set below target frequency");
}
else
{
slogi("Effect modulation found, set to FREQUENCY");
}
}
else if(strcicmp(temp, "AMPLIFY") == 0)
{
ds->hapticsettings.modulation = EFFECT_MODULATION_AMPLIFY;
slogi("Effect modulation found, set to AMPLIFY");
}
else
{
slogw("%s is not a valid modulation type, falling back to no effect modulation");
ds->hapticsettings.modulation = EFFECT_MODULATION_NONE;
}
}
ds->hapticsettings.motorposition = 0;
int motorposition = 1;
config_setting_lookup_int(device_settings, "motors", &motorposition);
ds->hapticsettings.motorposition = motorposition;
}
if (ds->dev_type == SIMDEV_SOUND) if (ds->dev_type == SIMDEV_SOUND)
{ {
slogi("reading configured sound device settings"); slogi("reading configured sound device settings");
ds->sounddevsettings.frequency = 0;
ds->sounddevsettings.frequencyMax = 0;
ds->sounddevsettings.amplitude = 50;
ds->sounddevsettings.amplitudeMax = 50;
ds->sounddevsettings.volume = 0; ds->sounddevsettings.volume = 0;
ds->sounddevsettings.pan = 0; ds->sounddevsettings.pan = 0;
ds->sounddevsettings.channels = 1; ds->sounddevsettings.channels = 1;
ds->sounddevsettings.duration = 2.0;
ds->sounddevsettings.noise = 0; ds->sounddevsettings.noise = 0;
if (ds->effect_type == EFFECT_GEARSHIFT) if (ds->hapticsettings.effect_type == EFFECT_GEARSHIFT)
{ {
ds->sounddevsettings.duration = .125; ds->sounddevsettings.duration = .125;
} }
@@ -780,13 +817,8 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
{ {
config_setting_lookup_int(device_settings, "volume", &ds->sounddevsettings.volume); config_setting_lookup_int(device_settings, "volume", &ds->sounddevsettings.volume);
config_setting_lookup_int(device_settings, "frequency", &ds->sounddevsettings.frequency);
config_setting_lookup_int(device_settings, "frequencyMax", &ds->sounddevsettings.frequencyMax);
config_setting_lookup_int(device_settings, "amplitude", &ds->sounddevsettings.amplitude);
config_setting_lookup_int(device_settings, "amplitudeMax", &ds->sounddevsettings.amplitudeMax);
config_setting_lookup_int(device_settings, "pan", &ds->sounddevsettings.pan); config_setting_lookup_int(device_settings, "pan", &ds->sounddevsettings.pan);
config_setting_lookup_int(device_settings, "channels", &ds->sounddevsettings.channels); config_setting_lookup_int(device_settings, "channels", &ds->sounddevsettings.channels);
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
config_setting_lookup_int(device_settings, "noise", &ds->sounddevsettings.noise); config_setting_lookup_int(device_settings, "noise", &ds->sounddevsettings.noise);
const char* temp = NULL; const char* temp = NULL;
@@ -805,40 +837,8 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
} }
found = config_setting_lookup_string(device_settings, "modulation", &temp);
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_NONE;
if (found == 0)
{
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_NONE;
slogd("Effect modulation not found, set to none");
}
else
{
if(strcicmp(temp, "FREQUENCY") == 0)
{
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_FREQUENCY;
if(ds->sounddevsettings.frequencyMax == 0 || ds->sounddevsettings.frequencyMax < ds->sounddevsettings.frequency)
{
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_NONE;
slogw("Falling back to no frequency modulation since frequencyMax is either not set or set below target frequency");
}
else
{
slogi("Effect modulation found, set to FREQUENCY");
}
}
else if(strcicmp(temp, "AMPLIFY") == 0)
{
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_AMPLIFY;
slogi("Effect modulation found, set to AMPLIFY");
}
else
{
slogw("%s is not a valid modulation type, falling back to no effect modulation");
ds->sounddevsettings.modulation = SOUND_EFFECT_MODULATION_NONE;
}
}
} }
} }
} }
+27 -12
View File
@@ -74,6 +74,14 @@ typedef enum
} }
VibrationEffectType; VibrationEffectType;
typedef enum
{
EFFECT_MODULATION_NONE = 0,
EFFECT_MODULATION_FREQUENCY = 1,
EFFECT_MODULATION_AMPLIFY = 2,
}
EffectModulationType;
typedef enum typedef enum
{ {
MOTOR_1 = 0, MOTOR_1 = 0,
@@ -177,29 +185,35 @@ SerialDeviceSettings;
typedef struct typedef struct
{ {
uint32_t frequency;
uint32_t volume; uint32_t volume;
int lowbound_frequency;
int upperbound_frequency;
uint32_t frequencyMax;
uint32_t amplitudeMax;
uint32_t amplitude;
int pan; int pan;
int channels; int channels;
double duration; double duration;
char* dev; char* dev;
SoundEffectModulationType modulation;
int noise; int noise;
} }
SoundDeviceSettings; SoundDeviceSettings;
typedef struct typedef struct
{ {
int value0;
int value1;
uint32_t frequency; uint32_t frequency;
uint32_t amplitude; uint32_t amplitude;
MotorPosition motorsposition; uint32_t volume;
uint32_t frequencyMax;
uint32_t amplitudeMax;
double threshold;
double duration;
MotorPosition motorposition;
VibrationEffectType effect_type;
MonocoqueTyreIdentifier tyre;
EffectModulationType modulation;
}
HapticEffectSettings;
typedef struct
{
char* dev; char* dev;
} }
USBDeviceSettings; USBDeviceSettings;
@@ -211,14 +225,15 @@ typedef struct
DeviceType dev_type; DeviceType dev_type;
DeviceSubType dev_subtype; DeviceSubType dev_subtype;
DeviceSubSubType dev_subsubtype; DeviceSubSubType dev_subsubtype;
bool has_haptic_effects;
// to get really fancy move the effect information to it's own structure that would be a member of // 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 // any device settings member structure that can carry an effect
VibrationEffectType effect_type;
MonocoqueTyreIdentifier tyre;
double threshold; double threshold;
bool has_config; bool has_config;
char* specific_config_file; char* specific_config_file;
// union? // union?
HapticEffectSettings hapticsettings;
TachometerSettings tachsettings; TachometerSettings tachsettings;
SerialDeviceSettings serialdevsettings; SerialDeviceSettings serialdevsettings;
SoundDeviceSettings sounddevsettings; SoundDeviceSettings sounddevsettings;