From ea100ca2cf5fe485f729c6b4e63459693a87d97e Mon Sep 17 00:00:00 2001 From: Paul Dino Jones Date: Mon, 1 Jul 2024 22:45:54 +0000 Subject: [PATCH] Add haptic effect to serial haptic device type --- src/monocoque/devices/hapticeffect.h | 8 ++++++++ src/monocoque/devices/serialdevice.c | 9 +++++++++ src/monocoque/devices/simdevice.h | 2 ++ 3 files changed, 19 insertions(+) diff --git a/src/monocoque/devices/hapticeffect.h b/src/monocoque/devices/hapticeffect.h index c5bb89a..9667052 100644 --- a/src/monocoque/devices/hapticeffect.h +++ b/src/monocoque/devices/hapticeffect.h @@ -2,8 +2,16 @@ #define _HAPTICEFFECT_H #include +#include "../helper/confighelper.h" #include "../simulatorapi/simapi/simapi/simdata.h" +typedef struct +{ + double threshold; + VibrationEffectType effecttype; +} +HapticEffect; + int slipeffect(SimData* simdata, int effecttype, int tyre, double threshold, int useconfig, int* configcheck, char* configfile); #endif diff --git a/src/monocoque/devices/serialdevice.c b/src/monocoque/devices/serialdevice.c index 790c13b..3b30adb 100644 --- a/src/monocoque/devices/serialdevice.c +++ b/src/monocoque/devices/serialdevice.c @@ -6,6 +6,7 @@ #include "simdevice.h" #include "serialdevice.h" +#include "hapticeffect.h" #include "serial/arduino.h" #include "../helper/parameters.h" #include "../simulatorapi/simapi/simapi/simdata.h" @@ -59,6 +60,8 @@ int arduino_haptic_update(SimDevice* this, SimData* simdata) SerialDevice* serialdevice = (void *) this->derived; int result = 1; + int play = slipeffect(simdata, serialdevice->hapticeffect.effecttype, this->tyre, serialdevice->hapticeffect.threshold, this->useconfig, this->configcheck, this->tyrediameterconfig); + slogt("Updating arduino haptic device"); arduino_update(serialdevice, simdata, sizeof(SimData)); @@ -122,6 +125,12 @@ SerialDevice* new_serial_device(DeviceSettings* ds) { break; } + if(this->devicetype == ARDUINODEV__HAPTIC) + { + this->hapticeffect.threshold = ds->threshold; + this->hapticeffect.effecttype = ds->effect_type; + } + int error = serialdev_init(this, ds->serialdevsettings.portdev); if (error != 0) diff --git a/src/monocoque/devices/simdevice.h b/src/monocoque/devices/simdevice.h index dc0924d..7e03377 100644 --- a/src/monocoque/devices/simdevice.h +++ b/src/monocoque/devices/simdevice.h @@ -6,6 +6,7 @@ #include "usbdevice.h" #include "sounddevice.h" #include "serialdevice.h" +#include "hapticeffect.h" #include "../helper/confighelper.h" #include "../simulatorapi/simapi/simapi/simdata.h" @@ -50,6 +51,7 @@ typedef struct SerialType type; struct sp_port* port; SerialDeviceType devicetype; + HapticEffect hapticeffect; union { SimWindData simwinddata;