Compare commits

...
33 Commits
Author SHA1 Message Date
Paul Dino Jones 27b7da8c89 disable arch builds for now 2026-06-24 16:16:27 -04:00
Paul Dino Jones 78cc80064a Fix issue with new haptic code on usb devices and consolidate some function calls 2026-06-23 20:07:53 -04:00
Paul Dino Jones 8eb433f01e Refactor haptic code and devices that rely on it, to more easily allow devices to use the haptic attributes 2026-06-23 13:29:49 -04:00
Paul Dino Jones c4fa9e4138 custom nspawn script for arch build 2026-06-22 13:09:50 -04:00
Paul Dino Jones a9f49d91b9 update to use parent arch pkgbuild workflow action 2026-06-22 12:54:14 -04:00
Paul Dino Jones 87818b6a22 specify correct arch build action 2026-06-22 12:44:31 -04:00
Paul Dino Jones 17dcdcde23 fix path to PKGBUILD 2026-06-22 12:34:38 -04:00
Paul Dino Jones 5c0f871415 Update path to PKGBUILD 2026-06-22 12:32:47 -04:00
Paul Dino Jones 44b9dce139 Add arch build to CI 2026-06-22 12:27:52 -04:00
Paul Dino Jones a776085b76 Add arch build to CI 2026-06-22 12:25:49 -04:00
Paul Dino Jones 0d30170de0 Set buffer size to 64 bytes for simnet pedals. Send 0 for frequency and amplitude when no effect is playing 2026-06-11 18:28:21 -04:00
Paul Dino Jones 2aee847d7c update to latest simapi for ac evo 2026-06-09 13:05:59 -04:00
Paul Dino Jones 9712396c6f Add initial support for simnet pedals 2026-06-01 16:00:13 -04:00
Paul Dino Jones 6a36c2825f further fix return codes on serial devices 2026-05-29 18:21:52 -04:00
Paul Dino Jones 2b787cba00 cleanup the way errors are returned for arduino type devices 2026-05-29 14:28:24 -04:00
Paul Dino Jones 3c81f749b8 various fixes for weirdness with serial devices 2026-05-28 16:25:55 -04:00
David Scott 3c1b1948fd create a rootful, privileged distrobox container (#47) 2026-05-27 13:49:30 -04:00
Paul Dino Jones 3b10509ecd add some directives that seem necessary for debian 2026-05-25 23:58:33 -04:00
Paul Dino Jones b734330d38 fix lua linking 2026-05-25 23:36:57 -04:00
Paul Dino Jones eb95db1dda rename lua in headers 2026-05-25 23:13:53 -04:00
Paul Dino Jones 3a803550ea add more lua variables back to cmake 2026-05-25 23:11:04 -04:00
Paul Dino Jones 26e0e87cd7 add macro for lua 5.4 backwards compatibility so we can compile against lua 5.4 or 5.5 2026-05-25 23:03:57 -04:00
Paul Dino Jones 7f17a5307c refer explicitly to lua 5.4 in headers 2026-05-25 20:46:47 -04:00
Paul Dino Jones ae87a2eaa5 add more dependencies to install.sh 2026-05-25 19:54:08 -04:00
Paul Dino Jones 738a181d61 force lua 5.4 in cmake 2026-05-25 19:53:47 -04:00
Paul Dino Jones ba6c624a59 Improve lua dependency detection for linking 2026-05-25 19:17:47 -04:00
Brandan Cotton 822d4096e7 make additional data available to lua scripts (#45) 2026-05-25 08:42:19 -04:00
Paul Dino Jones a3e932e2dc updated to latest simapi for process detection 2026-05-23 12:40:42 -04:00
Paul Dino Jones ad53dd654c build simapi in install script 2026-05-22 17:45:36 -04:00
Paul Dino Jones 522185d19b remove deprectated getpid.h file 2026-04-26 19:38:15 -04:00
Paul Dino Jones 030813cd4f Update to latest simapi 2026-04-26 19:16:29 -04:00
Paul Dino Jones 53467a2a5e Fix cmake compile definitions 2026-04-23 17:35:50 -04:00
Paul Dino Jones b5fa399f79 fix cmake boolean 2026-04-23 17:20:57 -04:00
34 changed files with 740 additions and 400 deletions
+18
View File
@@ -0,0 +1,18 @@
#!/bin/bash
# https://gitlab.archlinux.org/archlinux/devtools/-/merge_requests/197
args=("$@")
has_keep_unit=0
for arg in "${args[@]}"; do
if [[ "$arg" == "--keep-unit" ]]; then
has_keep_unit=1
fi
done
if ! (( has_keep_unit )); then
args=("--keep-unit" "${args[@]}")
fi
exec /usr/bin/systemd-nspawn "${args[@]}"
+20
View File
@@ -79,3 +79,23 @@ jobs:
with:
files: monocoque-${{ matrix.os }}.rpm
#arch-build:
# runs-on: ubuntu-latest
# container:
# image: archlinux
# options: --privileged
# steps:
# - uses: actions/checkout@v3
# - name: Set proper repository url in PKGBUILD
# run: sed -i "s|%URL%|${{ github.server_url }}/${{ github.repository }}|" $GITHUB_WORKSPACE/tools/distro/arch/git/PKGBUILD
# - run: echo "$GITHUB_WORKSPACE/.github/bin" >> "$GITHUB_PATH"
# - name: Build Arch Linux package
# uses: FFY00/build-arch-package@v1
# with:
# BUILD_SCRIPT: extra-x86_64-build
# PKGBUILD: $GITHUB_WORKSPACE/tools/distro/arch/git/PKGBUILD
# OUTDIR: $HOME/arch-packages
# - name: Release the Package
# uses: softprops/action-gh-release@v1
# with:
# files: $HOME/arch-packages/monocoque*.zst
+22 -12
View File
@@ -1,7 +1,4 @@
# minimum CMake version required for C++20 support, among other things
cmake_minimum_required(VERSION 3.18)
# detect if Monocoque is being used as a sub-project of another CMake project
if(NOT DEFINED PROJECT_NAME)
set(MONOCOQUE_SUBPROJECT OFF)
@@ -20,12 +17,25 @@ set(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed -ldl")
set(LIBUSB_INCLUDE_DIR /usr/include/libusb-1.0)
set(LIBXML_INCLUDE_DIR /usr/include/libxml2)
FIND_PACKAGE(Lua 5.4 EXACT REQUIRED)
FIND_PACKAGE(Lua)
set(INCLUDE_DIRS ${LUA_INCLUDE_DIR})
include_directories(${LUA_INCLUDE_DIR})
if(Lua_FOUND AND NOT TARGET Lua::Lua)
add_library(Lua::Lua INTERFACE IMPORTED)
set_target_properties(
Lua::Lua
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${LUA_LIBRARIES}"
)
endif()
message("Lua ${Lua_VERSION} found")
if (Lua_VERSION VERSION_GREATER_EQUAL "5.5.0")
add_compile_definitions(USE_LUA_55)
else()
remove_definitions(USE_LUA_55)
endif()
#FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h
# HINTS $ENV{LIBUSB_ROOT}
@@ -47,13 +57,13 @@ pkg_check_modules(LIBPROCPS libprocps)
pkg_check_modules(LIBPROC2 libproc2)
if (LIBPROCPS_FOUND)
add_compile_definitions(USE_OLD_PID_VAL=false)
#add_compile_definitions(USE_OLD_PID_VAL=0)
elseif (LIBPROC2_FOUND)
if (LIBPROC2_VERSION VERSION_GREATER_EQUAL "4.0.5")
add_compile_definitions(USE_OLD_PID_VAL=false)
#add_compile_definitions(USE_OLD_PID_VAL=0)
else()
add_compile_definitions(USE_OLD_PID_VAL=1)
endif()
add_compile_definitions(USE_OLD_PID_VAL=true)
else()
message(FATAL_ERROR "Either libprocps or libproc2 is required")
endif()
@@ -64,9 +74,9 @@ endif()
message("Using pulseaudio backend...")
add_compile_definitions(USE_PULSEAUDIO=true)
target_link_libraries(monocoque m hidapi-hidraw pulse serialport xml2 argtable2 config gameloop helper devices slog simulatorapi uv xdg-basedir ${LUA_LIBRARY} proc2)
target_link_libraries(monocoque m hidapi-hidraw pulse serialport xml2 argtable2 config gameloop helper devices slog simulatorapi uv xdg-basedir Lua::Lua proc2)
target_include_directories(monocoque PUBLIC config ${LIBXML_INCLUDE_DIR})
target_include_directories(monocoque PUBLIC config ${LIBXML_INCLUDE_DIR} ${LUA_INCLUDE_DIR})
add_subdirectory(src/monocoque/gameloop)
add_subdirectory(src/monocoque/simulatorapi)
+2 -2
View File
@@ -95,7 +95,7 @@ install_dependencies() {
case $DISTRO in
arch|manjaro)
local deps="yder libuv argtable libserialport libconfig hidapi lua libxdg-basedir mingw-w64-gcc"
local deps="yder libuv argtable libserialport libconfig hidapi lua54 libpulse pkgconfig libxdg-basedir mingw-w64-gcc"
# Check if yay is available for AUR
if command -v yay &> /dev/null; then
@@ -537,7 +537,7 @@ main() {
clone_repositories
log_info "Building components (this may take a few minutes)..."
#build_simapi
build_simapi
build_simd
build_monocoque
build_simshmbridge
-1
View File
@@ -1 +0,0 @@
../../monocoque/simulatorapi/simapi/simapi/simdata.h
+2 -2
View File
@@ -13,8 +13,6 @@ set(devices_source_files
tachdevice.c
wheeldevice.h
wheeldevice.c
usbhapticdevice.h
usbhapticdevice.c
hapticeffect.h
hapticeffect.c
sound.h
@@ -25,6 +23,8 @@ set(devices_source_files
usb/cslelitev3.c
usb/simagicp1000.h
usb/simagicp1000.c
usb/simnetpedals.h
usb/simnetpedals.c
usb/wheels/logitechg29.h
usb/wheels/logitechg29.c
usb/wheels/cammusc5.h
+62 -4
View File
@@ -6,6 +6,7 @@
#include <math.h>
#include "usbhapticdevice.h"
#include "simdevice.h"
#include "../../helper/confighelper.h"
#include "../../simulatorapi/simapi/simapi/simdata.h"
#include "../../simulatorapi/simapi/simapi/simmapper.h"
@@ -194,9 +195,66 @@ void getTyreDiameter(SimData* simdata)
}
}
double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, int useconfig, int* configcheck, char* configfile)
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;
slogi("Haptic effect: %i %i, tyre %i %i", h->effecttype, hs->effect_type, h->tyre, hs->tyre);
h->threshold = hs->threshold;
h->modulationType = hs->modulation;
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, HapticEffect* h, int useconfig, int* configcheck, char* configfile)
{
int effecttype = h->effecttype;
int tyre = h->tyre;
double threshold = h->threshold;
double play = 0;
double wheelslip[4];
wheelslip[0] = 0;
@@ -212,7 +270,7 @@ double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold,
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)
{
@@ -246,7 +304,7 @@ double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold,
case EFFECT_SUSPENSION:
break;
default:
slogd("Unknown effect type");
slogw("Unknown effect type %i", effecttype);
}
if(simdata->Yvelocity <= 0)
{
+34 -3
View File
@@ -2,21 +2,52 @@
#define _HAPTICEFFECT_H
#include <stdio.h>
#include "../helper/confighelper.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
{
double threshold;
VibrationEffectType effecttype;
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* configcheck;
char* tyrediameterconfig;
}
HapticEffect;
double slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, int useconfig, int* configcheck, char* configfile);
int initializeHapticEffect(HapticEffect* h, HapticEffectSettings* hs, MonocoqueSettings* ms);
double slipeffect(SimData* simdata, HapticEffect* h, int useconfig, int* configcheck, char* configfile);
bool hasTyreDiameter(SimData* simdata);
int loadtyreconfig(SimData* simdata, char* configfile, bool setDiameters);
int savetyreconfig(SimData* simdata, char* configfile);
+6 -7
View File
@@ -128,21 +128,20 @@ int GetNumberOfLeds(SerialDevice* serialdevice, int* numlights)
int arduino_init(SerialDevice* serialdevice, const char* portdev)
{
serialdevice->id = monocoque_serial_open(serialdevice, portdev);
return serialdevice->id;
int id = monocoque_serial_open(serialdevice, portdev);
if (id < 0) return id;
serialdevice->id = id;
return 0;
}
int arduino_custom_init(SerialDevice* serialdevice, const char* portdev, const char* luafile, bool uselights)
{
serialdevice->id = monocoque_serial_open(serialdevice, portdev);
int error = arduino_init(serialdevice, portdev);
int numlights = 0;
monocoque_serial_device serialdev = monocoque_serial_devices[serialdevice->id];
int error = 0;
if(uselights == true)
{
error = GetNumberOfLeds(serialdevice, &numlights);
@@ -179,7 +178,7 @@ int arduino_custom_init(SerialDevice* serialdevice, const char* portdev, const c
slogi("LUA config setup successful.");
return serialdevice->id;
return 0;
}
@@ -64,6 +64,39 @@ int simdata_to_lua(lua_State *L, SimData* simdata) {
}
lua_setfield(L, -2, "pd");
lua_pushnumber(L, simdata->gas);
lua_setfield(L, -2, "gas");
lua_pushnumber(L, simdata->fuel);
lua_setfield(L, -2, "fuel");
lua_pushnumber(L, simdata->turboboost);
lua_setfield(L, -2, "turboboost");
lua_newtable(L);
for(int i = 0; i < 4; i++)
{
lua_pushnumber(L, simdata->tyreRPS[i]);
lua_rawseti(L, -2, i+1);
}
lua_setfield(L, -2, "tyreRPS");
lua_newtable(L);
for(int i = 0; i < 4; i++)
{
lua_pushnumber(L, simdata->tyrediameter[i]);
lua_rawseti(L, -2, i+1);
}
lua_setfield(L, -2, "tyrediameter");
lua_newtable(L);
for(int i = 0; i < 4; i++)
{
lua_pushnumber(L, simdata->tyretemp[i]);
lua_rawseti(L, -2, i+1);
}
lua_setfield(L, -2, "tyretemp");
return 0; // Return the table to Lua
}
+8 -3
View File
@@ -1,9 +1,14 @@
#ifndef _ARDUINOLEDLUA_H
#define _ARDUINOLEDLUA_H
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
//#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#ifdef USE_LUA_55
/* open all libraries */
#define luaL_openlibs(L) luaL_openselectedlibs(L, ~0, 0)
#endif
#include "../../simulatorapi/simapi/simapi/simdata.h"
+20 -14
View File
@@ -140,8 +140,12 @@ int arduino_simhaptic_update(SimDevice* this, SimData* simdata)
int result = 1;
slogt("arduino haptic device updating");
serialdevice->u.simhapticdata.motor1 = 0;
serialdevice->u.simhapticdata.motor2 = 0;
serialdevice->u.simhapticdata.motor3 = 0;
serialdevice->u.simhapticdata.motor4 = 0;
double play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
double play = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
double rplay = play;
play = play * serialdevice->ampfactor;
@@ -149,25 +153,27 @@ int arduino_simhaptic_update(SimDevice* this, SimData* simdata)
{
play = 1.0;
}
int effectspeed = ceil(255 * play);
uint8_t effectspeed = ceil(255 * play);
int motor = serialdevice->motorsposition;
uint8_t motor = this->hapticeffect.motorposition;
if (play != serialdevice->state)
if (play != serialdevice->hapticstate)
{
// motor 1
if (motor == 0 || motor == 4 || motor == 7 || motor == 8 || motor == 10 || motor == 11 || motor == 13 || motor == 14)
{
serialdevice->u.simhapticdata.effect1 = effectspeed;
serialdevice->u.simhapticdata.motor1 = 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, serialdevice->motorsposition, 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.effect1, 1, rplay, serialdevice->ampfactor);
}
// motor 3
if (motor == 2 || motor == 6 || motor == 8 || motor == 9 || motor == 10 || motor == 11 || motor == 12 || motor == 14)
{
serialdevice->u.simhapticdata.effect3 = effectspeed;
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, serialdevice->motorsposition, 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);
@@ -191,7 +197,7 @@ int serialdev_free(SimDevice* this)
serialdevice->u.simhapticdata.motor3 = 1;
serialdevice->u.simhapticdata.effect4 = 0;
serialdevice->u.simhapticdata.motor4 = 1;
serialdevice->state = 0;
serialdevice->hapticstate = 0;
size_t size = sizeof(SimHapticData);
monocoque_serial_write_block(serialdevice->id, &serialdevice->u.simhapticdata, size, 9000);
@@ -350,7 +356,7 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms, SimIn
this->u.simhapticdata.effect2 = 0;
this->u.simhapticdata.effect3 = 0;
this->u.simhapticdata.effect4 = 0;
this->state = 0;
this->hapticstate = 0;
this->ampfactor = ds->serialdevsettings.ampfactor;
this->fanpower = ds->serialdevsettings.fanpower;
slogi("Initializing arduino device for haptic effects.");
@@ -382,10 +388,10 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms, SimIn
if(this->devicetype == ARDUINODEV__HAPTIC && error == 0)
{
this->m.hapticeffect.threshold = ds->threshold;
this->m.hapticeffect.effecttype = ds->effect_type;
slogt("Haptic effect: %i %i", this->m.hapticeffect.effecttype, ds->effect_type);
this->m.hapticeffect.tyre = ds->tyre;
this->m.hapticeffect.threshold = ds->hapticsettings.threshold;
this->m.hapticeffect.effecttype = ds->hapticsettings.effect_type;
slogt("Haptic effect: %i %i", this->m.hapticeffect.effecttype, ds->hapticsettings.effect_type);
this->m.hapticeffect.tyre = ds->hapticsettings.tyre;
this->m.hapticeffect.useconfig = ms->useconfig;
this->m.hapticeffect.configcheck = &ms->configcheck;
this->m.hapticeffect.tyrediameterconfig = ms->tyre_diameter_config;
@@ -399,7 +405,7 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms, SimIn
if (error != 0)
{
slogw("Did not initialize usb device due to error code %i", error);
slogw("Did not initialize serial device due to error code %i", error);
free(this);
return NULL;
}
+11 -9
View File
@@ -4,7 +4,7 @@
#include <stdbool.h>
#include <hidapi/hidapi.h>
#include "lua.h"
#include <lua.h>
#include "usbdevice.h"
#include "sounddevice.h"
@@ -67,7 +67,7 @@ typedef struct
int baudrate;
double ampfactor;
double fanpower;
double state;
double hapticstate;
union
{
SimWindData simwinddata;
@@ -88,10 +88,10 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms, SimIn
/********* USB HID Devices *****/
typedef enum
{
USBDEV_UNKNOWN = 0,
USBDEV_TACHOMETER = 1,
USBDEV_GENERICHAPTIC = 2,
USBDEV_WHEEL = 3
USBDEV_UNKNOWN = 0,
USBDEV_TACHOMETER = 1,
USBDEV_GENERICHAPTIC = 2,
USBDEV_WHEEL_OR_PEDALS = 3
}
USBType;
@@ -100,12 +100,14 @@ typedef struct
SimDevice m;
int id;
hid_device* handle;
FILE* filehandle;
char* dev;
double hapticstate;
USBType type;
union
{
TachDevice tachdevice;
WheelDevice wheeldevice;
USBGenericHapticDevice hapticdevice;
} u;
}
USBDevice;
@@ -122,7 +124,6 @@ typedef struct
SimDevice m;
int id;
int configcheck;
SoundEffectModulationType modulationType;
SoundData sounddata;
//#ifdef USE_PULSEAUDIO
pa_stream *stream;
@@ -154,7 +155,8 @@ int simdevfree(SimDevice* this);
/****** 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_free(USBDevice* usbdevice);
+37 -87
View File
@@ -15,13 +15,15 @@
#include "../helper/parameters.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)
{
//sounddevice->sounddata.gear_sound_data = 3.14;
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude;
sounddevice->sounddata.curr_frequency = this->hapticeffect.basefrequency;
sounddevice->sounddata.curr_amplitude = this->hapticeffect.baseamplitude;
sounddevice->sounddata.curr_duration = 0;
}
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;
switch (modulation)
{
case SOUND_EFFECT_MODULATION_FREQUENCY:
modulated_effect = ((sounddevice->sounddata.frequencyMax - sounddevice->sounddata.frequency) * raw_effect) + sounddevice->sounddata.frequency;
case HAPTIC_EFFECT_MODULATION_FREQUENCY:
modulated_effect = ((this->hapticeffect.frequencyMax - this->hapticeffect.basefrequency) * raw_effect) + this->hapticeffect.basefrequency;
sounddevice->sounddata.curr_frequency = modulated_effect;
sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude;
slogt("set curr frequency to %f from raw effect %f and base frequency %i", sounddevice->sounddata.curr_frequency, raw_effect, sounddevice->sounddata.frequency);
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, this->hapticeffect.basefrequency);
break;
case SOUND_EFFECT_MODULATION_AMPLIFY:
modulated_effect = ((sounddevice->sounddata.amplitudeMax - sounddevice->sounddata.amplitude) * raw_effect) + sounddevice->sounddata.amplitude;
case HAPTIC_EFFECT_MODULATION_AMPLIFY:
modulated_effect = ((this->hapticeffect.amplitudeMax - this->hapticeffect.baseamplitude) * raw_effect) + this->hapticeffect.baseamplitude;
sounddevice->sounddata.curr_amplitude = modulated_effect;
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
slogt("set curr amplitude to %i from raw effect %f and base amplitude %i", sounddevice->sounddata.curr_amplitude, raw_effect, sounddevice->sounddata.amplitude);
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, this->hapticeffect.baseamplitude);
break;
case SOUND_EFFECT_MODULATION_NONE:
case HAPTIC_EFFECT_MODULATION_NONE:
default:
sounddevice->sounddata.curr_frequency = sounddevice->sounddata.frequency;
sounddevice->sounddata.curr_amplitude = sounddevice->sounddata.amplitude;
sounddevice->sounddata.curr_frequency = this->hapticeffect.basefrequency;
sounddevice->sounddata.curr_amplitude = this->hapticeffect.baseamplitude;
break;
}
@@ -64,19 +68,19 @@ int sounddev_engine_update(SimDevice* this, SimData* simdata)
double effect = ((double)simdata->rpms/60)/((double)simdata->maxrpm/60);
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)
{
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);
slogt("Updating sound device frequency from original tyre slip effect %f", effect);
double effect = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
slogt("Updating sound device frequency from original %i tyre slip effect %f", this->hapticeffect.effecttype, effect);
if (effect > 0)
{
modulate(sounddevice, effect, sounddevice->modulationType);
modulate(this, effect, this->hapticeffect.modulationType);
}
else
{
@@ -91,12 +95,12 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;
double play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
double play = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
slogt("Updating sound device frequency from original tyre lock effect %f", play);
if (play > 0)
{
modulate(sounddevice, play, sounddevice->modulationType);
modulate(this, play, this->hapticeffect.modulationType);
}
else
{
@@ -109,12 +113,12 @@ int sounddev_tyrelock_update(SimDevice* this, SimData* simdata)
int sounddev_absbrakes_update(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;
double play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
double play = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
slogt("Updating sound device frequency from original abs effect %f", play);
if (play > 0)
{
modulate(sounddevice, play, sounddevice->modulationType);
modulate(this, play, this->hapticeffect.modulationType);
}
else
{
@@ -128,13 +132,13 @@ int sounddev_suspension_update(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;
double effect = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
double effect = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
effect = effect * 10;
slogt("Updating sound device output from original suspension travel effect %f", effect);
if (effect > 0)
{
effect = modulate(sounddevice, effect, sounddevice->modulationType);
effect = modulate(this, effect, this->hapticeffect.modulationType);
}
else
{
@@ -147,9 +151,7 @@ int sounddev_suspension_update(SimDevice* this, SimData* simdata)
int sounddev_gearshift_update(SimDevice* this, SimData* simdata)
{
SoundDevice* sounddevice = (void *) this->derived;
gear_sound_set(sounddevice, simdata);
gear_sound_set(this, simdata);
}
@@ -163,28 +165,17 @@ int sounddev_free(SimDevice* this)
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("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("channels is: %i", sds.channels);
slogi("duration is: %f", sds.duration);
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.curr_duration = 0;
@@ -240,7 +231,7 @@ SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo
this->m.derived = this;
int error = 0;
switch (ds->effect_type)
switch (ds->hapticsettings.effect_type)
{
case (EFFECT_TYRESLIP):
case (EFFECT_TYRELOCK):
@@ -258,73 +249,32 @@ SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo
if(error == 0)
{
slogt("Attempting to configure sound device with subtype: %i", ds->effect_type);
switch (ds->effect_type)
initializeHapticEffect(&this->m.hapticeffect, &ds->hapticsettings, ms);
slogt("Attempting to configure sound device with subtype: %i", ds->hapticsettings.effect_type);
switch (ds->hapticsettings.effect_type)
{
case (EFFECT_ENGINERPM):
this->m.hapticeffect.effecttype = EFFECT_ENGINERPM;
this->m.vtable = &engine_sound_simdevice_vtable;
slogi("Initializing sound device for engine vibrations.");
break;
case (EFFECT_GEARSHIFT):
this->m.hapticeffect.effecttype = EFFECT_GEARSHIFT;
this->m.vtable = &gear_sound_simdevice_vtable;
slogi("Initializing sound device for gear shift vibrations.");
break;
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;
slogi("Initializing sound device for tyre slip vibrations.");
break;
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;
slogi("Initializing sound device for tyre slip vibrations.");
slogi("Initializing sound device for tyre lock vibrations.");
break;
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;
slogi("Initializing sound device for abs vibrations.");
break;
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;
slogi("Initializing sound device for suspension vibrations.");
break;
@@ -334,7 +284,7 @@ SoundDevice* new_sound_device(DeviceSettings* ds, MonocoqueSettings* ms, SimInfo
if(error == 0)
{
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)
-12
View File
@@ -8,23 +8,11 @@
//#endif
typedef enum
{
SOUND_EFFECT_MODULATION_NONE = 0,
SOUND_EFFECT_MODULATION_FREQUENCY = 1,
SOUND_EFFECT_MODULATION_AMPLIFY = 2,
}
SoundEffectModulationType;
#define MAX_TABLE_SIZE (6000)
typedef struct
{
uint8_t last_gear;
int volume;
uint32_t frequency;
uint32_t frequencyMax;
uint32_t amplitude;
uint32_t amplitudeMax;
double duration;
double curr_frequency;
uint32_t curr_amplitude;
+12 -13
View File
@@ -3,7 +3,7 @@
#include <string.h>
#include <glob.h>
#include "usbhapticdevice.h"
#include "cslelitev3.h"
#include "../../helper/confighelper.h"
#include "../slog/slog.h"
@@ -11,7 +11,7 @@
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;
@@ -33,26 +33,25 @@ int cslelitev3_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, i
}
}
fprintf(usbhapticdevice->filehandle, "%i\n", value);
fflush(usbhapticdevice->filehandle);
fprintf(usbdevice->filehandle, "%i\n", value);
fflush(usbdevice->filehandle);
return res;
}
int cslelitev3_free(USBGenericHapticDevice* usbhapticdevice)
int cslelitev3_free(USBDevice* usbdevice)
{
int res = 0;
free(usbhapticdevice->dev);
free(usbdevice->dev);
fflush(usbhapticdevice->filehandle);
fclose(usbhapticdevice->filehandle);
fflush(usbdevice->filehandle);
fclose(usbdevice->filehandle);
return res;
}
int cslelitev3_init(USBGenericHapticDevice* usbhapticdevice)
int cslelitev3_init(USBDevice* usbdevice)
{
slogi("initializing CSL Elite V3 Pedals...");
@@ -75,7 +74,7 @@ int cslelitev3_init(USBGenericHapticDevice* usbhapticdevice)
{
if (i == 0)
{
usbhapticdevice->dev = strdup(globlist.gl_pathv[i]);
usbdevice->dev = strdup(globlist.gl_pathv[i]);
}
i++;
}
@@ -91,9 +90,9 @@ int cslelitev3_init(USBGenericHapticDevice* usbhapticdevice)
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...");
return res;
+6 -3
View File
@@ -1,8 +1,11 @@
#ifndef _CSLELITEV3_H
#define _CSLELITEV3_H
int cslelitev3_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play);
int cslelitev3_init(USBGenericHapticDevice* usbhapticdevice);
int cslelitev3_free(USBGenericHapticDevice* usbhapticdevice);
#include "../wheeldevice.h"
#include "../simdevice.h"
int cslelitev3_update(USBDevice* usbdevice, int effecttype, int play);
int cslelitev3_init(USBDevice* usbdevice);
int cslelitev3_free(USBDevice* usbdevice);
#endif
+17 -17
View File
@@ -3,7 +3,7 @@
#include <string.h>
#include <hidapi/hidapi.h>
#include "usbhapticdevice.h"
#include "simagicp1000.h"
#include "../../helper/confighelper.h"
#include "../slog/slog.h"
@@ -14,12 +14,12 @@
const size_t SIMAGIC_P1000_BUFSIZE = 49;
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;
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);
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;
}
int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play)
int simagicp1000_update(USBDevice* usbdevice, int effecttype, int play)
{
int res = 0;
@@ -54,17 +54,17 @@ int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype,
{
case (EFFECT_TYRESLIP):
bytes[2] = 0x02;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
break;
case (EFFECT_TYRELOCK):
bytes[2] = 0x01;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
break;
case (EFFECT_ABSBRAKES):
bytes[2] = 0x02;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
bytes[2] = 0x01;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
break;
}
}
@@ -72,19 +72,19 @@ int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype,
{
bytes[0] = 241;
bytes[2] = 0x01;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
bytes[2] = 0x02;
senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
}
return res;
}
int simagicp1000_free(USBGenericHapticDevice* usbhapticdevice)
int simagicp1000_free(USBDevice* usbdevice)
{
int res = 0;
hid_close(usbhapticdevice->handle);
hid_close(usbdevice->handle);
res = hid_exit();
return res;
@@ -92,7 +92,7 @@ int simagicp1000_free(USBGenericHapticDevice* usbhapticdevice)
return res;
}
int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice)
int simagicp1000_init(USBDevice* usbdevice)
{
slogi("initializing %s...", SIMAGICP1000DEVSTRING);
@@ -100,9 +100,9 @@ int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice)
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);
res = hid_exit();
@@ -123,7 +123,7 @@ int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice)
bytes[5] = 0x00;
bytes[6] = 0x01;
bytes[7] = 0x02;
res = senddevreport(usbhapticdevice, bytes, SIMAGIC_P1000_BUFSIZE);
res = senddevreport(usbdevice, bytes, SIMAGIC_P1000_BUFSIZE);
slogd("Initialization returned %i", res);
if(res != 0)
{
+6 -3
View File
@@ -1,8 +1,11 @@
#ifndef _SIMAGICP1000_H
#define _SIMAGICP1000_H
int simagicp1000_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play);
int simagicp1000_init(USBGenericHapticDevice* usbhapticdevice);
int simagicp1000_free(USBGenericHapticDevice* usbhapticdevice);
#include "../wheeldevice.h"
#include "../simdevice.h"
int simagicp1000_update(USBDevice* usbdevice, int effecttype, int play);
int simagicp1000_init(USBDevice* usbdevice);
int simagicp1000_free(USBDevice* usbdevice);
#endif
+90
View File
@@ -0,0 +1,90 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glob.h>
#include "simnetpedals.h"
#include "../../helper/confighelper.h"
#include "../slog/slog.h"
#define SIMNETPEDALS_BUFSIZE 64
//Byte[0] : 0x01 (fixed) = Report ID
//Byte[1] : 0x00 (fixed)
//Byte[2] : motor number (0x01, 0x2 or 0x4)
//Byte[3]: motor 1 frequency in hz
//Byte[4] : motor 1 amplitude (0 to 100%)
//Byte[5] : motor 2 frequency in hz
//Byte[6]: motor 2 amplitude (0 to 100%)
//Byte[7]: motor 3 frequency in hz
//Byte[8]: motor 3 amplitude (0 to 100%)
int simnetpedals_update(USBDevice* usbdevice, int effecttype, int play, int motorposition, int frequency, int amplitude)
{
int res = 0;
unsigned char bytes[SIMNETPEDALS_BUFSIZE];
for (int x = 0; x < SIMNETPEDALS_BUFSIZE; x++)
{
bytes[x] = 0x00;
}
bytes[0] = 0x01;
bytes[1] = 0x00;
bytes[2] = motorposition;
uint8_t motormultiple = motorposition - 1;
if(motorposition == 0x04)
{
motormultiple = 2;
}
if(play > 0)
{
bytes[3 + (motormultiple * 2)] = frequency;
bytes[4 + (motormultiple * 2)] = amplitude;
}
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]);
res = hid_write(usbdevice->handle, bytes, SIMNETPEDALS_BUFSIZE);
}
else
{
slogd("no handle");
}
return res;
}
int simnetpedals_free(USBDevice* usbdevice)
{
int res = 0;
hid_close(usbdevice->handle);
res = hid_exit();
return res;
}
int simnetpedals_init(USBDevice* usbdevice)
{
slogi("initializing simnet pedals...");
int res = 0;
res = hid_init();
usbdevice->handle = hid_open(0xcafe, 0xa301, NULL);
if (!usbdevice->handle)
{
sloge("Could not find attached Simnet Pedals");
res = hid_exit();
return 1;
}
slogd("Found Simnet Pedals handle %i...", usbdevice->handle);
return res;
}
+11
View File
@@ -0,0 +1,11 @@
#ifndef _SIMNETPEDALS_H
#define _SIMNETPEDALS_H
#include "../wheeldevice.h"
#include "../simdevice.h"
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
@@ -2,7 +2,6 @@
#define _CAMMUSC12_H
#include "../../wheeldevice.h"
#include "../../simdevice.h"
int cammusc12_update(USBDevice* wheeldevice, int maxrpm, int rpm, int gear, int velocity);
+27 -29
View File
@@ -19,11 +19,9 @@ int usbdev_update(SimDevice* this, SimData* simdata)
case USBDEV_TACHOMETER :
tachdev_update(usbdevice, simdata);
break;
case USBDEV_WHEEL :
wheeldev_update(usbdevice, simdata);
break;
case USBDEV_GENERICHAPTIC :
usbhapticdev_update(&usbdevice->u.hapticdevice, simdata, this->hapticeffect.tyre, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
case USBDEV_WHEEL_OR_PEDALS :
// this should be directed via vtable to wheeldevice.c
//wheeldev_update(usbdevice, simdata);
break;
}
@@ -41,12 +39,9 @@ int usbdev_free(SimDevice* this)
case USBDEV_TACHOMETER :
tachdev_free(usbdevice);
break;
case USBDEV_WHEEL :
case USBDEV_WHEEL_OR_PEDALS :
wheeldev_free(usbdevice);
break;
case USBDEV_GENERICHAPTIC :
usbhapticdev_free(&usbdevice->u.hapticdevice);
break;
}
free(usbdevice);
@@ -66,53 +61,56 @@ int usbdev_init(USBDevice* usbdevice, DeviceSettings* ds, SimInfo* siminfo)
case USBDEV_TACHOMETER :
error = tachdev_init(usbdevice, ds);
break;
case USBDEV_WHEEL :
case USBDEV_WHEEL_OR_PEDALS :
error = wheeldev_init(usbdevice, ds);
break;
case USBDEV_GENERICHAPTIC :
error = usbhapticdev_init(&usbdevice->u.hapticdevice, ds, siminfo);
break;
}
return error;
}
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* this = (USBDevice*) malloc(sizeof(USBDevice));
int error = 0;
this->m.update = &update;
this->m.free = &simdevfree;
this->m.derived = this;
this->m.vtable = &usb_simdevice_vtable;
// TODO: turn this into a switch when we get more devices
this->type = USBDEV_TACHOMETER;
if(ds->dev_subtype == SIMDEVTYPE_USBWHEEL)
{
this->type = USBDEV_WHEEL;
this->type = USBDEV_WHEEL_OR_PEDALS;
this->m.vtable = &usb_wheeldevice_vtable;
}
// 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)
if(ds->has_haptic_effects == true)
{
this->m.hapticeffect.threshold = ds->threshold;
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->type = USBDEV_GENERICHAPTIC;
if(siminfo->SimSupportsHapticEffects == false)
{
// if the user added haptic effects to the config and the sim does not support it, but still wishes to use features
// just remove the haptic effect from the config?
slogi("This sim does not support haptic effects");
error = MONOCOQUE_ERROR_UNSUPPORTED_SIM_FEATURE;
}
else
{
int error = 0;
this->type = USBDEV_WHEEL_OR_PEDALS;
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)
{
+20 -24
View File
@@ -7,6 +7,7 @@
#include "hapticeffect.h"
#include "usb/cslelitev3.h"
#include "usb/simagicp1000.h"
#include "usb/simnetpedals.h"
#include "../../helper/confighelper.h"
#include "../../simulatorapi/simapi/simapi/simdata.h"
@@ -16,7 +17,7 @@
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)
{
@@ -27,10 +28,13 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat
switch ( usbhapticdevice->type )
{
case USBHAPTIC_CSLELITEV3PEDALS:
cslelitev3_update(usbhapticdevice, usbhapticdevice->effecttype, rplay);
cslelitev3_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
break;
case USBHAPTIC_SIMAGICP1000PEDALS:
simagicp1000_update(usbhapticdevice, usbhapticdevice->effecttype, rplay);
simagicp1000_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
break;
case USBHAPTIC_SIMNETPEDALS:
simnetpedals_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
break;
}
}
@@ -39,10 +43,13 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat
switch ( usbhapticdevice->type )
{
case USBHAPTIC_CSLELITEV3PEDALS:
cslelitev3_update(usbhapticdevice, usbhapticdevice->effecttype, rplay);
cslelitev3_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
break;
case USBHAPTIC_SIMAGICP1000PEDALS:
simagicp1000_update(usbhapticdevice, usbhapticdevice->effecttype, rplay);
simagicp1000_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
break;
case USBHAPTIC_SIMNETPEDALS:
simnetpedals_update(usbhapticdevice, this->hapticeffect.effecttype, rplay);
break;
}
}
@@ -62,6 +69,9 @@ int usbhapticdev_free(USBGenericHapticDevice* usbhapticdevice)
case USBHAPTIC_SIMAGICP1000PEDALS:
simagicp1000_free(usbhapticdevice);
break;
case USBHAPTIC_SIMNETPEDALS:
simnetpedals_free(usbhapticdevice);
break;
}
return 0;
@@ -76,25 +86,7 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
}
int error = 0;
usbhapticdevice->state = 0;
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;
}
initializeHapticEffect(&this->m.hapticeffect, &ds->hapticsettings, ms);
slogi("initializing standalone usb haptic device...");
// detection of usb device model
@@ -107,6 +99,10 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d
usbhapticdevice->type = USBHAPTIC_CSLELITEV3PEDALS;
error = cslelitev3_init(usbhapticdevice);
break;
case (SIMDEVSUBTYPE_SIMNETPEDALS):
usbhapticdevice->type = USBHAPTIC_SIMNETPEDALS;
error = simnetpedals_init(usbhapticdevice);
break;
default:
slogw("Possibly unknown device");
}
+2 -7
View File
@@ -10,19 +10,14 @@ typedef enum
{
USBHAPTIC_UNKNOWN = 0,
USBHAPTIC_CSLELITEV3PEDALS = 1,
USBHAPTIC_SIMAGICP1000PEDALS = 2
USBHAPTIC_SIMAGICP1000PEDALS = 2,
USBHAPTIC_SIMNETPEDALS = 3
}
HapticType;
typedef struct
{
int id;
HapticType type;
double state;
double threshold;
int value0;
int value1;
VibrationEffectType effecttype;
FILE* filehandle;
hid_device* handle;
char* dev;
+80 -7
View File
@@ -2,20 +2,73 @@
#include <stdlib.h>
#include <string.h>
#include "usb/wheels/logitechg29.h"
#include "usb/wheels/cammusc5.h"
#include "usb/wheels/cammusc12.h"
#include "usb/wheels/gtneo.h"
#include "serial/moza.h"
#include "usb/cslelitev3.h"
#include "usb/simagicp1000.h"
#include "usb/simnetpedals.h"
#include "simdevice.h"
#include "../helper/confighelper.h"
#include "../simulatorapi/simapi/simapi/simdata.h"
#include "../slog/slog.h"
int wheeldev_update(USBDevice* usbdevice, SimData* simdata)
int wheelhapticdev_update(SimDevice* this, SimData* simdata)
{
USBDevice* usbdevice = (void *) this->derived;
WheelDevice* wheeldevice = &usbdevice->u.wheeldevice;
double play = slipeffect(simdata, &this->hapticeffect, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig);
if (play != usbdevice->hapticstate)
{
int rplay = 0;
if(play > 0)
{
rplay = 1;
switch ( wheeldevice->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 ( wheeldevice->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;
switch ( wheeldevice->type )
{
case WHEELDEV_UNKNOWN :
@@ -72,6 +125,15 @@ int wheeldev_free(USBDevice* usbdevice)
free(usbdevice->m.device_specific_config_file);
}
break;
case WHEELDEV_CSLELITEV3PEDALS:
cslelitev3_free(usbdevice);
break;
case WHEELDEV_SIMAGICP1000PEDALS:
simagicp1000_free(usbdevice);
break;
case WHEELDEV_SIMNETPEDALS:
simnetpedals_free(usbdevice);
break;
}
return 0;
@@ -79,8 +141,9 @@ int wheeldev_free(USBDevice* usbdevice)
int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds)
{
slogi("initializing wheel device...");
slogi("initializing wheel or pedals device...");
int error = 0;
usbdevice->hapticstate = 0;
// detection of wheel model
WheelDevice* wheeldevice = &usbdevice->u.wheeldevice;
switch (ds->dev_subsubtype) {
@@ -138,11 +201,21 @@ int wheeldev_init(USBDevice* usbdevice, DeviceSettings* ds)
error = -1;
}
break;
default:
wheeldevice->type = WHEELDEV_UNKNOWN;
slogw("Unknown cammus wheel detected, trying C5");
error = cammusc5_init(usbdevice);
case (SIMDEVSUBTYPE_SIMAGICP1000PEDALS):
wheeldevice->type = WHEELDEV_SIMAGICP1000PEDALS;
error = simagicp1000_init(usbdevice);
break;
case (SIMDEVSUBTYPE_CSLELITEV3PEDALS):
slogi("Attempting to initialize CSL Elite V3 Pedals");
wheeldevice->type = WHEELDEV_CSLELITEV3PEDALS;
error = cslelitev3_init(usbdevice);
break;
case (SIMDEVSUBTYPE_SIMNETPEDALS):
wheeldevice->type = WHEELDEV_SIMNETPEDALS;
error = simnetpedals_init(usbdevice);
break;
default:
slogw("Possibly unknown wheel device");
}
+9 -6
View File
@@ -8,12 +8,15 @@
typedef enum
{
WHEELDEV_UNKNOWN = 0,
WHEELDEV_CAMMUSC5 = 1,
WHEELDEV_CAMMUSC12 = 2,
WHEELDEV_MOZAR5 = 3,
WHEELDEV_SIMAGICGTNEO = 4,
WHEELDEV_LOGITECHG29 = 5
WHEELDEV_UNKNOWN = 0,
WHEELDEV_CAMMUSC5 = 1,
WHEELDEV_CAMMUSC12 = 2,
WHEELDEV_MOZAR5 = 3,
WHEELDEV_SIMAGICGTNEO = 4,
WHEELDEV_LOGITECHG29 = 5,
WHEELDEV_CSLELITEV3PEDALS = 6,
WHEELDEV_SIMAGICP1000PEDALS = 7,
WHEELDEV_SIMNETPEDALS = 8
}
WheelType;
+4
View File
@@ -737,6 +737,10 @@ int tester(SimDevice* devices, int numdevices)
simdata->tyrediameter[1] = -1;
simdata->tyrediameter[2] = -1;
simdata->tyrediameter[3] = -1;
simdata->tyreslipratio[0] = 0;
simdata->tyreslipratio[1] = 0;
simdata->tyreslipratio[2] = 0;
simdata->tyreslipratio[3] = 0;
simdata->Xvelocity = 0;
simdata->Yvelocity = 100;
simdata->Zvelocity = 0;
+141 -114
View File
@@ -37,35 +37,35 @@ int strtoeffecttype(const char* effect, DeviceSettings* ds)
if (strcicmp(effect, "Engine") == 0)
{
ds->is_valid = true;
ds->effect_type = EFFECT_ENGINERPM;
ds->hapticsettings.effect_type = EFFECT_ENGINERPM;
}
if (strcicmp(effect, "Gear") == 0)
{
ds->is_valid = true;
ds->effect_type = EFFECT_GEARSHIFT;
ds->hapticsettings.effect_type = EFFECT_GEARSHIFT;
}
if (strcicmp(effect, "Suspension") == 0)
{
ds->is_valid = true;
ds->effect_type = EFFECT_SUSPENSION;
ds->hapticsettings.effect_type = EFFECT_SUSPENSION;
}
if (strcicmp(effect, "ABS") == 0)
{
ds->is_valid = true;
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))
{
ds->is_valid = true;
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))
{
ds->is_valid = true;
slogt("found tyreslock effect set");
ds->effect_type = EFFECT_TYRELOCK;
ds->hapticsettings.effect_type = EFFECT_TYRELOCK;
}
if (ds->is_valid == false)
@@ -128,6 +128,11 @@ int strtodevsubsubtype(const char* device_subsubtype, DeviceSettings* ds)
ds->dev_subsubtype = SIMDEVSUBTYPE_CSLELITEV3PEDALS;
devfound = true;
}
if (strcicmp(device_subsubtype, "SIMNETPEDALS") == 0)
{
ds->dev_subsubtype = SIMDEVSUBTYPE_SIMNETPEDALS;
devfound = true;
}
if (strcicmp(device_subsubtype, "SIMAGICP1000PEDALS") == 0)
{
ds->dev_subsubtype = SIMDEVSUBTYPE_SIMAGICP1000PEDALS;
@@ -586,31 +591,31 @@ int gettyre(config_setting_t* device_settings, DeviceSettings* ds) {
const char* temp;
int found = config_setting_lookup_string(device_settings, "tyre", &temp);
ds->tyre = ALLFOUR;
ds->hapticsettings.tyre = ALLFOUR;
if (strcicmp(temp, "FRONTS") == 0)
{
ds->tyre = FRONTS;
ds->hapticsettings.tyre = FRONTS;
}
if (strcicmp(temp, "REARS") == 0)
{
ds->tyre = REARS;
ds->hapticsettings.tyre = REARS;
}
if (strcicmp(temp, "FRONTLEFT") == 0)
{
ds->tyre = FRONTLEFT;
ds->hapticsettings.tyre = FRONTLEFT;
}
if (strcicmp(temp, "FRONTRIGHT") == 0)
{
ds->tyre = FRONTRIGHT;
ds->hapticsettings.tyre = FRONTRIGHT;
}
if (strcicmp(temp, "REARLEFT") == 0)
{
ds->tyre = REARLEFT;
ds->hapticsettings.tyre = REARLEFT;
}
if (strcicmp(temp, "REARRIGHT") == 0)
{
ds->tyre = REARRIGHT;
ds->hapticsettings.tyre = REARRIGHT;
}
}
@@ -720,110 +725,15 @@ 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)
if (ds->dev_type == SIMDEV_USB)
{
// 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)
if (device_settings != NULL)
{
b = strtodevsubsubtype(temp, ds);
}
}
if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_type == SIMDEV_SOUND || ds->dev_subtype == SIMDEVTYPE_SERIALHAPTIC)
{
slogt("analysing haptic effect settings");
const char* effect;
config_setting_lookup_string(device_settings, "effect", &effect);
strtoeffecttype(effect, ds);
if (ds->effect_type == EFFECT_TYRESLIP || ds->effect_type == EFFECT_TYRELOCK || ds->effect_type == EFFECT_ABSBRAKES || ds->effect_type == EFFECT_SUSPENSION )
{
gettyre(device_settings, ds);
ds->threshold = 0;
int found = config_setting_lookup_float(device_settings, "threshold", &ds->threshold);
}
if (ds->dev_type == SIMDEV_SOUND)
{
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.pan = 0;
ds->sounddevsettings.channels = 1;
ds->sounddevsettings.duration = 2.0;
ds->sounddevsettings.noise = 0;
if (ds->effect_type == EFFECT_GEARSHIFT)
const char* temp;
int found = config_setting_lookup_string(device_settings, "subtype", &temp);
if(temp != NULL && found > 0)
{
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, "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, "channels", &ds->sounddevsettings.channels);
config_setting_lookup_float(device_settings, "duration", &ds->sounddevsettings.duration);
config_setting_lookup_int(device_settings, "noise", &ds->sounddevsettings.noise);
const char* temp = NULL;
int found = 0;
found = config_setting_lookup_string(device_settings, "devid", &temp);
if (found == CONFIG_FALSE)
{
ds->sounddevsettings.dev = NULL;
}
else
{
if(temp != NULL)
{
ds->sounddevsettings.dev = strdup(temp);
}
}
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;
}
}
strtodevsubsubtype(temp, ds);
}
}
}
@@ -881,6 +791,123 @@ 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_type == SIMDEV_SOUND || ds->dev_subtype == SIMDEVTYPE_SERIALHAPTIC)
{
slogt("analysing haptic effect settings");
ds->has_haptic_effects = true;
const char* effect;
config_setting_lookup_string(device_settings, "effect", &effect);
strtoeffecttype(effect, ds);
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);
ds->threshold = 0;
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)
{
slogi("reading configured sound device settings");
ds->sounddevsettings.volume = 0;
ds->sounddevsettings.pan = 0;
ds->sounddevsettings.channels = 1;
ds->sounddevsettings.noise = 0;
if (ds->hapticsettings.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, "pan", &ds->sounddevsettings.pan);
config_setting_lookup_int(device_settings, "channels", &ds->sounddevsettings.channels);
config_setting_lookup_int(device_settings, "noise", &ds->sounddevsettings.noise);
const char* temp = NULL;
int found = 0;
found = config_setting_lookup_string(device_settings, "devid", &temp);
if (found == CONFIG_FALSE)
{
ds->sounddevsettings.dev = NULL;
}
else
{
if(temp != NULL)
{
ds->sounddevsettings.dev = strdup(temp);
}
}
}
}
}
return error;
}
+31 -12
View File
@@ -46,7 +46,8 @@ typedef enum
SIMDEVSUBTYPE_SIMAGICGTNEO = 6,
SIMDEVSUBTYPE_MOZA_NEW = 7,
SIMDEVSUBTYPE_LOGITECH_G29 = 8,
SIMDEVSUBTYPE_MOZA_KS_PRO_WHEEL = 9
SIMDEVSUBTYPE_MOZA_KS_PRO_WHEEL = 9,
SIMDEVSUBTYPE_SIMNETPEDALS = 10
}
DeviceSubSubType;
@@ -73,6 +74,14 @@ typedef enum
}
VibrationEffectType;
typedef enum
{
EFFECT_MODULATION_NONE = 0,
EFFECT_MODULATION_FREQUENCY = 1,
EFFECT_MODULATION_AMPLIFY = 2,
}
EffectModulationType;
typedef enum
{
MOTOR_1 = 0,
@@ -176,26 +185,35 @@ SerialDeviceSettings;
typedef struct
{
uint32_t frequency;
uint32_t volume;
int lowbound_frequency;
int upperbound_frequency;
uint32_t frequencyMax;
uint32_t amplitudeMax;
uint32_t amplitude;
int pan;
int channels;
double duration;
char* dev;
SoundEffectModulationType modulation;
int noise;
}
SoundDeviceSettings;
typedef struct
{
int value0;
int value1;
uint32_t frequency;
uint32_t amplitude;
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;
}
USBDeviceSettings;
@@ -207,14 +225,15 @@ typedef struct
DeviceType dev_type;
DeviceSubType dev_subtype;
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
// any device settings member structure that can carry an effect
VibrationEffectType effect_type;
MonocoqueTyreIdentifier tyre;
double threshold;
bool has_config;
char* specific_config_file;
// union?
HapticEffectSettings hapticsettings;
TachometerSettings tachsettings;
SerialDeviceSettings serialdevsettings;
SoundDeviceSettings sounddevsettings;
@@ -40,7 +40,6 @@ set(simulatorapi_source_files
simapi/simapi/mapping/wreckfest2mapper.c
simapi/simapi/mapping/forzamapper.c
simapi/simapi/getpid.c
simapi/simapi/getpid.h
)
add_library(simulatorapi STATIC ${simulatorapi_source_files})
+6 -4
View File
@@ -122,6 +122,8 @@ if ! distrobox list 2>/dev/null | grep -q "$CONTAINER"; then
distrobox create \
--image docker.io/library/archlinux:latest \
--name "$CONTAINER" \
--root \
--additional-flags "--privileged --security-opt seccomp=unconfined" \
--pre-init-hooks "sed -i 's/^SigLevel.*/SigLevel = Never/' /etc/pacman.conf && pacman -Sy --noconfirm archlinux-keyring && pacman-key --init && pacman-key --populate archlinux && sed -i 's/^SigLevel.*/SigLevel = Required DatabaseOptional/' /etc/pacman.conf"
log_success "Container '$CONTAINER' created"
else
@@ -130,7 +132,7 @@ fi
# Install packages inside the container
log_info "Installing packages inside container (this may take a few minutes)..."
distrobox enter "$CONTAINER" -- bash -c '
distrobox enter --root "$CONTAINER" -- bash -c '
set -euo pipefail
# Install build dependencies
@@ -181,19 +183,19 @@ mkdir -p "$BIN_DIR"
cat > "$BIN_DIR/start-simd" << 'EOF'
#!/usr/bin/env bash
exec distrobox enter simracing -- simd "$@"
exec distrobox enter --root simracing -- simd "$@"
EOF
chmod +x "$BIN_DIR/start-simd"
cat > "$BIN_DIR/start-monocoque" << 'EOF'
#!/usr/bin/env bash
exec distrobox enter simracing -- monocoque play "$@"
exec distrobox enter --root simracing -- monocoque play "$@"
EOF
chmod +x "$BIN_DIR/start-monocoque"
cat > "$BIN_DIR/test-monocoque" << 'EOF'
#!/usr/bin/env bash
exec distrobox enter simracing -- monocoque test -vv "$@"
exec distrobox enter --root simracing -- monocoque test -vv "$@"
EOF
chmod +x "$BIN_DIR/test-monocoque"
@@ -72,9 +72,9 @@ if [ -d "$INSTALL_DIR" ]; then
fi
# Remove distrobox container
if distrobox list 2>/dev/null | grep -q "$CONTAINER"; then
if distrobox list --root 2>/dev/null | grep -q "$CONTAINER"; then
log_info "Removing distrobox container '$CONTAINER'..."
distrobox rm --force "$CONTAINER"
distrobox rm --root --force "$CONTAINER"
log_success "Container '$CONTAINER' removed"
else
log_info "Container '$CONTAINER' not found, skipping"