未验证 提交 084a7d8a 编写于 作者: R Rich Lander 提交者: GitHub

Remove space (#1275)

* Remove space

* Fix Mcp3xxx switch condition causing the build to break

* Fix other switch statements that were changed incorrectly
Co-authored-by: NJose Perez Rodriguez <joperezr@microsoft.com>
上级 0b7733e5
......@@ -508,13 +508,26 @@ namespace Iot.Device.Card.Mifare
/// </summary>
/// <param name="blockNumber">Input block number</param>
/// <returns>True if it is a sector block</returns>
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;
}
}
}
/// <summary>
/// Depending on the command, serialize the needed data
......
......@@ -119,18 +119,26 @@ namespace Iot.Device.GrovePiDevice
/// <returns></returns>
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];
......
......@@ -45,22 +45,47 @@ namespace Iot.Device.Mcp3428
{
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)
......
......@@ -129,24 +129,47 @@ namespace Iot.Device.Adc
/// <returns>A value corresponding to relative voltage level on specified device channel</returns>
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
......
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册