Add basic support for arduino haptic motors

This commit is contained in:
Paul Dino Jones 2024-07-01 15:23:46 +00:00
parent 62e619780f
commit 1ebffa9f63
5 changed files with 28 additions and 2 deletions

View File

@ -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);

View File

@ -7,6 +7,7 @@ typedef enum
{
ARDUINODEV__SHIFTLIGHTS = 0,
ARDUINODEV__SIMWIND = 1,
ARDUINODEV__HAPTIC = 2,
}
SerialDeviceType;

View File

@ -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);

View File

@ -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);

View File

@ -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;