Update so multiple defined serial haptic effects do not conflict with eachother.

This commit is contained in:
Paul Dino Jones 2024-07-13 09:38:00 -04:00
parent 42d63ffe89
commit f3e7674aa7
2 changed files with 18 additions and 7 deletions

View File

@ -76,15 +76,23 @@ int arduino_simhaptic_update(SimDevice* this, SimData* simdata)
if (motor == 0 || motor == 4 || motor == 7 || motor == 8 || motor == 10 || motor == 11 || motor == 13 || motor == 14) if (motor == 0 || motor == 4 || motor == 7 || motor == 8 || motor == 10 || motor == 11 || motor == 13 || motor == 14)
{ {
serialdevice->u.simhapticdata.effect1 = effectspeed; if (play != serialdevice->state)
serialdevice->u.simhapticdata.motor1 = 1; {
slogt("Updating arduino haptic device speed motor speed %i on motor %i from original effect %f", serialdevice->u.simhapticdata.effect1, serialdevice->motorsposition, rplay); serialdevice->u.simhapticdata.effect1 = effectspeed;
serialdevice->u.simhapticdata.motor1 = 1;
slogt("Updating arduino haptic device speed motor speed %i on motor %i from original effect %f", serialdevice->u.simhapticdata.effect1, serialdevice->motorsposition, rplay);
serialdevice->state = play;
}
} }
if (motor == 2 || motor == 6 || motor == 8 || motor == 9 || motor == 10 || motor == 11 || motor == 12 || motor == 14) if (motor == 2 || motor == 6 || motor == 8 || motor == 9 || motor == 10 || motor == 11 || motor == 12 || motor == 14)
{ {
serialdevice->u.simhapticdata.effect3 = effectspeed; if (play != serialdevice->state)
serialdevice->u.simhapticdata.motor3 = 1; {
slogt("Updating arduino haptic device speed motor speed %i on motor %i from original effect %f", serialdevice->u.simhapticdata.effect3, serialdevice->motorsposition, rplay); serialdevice->u.simhapticdata.effect3 = effectspeed;
serialdevice->u.simhapticdata.motor3 = 1;
slogt("Updating arduino haptic device speed motor speed %i on motor %i from original effect %f", serialdevice->u.simhapticdata.effect3, serialdevice->motorsposition, rplay);
serialdevice->state = play;
}
} }
size_t size = sizeof(SimHapticData); size_t size = sizeof(SimHapticData);
@ -156,6 +164,7 @@ SerialDevice* new_serial_device(DeviceSettings* ds, MonocoqueSettings* ms) {
this->u.simhapticdata.effect2 = 0; this->u.simhapticdata.effect2 = 0;
this->u.simhapticdata.effect3 = 0; this->u.simhapticdata.effect3 = 0;
this->u.simhapticdata.effect4 = 0; this->u.simhapticdata.effect4 = 0;
this->state = 0;
slogi("Initializing arduino device for haptic effects."); slogi("Initializing arduino device for haptic effects.");
break; break;
} }

View File

@ -47,8 +47,10 @@ typedef struct
int id; int id;
SerialType type; SerialType type;
struct sp_port* port; struct sp_port* port;
int motorsposition;
SerialDeviceType devicetype; SerialDeviceType devicetype;
// move these two they only apply to the haptic device
int motorsposition;
double state;
union union
{ {
SimWindData simwinddata; SimWindData simwinddata;