public async Task<bool> SetupSensors()
{
bool retval = true;
for(int idxArduino = 0; idxArduino<2; idxArduino++)
{
bool needsetup = false;
for (int i=0; i<2; i++)
{
int port = idxArduino * 2 + i;
if (prevType[port] != (int)brickPi.Sensor[port].Type)
{
needsetup = true;
prevType[port] = (int)brickPi.Sensor[port].Type;
}
}
if (needsetup)
{
if (!isThreadRunning)
ThreadPool.RunAsync(async (iasyn) =>
{
bool ret = await BrickPiSetupSensors(idxArduino);
retval &= ret;
}, WorkItemPriority.High).AsTask().Wait();
else
{
bool ret = await BrickPiSetupSensors(idxArduino);
retval &= ret;
}
}
}
return retval;
}