Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed "pin" type to uint to extend max pin number #1768

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Base/ComboBoxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ static public bool BindMobiFlightFreePins(ComboBox comboBox, List<MobiFlightPin>
// Deep-clone list as 'Used' list
List<MobiFlightPin> UsablePins = Pins.ConvertAll(pin => new MobiFlightPin(pin));
// Mark current pin (if any specified) as free
if (CurrentPin != "" && UsablePins.Exists(x => x.Pin == byte.Parse(CurrentPin))) {
UsablePins.Find(x => x.Pin == byte.Parse(CurrentPin)).Used = false;
if (CurrentPin != "" && UsablePins.Exists(x => x.Pin == uint.Parse(CurrentPin))) {
UsablePins.Find(x => x.Pin == uint.Parse(CurrentPin)).Used = false;
}

if (analogOnly == true)
Expand All @@ -96,7 +96,7 @@ static public bool BindMobiFlightFreePins(ComboBox comboBox, List<MobiFlightPin>

// Restore the original item selection (if any)
if (CurrentPin != "") {
var pinNo = byte.Parse(CurrentPin);
var pinNo = uint.Parse(CurrentPin);
try {
comboBox.SelectedValue = pinNo;
}
Expand Down Expand Up @@ -126,7 +126,7 @@ static public void reassignPin(string newPin, List<MobiFlightPin> pinList, ref s
}
static public void freePin(List<MobiFlightPin> pinList, string currentPin)
{
byte nBefore = byte.Parse(currentPin);
uint nBefore = uint.Parse(currentPin);
try {
MobiFlightPin p;
p = pinList.Find(x => x.Pin == nBefore);
Expand All @@ -145,7 +145,7 @@ static public void assignPin(List<MobiFlightPin> pinList, ref string newPin)
MobiFlightPin p = null;
if (newPin != "") {
// A desired pin is specified: seek it
byte newPinNo = byte.Parse(newPin);
uint newPinNo = uint.Parse(newPin);
p = pinList.Find(x => x.Pin == newPinNo);
if (p == null) throw new Exception("Nonexistent pin number");
}
Expand Down
68 changes: 34 additions & 34 deletions MobiFlight/MobiFlightModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,51 +1323,51 @@ public List<MobiFlightPin> GetPins(bool FreeOnly = false, bool ExcludeI2CDevices
List<MobiFlightPin> ResultPins = new List<MobiFlightPin>();
ResultPins.AddRange(Board.Pins.Select(x => new MobiFlightPin(x)));

List<byte> usedPins = new List<byte>();
List<uint> usedPins = new List<uint>();

foreach (Config.BaseDevice device in Config.Items)
{
String deviceName = device.Name;
switch (device.Type)
{
case DeviceType.LedModule:
usedPins.Add(Convert.ToByte((device as LedModule).ClkPin));
usedPins.Add(Convert.ToUInt32((device as LedModule).ClkPin));
if ((device as LedModule).ModelType == LedModule.MODEL_TYPE_MAX72xx)
{
if ((device as LedModule).ClsPin != "")
usedPins.Add(Convert.ToByte((device as LedModule).ClsPin));
usedPins.Add(Convert.ToUInt32((device as LedModule).ClsPin));
}
usedPins.Add(Convert.ToByte((device as LedModule).DinPin));
usedPins.Add(Convert.ToUInt32((device as LedModule).DinPin));
break;

case DeviceType.Stepper:
usedPins.Add(Convert.ToByte((device as Stepper).Pin1));
usedPins.Add(Convert.ToByte((device as Stepper).Pin2));
usedPins.Add(Convert.ToByte((device as Stepper).Pin3));
usedPins.Add(Convert.ToByte((device as Stepper).Pin4));
usedPins.Add(Convert.ToUInt32((device as Stepper).Pin1));
usedPins.Add(Convert.ToUInt32((device as Stepper).Pin2));
usedPins.Add(Convert.ToUInt32((device as Stepper).Pin3));
usedPins.Add(Convert.ToUInt32((device as Stepper).Pin4));

// We don't have to set the default 0 pin (for none auto zero)
if ((device as MobiFlight.Config.Stepper).BtnPin != "0")
usedPins.Add(Convert.ToByte((device as Stepper).BtnPin));
usedPins.Add(Convert.ToUInt32((device as Stepper).BtnPin));
break;

case DeviceType.Servo:
usedPins.Add(Convert.ToByte((device as Servo).DataPin));
usedPins.Add(Convert.ToUInt32((device as Servo).DataPin));
break;

case DeviceType.Button:
usedPins.Add(Convert.ToByte((device as Button).Pin));
usedPins.Add(Convert.ToUInt32((device as Button).Pin));
break;

case DeviceType.Encoder:
usedPins.Add(Convert.ToByte((device as Config.Encoder).PinLeft));
usedPins.Add(Convert.ToByte((device as Config.Encoder).PinRight));
usedPins.Add(Convert.ToUInt32((device as Config.Encoder).PinLeft));
usedPins.Add(Convert.ToUInt32((device as Config.Encoder).PinRight));
break;

case DeviceType.InputShiftRegister:
usedPins.Add(Convert.ToByte((device as InputShiftRegister).ClockPin));
usedPins.Add(Convert.ToByte((device as InputShiftRegister).DataPin));
usedPins.Add(Convert.ToByte((device as InputShiftRegister).LatchPin));
usedPins.Add(Convert.ToUInt32((device as InputShiftRegister).ClockPin));
usedPins.Add(Convert.ToUInt32((device as InputShiftRegister).DataPin));
usedPins.Add(Convert.ToUInt32((device as InputShiftRegister).LatchPin));
break;

case DeviceType.LcdDisplay:
Expand All @@ -1379,44 +1379,44 @@ public List<MobiFlightPin> GetPins(bool FreeOnly = false, bool ExcludeI2CDevices
// Statically add correct I2C pins
foreach (MobiFlightPin pin in Board.Pins.FindAll(x => x.isI2C))
{
if (usedPins.Contains(Convert.ToByte(pin.Pin))) continue;
usedPins.Add(Convert.ToByte(pin.Pin));
if (usedPins.Contains(Convert.ToUInt32(pin.Pin))) continue;
usedPins.Add(Convert.ToUInt32(pin.Pin));
}
break;

case DeviceType.Output:
usedPins.Add(Convert.ToByte((device as Output).Pin));
usedPins.Add(Convert.ToUInt32((device as Output).Pin));
break;

case DeviceType.AnalogInput:
usedPins.Add(Convert.ToByte((device as AnalogInput).Pin));
usedPins.Add(Convert.ToUInt32((device as AnalogInput).Pin));
break;

case DeviceType.ShiftRegister:
usedPins.Add(Convert.ToByte((device as ShiftRegister).ClockPin));
usedPins.Add(Convert.ToByte((device as ShiftRegister).LatchPin));
usedPins.Add(Convert.ToByte((device as ShiftRegister).DataPin));
usedPins.Add(Convert.ToUInt32((device as ShiftRegister).ClockPin));
usedPins.Add(Convert.ToUInt32((device as ShiftRegister).LatchPin));
usedPins.Add(Convert.ToUInt32((device as ShiftRegister).DataPin));
break;

case DeviceType.InputMultiplexer:
usedPins.Add(Convert.ToByte((device as InputMultiplexer).DataPin));
usedPins.Add(Convert.ToByte((device as InputMultiplexer).Selector.PinSx[0]));
usedPins.Add(Convert.ToByte((device as InputMultiplexer).Selector.PinSx[1]));
usedPins.Add(Convert.ToByte((device as InputMultiplexer).Selector.PinSx[2]));
usedPins.Add(Convert.ToByte((device as InputMultiplexer).Selector.PinSx[3]));
usedPins.Add(Convert.ToUInt32((device as InputMultiplexer).DataPin));
usedPins.Add(Convert.ToUInt32((device as InputMultiplexer).Selector.PinSx[0]));
usedPins.Add(Convert.ToUInt32((device as InputMultiplexer).Selector.PinSx[1]));
usedPins.Add(Convert.ToUInt32((device as InputMultiplexer).Selector.PinSx[2]));
usedPins.Add(Convert.ToUInt32((device as InputMultiplexer).Selector.PinSx[3]));
break;

case DeviceType.CustomDevice:
(device as CustomDevice).ConfiguredPins.ForEach(p => usedPins.Add(Convert.ToByte((p))));
(device as CustomDevice).ConfiguredPins.ForEach(p => usedPins.Add(Convert.ToUInt32((p))));
break;

// If the multiplexerDriver is to be handled as a regular device
// but explicitly defined by its own config line, following 'case' is required:
//case DeviceType.MultiplexerDriver:
// usedPins.Add(Convert.ToByte((device as MultiplexerDriver).PinSx[0]));
// usedPins.Add(Convert.ToByte((device as MultiplexerDriver).PinSx[1]));
// usedPins.Add(Convert.ToByte((device as MultiplexerDriver).PinSx[2]));
// usedPins.Add(Convert.ToByte((device as MultiplexerDriver).PinSx[3]));
// usedPins.Add(Convert.ToUInt32((device as MultiplexerDriver).PinSx[0]));
// usedPins.Add(Convert.ToUInt32((device as MultiplexerDriver).PinSx[1]));
// usedPins.Add(Convert.ToUInt32((device as MultiplexerDriver).PinSx[2]));
// usedPins.Add(Convert.ToUInt32((device as MultiplexerDriver).PinSx[3]));
// break;

default:
Expand All @@ -1425,7 +1425,7 @@ public List<MobiFlightPin> GetPins(bool FreeOnly = false, bool ExcludeI2CDevices
}

// Mark all the used pins as used in the result list.
foreach (byte pinNo in usedPins)
foreach (uint pinNo in usedPins)
{
MobiFlightPin pin = ResultPins.Find(resultPin => resultPin.Pin == pinNo);
if (pin != null) pin.Used = true;
Expand Down
2 changes: 1 addition & 1 deletion MobiFlight/MobiFlightPin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace MobiFlight
public class MobiFlightPin
{
[XmlAttribute]
public byte Pin { get; set; }
public uint Pin { get; set; }
[XmlAttribute]
public bool isAnalog = false;
[XmlAttribute]
Expand Down
2 changes: 1 addition & 1 deletion UI/Panels/Device/MFAnalogPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public MFAnalogPanel(MobiFlight.Config.AnalogInput analogDevice, List<MobiFlight

this.analog = analogDevice;

mfPinComboBox.SelectedValue = byte.Parse(analog.Pin);
mfPinComboBox.SelectedValue = uint.Parse(analog.Pin);
textBox1.Text = analog.Name;
SensitivityTrackBar.Value = byte.Parse(analog.Sensitivity);

Expand Down
2 changes: 1 addition & 1 deletion UI/Panels/Device/MFButtonPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public MFButtonPanel(MobiFlight.Config.Button button, List<MobiFlightPin> Pins):
ComboBoxHelper.BindMobiFlightFreePins(mfPinComboBox, Pins, button.Pin);

this.button = button;
mfPinComboBox.SelectedValue = byte.Parse(button.Pin);
mfPinComboBox.SelectedValue = uint.Parse(button.Pin);
textBox1.Text = button.Name;
////setValues();

Expand Down
2 changes: 1 addition & 1 deletion UI/Panels/Device/MFOutputPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void value_Changed(object sender, EventArgs e)
private bool isPwmPin()
{
bool result = false;
byte bPin = byte.Parse(mfPinComboBox.SelectedItem.ToString());
uint bPin = uint.Parse(mfPinComboBox.SelectedItem.ToString());
var pin = MobiFlightBoard.Pins.Find(x => (x.Pin == bPin));
return pin.isPWM;
}
Expand Down
2 changes: 1 addition & 1 deletion UI/Panels/Device/MFServoPanel.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion UI/Panels/Output/DisplayPinPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private void displayPinComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
pwmPinPanel.Enabled = pwmPinPanel.Visible
= Module.getPwmPins()
.Find(x => x.Pin == (byte)(item as MobiFlightOutput).Pin) != null;
.Find(x => x.Pin == (uint)(item as MobiFlightOutput).Pin) != null;
return;
}
}
Expand Down