diff --git a/.gitignore b/.gitignore
index 6cf7b8f..1a16dd3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
charger-gui/.vs/
charger-gui/bin/
charger-gui/obj/
+charger-gui/publish/
diff --git a/charger-gui/MainWindow.xaml b/charger-gui/MainWindow.xaml
index a6936e3..ac9c394 100644
--- a/charger-gui/MainWindow.xaml
+++ b/charger-gui/MainWindow.xaml
@@ -36,21 +36,26 @@
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -61,6 +66,7 @@
+
diff --git a/charger-gui/MainWindow.xaml.cs b/charger-gui/MainWindow.xaml.cs
index 3da0169..0468117 100644
--- a/charger-gui/MainWindow.xaml.cs
+++ b/charger-gui/MainWindow.xaml.cs
@@ -60,6 +60,16 @@ namespace charger_gui
model.IsCharging = !model.IsCharging;
}
+ private void CalibrateButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (model.CurrentOperation != null)
+ {
+ model.CurrentOperation.Cancel();
+ }
+ model.CurrentOperation = new CalibrateOperation(log, model);
+ model.CurrentOperation.Start();
+ }
+
private void DischargeButton_Click(object sender, RoutedEventArgs e)
{
if (model.CurrentOperation != null)
@@ -92,7 +102,7 @@ namespace charger_gui
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
- Application.Current.Shutdown();
+ Environment.Exit(0);
}
}
}
diff --git a/charger-gui/MainWindowViewModel.cs b/charger-gui/MainWindowViewModel.cs
index 5cf1d3a..aafb9fb 100644
--- a/charger-gui/MainWindowViewModel.cs
+++ b/charger-gui/MainWindowViewModel.cs
@@ -21,17 +21,27 @@ namespace charger_gui
}
}
- private float iAcc;
- public float IAcc
+ private float iRaw;
+ public float IRaw
{
get
{
- return iAcc;
+ return iRaw;
}
set
{
- iAcc = value;
- OnPropertyChanged("IAcc");
+ iRaw = value;
+ OnPropertyChanged("IRaw");
+ OnPropertyChanged("IReal");
+ }
+ }
+ public float IZero { get; internal set; }
+
+ public float IReal
+ {
+ get
+ {
+ return IRaw - IZero;
}
}
@@ -60,6 +70,7 @@ namespace charger_gui
{
u3 = value;
OnPropertyChanged("U3");
+ OnPropertyChanged("UAcc");
}
}
@@ -88,6 +99,15 @@ namespace charger_gui
{
u5 = value;
OnPropertyChanged("U5");
+ OnPropertyChanged("UAcc");
+ }
+ }
+
+ public float UAcc
+ {
+ get
+ {
+ return U3 - U5;
}
}
diff --git a/charger-gui/Properties/app.manifest b/charger-gui/Properties/app.manifest
new file mode 100644
index 0000000..3d38900
--- /dev/null
+++ b/charger-gui/Properties/app.manifest
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/charger-gui/UpdateWorker.cs b/charger-gui/UpdateWorker.cs
index a815e28..f3bd07a 100644
--- a/charger-gui/UpdateWorker.cs
+++ b/charger-gui/UpdateWorker.cs
@@ -68,7 +68,7 @@ namespace charger_gui
while (!shouldRestart)
{
var r1 = master.ReadHoldingRegisters(SLAVE_ADDRESS, 0, 2);
- model.IAcc = ToFloat(r1[0], r1[1]);
+ model.IRaw = ToFloat(r1[0], r1[1]);
var r2 = master.ReadHoldingRegisters(SLAVE_ADDRESS, 6, 8);
model.U2 = ToFloat(r2[0], r2[1]);
model.U3 = ToFloat(r2[2], r2[3]);
diff --git a/charger-gui/charger-gui.csproj b/charger-gui/charger-gui.csproj
index 9a3deb7..e6bfa0d 100644
--- a/charger-gui/charger-gui.csproj
+++ b/charger-gui/charger-gui.csproj
@@ -13,7 +13,8 @@
{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
4
true
- C:\Work\charger\charger-gui\publish\
+ false
+ W:\temp\charger-gui\
true
Disk
false
@@ -23,12 +24,11 @@
false
false
true
- 0
+ 4
1.0.0.%2a
- false
false
true
- true
+ false
AnyCPU
@@ -59,7 +59,13 @@
true
- true
+ false
+
+
+ LocalIntranet
+
+
+ Properties\app.manifest
@@ -86,6 +92,7 @@
+
@@ -124,6 +131,7 @@
+
SettingsSingleFileGenerator
Settings.Designer.cs
diff --git a/charger-gui/charger-gui.csproj.user b/charger-gui/charger-gui.csproj.user
index 9d9e44c..c69ee8e 100644
--- a/charger-gui/charger-gui.csproj.user
+++ b/charger-gui/charger-gui.csproj.user
@@ -1,7 +1,7 @@
-
+ W:\temp\charger-gui\|C:\Work\charger\charger-gui\publish\
@@ -10,4 +10,7 @@
ru-RU
false
+
+ false
+
\ No newline at end of file
diff --git a/charger-gui/operations/CalibrateOperation.cs b/charger-gui/operations/CalibrateOperation.cs
new file mode 100644
index 0000000..e75da72
--- /dev/null
+++ b/charger-gui/operations/CalibrateOperation.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+
+namespace charger_gui.operations
+{
+ class CalibrateOperation : AutomaticOperation
+ {
+ const float SECONDS_TO_PASS = 10f;
+
+ private int passed;
+ private bool isComplete = false;
+ public override string Status
+ {
+ get
+ {
+ if (isComplete) return "Calibrating complete in " + passed + " seconds";
+ else return "Calibrating, passed " + passed + " seconds";
+ }
+ }
+
+ public CalibrateOperation(Logger log, MainWindowViewModel model) : base(log, model)
+ {
+ }
+
+ protected override void Work()
+ {
+ log.Log("Calibrating started");
+ var start = DateTime.Now;
+ model.IsCharging = false;
+ model.IsLampOn = false;
+ Thread.Sleep(500);
+ float sum = 0;
+ int cnt = 0;
+ while (passed < SECONDS_TO_PASS)
+ {
+ Thread.Sleep(20);
+ sum += model.IRaw;
+ cnt++;
+ passed = (int)((DateTime.Now - start).TotalSeconds);
+ OnStatusChanged();
+ }
+ model.IZero = sum / cnt;
+ log.Log("Calibrating complete in " + passed + " seconds");
+ model.IsLampOn = false;
+ isComplete = true;
+ OnStatusChanged();
+ }
+ }
+}
diff --git a/charger-gui/operations/ChargeOperation.cs b/charger-gui/operations/ChargeOperation.cs
index 64efe09..fd53e7f 100644
--- a/charger-gui/operations/ChargeOperation.cs
+++ b/charger-gui/operations/ChargeOperation.cs
@@ -32,12 +32,12 @@ namespace charger_gui.operations
model.IsCharging = true;
model.IsLampOn = false;
Thread.Sleep(500);
- while (model.U3 < MAX_VOLTAGE)
+ while (model.UAcc < MAX_VOLTAGE)
{
Thread.Sleep(1000);
passed = (int)((DateTime.Now - start).TotalSeconds);
OnStatusChanged();
- log.Log("Charging " + passed + "s " + model.U3.ToString("F4"));
+ log.Log("Charging " + passed + "s " + model.UAcc.ToString("F4"));
if (model.U2 < 10f)
{
log.Log("Charging error: NO POWER. " + model.U2.ToString("F4"));
diff --git a/charger-gui/operations/DischargeOperation.cs b/charger-gui/operations/DischargeOperation.cs
index bffd6d5..a56c097 100644
--- a/charger-gui/operations/DischargeOperation.cs
+++ b/charger-gui/operations/DischargeOperation.cs
@@ -32,7 +32,7 @@ namespace charger_gui.operations
model.IsCharging = false;
model.IsLampOn = true;
Thread.Sleep(500);
- while (model.U3 > MIN_VOLTAGE)
+ while (model.UAcc > MIN_VOLTAGE)
{
Thread.Sleep(1000);
passed = (int)((DateTime.Now - start).TotalSeconds);
diff --git a/charger-gui/operations/TrainOperation.cs b/charger-gui/operations/TrainOperation.cs
index 861d229..ab49443 100644
--- a/charger-gui/operations/TrainOperation.cs
+++ b/charger-gui/operations/TrainOperation.cs
@@ -47,7 +47,7 @@ namespace charger_gui.operations
Thread.Sleep(50);
passed = (int)((DateTime.Now - start).TotalSeconds);
OnStatusChanged();
- log.Log("Training" + passed + "s " + model.U3.ToString("F4"));
+ log.Log("Training" + passed + "s " + model.UAcc.ToString("F4"));
if (model.U2 < 10f)
{
log.Log("Training error: NO POWER. " + model.U2.ToString("F4"));