public MainV2() { var newForm = new Rectangles_form(); var newForm2 = new Rectangles_form(); newForm.Show(); newForm2.Show(); log.Info("Mainv2 ctor"); // set this before we reset it MainV2.config["NUM_tracklength"] = "200"; // create one here - but override on load MainV2.config["guid"] = Guid.NewGuid().ToString(); // load config xmlconfig(false); // force language to be loaded L10N.GetConfigLang(); ShowAirports = true; // setup adsb Utilities.adsb.UpdatePlanePosition += adsb_UpdatePlanePosition; Form splash = Program.Splash; splash.Refresh(); Application.DoEvents(); instance = this; //disable dpi scaling if (Font.Name != "宋体") //Chinese displayed normally when scaling. But would be too small or large using this line of code. Font = new Font(Font.Name, 8.25f * 96f / CreateGraphics().DpiX, Font.Style, Font.Unit, Font.GdiCharSet, Font.GdiVerticalFont); InitializeComponent(); MyView = new MainSwitcher(this); View = MyView; AdvancedChanged += updateAdvanced; //startup console TCPConsole.Write((byte)'S'); _connectionControl = toolStripConnectionControl.ConnectionControl; _connectionControl.CMB_baudrate.TextChanged += this.CMB_baudrate_TextChanged; _connectionControl.CMB_serialport.SelectedIndexChanged += this.CMB_serialport_SelectedIndexChanged; _connectionControl.CMB_serialport.Click += this.CMB_serialport_Click; _connectionControl.TOOL_APMFirmware.SelectedIndexChanged += this.TOOL_APMFirmware_SelectedIndexChanged; _connectionControl.ShowLinkStats += (sender, e) => ShowConnectionStatsForm(); srtm.datadirectory = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "srtm"; var t = Type.GetType("Mono.Runtime"); MONO = (t != null); speechEngine = new Speech(); Warnings.CustomWarning.defaultsrc = comPort.MAV.cs; Warnings.WarningEngine.Start(); // proxy loader - dll load now instead of on config form load new Transition(new TransitionType_EaseInEaseOut(2000)); foreach (object obj in Enum.GetValues(typeof(Firmwares))) { _connectionControl.TOOL_APMFirmware.Items.Add(obj); } if (_connectionControl.TOOL_APMFirmware.Items.Count > 0) _connectionControl.TOOL_APMFirmware.SelectedIndex = 0; comPort.BaseStream.BaudRate = 115200; PopulateSerialportList(); if (_connectionControl.CMB_serialport.Items.Count > 0) { _connectionControl.CMB_baudrate.SelectedIndex = 8; _connectionControl.CMB_serialport.SelectedIndex = 0; } // ** Done splash.Refresh(); Application.DoEvents(); if (MainV2.config.ContainsKey("comport")) { string temp = (string)config["comport"]; _connectionControl.CMB_serialport.SelectedIndex = _connectionControl.CMB_serialport.FindString(temp); if (_connectionControl.CMB_serialport.SelectedIndex == -1) { _connectionControl.CMB_serialport.Text = temp; // allows ports that dont exist - yet } comPort.BaseStream.PortName = temp; comPortName = temp; } if (MainV2.config.ContainsKey("baudrate")) { string temp2 = (string)config["baudrate"]; _connectionControl.CMB_baudrate.SelectedIndex = _connectionControl.CMB_baudrate.FindString(temp2); if (_connectionControl.CMB_baudrate.SelectedIndex == -1) { _connectionControl.CMB_baudrate.Text = temp2; } } if (MainV2.config.ContainsKey("APMFirmware")) { string temp3 = (string)config["APMFirmware"]; _connectionControl.TOOL_APMFirmware.SelectedIndex = _connectionControl.TOOL_APMFirmware.FindStringExact(temp3); if (_connectionControl.TOOL_APMFirmware.SelectedIndex == -1) _connectionControl.TOOL_APMFirmware.SelectedIndex = 0; MainV2.comPort.MAV.cs.firmware = (MainV2.Firmwares)Enum.Parse(typeof(MainV2.Firmwares), _connectionControl.TOOL_APMFirmware.Text); } MissionPlanner.Utilities.Tracking.cid = new Guid(MainV2.config["guid"].ToString()); // setup guids for droneshare if (!MainV2.config.ContainsKey("plane_guid")) MainV2.config["plane_guid"] = Guid.NewGuid().ToString(); if (!MainV2.config.ContainsKey("copter_guid")) MainV2.config["copter_guid"] = Guid.NewGuid().ToString(); if (!MainV2.config.ContainsKey("rover_guid")) MainV2.config["rover_guid"] = Guid.NewGuid().ToString(); if (config.ContainsKey("language") && !string.IsNullOrEmpty((string)config["language"])) { changelanguage(CultureInfoEx.GetCultureInfo((string)config["language"])); } this.Text = splash.Text; titlebar = splash.Text; if (!MONO) // windows only { if (MainV2.config["showconsole"] != null && MainV2.config["showconsole"].ToString() == "True") { } else { int win = NativeMethods.FindWindow("ConsoleWindowClass", null); NativeMethods.ShowWindow(win, NativeMethods.SW_HIDE); // hide window } // prevent system from sleeping while mp open var previousExecutionState = NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS | NativeMethods.ES_SYSTEM_REQUIRED); } ChangeUnits(); if (config["theme"] != null) { ThemeManager.SetTheme((ThemeManager.Themes)Enum.Parse(typeof(ThemeManager.Themes), MainV2.config["theme"].ToString())); if (ThemeManager.CurrentTheme == ThemeManager.Themes.Custom) { try { ThemeManager.BGColor = Color.FromArgb(int.Parse(MainV2.config["theme_bg"].ToString())); ThemeManager.ControlBGColor = Color.FromArgb(int.Parse(MainV2.config["theme_ctlbg"].ToString())); ThemeManager.TextColor = Color.FromArgb(int.Parse(MainV2.config["theme_text"].ToString())); ThemeManager.ButBG = Color.FromArgb(int.Parse(MainV2.config["theme_butbg"].ToString())); ThemeManager.ButBorder = Color.FromArgb(int.Parse(MainV2.config["theme_butbord"].ToString())); } catch { log.Error("Bad Custom theme - reset to standard"); ThemeManager.SetTheme(ThemeManager.Themes.BurntKermit); } } if (ThemeManager.CurrentTheme == ThemeManager.Themes.HighContrast) { switchlight(new menuicons2()); } } if (MainV2.config["showairports"] != null) { MainV2.ShowAirports = bool.Parse(config["showairports"].ToString()); } // set default ShowTFR = true; // load saved if (MainV2.config["showtfr"] != null) { MainV2.ShowTFR = bool.Parse(config["showtfr"].ToString()); } if (MainV2.config["enableadsb"] != null) { MainV2.instance.EnableADSB = bool.Parse(config["enableadsb"].ToString()); } // load this before the other screens get loaded if (MainV2.config["advancedview"] != null) { MainV2.Advanced = bool.Parse(config["advancedview"].ToString()); } else { // existing user - enable advanced view if (MainV2.config.Count > 3) { config["advancedview"] = true.ToString(); MainV2.Advanced = true; } else { config["advancedview"] = false.ToString(); } } try { log.Info("Create FD"); FlightData = new GCSViews.FlightData(); log.Info("Create FP"); FlightPlanner = new GCSViews.FlightPlanner(); //Configuration = new GCSViews.ConfigurationView.Setup(); log.Info("Create SIM"); Simulation = new GCSViews.Simulation(); //Firmware = new GCSViews.Firmware(); //Terminal = new GCSViews.Terminal(); FlightData.Width = MyView.Width; FlightPlanner.Width = MyView.Width; Simulation.Width = MyView.Width; } catch (ArgumentException e) { //http://www.microsoft.com/en-us/download/details.aspx?id=16083 //System.ArgumentException: Font 'Arial' does not support style 'Regular'. log.Fatal(e); CustomMessageBox.Show(e.ToString() + "\n\n Font Issues? Please install this http://www.microsoft.com/en-us/download/details.aspx?id=16083"); //splash.Close(); //this.Close(); Application.Exit(); } catch (Exception e) { log.Fatal(e); CustomMessageBox.Show("A Major error has occured : " + e.ToString()); Application.Exit(); } if (MainV2.config["CHK_GDIPlus"] != null) GCSViews.FlightData.myhud.UseOpenGL = !bool.Parse(MainV2.config["CHK_GDIPlus"].ToString()); if (MainV2.config["CHK_hudshow"] != null) GCSViews.FlightData.myhud.hudon = bool.Parse(MainV2.config["CHK_hudshow"].ToString()); try { if (config["MainLocX"] != null && config["MainLocY"] != null) { this.StartPosition = FormStartPosition.Manual; Point startpos = new Point(int.Parse(config["MainLocX"].ToString()), int.Parse(config["MainLocY"].ToString())); this.Location = startpos; } if (config["MainMaximised"] != null) { this.WindowState = (FormWindowState)Enum.Parse(typeof(FormWindowState), config["MainMaximised"].ToString()); // dont allow minimised start state if (this.WindowState == FormWindowState.Minimized) { this.WindowState = FormWindowState.Normal; this.Location = new Point(100, 100); } } if (config["MainHeight"] != null) this.Height = int.Parse(config["MainHeight"].ToString()); if (config["MainWidth"] != null) this.Width = int.Parse(config["MainWidth"].ToString()); if (config["CMB_rateattitude"] != null) CurrentState.rateattitudebackup = byte.Parse(config["CMB_rateattitude"].ToString()); if (config["CMB_rateposition"] != null) CurrentState.ratepositionbackup = byte.Parse(config["CMB_rateposition"].ToString()); if (config["CMB_ratestatus"] != null) CurrentState.ratestatusbackup = byte.Parse(config["CMB_ratestatus"].ToString()); if (config["CMB_raterc"] != null) CurrentState.ratercbackup = byte.Parse(config["CMB_raterc"].ToString()); if (config["CMB_ratesensors"] != null) CurrentState.ratesensorsbackup = byte.Parse(config["CMB_ratesensors"].ToString()); // make sure rates propogate MainV2.comPort.MAV.cs.ResetInternals(); if (config["speechenable"] != null) MainV2.speechEnable = bool.Parse(config["speechenable"].ToString()); if (MainV2.config["analyticsoptout"] != null) MissionPlanner.Utilities.Tracking.OptOut = bool.Parse(config["analyticsoptout"].ToString()); try { if (config["TXT_homelat"] != null) MainV2.comPort.MAV.cs.HomeLocation.Lat = double.Parse(config["TXT_homelat"].ToString()); if (config["TXT_homelng"] != null) MainV2.comPort.MAV.cs.HomeLocation.Lng = double.Parse(config["TXT_homelng"].ToString()); if (config["TXT_homealt"] != null) MainV2.comPort.MAV.cs.HomeLocation.Alt = double.Parse(config["TXT_homealt"].ToString()); // remove invalid entrys if (Math.Abs(MainV2.comPort.MAV.cs.HomeLocation.Lat) > 90 || Math.Abs(MainV2.comPort.MAV.cs.HomeLocation.Lng) > 180) MainV2.comPort.MAV.cs.HomeLocation = new PointLatLngAlt(); } catch { } } catch { } if (CurrentState.rateattitudebackup == 0) // initilised to 10, configured above from save { CustomMessageBox.Show("NOTE: your attitude rate is 0, the hud will not work\nChange in Configuration > Planner > Telemetry Rates"); } // log dir if (config["logdirectory"] != null) MainV2.LogDir = config["logdirectory"].ToString(); // create log dir if it doesnt exist if (!Directory.Exists(MainV2.LogDir)) Directory.CreateDirectory(MainV2.LogDir); //System.Threading.Thread.Sleep(2000); Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; // make sure new enough .net framework is installed if (!MONO) { Microsoft.Win32.RegistryKey installed_versions = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP"); string[] version_names = installed_versions.GetSubKeyNames(); //version names start with 'v', eg, 'v3.5' which needs to be trimmed off before conversion double Framework = Convert.ToDouble(version_names[version_names.Length - 1].Remove(0, 1), CultureInfo.InvariantCulture); int SP = Convert.ToInt32(installed_versions.OpenSubKey(version_names[version_names.Length - 1]).GetValue("SP", 0)); if (Framework < 4.0) { CustomMessageBox.Show("This program requires .NET Framework 4.0. You currently have " + Framework); } } if (Program.Logo != null) { this.Icon = Icon.FromHandle(((Bitmap)Program.Logo).GetHicon()); } if (Program.Logo != null && Program.vvvvz) { MenuDonate.Click -= this.toolStripMenuItem1_Click; MenuDonate.Text = ""; MenuDonate.Image = Program.Logo; MenuDonate.Click += MenuCustom_Click; MenuFlightData.Visible = false; MenuFlightPlanner.Visible = true; MenuConfigTune.Visible = false; MenuHelp.Visible = false; MenuInitConfig.Visible = false; MenuSimulation.Visible = false; MenuTerminal.Visible = false; } Application.DoEvents(); Comports.Add(comPort); // save config to test we have write access xmlconfig(true); }
/// <summary> /// keyboard shortcuts override /// </summary> /// <param name="msg"></param> /// <param name="keyData"></param> /// <returns></returns> protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.F12) { MenuConnect_Click(null, null); return true; } if (keyData == Keys.F2) { MenuFlightData_Click(null, null); return true; } if (keyData == Keys.F3) { MenuFlightPlanner_Click(null, null); return true; } if (keyData == Keys.F4) { MenuTuning_Click(null, null); return true; } if (keyData == Keys.F5) { comPort.getParamList(); MyView.ShowScreen(MyView.current.Name); return true; } if (keyData == (Keys.Control | Keys.F)) // temp { Form frm = new temp(); ThemeManager.ApplyThemeTo(frm); frm.Show(); return true; } if (keyData == (Keys.Control | Keys.R)) // new rectangle form { var newRectangleForm = new Rectangles_form(); newRectangleForm.Show(); return true; } /*if (keyData == (Keys.Control | Keys.S)) // screenshot { ScreenShot(); return true; }*/ if (keyData == (Keys.Control | Keys.G)) // nmea out { Form frm = new SerialOutputNMEA(); ThemeManager.ApplyThemeTo(frm); frm.Show(); return true; } if (keyData == (Keys.Control | Keys.X)) // select sysid { MissionPlanner.Controls.SysidSelector id = new SysidSelector(); id.TopMost = true; id.Show(); return true; } if (keyData == (Keys.Control | Keys.L)) // limits { return true; } if (keyData == (Keys.Control | Keys.W)) // test ac config { return true; } if (keyData == (Keys.Control | Keys.Z)) { MissionPlanner.GenOTP otp = new MissionPlanner.GenOTP(); otp.ShowDialog(this); return true; } if (keyData == (Keys.Control | Keys.T)) // for override connect { try { MainV2.comPort.Open(false); } catch (Exception ex) { CustomMessageBox.Show(ex.ToString()); } return true; } if (keyData == (Keys.Control | Keys.Y)) // for ryan beall and ollyw42 { // write try { MainV2.comPort.doCommand(MAVLink.MAV_CMD.PREFLIGHT_STORAGE, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); } catch { CustomMessageBox.Show("Invalid command"); return true; } //read ///////MainV2.comPort.doCommand(MAVLink09.MAV_CMD.PREFLIGHT_STORAGE, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); CustomMessageBox.Show("Done MAV_ACTION_STORAGE_WRITE"); return true; } if (keyData == (Keys.Control | Keys.J)) { /* var test = MainV2.comPort.GetLogList(); foreach (var item in test) { var ms = comPort.GetLog(item.id); using (BinaryWriter bw = new BinaryWriter(File.OpenWrite("test" + item.id + ".bin"))) { bw.Write(ms.ToArray()); } var temp1 = Log.BinaryLog.ReadLog("test" + item.id + ".bin"); File.WriteAllLines("test" + item.id + ".log", temp1); }*/ return true; } return base.ProcessCmdKey(ref msg, keyData); }