Improve handling of devices referenced in config but not actually able to be used for some reason

This commit is contained in:
Paul Dino Jones 2024-06-27 20:20:13 +00:00
parent 8f4729c77a
commit 62e619780f
3 changed files with 59 additions and 17 deletions

View File

@ -38,7 +38,7 @@ int devinit(SimDevice* simdevices, int numdevices, DeviceSettings* ds, Monocoque
if (sim != NULL) if (sim != NULL)
{ {
simdevices[j] = sim->m; simdevices[j] = sim->m;
//simdevices[j].initialized = true; simdevices[j].initialized = true;
simdevices[j].type = SIMDEV_USB; simdevices[j].type = SIMDEV_USB;
simdevices[j].tyre = ds[j].tyre; simdevices[j].tyre = ds[j].tyre;
simdevices[j].useconfig = ms->useconfig; simdevices[j].useconfig = ms->useconfig;

View File

@ -202,9 +202,12 @@ int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdat
} }
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{
if (devices[x].initialized == true)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
}
if( poll(&mypoll, 1, 1000.0/update_rate) ) if( poll(&mypoll, 1, 1000.0/update_rate) )
{ {
@ -219,9 +222,12 @@ int clilooper(SimDevice* devices, int numdevices, Parameters* p, SimData* simdat
simdata->velocity = 0; simdata->velocity = 0;
simdata->rpms = 100; simdata->rpms = 100;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{
if (devices[x].initialized == true)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
}
fprintf(stdout, "\n"); fprintf(stdout, "\n");
@ -338,97 +344,133 @@ int tester(SimDevice* devices, int numdevices)
fprintf(stdout, "Setting rpms to 1000\n"); fprintf(stdout, "Setting rpms to 1000\n");
simdata->rpms = 1000; simdata->rpms = 1000;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{
if (devices[x].initialized == true)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
}
sleep(3); sleep(3);
fprintf(stdout, "Shifting into first gear\n"); fprintf(stdout, "Shifting into first gear\n");
simdata->gear = 2; simdata->gear = 2;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{
if (devices[x].initialized == true)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
}
sleep(3); sleep(3);
fprintf(stdout, "Setting speed to 100\n"); fprintf(stdout, "Setting speed to 100\n");
simdata->velocity = 100; simdata->velocity = 100;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{
if (devices[x].initialized == true)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
}
sleep(3); sleep(3);
fprintf(stdout, "Shifting into second gear\n"); fprintf(stdout, "Shifting into second gear\n");
simdata->gear = 3; simdata->gear = 3;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{
if (devices[x].initialized == true)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
}
sleep(3); sleep(3);
fprintf(stdout, "Setting speed to 200\n"); fprintf(stdout, "Setting speed to 200\n");
simdata->velocity = 200; simdata->velocity = 200;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{
if (devices[x].initialized == true)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
}
sleep(3); sleep(3);
fprintf(stdout, "Shifting into third gear\n"); fprintf(stdout, "Shifting into third gear\n");
simdata->gear = 4; simdata->gear = 4;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{
if (devices[x].initialized == true)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
}
sleep(3); sleep(3);
fprintf(stdout, "Setting rpms to 2000\n"); fprintf(stdout, "Setting rpms to 2000\n");
simdata->rpms = 2000; simdata->rpms = 2000;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{
if (devices[x].initialized == true)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
}
sleep(3); sleep(3);
fprintf(stdout, "Setting rpms to 4000\n"); fprintf(stdout, "Setting rpms to 4000\n");
simdata->rpms = 4000; simdata->rpms = 4000;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{
if (devices[x].initialized == true)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
}
sleep(3); sleep(3);
fprintf(stdout, "Shifting into fourth gear\n"); fprintf(stdout, "Shifting into fourth gear\n");
simdata->gear = 5; simdata->gear = 5;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{
if (devices[x].initialized == true)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
}
sleep(3); sleep(3);
fprintf(stdout, "Setting speed to 300\n"); fprintf(stdout, "Setting speed to 300\n");
simdata->velocity = 300; simdata->velocity = 300;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{
if (devices[x].initialized == true)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
}
sleep(3); sleep(3);
fprintf(stdout, "Setting rpms to 8000\n"); fprintf(stdout, "Setting rpms to 8000\n");
simdata->rpms = 8000; simdata->rpms = 8000;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{
if (devices[x].initialized == true)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
}
sleep(3); sleep(3);
simdata->velocity = 0; simdata->velocity = 0;
simdata->rpms = 100; simdata->rpms = 100;
for (int x = 0; x < numdevices; x++) for (int x = 0; x < numdevices; x++)
{
if (devices[x].initialized == true)
{ {
devices[x].update(&devices[x], simdata); devices[x].update(&devices[x], simdata);
} }
}
sleep(1); sleep(1);
fflush(stdout); fflush(stdout);

View File

@ -223,7 +223,7 @@ int main(int argc, char** argv)
pulseaudio = true; pulseaudio = true;
#endif #endif
error = looper(devices, initdevices, p); error = looper(devices, numdevices, p);
if (error == MONOCOQUE_ERROR_NONE) if (error == MONOCOQUE_ERROR_NONE)
{ {
slogi("Game loop exited succesfully with error code: %i", error); slogi("Game loop exited succesfully with error code: %i", error);
@ -242,7 +242,7 @@ int main(int argc, char** argv)
pulseaudio = true; pulseaudio = true;
#endif #endif
error = tester(devices, initdevices); error = tester(devices, numdevices);
if (error == MONOCOQUE_ERROR_NONE) if (error == MONOCOQUE_ERROR_NONE)
{ {
slogi("Test exited succesfully with error code: %i", error); slogi("Test exited succesfully with error code: %i", error);