Skip to content

Commit

Permalink
FlightData: Actions: add safety switch toggle
Browse files Browse the repository at this point in the history
Needed to add indication of safety state to HUD with this
  • Loading branch information
robertlong13 authored and meee1 committed Jul 6, 2023
1 parent bfed473 commit 4db7b20
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ExtLibs/ArduPilot/CurrentState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,7 @@ public float gimballng

[GroupText("Software")] public bool landed { get; set; }

[GroupText("Software")] public bool safteyactive { get; set; }
[GroupText("Software")] public bool safetyactive { get; set; }

[GroupText("Terrain")] public bool terrainactive { get; set; }

Expand Down Expand Up @@ -2657,7 +2657,7 @@ private void Parent_OnPacketReceived(object sender, MAVLink.MAVLinkMessage mavLi

terrainactive = sensors_health.terrain && sensors_enabled.terrain && sensors_present.terrain;

safteyactive = !sensors_enabled.motor_control;
safetyactive = !sensors_enabled.motor_control;

if (errors_count1 > 0 || errors_count2 > 0)
{
Expand Down
18 changes: 14 additions & 4 deletions ExtLibs/Controls/HUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,9 @@ public DateTime datetime
[System.ComponentModel.Browsable(true), System.ComponentModel.Category("Values")]
public bool failsafe { get; set; }

[System.ComponentModel.Browsable(true), System.ComponentModel.Category("Values")]
public bool safetyactive { get; set; }

[System.ComponentModel.Browsable(true), System.ComponentModel.Category("Values")]
public bool lowvoltagealert { get; set; }

Expand Down Expand Up @@ -2998,7 +3001,7 @@ internal void doPaint()
//if ((armedtimer.AddSeconds(8) > DateTime.Now))
{

var size = calcsize(HUDT.DISARMED, font, fontsize + 10, (SolidBrush)Brushes.Red, Width - 50 - 50);
var size = calcsize(HUDT.DISARMED, fontsize + 10, (SolidBrush)Brushes.Red);

drawstring(HUDT.DISARMED, font, fontsize + 10, (SolidBrush) Brushes.Red, size.Width/ -2/* - 85*/,
halfheight / -3);
Expand All @@ -3009,12 +3012,19 @@ internal void doPaint()
{
if ((armedtimer.AddSeconds(8) > DateTime.Now))
{
var size = calcsize(HUDT.ARMED, font, fontsize + 10, (SolidBrush)Brushes.Red, Width - 50 - 50);
var size = calcsize(HUDT.ARMED, fontsize + 20, (SolidBrush)Brushes.Red);
drawstring(HUDT.ARMED, font, fontsize + 20, (SolidBrush) Brushes.Red, size.Width / -2/* - 70*/,
halfheight / -3);
statuslast = status;
}
}

if (safetyactive)
{
var size = calcsize(HUDT.SAFE, fontsize + 10, (SolidBrush)Brushes.Red);
drawstring(HUDT.SAFE, font, fontsize + 10, (SolidBrush)Brushes.Red, size.Width / -2, halfheight / -6);
statuslast = status;
}

if (failsafe == true)
{
Expand All @@ -3035,7 +3045,7 @@ internal void doPaint()

var newfontsize = calcfontsize(message, font, fontsize + 10, (SolidBrush) brush, Width - 50 - 50);

var size = calcsize(message, font, newfontsize, (SolidBrush)Brushes.Red, Width - 50 - 50);
var size = calcsize(message, newfontsize, (SolidBrush)Brushes.Red);

drawstring(message, font, newfontsize, (SolidBrush) brush, size.Width / -2,
halfheight / 3);
Expand Down Expand Up @@ -3300,7 +3310,7 @@ float calcfontsize(string text, Font font, float fontsize, SolidBrush brush, int
return fontsize;
}

Size calcsize(string text, Font font, float fontsize, SolidBrush brush, int targetwidth)
Size calcsize(string text, float fontsize, SolidBrush brush)
{
if (text == null)
return new Size(0, 0);
Expand Down
9 changes: 9 additions & 0 deletions ExtLibs/Controls/HUDT.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ExtLibs/Controls/HUDT.resx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@
<data name="S" xml:space="preserve">
<value>S</value>
</data>
<data name="SAFE" xml:space="preserve">
<value>SAFE</value>
</data>
<data name="SE" xml:space="preserve">
<value>SE</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions ExtLibs/Controls/HUDT.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,7 @@
<data name="ReadyToArm" xml:space="preserve">
<value>准备解锁</value>
</data>
<data name="SAFE" xml:space="preserve">
<value>安全</value>
</data>
</root>
1 change: 1 addition & 0 deletions GCSViews/FlightData.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion GCSViews/FlightData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ public enum actions
Scripting_cmd_stop_and_restart,
Scripting_cmd_stop,
HighLatency_Enable,
HighLatency_Disable
HighLatency_Disable,
Toggle_Safety_Switch,
}

private Dictionary<int, string> NIC_table = new Dictionary<int, string>()
Expand Down Expand Up @@ -1713,6 +1714,14 @@ private void BUTactiondo_Click(object sender, EventArgs e)
((Control)sender).Enabled = true;
return;
}
if (CMB_action.Text == actions.Toggle_Safety_Switch.ToString())
{
var custom_mode = (MainV2.comPort.MAV.cs.sensors_enabled.motor_control && MainV2.comPort.MAV.cs.sensors_enabled.seen) ? 1u : 0u;
var mode = new MAVLink.mavlink_set_mode_t() { custom_mode = custom_mode };
MainV2.comPort.setMode(mode, MAVLink.MAV_MODE_FLAG.SAFETY_ARMED);
((Control)sender).Enabled = true;
return;
}

if (CMB_action.Text == actions.Battery_Reset.ToString())
{
Expand Down

0 comments on commit 4db7b20

Please sign in to comment.