From 1ebffa9f634a042cee25791e0c617e55c3426824 Mon Sep 17 00:00:00 2001 From: Paul Dino Jones Date: Mon, 1 Jul 2024 15:23:46 +0000 Subject: [PATCH] Add basic support for arduino haptic motors --- src/monocoque/devices/serialdevice.c | 18 ++++++++++++++++++ src/monocoque/devices/serialdevice.h | 1 + src/monocoque/devices/simdevice.h | 1 + src/monocoque/helper/confighelper.c | 7 ++++++- src/monocoque/helper/confighelper.h | 3 ++- 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/monocoque/devices/serialdevice.c b/src/monocoque/devices/serialdevice.c index 312ce42..790c13b 100644 --- a/src/monocoque/devices/serialdevice.c +++ b/src/monocoque/devices/serialdevice.c @@ -54,6 +54,18 @@ int arduino_simwind_update(SimDevice* this, SimData* simdata) return result; } +int arduino_haptic_update(SimDevice* this, SimData* simdata) +{ + SerialDevice* serialdevice = (void *) this->derived; + int result = 1; + + slogt("Updating arduino haptic device"); + + arduino_update(serialdevice, simdata, sizeof(SimData)); + + return result; +} + int serialdev_free(SimDevice* this) { SerialDevice* serialdevice = (void *) this->derived; @@ -80,6 +92,7 @@ int serialdev_init(SerialDevice* serialdevice, const char* portdev) static const vtable serial_simdevice_vtable = { &serialdev_update, &serialdev_free }; static const vtable arduino_shiftlights_vtable = { &arduino_shiftlights_update, &serialdev_free }; static const vtable arduino_simwind_vtable = { &arduino_simwind_update, &serialdev_free }; +static const vtable arduino_haptic_vtable = { &arduino_haptic_update, &serialdev_free }; SerialDevice* new_serial_device(DeviceSettings* ds) { @@ -102,6 +115,11 @@ SerialDevice* new_serial_device(DeviceSettings* ds) { this->m.vtable = &arduino_simwind_vtable; slogi("Initializing arduino devices for sim wind."); break; + case (SIMDEVTYPE_SERIALHAPTIC): + this->devicetype = ARDUINODEV__HAPTIC; + this->m.vtable = &arduino_haptic_vtable; + slogi("Initializing arduino device for haptic effects."); + break; } int error = serialdev_init(this, ds->serialdevsettings.portdev); diff --git a/src/monocoque/devices/serialdevice.h b/src/monocoque/devices/serialdevice.h index f4c60d6..0df20a7 100644 --- a/src/monocoque/devices/serialdevice.h +++ b/src/monocoque/devices/serialdevice.h @@ -7,6 +7,7 @@ typedef enum { ARDUINODEV__SHIFTLIGHTS = 0, ARDUINODEV__SIMWIND = 1, + ARDUINODEV__HAPTIC = 2, } SerialDeviceType; diff --git a/src/monocoque/devices/simdevice.h b/src/monocoque/devices/simdevice.h index be8887b..dc0924d 100644 --- a/src/monocoque/devices/simdevice.h +++ b/src/monocoque/devices/simdevice.h @@ -60,6 +60,7 @@ SerialDevice; int arduino_shiftlights_update(SimDevice* this, SimData* simdata); int arduino_simwind_update(SimDevice* this, SimData* simdata); +int arduino_haptic_update(SimDevice* this, SimData* simdata); int serialdev_free(SimDevice* this); SerialDevice* new_serial_device(DeviceSettings* ds); diff --git a/src/monocoque/helper/confighelper.c b/src/monocoque/helper/confighelper.c index 1353a44..0fcf398 100644 --- a/src/monocoque/helper/confighelper.c +++ b/src/monocoque/helper/confighelper.c @@ -110,6 +110,11 @@ int strtodevsubtype(const char* device_subtype, DeviceSettings* ds, int simdev) ds->dev_subtype = SIMDEVTYPE_SIMWIND; break; } + if (strcicmp(device_subtype, "SerialHaptic") == 0 || strcicmp(device_subtype, "Haptic") == 0) + { + ds->dev_subtype = SIMDEVTYPE_SERIALHAPTIC; + break; + } case SIMDEV_SOUND: ds->is_valid = true; break; @@ -336,7 +341,7 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co // logic for different devices } - if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_type == SIMDEV_SOUND) { + if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_type == SIMDEV_SOUND || ds->dev_type == SIMDEVTYPE_SERIALHAPTIC ) { const char* effect; config_setting_lookup_string(device_settings, "effect", &effect); strtoeffecttype(effect, ds); diff --git a/src/monocoque/helper/confighelper.h b/src/monocoque/helper/confighelper.h index 97625c1..0fc6dea 100644 --- a/src/monocoque/helper/confighelper.h +++ b/src/monocoque/helper/confighelper.h @@ -24,7 +24,8 @@ typedef enum SIMDEVTYPE_TACHOMETER = 1, SIMDEVTYPE_USBHAPTIC = 2, SIMDEVTYPE_SHIFTLIGHTS = 3, - SIMDEVTYPE_SIMWIND = 4 + SIMDEVTYPE_SIMWIND = 4, + SIMDEVTYPE_SERIALHAPTIC = 5 } DeviceSubType;