Files
charger/charger-gui/operations/TrainOperation.cs
T

64 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace charger_gui.operations
{
class TrainOperation : AutomaticOperation
{
const float MAX_VOLTAGE = 14.5f;
private int passed;
private bool isComplete = false;
private int duration;
public override string Status
{
get
{
if (isComplete) return "Training complete in " + passed + " seconds";
else return "Training, passed " + passed + " seconds (of " + duration + ")";
}
}
public TrainOperation(Logger log, MainWindowViewModel model, int duration) : base(log, model)
{
this.duration = duration;
}
protected override void Work()
{
log.Log("Training started");
var start = DateTime.Now;
while (passed < duration)
{
model.IsCharging = true;
model.IsLampOn = false;
Thread.Sleep(1000);
model.IsCharging = false;
model.IsLampOn = false;
Thread.Sleep(50);
model.IsCharging = false;
model.IsLampOn = true;
Thread.Sleep(1000);
model.IsCharging = false;
model.IsLampOn = false;
Thread.Sleep(50);
passed = (int)((DateTime.Now - start).TotalSeconds);
OnStatusChanged();
log.Log("Training" + passed + "s " + model.UAcc.ToString("F4"));
if (model.U2 < 10f)
{
log.Log("Training error: NO POWER. " + model.U2.ToString("F4"));
}
}
log.Log("Training complete in " + passed + " seconds");
model.IsCharging = false;
model.IsLampOn = false;
isComplete = true;
OnStatusChanged();
}
}
}