-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
ConfigBatteryMonitoring.cs
655 lines (592 loc) · 26.8 KB
/
ConfigBatteryMonitoring.cs
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
using MissionPlanner.Controls;
using MissionPlanner.Utilities;
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace MissionPlanner.GCSViews.ConfigurationView
{
public partial class ConfigBatteryMonitoring : MyUserControl, IActivate, IDeactivate
{
private bool startup;
public ConfigBatteryMonitoring()
{
InitializeComponent();
}
public void Activate()
{
if (!MainV2.comPort.BaseStream.IsOpen || !MainV2.comPort.MAV.param.ContainsKey("BATT_MONITOR"))
{
Enabled = false;
return;
}
startup = true;
CMB_batmontype.setup(
ParameterMetaDataRepository.GetParameterOptionsInt("BATT_MONITOR",
MainV2.comPort.MAV.cs.firmware.ToString()), "BATT_MONITOR", MainV2.comPort.MAV.param);
if (MainV2.comPort.MAV.param["BATT_CAPACITY"] != null)
TXT_battcapacity.Text = MainV2.comPort.MAV.param["BATT_CAPACITY"].ToString();
TXT_voltage.Text = MainV2.comPort.MAV.cs.battery_voltage.ToString();
TXT_measuredvoltage.Text = TXT_voltage.Text;
if (MainV2.comPort.MAV.param["BATT_AMP_PERVLT"] != null)
TXT_AMP_PERVLT.Text = MainV2.comPort.MAV.param["BATT_AMP_PERVLT"].ToString();
// new
if (MainV2.comPort.MAV.param["BATT_VOLT_MULT"] != null)
TXT_divider_VOLT_MULT.Text = MainV2.comPort.MAV.param["BATT_VOLT_MULT"].ToString();
if (MainV2.comPort.MAV.param["BATT_AMP_PERVOLT"] != null)
TXT_AMP_PERVLT.Text = MainV2.comPort.MAV.param["BATT_AMP_PERVOLT"].ToString();
// old
if (MainV2.comPort.MAV.param["VOLT_DIVIDER"] != null)
TXT_divider_VOLT_MULT.Text = MainV2.comPort.MAV.param["VOLT_DIVIDER"].ToString();
if (MainV2.comPort.MAV.param["AMP_PER_VOLT"] != null)
TXT_AMP_PERVLT.Text = MainV2.comPort.MAV.param["AMP_PER_VOLT"].ToString();
if (Settings.Instance.GetBoolean("speechbatteryenabled") && Settings.Instance.GetBoolean("speechenable"))
{
CHK_speechbattery.Checked = true;
}
else
{
CHK_speechbattery.Checked = false;
}
//http://plane.ardupilot.com/wiki/common-pixhawk-overview/#pixhawk_analog_input_pins_virtual_pin_firmware_mapped_pin_id
// determine the sensor type
if (TXT_AMP_PERVLT.Text == (13.6612).ToString() && TXT_divider_VOLT_MULT.Text == (4.127115).ToString())
{
CMB_batmonsensortype.SelectedIndex = 1;
}
else if (TXT_AMP_PERVLT.Text == (27.3224).ToString() && TXT_divider_VOLT_MULT.Text == (15.70105).ToString())
{
CMB_batmonsensortype.SelectedIndex = 2;
}
else if (TXT_AMP_PERVLT.Text == (54.64481).ToString() && TXT_divider_VOLT_MULT.Text == (15.70105).ToString())
{
CMB_batmonsensortype.SelectedIndex = 3;
}
else if (TXT_AMP_PERVLT.Text == (18.0018).ToString() && TXT_divider_VOLT_MULT.Text == (10.10101).ToString())
{
CMB_batmonsensortype.SelectedIndex = 4;
}
else if (TXT_AMP_PERVLT.Text == (17).ToString() && TXT_divider_VOLT_MULT.Text == (12.02).ToString())
{
CMB_batmonsensortype.SelectedIndex = 5;
}
else if (TXT_AMP_PERVLT.Text == (24).ToString() && TXT_divider_VOLT_MULT.Text == (12.02).ToString())
{
CMB_batmonsensortype.SelectedIndex = 6;
}
else if (TXT_AMP_PERVLT.Text == (39.877).ToString() && TXT_divider_VOLT_MULT.Text == (12.02).ToString())
{
CMB_batmonsensortype.SelectedIndex = 7;
}
else if (TXT_AMP_PERVLT.Text == (24).ToString() && TXT_divider_VOLT_MULT.Text == (18).ToString())
{
CMB_batmonsensortype.SelectedIndex = 8;
}
else if (TXT_AMP_PERVLT.Text == (36.364).ToString() && TXT_divider_VOLT_MULT.Text == (18.182).ToString())
{
CMB_batmonsensortype.SelectedIndex = 9;
}
else
{
CMB_batmonsensortype.SelectedIndex = 0;
}
// determine the board type
if (MainV2.comPort.MAV.param["BATT_VOLT_PIN"] != null)
{
CMB_HWVersion.Enabled = true;
var value = (double)MainV2.comPort.MAV.param["BATT_VOLT_PIN"];
if (value == 0) // apm1
{
CMB_HWVersion.SelectedIndex = 0;
}
else if (value == 1) // apm2
{
CMB_HWVersion.SelectedIndex = 1;
}
else if (value == 13) // apm2.5
{
CMB_HWVersion.SelectedIndex = 2;
}
else if (value == 100) // px4
{
CMB_HWVersion.SelectedIndex = 3;
}
else if (value == 2)
{
// pixhawk
CMB_HWVersion.SelectedIndex = 4;
}
else if (value == 6)
{
// vrbrain4
CMB_HWVersion.SelectedIndex = 7;
}
else if (value == 10)
{
// vrbrain 5 or micro
if ((double)MainV2.comPort.MAV.param["BATT_CURR_PIN"] == 11)
{
CMB_HWVersion.SelectedIndex = 5;
}
else
{
CMB_HWVersion.SelectedIndex = 6;
}
}
else if (value == 14)
{
// cubeorange
CMB_HWVersion.SelectedIndex = 8;
}
else if (value == 16)
{
// durandal
CMB_HWVersion.SelectedIndex = 9;
}
else if (value == 8)
{
// Pixhawk 6C/Pix32 v6
CMB_HWVersion.SelectedIndex = 10;
}
}
else
{
CMB_HWVersion.Enabled = false;
}
startup = false;
CMB_batmontype_SelectedIndexChanged(null, null);
CMB_batmonsensortype_SelectedIndexChanged(null, null);
timer1.Start();
}
public void Deactivate()
{
timer1.Stop();
startup = true;
}
private void TXT_battcapacity_Validated(object sender, EventArgs e)
{
if (startup || ((TextBox)sender).Enabled == false)
return;
try
{
if (MainV2.comPort.MAV.param["BATT_CAPACITY"] == null)
{
CustomMessageBox.Show(Strings.ErrorFeatureNotEnabled, Strings.ERROR);
}
else
{
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_CAPACITY", float.Parse(TXT_battcapacity.Text));
}
}
catch
{
CustomMessageBox.Show("Set BATT_CAPACITY Failed", Strings.ERROR);
}
}
private void CMB_batmontype_SelectedIndexChanged(object sender, EventArgs e)
{
if (startup)
return;
try
{
if (MainV2.comPort.MAV.param["BATT_MONITOR"] == null)
{
CustomMessageBox.Show(Strings.ErrorFeatureNotEnabled, Strings.ERROR);
}
else
{
var selection = (int)CMB_batmontype.SelectedValue;
CMB_batmonsensortype.Enabled = true;
TXT_voltage.Enabled = false;
if (selection == 0)
{
CMB_batmonsensortype.Enabled = false;
CMB_HWVersion.Enabled = false;
groupBox4.Enabled = false;
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_VOLT_PIN", -1);
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_CURR_PIN", -1);
}
else if (selection == 4)
{
CMB_batmonsensortype.Enabled = true;
CMB_HWVersion.Enabled = true;
groupBox4.Enabled = true;
TXT_AMP_PERVLT.Enabled = true;
}
else if (selection == 3)
{
groupBox4.Enabled = true;
CMB_batmonsensortype.Enabled = false;
CMB_HWVersion.Enabled = true;
TXT_AMP_PERVLT.Enabled = false;
TXT_measuredvoltage.Enabled = true;
TXT_divider_VOLT_MULT.Enabled = true;
}
if (MainV2.comPort.MAV.param.ContainsKey("BATT_MONITOR") &&
MainV2.comPort.MAV.param["BATT_MONITOR"].Value == 0 &&
selection != 0)
{
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_MONITOR", selection);
MainV2.comPort.getParamList();
this.Activate();
}
else
{
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_MONITOR", selection);
}
}
}
catch
{
CustomMessageBox.Show("Set BATT_MONITOR,BATT_VOLT_PIN,BATT_CURR_PIN Failed", Strings.ERROR);
}
}
private void TXT_measuredvoltage_Validating(object sender, CancelEventArgs e)
{
float ans = 0;
e.Cancel = !float.TryParse(TXT_measuredvoltage.Text, out ans);
}
private void TXT_measuredvoltage_Validated(object sender, EventArgs e)
{
if (startup || ((TextBox)sender).Enabled == false)
return;
try
{
var measuredvoltage = float.Parse(TXT_measuredvoltage.Text);
var voltage = float.Parse(TXT_voltage.Text);
var divider = float.Parse(TXT_divider_VOLT_MULT.Text);
if (voltage == 0)
return;
var new_divider = (measuredvoltage * divider) / voltage;
TXT_divider_VOLT_MULT.Text = new_divider.ToString();
}
catch
{
CustomMessageBox.Show(Strings.InvalidNumberEntered, Strings.ERROR);
return;
}
try
{
MainV2.comPort.setParam(new[] { "VOLT_DIVIDER", "BATT_VOLT_MULT" }, float.Parse(TXT_divider_VOLT_MULT.Text));
}
catch
{
if (MainV2.comPort.MAV.param.ContainsKey("BATT_MONITOR") &&
(MainV2.comPort.MAV.param["BATT_MONITOR"].Value == 3 ||
MainV2.comPort.MAV.param["BATT_MONITOR"].Value == 4)) {
CustomMessageBox.Show("Set BATT_VOLT_MULT Failed", Strings.ERROR);
}
}
}
private void TXT_divider_Validating(object sender, CancelEventArgs e)
{
float ans = 0;
e.Cancel = !float.TryParse(TXT_divider_VOLT_MULT.Text, out ans);
}
private void TXT_divider_Validated(object sender, EventArgs e)
{
if (startup || ((TextBox)sender).Enabled == false)
return;
try
{
MainV2.comPort.setParam(new[] { "VOLT_DIVIDER", "BATT_VOLT_MULT" }, float.Parse(TXT_divider_VOLT_MULT.Text));
}
catch
{
if (MainV2.comPort.MAV.param.ContainsKey("BATT_MONITOR") &&
(MainV2.comPort.MAV.param["BATT_MONITOR"].Value == 3 ||
MainV2.comPort.MAV.param["BATT_MONITOR"].Value == 4)) {
CustomMessageBox.Show("Set BATT_VOLT_MULT Failed", Strings.ERROR);
}
}
}
private void TXT_ampspervolt_Validating(object sender, CancelEventArgs e)
{
float ans = 0;
e.Cancel = !float.TryParse(TXT_AMP_PERVLT.Text, out ans);
}
private void TXT_ampspervolt_Validated(object sender, EventArgs e)
{
if (startup || ((TextBox)sender).Enabled == false)
return;
try
{
MainV2.comPort.setParam(new[] { "AMP_PER_VOLT", "BATT_AMP_PERVOLT", "BATT_AMP_PERVLT" }, float.Parse(TXT_AMP_PERVLT.Text));
}
catch
{
if (MainV2.comPort.MAV.param.ContainsKey("BATT_MONITOR") &&
(MainV2.comPort.MAV.param["BATT_MONITOR"].Value == 3 ||
MainV2.comPort.MAV.param["BATT_MONITOR"].Value == 4)) {
CustomMessageBox.Show("Set BATT_AMP_PERVOLT Failed", Strings.ERROR);
}
}
}
private void CMB_batmonsensortype_SelectedIndexChanged(object sender, EventArgs e)
{
var selection = int.Parse(CMB_batmonsensortype.Text.Substring(0, 1));
if (selection == 1) // atto 45
{
var maxvolt = 13.6f;
var maxamps = 44.7f;
var mvpervolt = 242.3f;
var mvperamp = 73.20f;
// ~ 3.295v
var topvolt = (maxvolt * mvpervolt) / 1000;
// ~ 3.294v
var topamps = (maxamps * mvperamp) / 1000;
TXT_divider_VOLT_MULT.Text = (maxvolt / topvolt).ToString();
TXT_AMP_PERVLT.Text = (maxamps / topamps).ToString();
}
else if (selection == 2) // atto 90
{
var maxvolt = 50f;
var maxamps = 89.4f;
var mvpervolt = 63.69f;
var mvperamp = 36.60f;
var topvolt = (maxvolt * mvpervolt) / 1000;
var topamps = (maxamps * mvperamp) / 1000;
TXT_divider_VOLT_MULT.Text = (maxvolt / topvolt).ToString();
TXT_AMP_PERVLT.Text = (maxamps / topamps).ToString();
}
else if (selection == 3) // atto 180
{
var maxvolt = 50f;
var maxamps = 178.8f;
var mvpervolt = 63.69f;
var mvperamp = 18.30f;
var topvolt = (maxvolt * mvpervolt) / 1000;
var topamps = (maxamps * mvperamp) / 1000;
TXT_divider_VOLT_MULT.Text = (maxvolt / topvolt).ToString();
TXT_AMP_PERVLT.Text = (maxamps / topamps).ToString();
}
else if (selection == 4) // 3dr iv
{
var maxvolt = 50f;
var maxamps = 90f;
var mvpervolt = 99f;
var mvperamp = 55.55f;
var topvolt = (maxvolt * mvpervolt) / 1000;
var topamps = (maxamps * mvperamp) / 1000;
TXT_divider_VOLT_MULT.Text = (maxvolt / topvolt).ToString();
TXT_AMP_PERVLT.Text = (maxamps / topamps).ToString();
}
else if (selection == 5) // 3dr 4 in one esc
{
TXT_divider_VOLT_MULT.Text = (12.02).ToString();
TXT_AMP_PERVLT.Text = (17).ToString();
}
else if (selection == 6) // hv 3dr apm - what i have
{
TXT_divider_VOLT_MULT.Text = (12.02).ToString();
TXT_AMP_PERVLT.Text = (24).ToString();
}
else if (selection == 7) // hv 3dr px4 cube
{
TXT_divider_VOLT_MULT.Text = (12.02).ToString();
TXT_AMP_PERVLT.Text = (39.877).ToString();
}
else if (selection == 8) // pixhack
{
TXT_divider_VOLT_MULT.Text = (18).ToString();
TXT_AMP_PERVLT.Text = (24).ToString();
}
else if (selection == 9) // Holybro Pixhawk4
{
TXT_divider_VOLT_MULT.Text = (18.182).ToString();
TXT_AMP_PERVLT.Text = (36.364).ToString();
}
// enable to update
TXT_divider_VOLT_MULT.Enabled = true;
TXT_AMP_PERVLT.Enabled = true;
TXT_measuredvoltage.Enabled = true;
// update
TXT_ampspervolt_Validated(TXT_AMP_PERVLT, null);
TXT_divider_Validated(TXT_divider_VOLT_MULT, null);
// disable
TXT_divider_VOLT_MULT.Enabled = false;
TXT_AMP_PERVLT.Enabled = false;
TXT_measuredvoltage.Enabled = false;
//reenable if needed
if (selection == 0)
{
TXT_divider_VOLT_MULT.Enabled = true;
TXT_AMP_PERVLT.Enabled = true;
TXT_measuredvoltage.Enabled = true;
}
}
private int getIndex(ComboBox ctl, int no)
{
foreach (var item in ctl.Items)
{
var ans = int.Parse(item.ToString().Substring(0, 1));
if (ans == no)
return ctl.Items.IndexOf(item);
}
return -1;
}
private void timer1_Tick(object sender, EventArgs e)
{
TXT_voltage.Text = MainV2.comPort.MAV.cs.battery_voltage.ToString();
txt_current.Text = MainV2.comPort.MAV.cs.current.ToString();
}
private void CMB_apmversion_SelectedIndexChanged(object sender, EventArgs e)
{
if (startup)
return;
var selection = int.Parse(CMB_HWVersion.Text.Substring(0, 2).Replace(":", ""));
try
{
if (selection == 0)
{
// apm1
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_VOLT_PIN", 0);
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_CURR_PIN", 1);
}
else if (selection == 1)
{
// apm2
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_VOLT_PIN", 1);
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_CURR_PIN", 2);
}
else if (selection == 2)
{
//apm2.5
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_VOLT_PIN", 13);
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_CURR_PIN", 12);
}
else if (selection == 3)
{
//px4
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_VOLT_PIN", 100);
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_CURR_PIN", 101);
}
else if (selection == 4)
{
//px4
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_VOLT_PIN", 2);
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_CURR_PIN", 3);
}
else if (selection == 5)
{
//vrbrain 5
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_VOLT_PIN", 10);
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_CURR_PIN", 11);
}
else if (selection == 6)
{
//vr micro brain 5
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_VOLT_PIN", 10);
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_CURR_PIN", -1);
}
else if (selection == 7)
{
//vr brain 4
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_VOLT_PIN", 6);
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_CURR_PIN", 7);
}
else if (selection == 8)
{
//cube orange
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_VOLT_PIN", 14);
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_CURR_PIN", 15);
}
else if (selection == 9)
{
//durandal
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_VOLT_PIN", 16);
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_CURR_PIN", 17);
}
else if (selection == 10)
{
//Pixhawk 6C/Pix32 v6
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_VOLT_PIN", 8);
MainV2.comPort.setParam((byte)MainV2.comPort.sysidcurrent, (byte)MainV2.comPort.compidcurrent, "BATT_CURR_PIN", 4);
}
}
catch
{
CustomMessageBox.Show("Set BATT_????_PIN Failed", Strings.ERROR);
}
}
private void CHK_speechbattery_CheckedChanged(object sender, EventArgs e)
{
if (startup)
return;
// enable the battery event
Settings.Instance["speechbatteryenabled"] = ((CheckBox)sender).Checked.ToString();
// enable speech engine
Settings.Instance["speechenable"] = true.ToString();
if (((CheckBox)sender).Checked)
{
var speechstring = "WARNING, Battery at {batv} Volt, {batp} percent";
if (Settings.Instance["speechbattery"] != null)
speechstring = Settings.Instance["speechbattery"].ToString();
if (DialogResult.Cancel ==
InputBox.Show("Notification", "What do you want it to say?", ref speechstring))
return;
Settings.Instance["speechbattery"] = speechstring;
speechstring = "9.6";
if (Settings.Instance["speechbatteryvolt"] != null)
speechstring = Settings.Instance["speechbatteryvolt"].ToString();
if (DialogResult.Cancel ==
InputBox.Show("Battery Level", "What Voltage do you want to warn at?", ref speechstring))
return;
Settings.Instance["speechbatteryvolt"] = speechstring;
speechstring = "20";
if (Settings.Instance["speechbatterypercent"] != null)
speechstring = Settings.Instance["speechbatterypercent"].ToString();
if (DialogResult.Cancel ==
InputBox.Show("Battery Level", "What percentage do you want to warn at?", ref speechstring))
return;
Settings.Instance["speechbatterypercent"] = speechstring;
}
}
private void TXT_measuredvoltage_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyData == Keys.Enter)
TXT_measuredvoltage_Validated(sender, e);
}
private void TXT_ampspervolt_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyData == Keys.Enter)
TXT_ampspervolt_Validated(sender, e);
}
private void TXT_divider_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyData == Keys.Enter)
TXT_divider_Validated(sender, e);
}
private void txt_meascurrent_Validated(object sender, EventArgs e)
{
if (startup || ((TextBox)sender).Enabled == false)
return;
try
{
var measuredcurrent = float.Parse(txt_meascurrent.Text);
var current = float.Parse(txt_current.Text);
var divider = float.Parse(TXT_AMP_PERVLT.Text);
if (current == 0)
return;
var new_divider = (measuredcurrent * divider) / current;
TXT_AMP_PERVLT.Text = new_divider.ToString();
}
catch
{
CustomMessageBox.Show(Strings.InvalidNumberEntered, Strings.ERROR);
return;
}
try
{
MainV2.comPort.setParam(new[] { "AMP_PER_VOLT", "BATT_AMP_PERVOLT", "BATT_AMP_PERVLT" }, float.Parse(TXT_AMP_PERVLT.Text));
}
catch
{
if (MainV2.comPort.MAV.param.ContainsKey("BATT_MONITOR") &&
(MainV2.comPort.MAV.param["BATT_MONITOR"].Value == 3 ||
MainV2.comPort.MAV.param["BATT_MONITOR"].Value == 4)) {
CustomMessageBox.Show("Set BATT_AMP_PERVOLT Failed", Strings.ERROR);
}
}
}
}
}