APM Planner

fix CAPM update firmware error
This commit is contained in:
Hazy 2012-02-26 19:14:08 +08:00
parent f27e9f9ca1
commit 71b73a669c
4 changed files with 91 additions and 69 deletions

View File

@ -445,6 +445,7 @@
<DependentUpon>temp.cs</DependentUpon> <DependentUpon>temp.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Radio\Uploader.cs" /> <Compile Include="Radio\Uploader.cs" />
<Compile Include="Utility.cs" />
<EmbeddedResource Include="Controls\ProgressReporterDialogue.resx"> <EmbeddedResource Include="Controls\ProgressReporterDialogue.resx">
<DependentUpon>ProgressReporterDialogue.cs</DependentUpon> <DependentUpon>ProgressReporterDialogue.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>

View File

@ -173,26 +173,20 @@ namespace ArdupilotMega.GCSViews
CultureInfo ci = null; CultureInfo ci = null;
foreach (string name in new string[] { "en-US", "zh-Hans", "zh-TW", "ru-RU", "Fr", "Pl", "it-IT", "es-ES" }) foreach (string name in new string[] { "en-US", "zh-Hans", "zh-TW", "ru-RU", "Fr", "Pl", "it-IT", "es-ES" })
{ {
ci = MainV2.getcultureinfo(name); ci = CultureInfoEx.GetCultureInfo(name);
if (ci != null) if (ci != null)
languages.Add(ci); languages.Add(ci);
} }
CMB_language.DisplayMember = "DisplayName"; CMB_language.DisplayMember = "DisplayName";
CMB_language.DataSource = languages; CMB_language.DataSource = languages;
bool match = false; ci = Thread.CurrentThread.CurrentUICulture;
for (int i = 0; i < languages.Count && !match; i++) for (int i = 0; i < languages.Count; i++)
{ {
ci = Thread.CurrentThread.CurrentUICulture; if (ci.IsChildOf(languages[i]))
while (!ci.Equals(CultureInfo.InvariantCulture))
{ {
if (ci.Equals(languages[i])) CMB_language.SelectedIndex = i;
{ break;
CMB_language.SelectedIndex = i;
match = true;
break;
}
ci = ci.Parent;
} }
} }
CMB_language.SelectedIndexChanged += CMB_language_SelectedIndexChanged; CMB_language.SelectedIndexChanged += CMB_language_SelectedIndexChanged;
@ -555,23 +549,23 @@ namespace ArdupilotMega.GCSViews
if (text.Length > 0) if (text.Length > 0)
{ {
if (text[0].GetType() == typeof(NumericUpDown)) if (text[0].GetType() == typeof(NumericUpDown))
{ {
decimal option = (decimal)(float.Parse(Params[e.ColumnIndex, e.RowIndex].Value.ToString())); decimal option = (decimal)(float.Parse(Params[e.ColumnIndex, e.RowIndex].Value.ToString()));
((NumericUpDown)text[0]).Value = option; ((NumericUpDown)text[0]).Value = option;
((NumericUpDown)text[0]).BackColor = Color.Green; ((NumericUpDown)text[0]).BackColor = Color.Green;
} }
else if (text[0].GetType() == typeof(ComboBox)) else if (text[0].GetType() == typeof(ComboBox))
{ {
int option = (int)(float.Parse(Params[e.ColumnIndex, e.RowIndex].Value.ToString())); int option = (int)(float.Parse(Params[e.ColumnIndex, e.RowIndex].Value.ToString()));
((ComboBox)text[0]).SelectedIndex = option; ((ComboBox)text[0]).SelectedIndex = option;
((ComboBox)text[0]).BackColor = Color.Green; ((ComboBox)text[0]).BackColor = Color.Green;
} }
} }
} }
catch { ((Control)text[0]).BackColor = Color.Red; } catch { ((Control)text[0]).BackColor = Color.Red; }
Params.Focus(); Params.Focus();
} }
private void BUT_load_Click(object sender, EventArgs e) private void BUT_load_Click(object sender, EventArgs e)
{ {
@ -599,12 +593,12 @@ namespace ArdupilotMega.GCSViews
continue; continue;
if (index2 != -1) if (index2 != -1)
line = line.Replace(',','.'); line = line.Replace(',', '.');
string name = line.Substring(0, index); string name = line.Substring(0, index);
float value = float.Parse(line.Substring(index + 1), new System.Globalization.CultureInfo("en-US")); float value = float.Parse(line.Substring(index + 1), new System.Globalization.CultureInfo("en-US"));
MAVLink.modifyParamForDisplay(true,name,ref value); MAVLink.modifyParamForDisplay(true, name, ref value);
// set param table as well // set param table as well
foreach (DataGridViewRow row in Params.Rows) foreach (DataGridViewRow row in Params.Rows)
@ -813,9 +807,10 @@ namespace ArdupilotMega.GCSViews
{ {
DsError.ThrowExceptionForHR(hr); DsError.ThrowExceptionForHR(hr);
} }
catch (Exception ex) { catch (Exception ex)
MessageBox.Show("Can not add video source\n" + ex.ToString()); {
return; MessageBox.Show("Can not add video source\n" + ex.ToString());
return;
} }
// Find the stream config interface // Find the stream config interface
@ -940,7 +935,7 @@ namespace ArdupilotMega.GCSViews
} }
catch { MessageBox.Show("Error: getting param list"); } catch { MessageBox.Show("Error: getting param list"); }

View File

@ -138,7 +138,7 @@ namespace ArdupilotMega
xmlconfig(false); xmlconfig(false);
if (config.ContainsKey("language") && !string.IsNullOrEmpty((string)config["language"])) if (config.ContainsKey("language") && !string.IsNullOrEmpty((string)config["language"]))
changelanguage(getcultureinfo((string)config["language"])); changelanguage(CultureInfoEx.GetCultureInfo((string)config["language"]));
if (!MONO) // windows only if (!MONO) // windows only
{ {
@ -2011,51 +2011,13 @@ namespace ArdupilotMega
{ {
ComponentResourceManager rm = new ComponentResourceManager(view.GetType()); ComponentResourceManager rm = new ComponentResourceManager(view.GetType());
foreach (Control ctrl in view.Controls) foreach (Control ctrl in view.Controls)
applyresource(rm, ctrl); rm.ApplyResource(ctrl);
rm.ApplyResources(view, "$this"); rm.ApplyResources(view, "$this");
} }
} }
} }
} }
private void applyresource(ComponentResourceManager rm, Control ctrl)
{
rm.ApplyResources(ctrl, ctrl.Name);
foreach (Control subctrl in ctrl.Controls)
applyresource(rm, subctrl);
if (ctrl.ContextMenu != null)
applyresource(rm, ctrl.ContextMenu);
if (ctrl is DataGridView)
{
foreach (DataGridViewColumn col in (ctrl as DataGridView).Columns)
rm.ApplyResources(col, col.Name);
}
}
private void applyresource(ComponentResourceManager rm, Menu menu)
{
rm.ApplyResources(menu, menu.Name);
foreach (MenuItem submenu in menu.MenuItems)
applyresource(rm, submenu);
}
public static CultureInfo getcultureinfo(string name)
{
try
{
return new CultureInfo(name);
}
catch (Exception)
{
return null;
}
}
private void MainV2_FormClosing(object sender, FormClosingEventArgs e) private void MainV2_FormClosing(object sender, FormClosingEventArgs e)
{ {
config["MainHeight"] = this.Height; config["MainHeight"] = this.Height;

View File

@ -0,0 +1,64 @@
//this file contains some simple extension methods
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.ComponentModel;
using System.Windows.Forms;
namespace ArdupilotMega
{
static class CultureInfoEx
{
public static CultureInfo GetCultureInfo(string name)
{
try { return new CultureInfo(name); }
catch (Exception) { return null; }
}
public static bool IsChildOf(this CultureInfo cX, CultureInfo cY)
{
if (cX == null || cY == null)
return false;
CultureInfo c = cX;
while (!c.Equals(CultureInfo.InvariantCulture))
{
if (c.Equals(cY))
return true;
c = c.Parent;
}
return false;
}
}
static class ComponentResourceManagerEx
{
public static void ApplyResource(this ComponentResourceManager rm, Control ctrl)
{
rm.ApplyResources(ctrl, ctrl.Name);
foreach (Control subctrl in ctrl.Controls)
ApplyResource(rm, subctrl);
if (ctrl.ContextMenu != null)
ApplyResource(rm, ctrl.ContextMenu);
if (ctrl is DataGridView)
{
foreach (DataGridViewColumn col in (ctrl as DataGridView).Columns)
rm.ApplyResources(col, col.Name);
}
}
public static void ApplyResource(this ComponentResourceManager rm, Menu menu)
{
rm.ApplyResources(menu, menu.Name);
foreach (MenuItem submenu in menu.MenuItems)
ApplyResource(rm, submenu);
}
}
}