Автозаряд и авторазряд will do well.

This commit is contained in:
ftc
2024-03-03 18:19:35 +03:00
parent acaba420d6
commit c93ec551a6
9 changed files with 432 additions and 48 deletions
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace charger_gui.operations
{
class AutomaticOperation
{
private Thread workingThread;
public bool IsComplete
{
get
{
return workingThread == null || workingThread.IsAlive;
}
}
public event Action StatusChanged;
public virtual string Status
{
get
{
return "UNKNOWN";
}
}
protected Logger log;
protected MainWindowViewModel model;
public AutomaticOperation(Logger log, MainWindowViewModel model)
{
this.log = log;
this.model = model;
}
public void Start()
{
workingThread = new Thread(Work);
workingThread.Start();
}
public void Cancel()
{
if (workingThread != null)
{
workingThread.Abort();
}
}
protected void OnStatusChanged()
{
StatusChanged?.Invoke();
}
protected virtual void Work()
{
}
}
}
+51
View File
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace charger_gui.operations
{
class ChargeOperation : AutomaticOperation
{
const float MAX_VOLTAGE = 14.5f;
private int passed;
private bool isComplete = false;
public override string Status
{
get
{
if (isComplete) return "Charging complete in " + passed + " seconds";
else return "Charging, passed " + passed + " seconds";
}
}
public ChargeOperation(Logger log, MainWindowViewModel model) : base(log, model)
{
}
protected override void Work()
{
log.Log("Charging started");
var start = DateTime.Now;
model.IsCharging = true;
model.IsLampOn = false;
Thread.Sleep(500);
while (model.U2Acc < MAX_VOLTAGE)
{
Thread.Sleep(1000);
passed = (int)((DateTime.Now - start).TotalSeconds);
OnStatusChanged();
log.Log("Charging " + passed + "s " + model.U2Acc.ToString("F4"));
if (model.U1Acc < 10f)
{
log.Log("Charging error: NO POWER. " + model.U1Acc.ToString("F4"));
}
}
log.Log("Charging complete in " + passed + " seconds");
isComplete = true;
OnStatusChanged();
}
}
}
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace charger_gui.operations
{
class DischargeOperation : AutomaticOperation
{
const float MIN_VOLTAGE = 10.8f;
private int passed;
private bool isComplete = false;
public override string Status
{
get
{
if (isComplete) return "Discharging complete in " + passed + " seconds";
else return "Discharging, passed " + passed + " seconds";
}
}
public DischargeOperation(Logger log, MainWindowViewModel model) : base(log, model)
{
}
protected override void Work()
{
log.Log("Discharging started");
var start = DateTime.Now;
model.IsCharging = false;
model.IsLampOn = true;
Thread.Sleep(500);
while (model.U2Acc > MIN_VOLTAGE)
{
Thread.Sleep(1000);
passed = (int)((DateTime.Now - start).TotalSeconds);
OnStatusChanged();
log.Log("Discharging " + passed + "s " + model.U2Acc.ToString("F4"));
}
log.Log("Discharging complete in " + passed + " seconds");
isComplete = true;
OnStatusChanged();
}
}
}