53 lines
1.1 KiB
C#
53 lines
1.1 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|