diff --git a/src/devices/Card/Mifare/MifareCard.cs b/src/devices/Card/Mifare/MifareCard.cs
index 81b58a01dd..c3c9f6c9dc 100644
--- a/src/devices/Card/Mifare/MifareCard.cs
+++ b/src/devices/Card/Mifare/MifareCard.cs
@@ -508,13 +508,26 @@ public void SetCapacity(ushort ATAQ, byte SAK)
///
/// Input block number
/// True if it is a sector block
- public bool IsSectorBlock(byte blockNumber) => Capacity switch
+ public bool IsSectorBlock(byte blockNumber)
{
- MifareCardCapacity.Mifare300 | MifareCardCapacity.Mifare1K | MifareCardCapacity.Mifare2K => blockNumber % 4 == 3,
- MifareCardCapacity.Mifare4K when blockNumber < 128 => blockNumber % 4 == 3,
- MifareCardCapacity.Mifare4K => blockNumber % 16 == 15,
- _ => blockNumber % 4 == 3,
- };
+ switch (Capacity)
+ {
+ default:
+ case MifareCardCapacity.Mifare300:
+ case MifareCardCapacity.Mifare1K:
+ case MifareCardCapacity.Mifare2K:
+ return blockNumber % 4 == 3;
+ case MifareCardCapacity.Mifare4K:
+ if (blockNumber < 128)
+ {
+ return blockNumber % 4 == 3;
+ }
+ else
+ {
+ return blockNumber % 16 == 15;
+ }
+ }
+ }
///
/// Depending on the command, serialize the needed data
diff --git a/src/devices/GrovePi/GrovePi.cs b/src/devices/GrovePi/GrovePi.cs
index 96a50b5fb6..8615ab4d22 100644
--- a/src/devices/GrovePi/GrovePi.cs
+++ b/src/devices/GrovePi/GrovePi.cs
@@ -119,18 +119,26 @@ public void WriteCommand(GrovePiCommand command, GrovePort pin, byte param1, byt
///
public byte[]? ReadCommand(GrovePiCommand command, GrovePort pin)
{
- int numberBytesToRead = command switch
+ int numberBytesToRead = 0;
+ switch (command)
{
- GrovePiCommand.DigitalRead => 1,
- GrovePiCommand.AnalogRead | GrovePiCommand.UltrasonicRead | GrovePiCommand.LetBarGet => 3,
- GrovePiCommand.Version => 4,
- GrovePiCommand.DhtTemp => 9,
- _ => 0,
- };
-
- if (numberBytesToRead == 0)
- {
- return null;
+ case GrovePiCommand.DigitalRead:
+ numberBytesToRead = 1;
+ break;
+ case GrovePiCommand.AnalogRead:
+ case GrovePiCommand.UltrasonicRead:
+ case GrovePiCommand.LetBarGet:
+ numberBytesToRead = 3;
+ break;
+ case GrovePiCommand.Version:
+ numberBytesToRead = 4;
+ break;
+ case GrovePiCommand.DhtTemp:
+ numberBytesToRead = 9;
+ break;
+ // No other commands are for read
+ default:
+ return null;
}
byte[] outArray = new byte[numberBytesToRead];
diff --git a/src/devices/Mcp3428/Helpers.cs b/src/devices/Mcp3428/Helpers.cs
index 45127bb0d6..2ccfedfb0c 100644
--- a/src/devices/Mcp3428/Helpers.cs
+++ b/src/devices/Mcp3428/Helpers.cs
@@ -45,22 +45,47 @@ public static byte I2CAddressFromPins(PinState adr0, PinState adr1)
{
byte addr = 0b1101000; // Base value from doc
- int idx = (byte)adr0 << 4 + (byte)adr1;
+ var idx = (byte)adr0 << 4 + (byte)adr1;
- byte addr2 = idx switch
+ switch (idx)
{
- 0 | 0x22 => 0,
- 0x02 => 1,
- 0x01 => 2,
- 0x10 => 4,
- 0x12 => 5,
- 0x11 => 6,
- 0x20 => 3,
- 0x21 => 7,
- _ => throw new ArgumentException("Invalid combination"),
- };
-
- return addr += addr2;
+ case 0:
+ case 0x22:
+ break;
+
+ case 0x02:
+ addr += 1;
+ break;
+
+ case 0x01:
+ addr += 2;
+ break;
+
+ case 0x10:
+ addr += 4;
+ break;
+
+ case 0x12:
+ addr += 5;
+ break;
+
+ case 0x11:
+ addr += 6;
+ break;
+
+ case 0x20:
+ addr += 3;
+ break;
+
+ case 0x21:
+ addr += 7;
+ break;
+
+ default:
+ throw new ArgumentException("Invalid combination");
+ }
+
+ return addr;
}
public static byte SetChannelBits(byte configByte, int channel)
diff --git a/src/devices/Mcp3xxx/Mcp3xxx.cs b/src/devices/Mcp3xxx/Mcp3xxx.cs
index 947de20983..891f0dc319 100644
--- a/src/devices/Mcp3xxx/Mcp3xxx.cs
+++ b/src/devices/Mcp3xxx/Mcp3xxx.cs
@@ -129,24 +129,47 @@ public virtual int ReadDifferential(int valueChannel, int referenceChannel)
/// A value corresponding to relative voltage level on specified device channel
protected int ReadInternal(int channel, InputType inputType, int adcResolutionBits)
{
+ int channelVal;
+ int requestVal;
+
CheckChannelRange(channel, inputType == InputType.SingleEnded ? ChannelCount : ChannelCount / 2);
// create a value that represents the channel value. For differental inputs
// then incorporate the lower bit which indicates if the channel is inverted or not.
- int channelVal = inputType switch
+ switch (inputType)
{
- InputType.Differential | InputType.InvertedDifferential => channel * 2,
- _ =>channel,
- };
+ case InputType.Differential:
+ channelVal = channel * 2;
+ break;
+
+ case InputType.InvertedDifferential:
+ channelVal = channel * 2;
+ break;
+
+ default:
+ channelVal = channel;
+ break;
+ }
// create a value to represent the request to the ADC
- int requestVal = ChannelCount switch
+ switch (ChannelCount)
{
- 4 | 8 => (inputType == InputType.SingleEnded ? 0b1_1000 : 0b1_0000) | channelVal,
- 2 => (inputType == InputType.SingleEnded ? 0b1101 : 0b1001) | channelVal << 1,
- 1 => 0,
- _ => throw new ArgumentOutOfRangeException("Unsupported Channel Count"),
- };
+ case 4:
+ case 8:
+ requestVal = (inputType == InputType.SingleEnded ? 0b1_1000 : 0b1_0000) | channelVal;
+ break;
+
+ case 2:
+ requestVal = (inputType == InputType.SingleEnded ? 0b1101 : 0b1001) | channelVal << 1;
+ break;
+
+ case 1:
+ requestVal = 0;
+ break;
+
+ default:
+ throw new ArgumentOutOfRangeException("Unsupported Channel Count");
+ }
// read the data from the device...
// the delayBits is set to account for the extra sampling delay on the 3004, 3008, 3204, 3208, 3302 and 3304
diff --git a/src/devices/Pca9685/README.md b/src/devices/Pca9685/README.md
index 352a88dc01..4010cf5392 100644
--- a/src/devices/Pca9685/README.md
+++ b/src/devices/Pca9685/README.md
@@ -10,6 +10,6 @@ You can also use it to control servos.
https://www.nxp.com/docs/en/data-sheet/PCA9685.pdf
-## References
+## References
https://www.nxp.com/products/analog/interfaces/ic-bus/ic-led-controllers/16-channel-12-bit-pwm-fm-plus-ic-bus-led-controller:PCA9685