Files

53 lines
1.2 KiB
C#

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.UAcc < MAX_VOLTAGE)
{
Thread.Sleep(1000);
passed = (int)((DateTime.Now - start).TotalSeconds);
OnStatusChanged();
log.Log("Charging " + passed + "s " + model.UAcc.ToString("F4"));
if (model.U2 < 10f)
{
log.Log("Charging error: NO POWER. " + model.U2.ToString("F4"));
}
}
log.Log("Charging complete in " + passed + " seconds");
model.IsCharging = false;
isComplete = true;
OnStatusChanged();
}
}
}