Skip to content

Commit

Permalink
Improve stability of test
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrawehr committed Dec 24, 2024
1 parent 36f9824 commit a46f801
Showing 1 changed file with 76 additions and 71 deletions.
147 changes: 76 additions & 71 deletions src/devices/Arduino/samples/ApiChecker/TestCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Device.Spi;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -77,9 +78,8 @@ private static int GetAnalogPin(ArduinoBoard board, int analogChannel)

private static void TestI2cBmp280(ArduinoBoard board)
{
var device = board.CreateI2cDevice(new I2cConnectionSettings(0, Bmp280.DefaultI2cAddress));

var bmp = new Bmp280(device);
using var device = board.CreateI2cDevice(new I2cConnectionSettings(0, Bmp280.DefaultI2cAddress));
using var bmp = new Bmp280(device);
bmp.StandbyTime = StandbyTime.Ms250;
bmp.SetPowerMode(Bmx280PowerMode.Normal);
Console.WriteLine("Device open");
Expand All @@ -91,8 +91,6 @@ private static void TestI2cBmp280(ArduinoBoard board)
Thread.Sleep(100);
}

bmp.Dispose();
device.Dispose();
Console.ReadKey();
Console.WriteLine();
}
Expand Down Expand Up @@ -220,73 +218,80 @@ internal bool Menu()
var key = Console.ReadKey();
Console.WriteLine();

switch (key.KeyChar)
try
{
case '1':
TestI2cBmp280(_board);
break;
case '2':
TestGpio();
break;
case '3':
TestInput();
break;
case '4':
TestEventsDirectWait();
break;
case '5':
TestEventsCallback();
break;
case '6':
TestPwm();
break;
case '7':
TestAnalogIn();
break;
case '8':
TestAnalogCallback(_board);
break;
case '9':
TestSpi(_board);
break;
case '0':
ScanDeviceAddressesOnI2cBus(_board);
break;
case 'h':
case 'H':
TestDht(_board);
break;
case 'b':
case 'B':
TestI2cBme680(_board);
break;
case 'f':
case 'F':
TestFrequency(_board);
break;
case 'a':
case 'A':
{
var test = new RgbLedTest(_board);
test.DoTest();
}

break;
case 'c':
case 'C':
ConfigurePins();
break;
case 'i':
case 'I':
BoardInformation();
break;
case 's':
case 'S':
SendBoardToSleep();
break;
case 'x':
case 'X':
return false;
switch (key.KeyChar)
{
case '1':
TestI2cBmp280(_board);
break;
case '2':
TestGpio();
break;
case '3':
TestInput();
break;
case '4':
TestEventsDirectWait();
break;
case '5':
TestEventsCallback();
break;
case '6':
TestPwm();
break;
case '7':
TestAnalogIn();
break;
case '8':
TestAnalogCallback(_board);
break;
case '9':
TestSpi(_board);
break;
case '0':
ScanDeviceAddressesOnI2cBus(_board);
break;
case 'h':
case 'H':
TestDht(_board);
break;
case 'b':
case 'B':
TestI2cBme680(_board);
break;
case 'f':
case 'F':
TestFrequency(_board);
break;
case 'a':
case 'A':
{
var test = new RgbLedTest(_board);
test.DoTest();
}

break;
case 'c':
case 'C':
ConfigurePins();
break;
case 'i':
case 'I':
BoardInformation();
break;
case 's':
case 'S':
SendBoardToSleep();
break;
case 'x':
case 'X':
return false;
}
}
catch (IOException x)
{
Console.WriteLine($"The command failed with the following error: {x.Message}");
}

return true;
Expand Down

0 comments on commit a46f801

Please sign in to comment.