Fix issue with bad data being send to cammus wheel on quit

This commit is contained in:
Paul Dino Jones 2024-08-05 17:08:23 -04:00
parent 3bcf2ee87e
commit aff76a3dd9
2 changed files with 18 additions and 9 deletions

View File

@ -27,10 +27,14 @@ int cammusc5_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int
// byte 2 is number of lit leds, assuming 9 available leds, // byte 2 is number of lit leds, assuming 9 available leds,
// if we send 10, all leds will blink singling a gear change // if we send 10, all leds will blink singling a gear change
// attempting to build in a margin before the maxrpm is achieved // attempting to build in a margin before the maxrpm is achieved
int litleds = 0;
if(rpm > 0 && maxrpm > 0)
{
int rpmmargin = ceil(.05*maxrpm); int rpmmargin = ceil(.05*maxrpm);
int rpminterval = (maxrpm-rpmmargin) / (num_avail_leds+1); int rpminterval = (maxrpm-rpmmargin) / (num_avail_leds+1);
int litleds = 0;
for (int l = 1; l <= (num_avail_leds+1); l++) for (int l = 1; l <= (num_avail_leds+1); l++)
{ {
if(rpm >= (rpminterval * l)) if(rpm >= (rpminterval * l))
@ -38,6 +42,7 @@ int cammusc5_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int
litleds = l; litleds = l;
} }
} }
}
bytes[1] = litleds; bytes[1] = litleds;
// bytes 2 and 3 are a 16 bit velocity // bytes 2 and 3 are a 16 bit velocity
@ -48,10 +53,12 @@ int cammusc5_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int
} }
// byte 4 is gear // byte 4 is gear
if(gear > 0)
{
bytes[4] = gear-1; bytes[4] = gear-1;
}
slogt("writing bytes %x%x%x%x%x from rpm %i velocity %i gear %i", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], rpm, velocity, gear); slogt("writing bytes x%02xx%02xx%02xx%02xx%02x from rpm %i velocity %i gear %i", bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], rpm, velocity, gear);
if (wheeldevice->handle) if (wheeldevice->handle)
{ {
res = hid_write(wheeldevice->handle, bytes, cammusc5_hidupdate_buf_size); res = hid_write(wheeldevice->handle, bytes, cammusc5_hidupdate_buf_size);

View File

@ -223,6 +223,7 @@ int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdat
simdata->velocity = 0; simdata->velocity = 0;
simdata->rpms = 100; simdata->rpms = 100;
simdata->gear = -1;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{ {
if (devices[x].initialized == true) if (devices[x].initialized == true)
@ -542,6 +543,7 @@ int tester(SimDevice* devices, int numdevices)
simdata->velocity = 0; simdata->velocity = 0;
simdata->rpms = 100; simdata->rpms = 100;
simdata->gear = -1;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{ {
if (devices[x].initialized == true) if (devices[x].initialized == true)