From 9712396c6f0984ee2011f0a187510ec39cc61697 Mon Sep 17 00:00:00 2001 From: Paul Dino Jones Date: Mon, 1 Jun 2026 16:00:13 -0400 Subject: [PATCH] Add initial support for simnet pedals --- src/monocoque/devices/CMakeLists.txt | 2 + src/monocoque/devices/usb/simnetpedals.c | 87 ++++++++++++++++++++++++ src/monocoque/devices/usb/simnetpedals.h | 8 +++ src/monocoque/devices/usbhapticdevice.c | 17 +++++ src/monocoque/devices/usbhapticdevice.h | 6 +- src/monocoque/helper/confighelper.c | 14 ++++ src/monocoque/helper/confighelper.h | 6 +- 7 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 src/monocoque/devices/usb/simnetpedals.c create mode 100644 src/monocoque/devices/usb/simnetpedals.h diff --git a/src/monocoque/devices/CMakeLists.txt b/src/monocoque/devices/CMakeLists.txt index 28119df..57298d4 100644 --- a/src/monocoque/devices/CMakeLists.txt +++ b/src/monocoque/devices/CMakeLists.txt @@ -25,6 +25,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 diff --git a/src/monocoque/devices/usb/simnetpedals.c b/src/monocoque/devices/usb/simnetpedals.c new file mode 100644 index 0000000..0879211 --- /dev/null +++ b/src/monocoque/devices/usb/simnetpedals.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include + +#include "usbhapticdevice.h" + +#include "../../helper/confighelper.h" +#include "../slog/slog.h" + +#define SIMNETPEDALS_BUFSIZE 9 + +//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(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play) +{ + + 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] = usbhapticdevice->motorposition; + uint8_t motormultiple = usbhapticdevice->motorposition - 1; + if(usbhapticdevice->motorposition == 0x04) + { + motormultiple = 2; + } + bytes[3 + (motormultiple * 2)] = usbhapticdevice->frequency; + bytes[4 + (motormultiple * 2)] = usbhapticdevice->amplitude; + + + if (usbhapticdevice->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(usbhapticdevice->handle, bytes, SIMNETPEDALS_BUFSIZE); + } + else + { + slogd("no handle"); + } + + return res; +} + +int simnetpedals_free(USBGenericHapticDevice* usbhapticdevice) +{ + int res = 0; + + hid_close(usbhapticdevice->handle); + res = hid_exit(); + + return res; +} + +int simnetpedals_init(USBGenericHapticDevice* usbhapticdevice) +{ + slogi("initializing simnet pedals..."); + + int res = 0; + + res = hid_init(); + + usbhapticdevice->handle = hid_open(0xcafe, 0xa301, NULL); + + if (!usbhapticdevice->handle) + { + sloge("Could not find attached Simnet Pedals"); + res = hid_exit(); + return 1; + } + slogd("Found Simnet Pedals handle %i...", usbhapticdevice->handle); + return res; +} diff --git a/src/monocoque/devices/usb/simnetpedals.h b/src/monocoque/devices/usb/simnetpedals.h new file mode 100644 index 0000000..95d7413 --- /dev/null +++ b/src/monocoque/devices/usb/simnetpedals.h @@ -0,0 +1,8 @@ +#ifndef _SIMNETPEDALS_H +#define _SIMNETPEDALS_H + +int simnetpedals_update(USBGenericHapticDevice* usbhapticdevice, int effecttype, int play); +int simnetpedals_init(USBGenericHapticDevice* usbhapticdevice); +int simnetpedals_free(USBGenericHapticDevice* usbhapticdevice); + +#endif diff --git a/src/monocoque/devices/usbhapticdevice.c b/src/monocoque/devices/usbhapticdevice.c index 89db1b5..d93613b 100644 --- a/src/monocoque/devices/usbhapticdevice.c +++ b/src/monocoque/devices/usbhapticdevice.c @@ -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" @@ -32,6 +33,9 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat case USBHAPTIC_SIMAGICP1000PEDALS: simagicp1000_update(usbhapticdevice, usbhapticdevice->effecttype, rplay); break; + case USBHAPTIC_SIMNETPEDALS: + simnetpedals_update(usbhapticdevice, usbhapticdevice->effecttype, rplay); + break; } } else @@ -44,6 +48,9 @@ int usbhapticdev_update(USBGenericHapticDevice* usbhapticdevice, SimData* simdat case USBHAPTIC_SIMAGICP1000PEDALS: simagicp1000_update(usbhapticdevice, usbhapticdevice->effecttype, rplay); break; + case USBHAPTIC_SIMNETPEDALS: + simnetpedals_update(usbhapticdevice, usbhapticdevice->effecttype, rplay); + break; } } usbhapticdevice->state = play; @@ -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; @@ -107,6 +117,13 @@ int usbhapticdev_init(USBGenericHapticDevice* usbhapticdevice, DeviceSettings* d usbhapticdevice->type = USBHAPTIC_CSLELITEV3PEDALS; error = cslelitev3_init(usbhapticdevice); break; + case (SIMDEVSUBTYPE_SIMNETPEDALS): + usbhapticdevice->type = USBHAPTIC_SIMNETPEDALS; + usbhapticdevice->motorposition = ds->usbdevsettings.motorsposition; + usbhapticdevice->frequency = ds->usbdevsettings.frequency; + usbhapticdevice->amplitude = ds->usbdevsettings.amplitude; + error = simnetpedals_init(usbhapticdevice); + break; default: slogw("Possibly unknown device"); } diff --git a/src/monocoque/devices/usbhapticdevice.h b/src/monocoque/devices/usbhapticdevice.h index edcc4f0..31ce0ed 100644 --- a/src/monocoque/devices/usbhapticdevice.h +++ b/src/monocoque/devices/usbhapticdevice.h @@ -10,7 +10,8 @@ typedef enum { USBHAPTIC_UNKNOWN = 0, USBHAPTIC_CSLELITEV3PEDALS = 1, - USBHAPTIC_SIMAGICP1000PEDALS = 2 + USBHAPTIC_SIMAGICP1000PEDALS = 2, + USBHAPTIC_SIMNETPEDALS = 3 } HapticType; @@ -22,6 +23,9 @@ typedef struct double threshold; int value0; int value1; + uint32_t frequency; + uint32_t amplitude; + uint32_t motorposition; VibrationEffectType effecttype; FILE* filehandle; hid_device* handle; diff --git a/src/monocoque/helper/confighelper.c b/src/monocoque/helper/confighelper.c index d55aad1..c8eebc9 100644 --- a/src/monocoque/helper/confighelper.c +++ b/src/monocoque/helper/confighelper.c @@ -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; @@ -731,6 +736,15 @@ int devsetup(const char* device_type, const char* device_subtype, const char* co { b = strtodevsubsubtype(temp, ds); } + ds->usbdevsettings.frequency = 0; + ds->usbdevsettings.amplitude = 0; + ds->usbdevsettings.motorsposition = 0; + config_setting_lookup_int(device_settings, "frequency", &ds->usbdevsettings.frequency); + config_setting_lookup_int(device_settings, "amplitude", &ds->usbdevsettings.amplitude); + + int motorposition = 1; + config_setting_lookup_int(device_settings, "motors", &motorposition); + ds->usbdevsettings.motorsposition = motorposition; } if (ds->dev_subtype == SIMDEVTYPE_USBHAPTIC || ds->dev_type == SIMDEV_SOUND || ds->dev_subtype == SIMDEVTYPE_SERIALHAPTIC) diff --git a/src/monocoque/helper/confighelper.h b/src/monocoque/helper/confighelper.h index d0eb751..5e8bb8b 100644 --- a/src/monocoque/helper/confighelper.h +++ b/src/monocoque/helper/confighelper.h @@ -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; @@ -196,6 +197,9 @@ typedef struct { int value0; int value1; + uint32_t frequency; + uint32_t amplitude; + MotorPosition motorsposition; char* dev; } USBDeviceSettings;