212 lines
3.2 KiB
C#
212 lines
3.2 KiB
C#
using charger_gui.operations;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO.Ports;
|
|
using System.Windows.Media;
|
|
|
|
namespace charger_gui
|
|
{
|
|
class MainWindowViewModel : INotifyPropertyChanged
|
|
{
|
|
private List<string> ports;
|
|
public List<string> Ports
|
|
{
|
|
get
|
|
{
|
|
if (ports == null)
|
|
{
|
|
FillPorts();
|
|
}
|
|
return ports;
|
|
}
|
|
}
|
|
|
|
private float iAcc;
|
|
public float IAcc
|
|
{
|
|
get
|
|
{
|
|
return iAcc;
|
|
}
|
|
set
|
|
{
|
|
iAcc = value;
|
|
OnPropertyChanged("IAcc");
|
|
}
|
|
}
|
|
|
|
private float u2;
|
|
public float U2
|
|
{
|
|
get
|
|
{
|
|
return u2;
|
|
}
|
|
set
|
|
{
|
|
u2 = value;
|
|
OnPropertyChanged("U2");
|
|
}
|
|
}
|
|
|
|
private float u3;
|
|
public float U3
|
|
{
|
|
get
|
|
{
|
|
return u3;
|
|
}
|
|
set
|
|
{
|
|
u3 = value;
|
|
OnPropertyChanged("U3");
|
|
}
|
|
}
|
|
|
|
private float u4;
|
|
public float U4
|
|
{
|
|
get
|
|
{
|
|
return u4;
|
|
}
|
|
set
|
|
{
|
|
u4 = value;
|
|
OnPropertyChanged("U4");
|
|
}
|
|
}
|
|
|
|
private float u5;
|
|
public float U5
|
|
{
|
|
get
|
|
{
|
|
return u5;
|
|
}
|
|
set
|
|
{
|
|
u5 = value;
|
|
OnPropertyChanged("U5");
|
|
}
|
|
}
|
|
|
|
private bool isConnected;
|
|
public bool IsConnected
|
|
{
|
|
set
|
|
{
|
|
if (isConnected != value)
|
|
{
|
|
isConnected = value;
|
|
OnPropertyChanged("ConnectionStatus");
|
|
}
|
|
}
|
|
}
|
|
private Brush connectedBrush = new SolidColorBrush(Color.FromRgb(0, 255, 0));
|
|
private Brush notConnectedBrush = new SolidColorBrush(Color.FromRgb(255, 0, 0));
|
|
|
|
public Brush ConnectionStatus
|
|
{
|
|
get
|
|
{
|
|
if (isConnected) return connectedBrush;
|
|
else return notConnectedBrush;
|
|
}
|
|
}
|
|
|
|
private bool isCharging;
|
|
public bool IsCharging
|
|
{
|
|
get { return isCharging; }
|
|
set
|
|
{
|
|
if (isCharging != value)
|
|
{
|
|
isCharging = value;
|
|
OnPropertyChanged("ChargeStatus");
|
|
}
|
|
}
|
|
|
|
}
|
|
public Brush ChargeStatus
|
|
{
|
|
get
|
|
{
|
|
if (isCharging) return connectedBrush;
|
|
else return notConnectedBrush;
|
|
}
|
|
}
|
|
private bool isLampOn;
|
|
public bool IsLampOn
|
|
{
|
|
get { return isLampOn; }
|
|
set
|
|
{
|
|
if (isLampOn != value)
|
|
{
|
|
isLampOn = value;
|
|
OnPropertyChanged("LampStatus");
|
|
}
|
|
}
|
|
}
|
|
public Brush LampStatus
|
|
{
|
|
get
|
|
{
|
|
if (isLampOn) return connectedBrush;
|
|
else return notConnectedBrush;
|
|
}
|
|
}
|
|
|
|
private AutomaticOperation currentOperation;
|
|
public AutomaticOperation CurrentOperation
|
|
{
|
|
get
|
|
{
|
|
return currentOperation;
|
|
}
|
|
set
|
|
{
|
|
if (currentOperation != null)
|
|
{
|
|
currentOperation.StatusChanged -= OnCurrentOperationStatusChanged;
|
|
}
|
|
currentOperation = value;
|
|
if (currentOperation != null)
|
|
{
|
|
currentOperation.StatusChanged += OnCurrentOperationStatusChanged;
|
|
}
|
|
OnPropertyChanged("OperationStatus");
|
|
}
|
|
}
|
|
|
|
private void OnCurrentOperationStatusChanged()
|
|
{
|
|
OnPropertyChanged("OperationStatus");
|
|
}
|
|
|
|
public string OperationStatus
|
|
{
|
|
get
|
|
{
|
|
if (currentOperation == null) return "MANUAL MODE";
|
|
return currentOperation.Status;
|
|
}
|
|
}
|
|
|
|
public int TrainDuration { get; set; }
|
|
|
|
private void FillPorts()
|
|
{
|
|
ports = new List<string>(SerialPort.GetPortNames());
|
|
}
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
public void OnPropertyChanged(string name = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
|
}
|
|
}
|
|
}
|