Advertisement
Guest User

VAS Monitoring Tool

a guest
Apr 25th, 2015
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.97 KB | None | 0 0
  1. /// VAS Monitoring Tool
  2. /// Author: Luke Gorman
  3. /// Copyright: Free for public use
  4.  
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. using System.Windows.Threading;  
  20.  
  21. namespace FsuipcSdk
  22. {
  23.     /// <summary>
  24.     /// Interaction logic for MainWindow.xaml
  25.     /// </summary>
  26.     public partial class MainWindow : Window
  27.     {
  28.         // FSUIPC Variables Declared
  29.         Fsuipc fsuipc = new Fsuipc();   // Our main fsuipc object!
  30.         bool result = false;            // Return boolean for FSUIPC method calls
  31.         bool stop = false;              // Flag to stop airspeed loop
  32.         int dwFSReq = 0;                // Any version of FS is OK
  33.         int dwResult = -1;              // Variable to hold returned results
  34.         int dwOffset = 0x02BC;          // 02BC = indicated airspeed
  35.         int dwSize = 4;                 // 4 bytes for indicated airspeed
  36.         int token = -1;
  37.         double vas;
  38.         int vasMB;
  39.  
  40.         // Events that occur when the program is loaded (grab data timer, init FSUIPC conn. and window)
  41.         public MainWindow()
  42.         {
  43.             InitializeComponent();
  44.             result = fsuipc.FSUIPC_Open(dwFSReq, ref dwResult);
  45.  
  46.             DispatcherTimer timer = new DispatcherTimer();
  47.             timer.Interval = TimeSpan.FromMilliseconds(2000);
  48.             timer.Tick += timer_Tick;
  49.             timer.Start();
  50.         }
  51.  
  52.         // Quit button exits the application
  53.         private void exitBtn_Click(object sender, RoutedEventArgs e)
  54.         {
  55.             Application.Current.Shutdown();
  56.         }
  57.  
  58.         bool inDrag = false;
  59.         Point anchorPoint;
  60.  
  61.         protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
  62.         {
  63.             anchorPoint = PointToScreen(e.GetPosition(this));
  64.             inDrag = true;
  65.             CaptureMouse();
  66.             e.Handled = true;
  67.         }
  68.  
  69.         protected override void OnMouseMove(MouseEventArgs e)
  70.         {
  71.             if (inDrag)
  72.             {
  73.                 Point currentPoint = PointToScreen(e.GetPosition(this));
  74.                 this.Left = this.Left + currentPoint.X - anchorPoint.X;
  75.                 this.Top = this.Top + currentPoint.Y - anchorPoint.Y;
  76.                 anchorPoint = currentPoint;
  77.             }
  78.         }
  79.  
  80.         protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
  81.         {
  82.             if (inDrag)
  83.             {
  84.                 ReleaseMouseCapture();
  85.                 inDrag = false;
  86.                 e.Handled = true;
  87.             }
  88.         }
  89.  
  90.         private void timer_Tick(object sender, object e)
  91.         {
  92.             bool played = false;
  93.  
  94.             result = fsuipc.FSUIPC_Read(0x024C, 32, ref token, ref dwResult); ;
  95.             result = fsuipc.FSUIPC_Process(ref dwResult);
  96.             result = fsuipc.FSUIPC_Get(ref token, ref dwResult);
  97.             vas = dwResult;
  98.  
  99.             vasMB = (int)vas / 1024;
  100.             String vas2 = String.Format("{0:00,0}", vas);
  101.  
  102.             if (result)
  103.             {
  104.                 // toolStripStatusLabel1.ForeColor = Color.DarkOliveGreen;
  105.                 // toolStripStatusLabel1.Text = "FSUIPC Connection Established";
  106.  
  107.                 int max = 4086;
  108.  
  109.                 progressBar.Value = vasMB;
  110.                 txtVAS.Content = "VAS: " + vas2 + " KB " + "(" + vasMB + " MB) ";
  111.                 percentage.Content = (((int)vas) / (int)max * 100) / 1000 + ("%");
  112.  
  113.                 // High VAS Usage Alert
  114.                 if (vasMB > 3600)
  115.                 {
  116.                     txtWarn.Content = "WARNING: High VAS Usage";
  117.                 }
  118.             }
  119.         }
  120.  
  121.         private void helpBtn_Click(object sender, RoutedEventArgs e)
  122.         {
  123.  
  124.         }
  125.  
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement