1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Added some code for Formula 1 2017 module. Data is already received, just needs to be mapped to a datamodel

This commit is contained in:
SpoinkyNL 2017-10-04 00:03:42 +02:00
parent 20dbc1985e
commit 9fc703196b
8 changed files with 255 additions and 1 deletions

View File

@ -377,6 +377,13 @@
<DependentUpon>AssettoCorsaView.xaml</DependentUpon>
</Compile>
<Compile Include="Modules\Games\AssettoCorsa\AssettoCorsaViewModel.cs" />
<Compile Include="Modules\Games\FormulaOne2017\FormulaOne2017Model.cs" />
<Compile Include="Modules\Games\FormulaOne2017\FormulaOne2017Settings.cs" />
<Compile Include="Modules\Games\FormulaOne2017\FormulaOne2017View.xaml.cs">
<DependentUpon>FormulaOne2017View.xaml</DependentUpon>
</Compile>
<Compile Include="Modules\Games\FormulaOne2017\FormulaOne2017ViewModel.cs" />
<Compile Include="Modules\Games\FormulaOne2017\FormulaOne2017DataModel.cs" />
<Compile Include="Modules\Games\Terraria\TerrariaDataModel.cs" />
<Compile Include="Modules\Games\Terraria\TerrariaSettings.cs" />
<Compile Include="Modules\Games\Terraria\TerrariaModel.cs" />
@ -881,6 +888,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Modules\Games\FormulaOne2017\FormulaOne2017View.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Modules\Games\Terraria\TerrariaView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@ -0,0 +1,89 @@
using System.Runtime.InteropServices;
using Artemis.Modules.Abstract;
using MoonSharp.Interpreter;
namespace Artemis.Modules.Games.FormulaOne2017
{
[MoonSharpUserData]
public class FormulaOne2017DataModel : ModuleDataModel
{
public FormulaOne2017DataModel()
{
}
[StructLayout(LayoutKind.Sequential)]
public struct UdpPacketData
{
public float m_time; // Total seconds driven from start line
public float m_lapTime; // Total seconds of current lap
public float m_lapDistance; // Total distance through lap in meters
public float m_totalDistance; // Total distance driven from start line
public float m_x; // World space position
public float m_y; // World space position
public float m_z; // World space position
public float m_speed; // Meters/sec
public float m_xv; // Velocity in world space
public float m_yv; // Velocity in world space
public float m_zv; // Velocity in world space
public float m_xr; // World space right direction
public float m_yr; // World space right direction
public float m_zr; // World space right direction
public float m_xd; // World space forward direction
public float m_yd; // World space forward direction
public float m_zd; // World space forward direction
public float m_susp_pos_bl; //
public float m_susp_pos_br; //
public float m_susp_pos_fl; //
public float m_susp_pos_fr; //
public float m_susp_vel_bl; //
public float m_susp_vel_br; //
public float m_susp_vel_fl; //
public float m_susp_vel_fr; //
public float m_wheel_speed_bl; //
public float m_wheel_speed_br; //
public float m_wheel_speed_fl; //
public float m_wheel_speed_fr; //
public float m_throttle; // Throttle input
public float m_steer; // Steering input (-1 left to +1 right)
public float m_brake; // Brake input
public float m_clutch; // Clutch input
public float m_gear; // 0 - R | 1 - N | 2-9 - 1-8
public float m_gforce_lat; // Lateral G's
public float m_gforce_lon; // Longiitude G's
public float m_lap; // Current lap number
public float m_engineRate; // Engine RPM
public float m_sli_pro_native_support; // SLI Pro support
public float m_car_position; // car race position
public float m_kers_level; // kers energy left
public float m_kers_max_level; // kers maximum energy
public float m_drs; // 0 = off, 1 = on
public float m_traction_control; // 0 (off) - 2 (high)
public float m_anti_lock_brakes; // 0 (off) - 1 (on)
public float m_fuel_in_tank; // current fuel mass
public float m_fuel_capacity; // fuel capacity
public float m_in_pits; // 0 = none, 1 = pitting, 2 = in pit area
public float m_sector; // 0 = sector1, 1 = sector2; 2 = sector3
public float m_sector1_time; // time of sector1 (or 0)
public float m_sector2_time; // time of sector2 (or 0)
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public float[] m_brakes_temp; // brakes temperature (centigrade)
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public float[] m_wheels_pressure; // wheels pressure PSI
public float m_team_info; // team ID
public float m_total_laps; // total number of laps in this race
public float m_track_size; // track size meters
public float m_last_lap_time; // last lap time
public float m_max_rpm; // cars max RPM, at which point the rev limiter will kick in
public float m_idle_rpm; // cars idle RPM
public float m_max_gears; // maximum number of gears
public float m_sessionType; // 0 = unknown, 1 = practice, 2 = qualifying, 3 = race
public float m_drsAllowed; // 0 = not allowed, 1 = allowed, -1 = invalid / unknown
public float m_track_number; // -1 for unknown, 0-21 for tracks
public float m_vehicleFIAFlags; // -1 = invalid/unknown, 0 = none, 1 = green, 2 = blue, 3 = yellow, 4 = red
}
public float Rpm { get; set; }
public float MaxRpm { get; set; }
public float IdleRpm { get; set; }
}
}

View File

@ -0,0 +1,69 @@
using System;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Artemis.DAL;
using Artemis.Managers;
using Artemis.Modules.Abstract;
namespace Artemis.Modules.Games.FormulaOne2017
{
public class FormulaOne2017Model : ModuleModel
{
private UdpClient _udpListener;
private bool _mustListen;
public FormulaOne2017Model(DeviceManager deviceManager, LuaManager luaManager) : base(deviceManager, luaManager)
{
Settings = SettingsProvider.Load<FormulaOne2017Settings>();
DataModel = new FormulaOne2017DataModel();
ProcessNames.Add("F1_2017");
}
public override string Name => "FormulaOne2017";
public override bool IsOverlay => false;
public override bool IsBoundToProcess => true;
public override void Update()
{
}
public override void Enable()
{
_mustListen = true;
Task.Run(async () =>
{
using (var udpClient = new UdpClient(20777))
{
string loggingEvent = "";
while (_mustListen)
{
//IPEndPoint object will allow us to read datagrams sent from any source.
var receivedResults = await udpClient.ReceiveAsync();
HandleGameData(receivedResults);
}
}
});
base.Enable();
}
private void HandleGameData(UdpReceiveResult receivedResults)
{
var dataModel = (FormulaOne2017DataModel) DataModel;
var pinnedPacket = GCHandle.Alloc(receivedResults.Buffer, GCHandleType.Pinned);
var msg = (FormulaOne2017DataModel.UdpPacketData) Marshal.PtrToStructure(pinnedPacket.AddrOfPinnedObject(), typeof(FormulaOne2017DataModel.UdpPacketData));
pinnedPacket.Free();
dataModel.Rpm = msg.m_engineRate;
dataModel.MaxRpm = msg.m_max_rpm;
dataModel.IdleRpm = msg.m_idle_rpm;
}
public override void Dispose()
{
_mustListen = false;
base.Dispose();
}
}
}

View File

@ -0,0 +1,8 @@
using Artemis.Modules.Abstract;
namespace Artemis.Modules.Games.FormulaOne2017
{
public class FormulaOne2017Settings : ModuleSettings
{
}
}

View File

@ -0,0 +1,45 @@
<UserControl x:Class="Artemis.Modules.Games.FormulaOne2017.FormulaOne2017View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cal="http://www.caliburnproject.org"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
mc:Ignorable="d"
d:DesignHeight="559.725" d:DesignWidth="882.696">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<!-- Header -->
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" FontSize="20" HorizontalAlignment="Left">
<Label.Content>
<AccessText TextWrapping="Wrap" Text="By default shows RPM on the F-keys, gear on the other keys and track flags on the numpad." />
</Label.Content>
</Label>
<!-- Enable -->
<StackPanel Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal">
<Label Content="Enable module" HorizontalAlignment="Right" Margin="0,0,0,3" />
<controls:ToggleSwitchButton IsChecked="{Binding Path=IsModuleEnabled, Mode=OneWay}" cal:Message.Attach="[Event Click] = [Action ToggleModule]"
Style="{StaticResource MahApps.Metro.Styles.ToggleSwitchButton.Win10}" ToolTip="Note: You can't enable an module when Artemis is disabled" />
</StackPanel>
<!-- Profile editor -->
<ContentControl Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" x:Name="ProfileEditor" />
<!-- Buttons -->
<StackPanel Grid.Column="0" Grid.Row="3" Orientation="Horizontal" VerticalAlignment="Bottom">
<Button x:Name="ResetSettings" Content="Reset effect" VerticalAlignment="Top" Width="100" Style="{DynamicResource SquareButtonStyle}" />
<Button x:Name="SaveSettings" Content="Save changes" VerticalAlignment="Top" Width="100" Margin="10,0,0,0" Style="{DynamicResource SquareButtonStyle}" />
</StackPanel>
</Grid>
</UserControl>

View File

@ -0,0 +1,12 @@
using System.Windows.Controls;
namespace Artemis.Modules.Games.FormulaOne2017
{
public partial class FormulaOne2017View : UserControl
{
public FormulaOne2017View()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,17 @@
using Artemis.Managers;
using Artemis.Modules.Abstract;
using Ninject;
namespace Artemis.Modules.Games.FormulaOne2017
{
public sealed class FormulaOne2017ViewModel : ModuleViewModel
{
public FormulaOne2017ViewModel(MainManager mainManager, [Named(nameof(FormulaOne2017Model))] ModuleModel moduleModel,
IKernel kernel) : base(mainManager, moduleModel, kernel)
{
DisplayName = "F1 2017";
}
public override bool UsesProfileEditor => true;
}
}

View File

@ -42,7 +42,6 @@ namespace Artemis.Profiles.Layers.Models
public double Width { get; set; }
public double Height { get; set; }
public bool Contain { get; set; }
public double Opacity { get; set; }
public double AnimationSpeed { get; set; }
public double OpacityEaseTime { get; set; }
public double HeightEaseTime { get; set; }
@ -55,6 +54,10 @@ namespace Artemis.Profiles.Layers.Models
public List<LayerKeybindModel> LayerKeybindModels { get; set; } = new List<LayerKeybindModel>();
public List<DynamicPropertiesModel> DynamicProperties { get; set; } = new List<DynamicPropertiesModel>();
// Opacity isn't saved since it's only accesable by LUA
[JsonIgnore]
public double Opacity { get; set; } = 1;
[JsonConverter(typeof(BrushJsonConverter))]
public Brush Brush
{