-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathServoOptions.cs
More file actions
162 lines (135 loc) · 5.08 KB
/
ServoOptions.cs
File metadata and controls
162 lines (135 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MissionPlanner.Controls
{
public partial class ServoOptions : UserControl
{
// start at 5 increment each instance
static int servo = 5;
public int thisservo { get; set; }
public ServoOptions()
{
InitializeComponent();
thisservo = servo;
TXT_rcchannel.Text = thisservo.ToString();
loadSettings();
servo++;
TXT_rcchannel.BackColor = Color.Gray;
}
void loadSettings()
{
string desc = MainV2.getConfig("Servo" + thisservo + "_desc");
string low = MainV2.getConfig("Servo" + thisservo + "_low");
string high = MainV2.getConfig("Servo" + thisservo + "_high");
string highdesc = MainV2.getConfig("Servo" + thisservo + "_highdesc");
string lowdesc = MainV2.getConfig("Servo" + thisservo + "_lowdesc");
if (low != "")
{
TXT_pwm_low.Text = low;
}
if (high != "")
{
TXT_pwm_high.Text = high;
}
if (desc != "")
{
TXT_rcchannel.Text = desc;
}
if (highdesc != "")
{
BUT_High.Text = highdesc;
}
if (lowdesc != "")
{
BUT_Low.Text = lowdesc;
}
}
private void BUT_Low_Click(object sender, EventArgs e)
{
try
{
if (MainV2.comPort.doCommand(MAVLink.MAV_CMD.DO_SET_SERVO, thisservo, int.Parse(TXT_pwm_low.Text), 0, 0, 0, 0, 0))
{
TXT_rcchannel.BackColor = Color.Red;
}
else
{
CustomMessageBox.Show("Command Failed", "Error");
}
}
catch (Exception ex) { CustomMessageBox.Show("Command Failed " + ex.ToString(), "Error"); }
}
private void BUT_High_Click(object sender, EventArgs e)
{
try
{
if (MainV2.comPort.doCommand(MAVLink.MAV_CMD.DO_SET_SERVO, thisservo, int.Parse(TXT_pwm_high.Text), 0, 0, 0, 0, 0))
{
TXT_rcchannel.BackColor = Color.Green;
}
else
{
CustomMessageBox.Show("Command Failed", "Error");
}
}
catch (Exception ex) { CustomMessageBox.Show("Command Failed " + ex.ToString(), "Error"); }
}
private void BUT_Repeat_Click(object sender, EventArgs e)
{
try
{
if (MainV2.comPort.doCommand(MAVLink.MAV_CMD.DO_SET_SERVO, thisservo, int.Parse(TXT_pwm_low.Text), 0, 0, 0, 0, 0))
{
TXT_rcchannel.BackColor = Color.Red;
}
Application.DoEvents();
System.Threading.Thread.Sleep(200);
if (MainV2.comPort.doCommand(MAVLink.MAV_CMD.DO_SET_SERVO, thisservo, int.Parse(TXT_pwm_high.Text), 0, 0, 0, 0, 0))
{
TXT_rcchannel.BackColor = Color.Green;
}
Application.DoEvents();
System.Threading.Thread.Sleep(200);
if (MainV2.comPort.doCommand(MAVLink.MAV_CMD.DO_SET_SERVO, thisservo, int.Parse(TXT_pwm_low.Text), 0, 0, 0, 0, 0))
{
TXT_rcchannel.BackColor = Color.Red;
}
}
catch (Exception ex) { CustomMessageBox.Show("Command Failed " + ex.ToString(), "Error"); }
// MainV2.comPort.doCommand(MAVLink.MAV_CMD.DO_SET_SERVO, int.Parse(TXT_rcchannel.Text), int.Parse(TXT_pwm_high.Text), 10, 1000, 0, 0, 0);
}
private void TXT_pwm_low_TextChanged(object sender, EventArgs e)
{
MainV2.config["Servo" + thisservo + "_low"] = TXT_pwm_low.Text;
}
private void TXT_pwm_high_TextChanged(object sender, EventArgs e)
{
MainV2.config["Servo" + thisservo + "_high"] = TXT_pwm_high.Text;
}
private void renameToolStripMenuItem_Click(object sender, EventArgs e)
{
Control sourcectl = ((ContextMenuStrip)renameToolStripMenuItem.Owner).SourceControl;
string desc = sourcectl.Text;
MissionPlanner.Controls.InputBox.Show("Description", "Enter new Description", ref desc);
sourcectl.Text = desc;
if (sourcectl == BUT_High)
{
MainV2.config["Servo" + thisservo + "_highdesc"] = desc;
}
else if (sourcectl == BUT_Low)
{
MainV2.config["Servo" + thisservo + "_lowdesc"] = desc;
}
else if (sourcectl == TXT_rcchannel)
{
MainV2.config["Servo" + thisservo + "_desc"] = desc;
}
}
}
}