From 45db6670c909a775e4cd4a43076ff9164f8d33ab Mon Sep 17 00:00:00 2001 From: Paul Dino Jones Date: Sat, 13 Jul 2024 14:21:35 -0400 Subject: [PATCH] Add ampfactor to control final motor power --- src/monocoque/devices/serialdevice.c | 4 +++- src/monocoque/devices/simdevice.h | 1 + src/monocoque/helper/confighelper.c | 12 ++++++++++++ src/monocoque/helper/confighelper.h | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/monocoque/devices/serialdevice.c b/src/monocoque/devices/serialdevice.c index f1723c4..b9da9d7 100644 --- a/src/monocoque/devices/serialdevice.c +++ b/src/monocoque/devices/serialdevice.c @@ -66,11 +66,12 @@ int arduino_simhaptic_update(SimDevice* this, SimData* simdata) double play = slipeffect(simdata, this->hapticeffect.effecttype, this->hapticeffect.tyre, this->hapticeffect.threshold, this->hapticeffect.useconfig, this->hapticeffect.configcheck, this->hapticeffect.tyrediameterconfig); double rplay = play; + play = play * serialdevice->ampfactor; if(play > 1.0) { play = 1.0; } - int effectspeed = ceil( 255 * play ); + int effectspeed = ceil(255 * play); int motor = serialdevice->motorsposition; @@ -161,6 +162,7 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms) { this->u.simhapticdata.effect3 = 0; this->u.simhapticdata.effect4 = 0; this->state = 0; + this->ampfactor = ds->serialdevsettings.ampfactor; slogi("Initializing arduino device for haptic effects."); break; } diff --git a/src/monocoque/devices/simdevice.h b/src/monocoque/devices/simdevice.h index f7fa705..1dba2cc 100644 --- a/src/monocoque/devices/simdevice.h +++ b/src/monocoque/devices/simdevice.h @@ -50,6 +50,7 @@ typedef struct SerialDeviceType devicetype; // move these two they only apply to the haptic device int motorsposition; + double ampfactor; double state; union { diff --git a/src/monocoque/helper/confighelper.c b/src/monocoque/helper/confighelper.c index 430c762..56d54c2 100644 --- a/src/monocoque/helper/confighelper.c +++ b/src/monocoque/helper/confighelper.c @@ -415,6 +415,18 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co int motorposition = 8; config_setting_lookup_int(device_settings, "motors", &motorposition); ds->serialdevsettings.motorsposition = motorposition; + + double ampfactor = 1.0; + ds->serialdevsettings.ampfactor = 1.0; + int found = config_setting_lookup_float(device_settings, "ampfactor", &factor); + if(found == 0) + { + ds->serialdevsettings.ampfactor = 1.0; + } + else + { + ds->serialdevsettings.ampfactor = ampfactor; + } } } diff --git a/src/monocoque/helper/confighelper.h b/src/monocoque/helper/confighelper.h index fc80197..d055d26 100644 --- a/src/monocoque/helper/confighelper.h +++ b/src/monocoque/helper/confighelper.h @@ -118,6 +118,7 @@ typedef struct { char* portdev; MotorPosition motorsposition; + float ampfactor; } SerialDeviceSettings;