diff --git a/LoraGamepad/Models/BtnConfig.cs b/LoraGamepad/Models/BtnConfig.cs new file mode 100644 index 0000000..e9c7b10 --- /dev/null +++ b/LoraGamepad/Models/BtnConfig.cs @@ -0,0 +1,66 @@ +using System.Drawing.Imaging; +using ReactiveUI; + +namespace LoraGamepad.Models; + +public class BtnConfig : ReactiveObject +{ + private bool _btnLeftUp; + private bool _btnRightUp; + private bool _btnRightDown; + + private bool _btnModel1; + private bool _btnModel2; + private bool _btnModel3; + private bool _btnModel4; + private bool _btnModel5; + private bool _btnModel6; + + public bool BtnModel1 + { + get => _btnModel1; + set => this.RaiseAndSetIfChanged(ref _btnModel1, value); + } + public bool BtnModel2 + { + get => _btnModel2; + set => this.RaiseAndSetIfChanged(ref _btnModel2, value); + } + public bool BtnModel3 + { + get => _btnModel3; + set => this.RaiseAndSetIfChanged(ref _btnModel3, value); + } + public bool BtnModel4 + { + get => _btnModel4; + set => this.RaiseAndSetIfChanged(ref _btnModel4, value); + } + public bool BtnModel5 + { + get => _btnModel5; + set => this.RaiseAndSetIfChanged(ref _btnModel5, value); + } + public bool BtnModel6 + { + get => _btnModel6; + set => this.RaiseAndSetIfChanged(ref _btnModel6, value); + } + public bool BtnLeftUp + { + get => _btnLeftUp; + set => this.RaiseAndSetIfChanged(ref _btnLeftUp, value); + } + public bool BtnRightUp + { + get => _btnRightUp; + set => this.RaiseAndSetIfChanged(ref _btnRightUp, value); + } + public bool BtnRightDown + { + get => _btnRightDown; + set => this.RaiseAndSetIfChanged(ref _btnRightDown, value); + } + + +} \ No newline at end of file diff --git a/LoraGamepad/Models/CrsfChMsg.cs b/LoraGamepad/Models/CrsfChMsg.cs index 96de29d..d46bf0e 100644 --- a/LoraGamepad/Models/CrsfChMsg.cs +++ b/LoraGamepad/Models/CrsfChMsg.cs @@ -30,7 +30,7 @@ public class CrsfChMsg // { // rs[i].CopyTo(ch,i); // } - + Console.WriteLine(BitConverter.ToString(raw)); ch[15] = ((raw[0 ] & 0xFF) << 3 ) + ((raw[1 ] & 0xE0) >> 5); //res: 5 ch[14] = ((raw[1 ] & 0x1F) << 6 ) + ((raw[2 ] & 0xFC) >> 2); //res: 3 ch[13] = ((raw[2 ] & 0x03) << 9 ) + ((raw[3 ] & 0xFF) << 1)+ ((raw[4 ] & 0x80) >> 7); diff --git a/LoraGamepad/Models/SliderConfig.cs b/LoraGamepad/Models/SliderConfig.cs index 7103cdd..ae5990f 100644 --- a/LoraGamepad/Models/SliderConfig.cs +++ b/LoraGamepad/Models/SliderConfig.cs @@ -10,6 +10,9 @@ public class SliderConfig : ReactiveObject private double _leftHorizonValue; private double _lefttVerticalValue; + private double _leftUpValue = 0; + private double _midLeftValue = 0; + private double _midRightValue = 0; public SliderConfig() { _rightHorizonValue = _rightVerticalValue = _leftHorizonValue = _lefttVerticalValue = 0; @@ -36,4 +39,19 @@ public class SliderConfig : ReactiveObject get => _lefttVerticalValue; set => this.RaiseAndSetIfChanged(ref _lefttVerticalValue, value); } + public double LeftUpValue + { + get => _leftUpValue; + set => this.RaiseAndSetIfChanged(ref _leftUpValue, value); + } + public double MidLeftValue + { + get => _midLeftValue; + set => this.RaiseAndSetIfChanged(ref _midLeftValue, value); + } + public double MidRightValue + { + get => _midRightValue; + set => this.RaiseAndSetIfChanged(ref _midRightValue, value); + } } \ No newline at end of file diff --git a/LoraGamepad/ViewModels/TProViewModel.cs b/LoraGamepad/ViewModels/TProViewModel.cs index 4575c07..1169aea 100644 --- a/LoraGamepad/ViewModels/TProViewModel.cs +++ b/LoraGamepad/ViewModels/TProViewModel.cs @@ -18,7 +18,8 @@ public class TProViewModel : ViewModelBase private ObservableCollection _portList = new(); public CBPortItem PortSelectItem { get; set; } - public SliderConfig SliderValue { get; set; } + public SliderConfig SliderValue { get; } + public BtnConfig BtnIsPressed { get; } private readonly SerialPipeIn _serialPipeIn; private readonly CrsfParserPipeIn _crsfParserPipeIn; @@ -29,6 +30,7 @@ public class TProViewModel : ViewModelBase public TProViewModel() { SliderValue = new SliderConfig(); + BtnIsPressed = new BtnConfig(); PortList = CBPortItem.GetPortList(); _serialPipeIn = new SerialPipeIn(); @@ -40,6 +42,20 @@ public class TProViewModel : ViewModelBase SliderValue.RightVerticalValue = data.channel[1]; SliderValue.LeftHorizonValue = data.channel[2]; SliderValue.LeftVerticalValue = data.channel[3]; + // Console.WriteLine($"{data.channel[4]},{data.channel[5]},{data.channel[6]},{data.channel[7]},{data.channel[8]},{data.channel[9]}"); + // Console.WriteLine($"{data.channel[10]},{data.channel[11]},{data.channel[12]},{data.channel[13]},{data.channel[14]},{data.channel[15]}"); + SliderValue.LeftUpValue = data.channel[4]; + BtnIsPressed.BtnLeftUp = data.channel[5] > 0; + BtnIsPressed.BtnRightUp = data.channel[6] > 0; + BtnIsPressed.BtnRightDown = data.channel[7] > 0; + SliderValue.MidLeftValue = data.channel[8]; + SliderValue.MidRightValue = data.channel[9]; + BtnIsPressed.BtnModel1 = data.channel[10] > 0; + BtnIsPressed.BtnModel2 = data.channel[11] > 0; + BtnIsPressed.BtnModel3 = data.channel[12] > 0; + BtnIsPressed.BtnModel4 = data.channel[13] > 0; + BtnIsPressed.BtnModel5 = data.channel[14] > 0; + BtnIsPressed.BtnModel6 = data.channel[15] > 0; }; ReadThread = new Thread(ReadThreadEntry); @@ -105,7 +121,7 @@ public class TProViewModel : ViewModelBase private void PortOpenButtonClick() { if (PortSelectItem.PortName == "") return; - SerialPort.Me.Open(PortSelectItem.PortName,115200,1000); + SerialPort.Me.Open(PortSelectItem.PortName,250000,1000); IsOpenPortButtonVisible = false; IsClosePortButtonVisible = true; ReadThread.Start(); diff --git a/LoraGamepad/Views/TProView.axaml b/LoraGamepad/Views/TProView.axaml index 2f572be..d77195f 100644 --- a/LoraGamepad/Views/TProView.axaml +++ b/LoraGamepad/Views/TProView.axaml @@ -11,6 +11,15 @@ + +