Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// VAS Monitoring Tool
- /// Author: Luke Gorman
- /// Copyright: Free for public use
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Windows.Threading;
- namespace FsuipcSdk
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- // FSUIPC Variables Declared
- Fsuipc fsuipc = new Fsuipc(); // Our main fsuipc object!
- bool result = false; // Return boolean for FSUIPC method calls
- bool stop = false; // Flag to stop airspeed loop
- int dwFSReq = 0; // Any version of FS is OK
- int dwResult = -1; // Variable to hold returned results
- int dwOffset = 0x02BC; // 02BC = indicated airspeed
- int dwSize = 4; // 4 bytes for indicated airspeed
- int token = -1;
- double vas;
- int vasMB;
- // Events that occur when the program is loaded (grab data timer, init FSUIPC conn. and window)
- public MainWindow()
- {
- InitializeComponent();
- result = fsuipc.FSUIPC_Open(dwFSReq, ref dwResult);
- DispatcherTimer timer = new DispatcherTimer();
- timer.Interval = TimeSpan.FromMilliseconds(2000);
- timer.Tick += timer_Tick;
- timer.Start();
- }
- // Quit button exits the application
- private void exitBtn_Click(object sender, RoutedEventArgs e)
- {
- Application.Current.Shutdown();
- }
- bool inDrag = false;
- Point anchorPoint;
- protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
- {
- anchorPoint = PointToScreen(e.GetPosition(this));
- inDrag = true;
- CaptureMouse();
- e.Handled = true;
- }
- protected override void OnMouseMove(MouseEventArgs e)
- {
- if (inDrag)
- {
- Point currentPoint = PointToScreen(e.GetPosition(this));
- this.Left = this.Left + currentPoint.X - anchorPoint.X;
- this.Top = this.Top + currentPoint.Y - anchorPoint.Y;
- anchorPoint = currentPoint;
- }
- }
- protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
- {
- if (inDrag)
- {
- ReleaseMouseCapture();
- inDrag = false;
- e.Handled = true;
- }
- }
- private void timer_Tick(object sender, object e)
- {
- bool played = false;
- result = fsuipc.FSUIPC_Read(0x024C, 32, ref token, ref dwResult); ;
- result = fsuipc.FSUIPC_Process(ref dwResult);
- result = fsuipc.FSUIPC_Get(ref token, ref dwResult);
- vas = dwResult;
- vasMB = (int)vas / 1024;
- String vas2 = String.Format("{0:00,0}", vas);
- if (result)
- {
- // toolStripStatusLabel1.ForeColor = Color.DarkOliveGreen;
- // toolStripStatusLabel1.Text = "FSUIPC Connection Established";
- int max = 4086;
- progressBar.Value = vasMB;
- txtVAS.Content = "VAS: " + vas2 + " KB " + "(" + vasMB + " MB) ";
- percentage.Content = (((int)vas) / (int)max * 100) / 1000 + ("%");
- // High VAS Usage Alert
- if (vasMB > 3600)
- {
- txtWarn.Content = "WARNING: High VAS Usage";
- }
- }
- }
- private void helpBtn_Click(object sender, RoutedEventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement