Fix issue with bad data being send to cammus wheel on quit
This commit is contained in:
parent
3bcf2ee87e
commit
aff76a3dd9
|
|
@ -27,15 +27,20 @@ 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 rpmmargin = ceil(.05*maxrpm);
|
|
||||||
int rpminterval = (maxrpm-rpmmargin) / (num_avail_leds+1);
|
|
||||||
|
|
||||||
int litleds = 0;
|
int litleds = 0;
|
||||||
for (int l = 1; l <= (num_avail_leds+1); l++)
|
|
||||||
|
if(rpm > 0 && maxrpm > 0)
|
||||||
{
|
{
|
||||||
if(rpm >= (rpminterval * l))
|
int rpmmargin = ceil(.05*maxrpm);
|
||||||
|
int rpminterval = (maxrpm-rpmmargin) / (num_avail_leds+1);
|
||||||
|
|
||||||
|
|
||||||
|
for (int l = 1; l <= (num_avail_leds+1); l++)
|
||||||
{
|
{
|
||||||
litleds = l;
|
if(rpm >= (rpminterval * l))
|
||||||
|
{
|
||||||
|
litleds = l;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bytes[1] = litleds;
|
bytes[1] = litleds;
|
||||||
|
|
@ -48,10 +53,12 @@ int cammusc5_update(WheelDevice* wheeldevice, int maxrpm, int rpm, int gear, int
|
||||||
}
|
}
|
||||||
|
|
||||||
// byte 4 is gear
|
// byte 4 is gear
|
||||||
bytes[4] = gear-1;
|
if(gear > 0)
|
||||||
|
{
|
||||||
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);
|
bytes[4] = gear-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue