Skip to content

Commit

Permalink
Merge pull request #2 from Ragot-Pierre/dev
Browse files Browse the repository at this point in the history
Improved UI handling of pins numbers over 255
  • Loading branch information
Ragot-Pierre committed May 31, 2023
2 parents 6f4988a + 7ed6c81 commit b9b0ec5
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 61 deletions.
10 changes: 5 additions & 5 deletions Base/ComboBoxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,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 as free
if (UsablePins.Exists(x => x.Pin == byte.Parse(CurrentPin)))
UsablePins.Find(x => x.Pin == byte.Parse(CurrentPin)).Used = false;
if (UsablePins.Exists(x => x.Pin == uint.Parse(CurrentPin)))
UsablePins.Find(x => x.Pin == uint.Parse(CurrentPin)).Used = false;

if (analogOnly == true)
{
Expand All @@ -79,7 +79,7 @@ static public bool BindMobiFlightFreePins(ComboBox comboBox, List<MobiFlightPin>
comboBox.ValueMember = "Pin";

// Restore the original item selection
comboBox.SelectedValue = byte.Parse(CurrentPin);
comboBox.SelectedValue = uint.Parse(CurrentPin);

return false;
}
Expand All @@ -91,8 +91,8 @@ static public void reassignPin(ComboBox comboBox, List<MobiFlightPin> pinList, r
// and the new one as used)
// - an updated pin list is associated to the ComboBox
string after = comboBox.SelectedItem.ToString();
byte nBefore = byte.Parse(signalPin);
byte nAfter = byte.Parse(after);
uint nBefore = uint.Parse(signalPin);
uint nAfter = uint.Parse(after);
try {
if (signalPin != after) {
// Pin 0 is used for the stepper.
Expand Down
66 changes: 33 additions & 33 deletions MobiFlight/MobiFlightModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public void Connect()
}

// Create Serial Port object
int baudRate = 115200;
int baudRate = 460800;
//baudRate = 57600;
_transportLayer = new SerialTransport()
//_transportLayer = new SerialPortManager
Expand Down Expand Up @@ -1246,47 +1246,47 @@ 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.ToByte((device as LedModule).ClsPin));
usedPins.Add(Convert.ToByte((device as LedModule).DinPin));
usedPins.Add(Convert.ToUInt32((device as LedModule).ClkPin));
usedPins.Add(Convert.ToUInt32((device as LedModule).ClsPin));
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 @@ -1298,40 +1298,40 @@ 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;

// 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 Down
36 changes: 18 additions & 18 deletions Properties/Settings.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/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 @@ -181,7 +181,7 @@ private void displayPinComboBox_SelectedIndexChanged(object sender, EventArgs e)
foreach (var item in Module.GetConnectedDevices(pin))
{
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

0 comments on commit b9b0ec5

Please sign in to comment.