1 Commits
Author SHA1 Message Date
Paul Dino Jones e1ddd73352 Add wheelslip and abs to test loop 2024-05-28 15:00:46 +00:00
13 changed files with 159 additions and 614 deletions
-2
View File
@@ -9,8 +9,6 @@ set(devices_source_files
serialdevice.c serialdevice.c
tachdevice.h tachdevice.h
tachdevice.c tachdevice.c
usbhapticdevice.h
usbhapticdevice.c
sound.h sound.h
sound.c sound.c
usb/revburner.h usb/revburner.h
-1
View File
@@ -61,7 +61,6 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds)
simdevices[j] = sim->m; simdevices[j] = sim->m;
simdevices[j].initialized = true; simdevices[j].initialized = true;
simdevices[j].type = SIMDEV_USB; simdevices[j].type = SIMDEV_USB;
simdevices[j].tyre = ds[j].tyre;
devices++; devices++;
} }
else else
+1 -3
View File
@@ -64,8 +64,7 @@ SerialDevice* new_serial_device(DeviceSettings* ds);
typedef enum typedef enum
{ {
USBDEV_UNKNOWN = 0, USBDEV_UNKNOWN = 0,
USBDEV_TACHOMETER = 1, USBDEV_TACHOMETER = 1
USBDEV_GENERICHAPTIC = 2
} }
USBType; USBType;
@@ -77,7 +76,6 @@ typedef struct
union union
{ {
TachDevice tachdevice; TachDevice tachdevice;
USBGenericHapticDevice hapticdevice;
} u; } u;
} }
USBDevice; USBDevice;
@@ -112,7 +112,7 @@ int usb_generic_shaker_init(SoundDevice* sounddevice, pa_threaded_mainloop* main
pa_stream_set_state_callback(stream, stream_state_cb, mainloop); pa_stream_set_state_callback(stream, stream_state_cb, mainloop);
if (sounddevice->effecttype == EFFECT_GEARSHIFT) if (sounddevice->effecttype == SOUNDEFFECT_GEARSHIFT)
{ {
pa_stream_set_write_callback(stream, gear_sound_stream, &sounddevice->sounddata); pa_stream_set_write_callback(stream, gear_sound_stream, &sounddevice->sounddata);
} }
+13 -13
View File
@@ -128,7 +128,7 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int
const char* streamname= "Engine"; const char* streamname= "Engine";
switch (sounddevice->effecttype) { switch (sounddevice->effecttype) {
case (EFFECT_GEARSHIFT): case (SOUNDEFFECT_GEARSHIFT):
sounddevice->sounddata.last_gear = 0; sounddevice->sounddata.last_gear = 0;
//sounddevice->sounddata.pitch = 500; //sounddevice->sounddata.pitch = 500;
@@ -139,12 +139,12 @@ int sounddev_init(SoundDevice* sounddevice, const char* devname, int volume, int
sounddevice->sounddata.curr_duration = duration; sounddevice->sounddata.curr_duration = duration;
streamname = "Gear"; streamname = "Gear";
break; break;
case (EFFECT_TYRESLIP): case (SOUNDEFFECT_TYRESLIP):
sounddevice->sounddata.duration = duration; sounddevice->sounddata.duration = duration;
sounddevice->sounddata.curr_duration = duration; sounddevice->sounddata.curr_duration = duration;
streamname = "TyreSlip"; streamname = "TyreSlip";
break; break;
case (EFFECT_ABSBRAKES): case (SOUNDEFFECT_ABSBRAKES):
sounddevice->sounddata.duration = duration; sounddevice->sounddata.duration = duration;
sounddevice->sounddata.curr_duration = duration; sounddevice->sounddata.curr_duration = duration;
streamname = "ABS"; streamname = "ABS";
@@ -175,25 +175,25 @@ SoundDevice* new_sound_device(DeviceSettings* ds) {
this->m.free = &simdevfree; this->m.free = &simdevfree;
this->m.derived = this; this->m.derived = this;
slogt("Attempting to configure sound device with subtype: %i", ds->effect_type); slogt("Attempting to configure sound device with subtype: %i", ds->dev_subtype);
switch (ds->effect_type) { switch (ds->dev_subtype) {
case (EFFECT_ENGINERPM): case (SIMDEVTYPE_ENGINESOUND):
this->effecttype = EFFECT_ENGINERPM; this->effecttype = SOUNDEFFECT_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 (SIMDEVTYPE_GEARSOUND):
this->effecttype = EFFECT_GEARSHIFT; this->effecttype = SOUNDEFFECT_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 (SIMDEVTYPE_TYRESLIP):
this->effecttype = EFFECT_TYRESLIP; this->effecttype = SOUNDEFFECT_TYRESLIP;
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_ABSBRAKES): case (SIMDEVTYPE_ABSBRAKES):
this->effecttype = EFFECT_ABSBRAKES; this->effecttype = SOUNDEFFECT_ABSBRAKES;
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;
+9
View File
@@ -14,6 +14,15 @@ typedef enum
} }
SoundType; SoundType;
typedef enum
{
SOUNDEFFECT_ENGINERPM = 0,
SOUNDEFFECT_GEARSHIFT = 1,
SOUNDEFFECT_ABSBRAKES = 2,
SOUNDEFFECT_TYRESLIP = 3
}
VibrationEffectType;
#define MAX_TABLE_SIZE (6000) #define MAX_TABLE_SIZE (6000)
typedef struct typedef struct
{ {
+1 -17
View File
@@ -19,9 +19,6 @@ int usbdev_update(SimDevice* this, SimData* simdata)
case USBDEV_TACHOMETER : case USBDEV_TACHOMETER :
tachdev_update(&usbdevice->u.tachdevice, simdata); tachdev_update(&usbdevice->u.tachdevice, simdata);
break; break;
case USBDEV_GENERICHAPTIC :
usbhapticdev_update(&usbdevice->u.hapticdevice, simdata);
break;
} }
return 0; return 0;
@@ -31,16 +28,12 @@ int usbdev_free(SimDevice* this)
{ {
USBDevice* usbdevice = (void *) this->derived; USBDevice* usbdevice = (void *) this->derived;
slogt("Usb device free");
switch ( usbdevice->type ) switch ( usbdevice->type )
{ {
case USBDEV_UNKNOWN : case USBDEV_UNKNOWN :
case USBDEV_TACHOMETER : case USBDEV_TACHOMETER :
tachdev_free(&usbdevice->u.tachdevice); tachdev_free(&usbdevice->u.tachdevice);
break; break;
case USBDEV_GENERICHAPTIC :
usbhapticdev_free(&usbdevice->u.hapticdevice);
break;
} }
free(usbdevice); free(usbdevice);
@@ -53,16 +46,13 @@ int usbdev_init(USBDevice* usbdevice, DeviceSettings* ds)
slogi("initializing usb device..."); slogi("initializing usb device...");
int error = 0; int error = 0;
//usbdevice->type = USBDEV_TACHOMETER; usbdevice->type = USBDEV_TACHOMETER;
switch ( usbdevice->type ) switch ( usbdevice->type )
{ {
case USBDEV_UNKNOWN : case USBDEV_UNKNOWN :
case USBDEV_TACHOMETER : case USBDEV_TACHOMETER :
error = tachdev_init(&usbdevice->u.tachdevice, ds); error = tachdev_init(&usbdevice->u.tachdevice, ds);
break; break;
case USBDEV_GENERICHAPTIC :
error = usbhapticdev_init(&usbdevice->u.hapticdevice, ds);
break;
} }
return error; return error;
@@ -79,12 +69,6 @@ USBDevice* new_usb_device(DeviceSettings* ds) {
this->m.derived = this; this->m.derived = this;
this->m.vtable = &usb_simdevice_vtable; this->m.vtable = &usb_simdevice_vtable;
this->type = USBDEV_TACHOMETER;
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC)
{
this->type = USBDEV_GENERICHAPTIC;
}
int error = usbdev_init(this, ds); int error = usbdev_init(this, ds);
if (error != 0) if (error != 0)
-1
View File
@@ -2,6 +2,5 @@
#define _USBDEVICE_H #define _USBDEVICE_H
#include "tachdevice.h" #include "tachdevice.h"
#include "usbhapticdevice.h"
#endif #endif
-99
View File
@@ -1,99 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include "usbhapticdevice.h"
#include "../../helper/confighelper.h"
#include "../../simulatorapi/simapi/simapi/simdata.h"
#include "../../slog/slog.h"
int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdata)
{
double play = 0;
switch (usbhapticdevice->effecttype)
{
case (EFFECT_TYRESLIP):
if (usbhapticdevice->effecttype == EFFECT_TYRESLIP)
{
if (usbhapticdevice->tyre == FRONTLEFT || usbhapticdevice->tyre == FRONTS || usbhapticdevice->tyre == ALLFOUR)
{
play += simdata->wheelslip[0];
}
if (usbhapticdevice->tyre == FRONTRIGHT || usbhapticdevice->tyre == FRONTS || usbhapticdevice->tyre == ALLFOUR)
{
play += simdata->wheelslip[1];
}
if (usbhapticdevice->tyre == REARLEFT || usbhapticdevice->tyre == REARS || usbhapticdevice->tyre == ALLFOUR)
{
play += simdata->wheelslip[2];
}
if (usbhapticdevice->tyre == REARRIGHT || usbhapticdevice->tyre == REARS || usbhapticdevice->tyre == ALLFOUR)
{
play += simdata->wheelslip[3];
}
}
break;
case (EFFECT_ABSBRAKES):
play += simdata->abs;
break;
}
if (play != usbhapticdevice->state)
{
if(play > 0)
{
fprintf(usbhapticdevice->handle, "%i\n", usbhapticdevice->value1);
fflush(usbhapticdevice->handle);
}
else
{
fprintf(usbhapticdevice->handle, "%i\n", usbhapticdevice->value0);
fflush(usbhapticdevice->handle);
}
usbhapticdevice->state = play;
}
return 0;
}
int usbhapticdev_free(USBGenericHapticDevice* usbhapticdevice)
{
slogt("closing usb haptic device");
fflush(usbhapticdevice->handle);
fclose(usbhapticdevice->handle);
free(usbhapticdevice->dev);
return 0;
}
int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* ds)
{
int error = 0;
usbhapticdevice->state = 0;
usbhapticdevice->dev = strdup(ds->usbdevsettings.dev);
usbhapticdevice->value0 = ds->usbdevsettings.value0;
usbhapticdevice->value1 = ds->usbdevsettings.value1;
usbhapticdevice->state = usbhapticdevice->value0;
usbhapticdevice->tyre = ds->tyre;
usbhapticdevice->effecttype = ds->effect_type;
usbhapticdevice->handle = fopen(usbhapticdevice->dev, "w");
if(usbhapticdevice->handle == 0)
{
error = MONOCOQUE_ERROR_INVALID_DEV;
return error;
}
slogt("Initializing standalone usb haptic device");
if(ds->effect_type == EFFECT_TYRESLIP)
{
usbhapticdevice->effecttype = EFFECT_TYRESLIP;
}
if(ds->effect_type == EFFECT_WHEELLOCK)
{
usbhapticdevice->effecttype = EFFECT_WHEELLOCK;
}
return error;
}
-35
View File
@@ -1,35 +0,0 @@
#ifndef _USBHAPTICDEVICE_H
#define _USBHAPTICDEVICE_H
#include <hidapi/hidapi.h>
#include "../helper/confighelper.h"
#include "../simulatorapi/simapi/simapi/simdata.h"
typedef enum
{
HAPTIC_UNKNOWN = 0,
HAPTIC_GENERIC = 1
}
HapticType;
typedef struct
{
int id;
HapticType type;
double state;
int value0;
int value1;
VibrationEffectType effecttype;
MonocoqueTyreIdentifier tyre;
FILE* handle;
char* dev;
}
USBGenericHapticDevice;
int usbhapticdev_update(USBGenericHapticDevice* hapticdevice, SimData* simdata);
int usbhapticdev_init(USBGenericHapticDevice* hapticdevice, DeviceSettings* ds);
int usbhapticdev_free(USBGenericHapticDevice* hapticdevice);
#endif
+35 -270
View File
@@ -1,4 +1,3 @@
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -6,31 +5,16 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <poll.h> #include <poll.h>
#include <termios.h> #include <termios.h>
#include <signal.h>
#include "gameloop.h" #include "gameloop.h"
#include "../helper/parameters.h" #include "../helper/parameters.h"
#include "../helper/confighelper.h" #include "../helper/confighelper.h"
#include "../devices/simdevice.h" #include "../devices/simdevice.h"
#include "../simulatorapi/simapi/simapi/simdata.h" #include "../simulatorapi/simdata.h"
#include "../simulatorapi/simapi/simapi/simmapper.h" #include "../simulatorapi/simmapper.h"
#include "../slog/slog.h" #include "../slog/slog.h"
#define DEFAULT_UPDATE_RATE 240.0 #define DEFAULT_UPDATE_RATE 120.0
#define SIM_CHECK_RATE 1.0
bool go = false;
bool go2 = false;
struct sigaction act;
void sighandler(int signum, siginfo_t* info, void* ptr)
{
sloge("caught signal");
go = false;
go2 = false;
//gfx_clear(pixels, pixels_len);
//gfx_swapbuffers();
//gfx_close();
}
int showstats(SimData* simdata) int showstats(SimData* simdata)
{ {
@@ -181,64 +165,20 @@ int showstats(SimData* simdata)
fflush(stdout); fflush(stdout);
} }
int looper(SimDevice* devices[], int numdevices, Simulator simulator)
int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdata, SimMap* simmap)
{ {
struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
double update_rate = DEFAULT_UPDATE_RATE;
char ch;
int t=0;
int s=0;
go2 = true;
while (go2 == true && simdata->simstatus > 1)
{
simdatamap(simdata, simmap, p->sim);
showstats(simdata);
t++;
s++;
if(simdata->rpms<100)
{
simdata->rpms=100;
}
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
if( poll(&mypoll, 1, 1000.0/update_rate) )
{
scanf("%c", &ch);
if(ch == 'q')
{
go2 = false;
}
}
}
simdata->velocity = 0;
simdata->rpms = 100;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
fprintf(stdout, "\n");
return 0;
}
int looper(SimDevice* devices, int numdevices, Parameters* p)
{
memset(&act, 0, sizeof(act));
act.sa_sigaction = sighandler;
act.sa_flags = SA_SIGINFO;
sigaction(SIGTERM, &act, NULL);
sigaction(SIGINT, &act, NULL);
sigaction(SIGTSTP, &act, NULL);
slogi("preparing game loop with %i devices...", numdevices);
SimData* simdata = malloc(sizeof(SimData)); SimData* simdata = malloc(sizeof(SimData));
SimMap* simmap = malloc(sizeof(SimMap)); SimMap* simmap = malloc(sizeof(SimMap));
int error = siminit(simdata, simmap, simulator);
if (error != MONOCOQUE_ERROR_NONE)
{
return error;
}
struct termios newsettings, canonicalmode; struct termios newsettings, canonicalmode;
tcgetattr(0, &canonicalmode); tcgetattr(0, &canonicalmode);
newsettings = canonicalmode; newsettings = canonicalmode;
@@ -249,41 +189,38 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
char ch; char ch;
struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI }; struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
fprintf(stdout, "Searching for sim data... Press q to quit...\n"); double update_rate = DEFAULT_UPDATE_RATE;
p->simon = false; int t=0;
double update_rate = SIM_CHECK_RATE; int go = true;
go = true;
while (go == true) while (go == true)
{ {
p->simon = false; simdatamap(simdata, simmap, simulator);
getSim(simdata, simmap, &p->simon, &p->sim); showstats(simdata);
t++;
if (p->simon == true && simdata->simstatus > 1) if(simdata->rpms<250)
{ {
slogi("preparing game loop with %i devices...", numdevices); simdata->rpms=250;
}
slogi("sending initial data to devices");
simdata->velocity = 16;
simdata->rpms = 100;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{ {
devices[x].update(&devices[x], simdata); if (devices[x]->type == SIMDEV_SERIAL)
}
sleep(3);
clilooper(devices, numdevices, p, simdata, simmap);
}
if (p->simon == true)
{ {
p->simon = false; if(t>=update_rate)
fprintf(stdout, "Searching for sim data... Press q again to quit...\n"); {
sleep(2); devupdate(devices[x], simdata);
}
}
else
{
devupdate(devices[x], simdata);
} }
if (poll(&mypoll, 1, 1000.0/update_rate) ) }
if(t>=update_rate)
{ {
if (go != false ) t=0;
}
if( poll(&mypoll, 1, 1000.0/update_rate) )
{ {
scanf("%c", &ch); scanf("%c", &ch);
if(ch == 'q') if(ch == 'q')
@@ -292,8 +229,6 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
} }
} }
} }
}
fprintf(stdout, "\n"); fprintf(stdout, "\n");
fflush(stdout); fflush(stdout);
tcsetattr(0, TCSANOW, &canonicalmode); tcsetattr(0, TCSANOW, &canonicalmode);
@@ -303,173 +238,3 @@ int looper(SimDevice* devices, int numdevices, Parameters* p)
return 0; return 0;
} }
int tester(SimDevice* devices, int numdevices)
{
slogi("preparing test with %i devices...", numdevices);
SimData* simdata = malloc(sizeof(SimData));
struct termios newsettings, canonicalmode;
tcgetattr(0, &canonicalmode);
newsettings = canonicalmode;
newsettings.c_lflag &= (~ICANON & ~ECHO);
newsettings.c_cc[VMIN] = 1;
newsettings.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &newsettings);
fprintf(stdout, "\n");
simdata->gear = 0;
simdata->velocity = 16;
simdata->rpms = 100;
simdata->maxrpm = 8000;
simdata->abs = 0;
simdata->wheelslip[0] = 0;
simdata->wheelslip[1] = 0;
simdata->wheelslip[2] = 0;
simdata->wheelslip[3] = 0;
sleep(3);
fprintf(stdout, "Setting rpms to 1000\n");
simdata->rpms = 1000;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
fprintf(stdout, "Setting ABS to 1\n");
simdata->abs = 1;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
simdata->abs = 0;
fprintf(stdout, "Setting Wheelslip to 1\n");
simdata->wheelslip[0] = 1;
simdata->wheelslip[1] = 1;
simdata->wheelslip[2] = 1;
simdata->wheelslip[3] = 1;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
simdata->wheelslip[0] = 0;
simdata->wheelslip[1] = 0;
simdata->wheelslip[2] = 0;
simdata->wheelslip[3] = 0;
fprintf(stdout, "Shifting into first gear\n");
simdata->gear = 2;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
fprintf(stdout, "Setting speed to 100\n");
simdata->velocity = 100;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
fprintf(stdout, "Shifting into second gear\n");
simdata->gear = 3;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
fprintf(stdout, "Setting speed to 200\n");
simdata->velocity = 200;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
fprintf(stdout, "Shifting into third gear\n");
simdata->gear = 4;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
fprintf(stdout, "Setting rpms to 2000\n");
simdata->rpms = 2000;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
fprintf(stdout, "Setting rpms to 4000\n");
simdata->rpms = 4000;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
fprintf(stdout, "Shifting into fourth gear\n");
simdata->gear = 5;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
fprintf(stdout, "Setting speed to 300\n");
simdata->velocity = 300;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
fprintf(stdout, "Setting rpms to 8000\n");
simdata->rpms = 8000;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(3);
simdata->velocity = 0;
simdata->rpms = 100;
for (int x = 0; x < numdevices; x++)
{
devices[x].update(&devices[x], simdata);
}
sleep(1);
fflush(stdout);
tcsetattr(0, TCSANOW, &canonicalmode);
free(simdata);
return 0;
}
+85 -140
View File
@@ -52,31 +52,6 @@ int strtogame(const char* game, MonocoqueSettings* ms)
return MONOCOQUE_ERROR_NONE; return MONOCOQUE_ERROR_NONE;
} }
int strtoeffecttype(const char* effect, DeviceSettings* ds)
{
ds->is_valid = false;
if (strcicmp(effect, "Engine") == 0)
{
ds->effect_type = EFFECT_ENGINERPM;
}
if (strcicmp(effect, "Gear") == 0)
{
ds->effect_type = EFFECT_GEARSHIFT;
}
if (strcicmp(effect, "ABS") == 0)
{
ds->effect_type = EFFECT_ABSBRAKES;
}
if ((strcicmp(effect, "SLIP") == 0) || (strcicmp(effect, "TYRESLIP") == 0) || (strcicmp(effect, "TIRESLIP") == 0))
{
ds->effect_type = EFFECT_TYRESLIP;
}
ds->is_valid = true;
return MONOCOQUE_ERROR_NONE;
}
int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev) int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
{ {
ds->is_valid = false; ds->is_valid = false;
@@ -89,11 +64,6 @@ int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
ds->dev_subtype = SIMDEVTYPE_TACHOMETER; ds->dev_subtype = SIMDEVTYPE_TACHOMETER;
break; break;
} }
if (strcicmp(device_subtype, "UsbHaptic") == 0 || strcicmp(device_subtype, "Haptic") == 0)
{
ds->dev_subtype = SIMDEVTYPE_USBHAPTIC;
break;
}
case SIMDEV_SERIAL: case SIMDEV_SERIAL:
if (strcicmp(device_subtype, "ShiftLights") == 0) if (strcicmp(device_subtype, "ShiftLights") == 0)
{ {
@@ -106,8 +76,26 @@ int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev)
break; break;
} }
case SIMDEV_SOUND: case SIMDEV_SOUND:
ds->is_valid = true; if (strcicmp(device_subtype, "Engine") == 0)
{
ds->dev_subtype = SIMDEVTYPE_ENGINESOUND;
break; break;
}
if (strcicmp(device_subtype, "Gear") == 0)
{
ds->dev_subtype = SIMDEVTYPE_GEARSOUND;
break;
}
if (strcicmp(device_subtype, "ABS") == 0)
{
ds->dev_subtype = SIMDEVTYPE_ABSBRAKES;
break;
}
if ((strcicmp(device_subtype, "SLIP") == 0) || (strcicmp(device_subtype, "TYRESLIP") == 0))
{
ds->dev_subtype = SIMDEVTYPE_TYRESLIP;
break;
}
default: default:
ds->is_valid = false; ds->is_valid = false;
slogw("%s does not appear to be a valid device sub type, but attempting to continue with other devices", device_subtype); slogw("%s does not appear to be a valid device sub type, but attempting to continue with other devices", device_subtype);
@@ -240,10 +228,74 @@ int loadtachconfig(const char* config_file, DeviceSettings* ds)
return 0; return 0;
} }
int gettyre(config_setting_t* device_settings, DeviceSettings* ds) { int loadconfig(const char* config_file, DeviceSettings* ds)
{
if (ds->dev_subtype == SIMDEVTYPE_TACHOMETER)
{
return loadtachconfig(config_file, ds);
}
return 0;
}
int devsetup(const char* device_type, const char* device_subtype, const char* config_file, MonocoqueSettings* ms, DeviceSettings* ds, config_setting_t* device_settings)
{
int error = MONOCOQUE_ERROR_NONE;
//slogt("Called device setup with %s %s %s", device_type, device_subtype, config_file);
ds->dev_type = SIMDEV_UNKNOWN;
error = strtodev(device_type, device_subtype, ds);
if (error != MONOCOQUE_ERROR_NONE)
{
return error;
}
if (ms->program_action == A_PLAY || ms->program_action == A_TEST)
{
error = loadconfig(config_file, ds);
}
if (error != MONOCOQUE_ERROR_NONE)
{
return error;
}
if (ds->dev_type == SIMDEV_SOUND)
{
slogi("reading configured sound device settings");
ds->sounddevsettings.frequency = -1;
ds->sounddevsettings.volume = -1;
ds->sounddevsettings.lowbound_frequency = -1;
ds->sounddevsettings.upperbound_frequency = -1;
ds->sounddevsettings.pan = 0;
ds->sounddevsettings.duration = 2.0;
if (ds->dev_subtype == SIMDEVTYPE_GEARSOUND)
{
ds->sounddevsettings.duration = .125;
}
if (device_settings != NULL)
{
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, "pan", &ds->sounddevsettings.pan);
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
const char* temp; const char* temp;
int found = config_setting_lookup_string(device_settings, "tyre", &temp); int found = 0;
found = config_setting_lookup_string(device_settings, "devid", &temp);
if (found == 0)
{
ds->sounddevsettings.dev = NULL;
}
else
{
ds->sounddevsettings.dev = strdup(temp);
}
if (ds->dev_subtype == SIMDEVTYPE_TYRESLIP)
{
found = config_setting_lookup_string(device_settings, "tyre", &temp);
ds->tyre = ALLFOUR; ds->tyre = ALLFOUR;
@@ -271,41 +323,9 @@ int gettyre(config_setting_t* device_settings, DeviceSettings* ds) {
{ {
ds->tyre = REARRIGHT; ds->tyre = REARRIGHT;
} }
}
int loadconfig(const char* config_file, DeviceSettings* ds)
{
if (ds->dev_subtype == SIMDEVTYPE_TACHOMETER)
{
return loadtachconfig(config_file, ds);
} }
return 0;
}
int devsetup(const char* device_type, const char* device_subtype, const char* config_file, MonocoqueSettings* ms, DeviceSettings* ds, config_setting_t* device_settings)
{
int error = MONOCOQUE_ERROR_NONE;
//slogt("Called device setup with %s %s %s", device_type, device_subtype, config_file);
ds->dev_type = SIMDEV_UNKNOWN;
error = strtodev(device_type, device_subtype, ds);
if (error != MONOCOQUE_ERROR_NONE)
{
return error;
} }
if (ms->program_action == A_PLAY || ms->program_action == A_TEST)
{
error = loadconfig(config_file, ds);
} }
if (error != MONOCOQUE_ERROR_NONE)
{
return error;
}
if (ds->dev_subtype == SIMDEVTYPE_TACHOMETER) if (ds->dev_subtype == SIMDEVTYPE_TACHOMETER)
{ {
@@ -326,73 +346,6 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co
} }
} }
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC)
{
if (device_settings != NULL)
{
ds->usbdevsettings.value0 = 0;
ds->usbdevsettings.value1 = 1;
const char* temp;
int found = config_setting_lookup_string(device_settings, "devpath", &temp);
if (found == 0)
{
ds->usbdevsettings.dev = NULL;
}
else
{
ds->usbdevsettings.dev = strdup(temp);
}
config_setting_lookup_int(device_settings, "value0", &ds->usbdevsettings.value0);
config_setting_lookup_int(device_settings, "value1", &ds->usbdevsettings.value1);
}
}
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_type == SIMDEV_SOUND) {
const char* effect;
config_setting_lookup_string(device_settings, "effect", &effect);
strtoeffecttype(effect, ds);
if (ds->effect_type == EFFECT_TYRESLIP || ds->effect_type == EFFECT_WHEELLOCK)
{
gettyre(device_settings, ds);
}
if (ds->dev_type == SIMDEV_SOUND)
{
slogi("reading configured sound device settings");
ds->sounddevsettings.frequency = -1;
ds->sounddevsettings.volume = -1;
ds->sounddevsettings.lowbound_frequency = -1;
ds->sounddevsettings.upperbound_frequency = -1;
ds->sounddevsettings.pan = 0;
ds->sounddevsettings.duration = 2.0;
if (ds->effect_type == EFFECT_GEARSHIFT)
{
ds->sounddevsettings.duration = .125;
}
if (device_settings != NULL)
{
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, "pan", &ds->sounddevsettings.pan);
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
const char* temp;
int found = 0;
found = config_setting_lookup_string(device_settings, "devid", &temp);
if (found == 0)
{
ds->sounddevsettings.dev = NULL;
}
else
{
ds->sounddevsettings.dev = strdup(temp);
}
}
}
}
if (ds->dev_subtype == SIMDEVTYPE_SIMWIND || ds->dev_subtype == SIMDEVTYPE_SHIFTLIGHTS) if (ds->dev_subtype == SIMDEVTYPE_SIMWIND || ds->dev_subtype == SIMDEVTYPE_SHIFTLIGHTS)
{ {
@@ -425,13 +378,5 @@ int settingsfree(DeviceSettings ds)
free(ds.sounddevsettings.dev); free(ds.sounddevsettings.dev);
} }
} }
if (ds.dev_type == SIMDEV_USB)
{
if (ds.usbdevsettings.dev != NULL )
{
free(ds.usbdevsettings.dev);
}
}
return 0; return 0;
} }
+6 -24
View File
@@ -22,9 +22,12 @@ typedef enum
{ {
SIMDEVTYPE_UNKNOWN = 0, SIMDEVTYPE_UNKNOWN = 0,
SIMDEVTYPE_TACHOMETER = 1, SIMDEVTYPE_TACHOMETER = 1,
SIMDEVTYPE_USBHAPTIC = 2, SIMDEVTYPE_SHIFTLIGHTS = 2,
SIMDEVTYPE_SHIFTLIGHTS = 3, SIMDEVTYPE_SIMWIND = 3,
SIMDEVTYPE_SIMWIND = 4 SIMDEVTYPE_ENGINESOUND = 4,
SIMDEVTYPE_GEARSOUND = 5,
SIMDEVTYPE_ABSBRAKES = 6,
SIMDEVTYPE_TYRESLIP = 7
} }
DeviceSubType; DeviceSubType;
@@ -40,16 +43,6 @@ typedef enum
} }
SimulatorUpdate; SimulatorUpdate;
typedef enum
{
EFFECT_ENGINERPM = 0,
EFFECT_GEARSHIFT = 1,
EFFECT_ABSBRAKES = 2,
EFFECT_TYRESLIP = 3,
EFFECT_WHEELLOCK = 4
}
VibrationEffectType;
typedef enum typedef enum
{ {
MONOCOQUE_ERROR_NONE = 0, MONOCOQUE_ERROR_NONE = 0,
@@ -108,25 +101,14 @@ typedef struct
} }
SoundDeviceSettings; SoundDeviceSettings;
typedef struct
{
int value0;
int value1;
char* dev;
}
USBDeviceSettings;
typedef struct typedef struct
{ {
bool is_valid; bool is_valid;
DeviceType dev_type; DeviceType dev_type;
DeviceSubType dev_subtype; DeviceSubType dev_subtype;
VibrationEffectType effect_type;
// union?
TachometerSettings tachsettings; TachometerSettings tachsettings;
SerialDeviceSettings serialdevsettings; SerialDeviceSettings serialdevsettings;
SoundDeviceSettings sounddevsettings; SoundDeviceSettings sounddevsettings;
USBDeviceSettings usbdevsettings;
MonocoqueTyreIdentifier tyre; MonocoqueTyreIdentifier tyre;
} }
DeviceSettings; DeviceSettings;