feat: 添加所有通道绑定

master
朱雅鸿 2022-11-08 23:54:44 +08:00
parent f866baad8d
commit 9e6524cee1
5 changed files with 133 additions and 18 deletions

View File

@ -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);
}
}

View File

@ -30,7 +30,7 @@ public class CrsfChMsg
// { // {
// rs[i].CopyTo(ch,i); // rs[i].CopyTo(ch,i);
// } // }
Console.WriteLine(BitConverter.ToString(raw));
ch[15] = ((raw[0 ] & 0xFF) << 3 ) + ((raw[1 ] & 0xE0) >> 5); //res: 5 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[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); ch[13] = ((raw[2 ] & 0x03) << 9 ) + ((raw[3 ] & 0xFF) << 1)+ ((raw[4 ] & 0x80) >> 7);

View File

@ -10,6 +10,9 @@ public class SliderConfig : ReactiveObject
private double _leftHorizonValue; private double _leftHorizonValue;
private double _lefttVerticalValue; private double _lefttVerticalValue;
private double _leftUpValue = 0;
private double _midLeftValue = 0;
private double _midRightValue = 0;
public SliderConfig() public SliderConfig()
{ {
_rightHorizonValue = _rightVerticalValue = _leftHorizonValue = _lefttVerticalValue = 0; _rightHorizonValue = _rightVerticalValue = _leftHorizonValue = _lefttVerticalValue = 0;
@ -36,4 +39,19 @@ public class SliderConfig : ReactiveObject
get => _lefttVerticalValue; get => _lefttVerticalValue;
set => this.RaiseAndSetIfChanged(ref _lefttVerticalValue, value); 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);
}
} }

View File

@ -18,7 +18,8 @@ public class TProViewModel : ViewModelBase
private ObservableCollection<CBPortItem> _portList = new(); private ObservableCollection<CBPortItem> _portList = new();
public CBPortItem PortSelectItem { get; set; } public CBPortItem PortSelectItem { get; set; }
public SliderConfig SliderValue { get; set; } public SliderConfig SliderValue { get; }
public BtnConfig BtnIsPressed { get; }
private readonly SerialPipeIn _serialPipeIn; private readonly SerialPipeIn _serialPipeIn;
private readonly CrsfParserPipeIn _crsfParserPipeIn; private readonly CrsfParserPipeIn _crsfParserPipeIn;
@ -29,6 +30,7 @@ public class TProViewModel : ViewModelBase
public TProViewModel() public TProViewModel()
{ {
SliderValue = new SliderConfig(); SliderValue = new SliderConfig();
BtnIsPressed = new BtnConfig();
PortList = CBPortItem.GetPortList(); PortList = CBPortItem.GetPortList();
_serialPipeIn = new SerialPipeIn(); _serialPipeIn = new SerialPipeIn();
@ -40,6 +42,20 @@ public class TProViewModel : ViewModelBase
SliderValue.RightVerticalValue = data.channel[1]; SliderValue.RightVerticalValue = data.channel[1];
SliderValue.LeftHorizonValue = data.channel[2]; SliderValue.LeftHorizonValue = data.channel[2];
SliderValue.LeftVerticalValue = data.channel[3]; 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); ReadThread = new Thread(ReadThreadEntry);
@ -105,7 +121,7 @@ public class TProViewModel : ViewModelBase
private void PortOpenButtonClick() private void PortOpenButtonClick()
{ {
if (PortSelectItem.PortName == "") return; if (PortSelectItem.PortName == "") return;
SerialPort.Me.Open(PortSelectItem.PortName,115200,1000); SerialPort.Me.Open(PortSelectItem.PortName,250000,1000);
IsOpenPortButtonVisible = false; IsOpenPortButtonVisible = false;
IsClosePortButtonVisible = true; IsClosePortButtonVisible = true;
ReadThread.Start(); ReadThread.Start();

View File

@ -11,6 +11,15 @@
</UserControl.DataContext> </UserControl.DataContext>
<!-- 样式设置 --> <!-- 样式设置 -->
<UserControl.Styles> <UserControl.Styles>
<Style Selector="Button.pad">
<Setter Property="Background" Value="{DynamicResource DarkBlueBrush}"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontSize" Value="18"/>
</Style>
<Style Selector="Button.pad:pressed /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource BrightRedBrush}"/>
<Setter Property="TextBlock.Foreground" Value="White"/>
</Style>
<Style Selector="Button.open"> <Style Selector="Button.open">
<Setter Property="Background" Value="{DynamicResource DarkBlueBrush}"/> <Setter Property="Background" Value="{DynamicResource DarkBlueBrush}"/>
<Setter Property="Foreground" Value="White"/> <Setter Property="Foreground" Value="White"/>
@ -39,8 +48,9 @@
<!-- 页面布局 --> <!-- 页面布局 -->
<Grid RowDefinitions="60,*,40,2*"> <Grid RowDefinitions="60,*,40,2*">
<Grid Grid.Row="0" Background="Blue" ColumnDefinitions="*,2*,2*,*"> <Grid Grid.Row="0" Background="Blue" ColumnDefinitions="*,2*,2*,*">
<Slider Grid.Column="0" Width="80" HorizontalAlignment="Center"/> <Slider Grid.Column="0" Width="80" HorizontalAlignment="Center"
<ComboBox Grid.Column="1" SelectedIndex="0" VerticalAlignment="Center" Width="120" HorizontalAlignment="Right" Margin="10,0" Value="{Binding SliderValue.LeftUpValue}"/>
<ComboBox Grid.Column="1" SelectedIndex="0" VerticalAlignment="Center" Width="100" HorizontalAlignment="Right" Margin="5,0"
Items="{Binding PortList}" Items="{Binding PortList}"
SelectedItem="{Binding PortSelectItem}" SelectedItem="{Binding PortSelectItem}"
PointerPressed="{eventBinder:EventBinding OnPortListComboBoxPressed}"> PointerPressed="{eventBinder:EventBinding OnPortListComboBoxPressed}">
@ -51,29 +61,34 @@
</ComboBox.ItemTemplate> </ComboBox.ItemTemplate>
</ComboBox> </ComboBox>
<Button Grid.Column="2" Classes="open" Command="{Binding OpenPort}" IsVisible="{Binding IsOpenPortButtonVisible}" <Button Grid.Column="2" Classes="open" Command="{Binding OpenPort}" IsVisible="{Binding IsOpenPortButtonVisible}"
HorizontalAlignment="Left" Margin="0,0,10,0" Content="打开串口" HorizontalContentAlignment="Center" Width="100" HorizontalAlignment="Left" Margin="5,0,0,0" Content="打开串口" HorizontalContentAlignment="Center" Width="100"
Name="BtnPortOpen"> Name="BtnPortOpen">
</Button> </Button>
<Button Grid.Column="2" Classes="close" Command="{Binding ClosePort}" IsVisible="{Binding IsClosePortButtonVisible}" <Button Grid.Column="2" Classes="close" Command="{Binding ClosePort}" IsVisible="{Binding IsClosePortButtonVisible}"
HorizontalAlignment="Left" Margin="0,0,10,0" Content="关闭串口" HorizontalContentAlignment="Center" Width="100" HorizontalAlignment="Left" Margin="5,0,0,0" Content="关闭串口" HorizontalContentAlignment="Center" Width="100"
Name="BtnPortClose"> Name="BtnPortClose">
</Button> </Button>
<Button Grid.Column="3" Width="100" Height="40"/> <Button Grid.Column="3" Classes="pad" Width="80" Height="40" HorizontalAlignment="Left"
IsPressed="{Binding BtnIsPressed.BtnRightDown}"/>
</Grid> </Grid>
<Grid Grid.Row="1" Background="Gray" ColumnDefinitions="2*,*,4*,*,2*"> <Grid Grid.Row="1" Background="Gray" ColumnDefinitions="2*,*,4*,*,2*">
<Button Grid.Column="0" Width="80" Height="60" HorizontalAlignment="Center"/> <Button Grid.Column="0" Classes="pad" Width="80" Height="60" HorizontalAlignment="Center"
<Slider Grid.Column="1" Orientation="Vertical" HorizontalAlignment="Center"/> IsPressed="{Binding BtnIsPressed.BtnLeftUp}"/>
<Slider Grid.Column="3" Orientation="Vertical" HorizontalAlignment="Center"/> <Slider Grid.Column="1" Orientation="Vertical" HorizontalAlignment="Center"
<Button Grid.Column="4" Width="80" Height="60" HorizontalAlignment="Center"/> Value="{Binding SliderValue.MidLeftValue}"/>
<Slider Grid.Column="3" Orientation="Vertical" HorizontalAlignment="Center"
Value="{Binding SliderValue.MidRightValue}"/>
<Button Grid.Column="4" Classes="pad" Width="80" Height="60" HorizontalAlignment="Center"
IsPressed="{Binding BtnIsPressed.BtnRightUp}"/>
</Grid> </Grid>
<Grid Grid.Row="2" Background="Yellow"> <Grid Grid.Row="2" Background="Yellow">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Width="40" Margin="10"/> <Button Classes="pad" IsPressed="{Binding BtnIsPressed.BtnModel1 }" Width="40" Margin="10"/>
<Button Width="40" Margin="10"/> <Button Classes="pad" IsPressed="{Binding BtnIsPressed.BtnModel2 }" Width="40" Margin="10"/>
<Button Width="40" Margin="10"/> <Button Classes="pad" IsPressed="{Binding BtnIsPressed.BtnModel3 }" Width="40" Margin="10"/>
<Button Width="40" Margin="10"/> <Button Classes="pad" IsPressed="{Binding BtnIsPressed.BtnModel4 }" Width="40" Margin="10"/>
<Button Width="40" Margin="10"/> <Button Classes="pad" IsPressed="{Binding BtnIsPressed.BtnModel5 }" Width="40" Margin="10"/>
<Button Width="40" Margin="10"/> <Button Classes="pad" IsPressed="{Binding BtnIsPressed.BtnModel6 }" Width="40" Margin="10"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
<Grid Grid.Row="3" Background="Green" ColumnDefinitions="*,2*,*"> <Grid Grid.Row="3" Background="Green" ColumnDefinitions="*,2*,*">