224 lines
3.4 KiB
C#
224 lines
3.4 KiB
C#
using charger_gui.operations;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.IO.Ports;
|
|
using System.Linq;
|
|
using System.Text;
|
|
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 u1Acc;
|
|
public float U1Acc
|
|
{
|
|
get
|
|
{
|
|
return u1Acc;
|
|
}
|
|
set
|
|
{
|
|
u1Acc = value;
|
|
OnPropertyChanged("U1Acc");
|
|
}
|
|
}
|
|
|
|
private float u2Acc;
|
|
public float U2Acc
|
|
{
|
|
get
|
|
{
|
|
return u2Acc;
|
|
}
|
|
set
|
|
{
|
|
u2Acc = value;
|
|
OnPropertyChanged("U2Acc");
|
|
}
|
|
}
|
|
|
|
private float iLamp;
|
|
public float ILamp
|
|
{
|
|
get
|
|
{
|
|
return iLamp;
|
|
}
|
|
set
|
|
{
|
|
iLamp = value;
|
|
OnPropertyChanged("ILamp");
|
|
}
|
|
}
|
|
|
|
private float u1Lamp;
|
|
public float U1Lamp
|
|
{
|
|
get
|
|
{
|
|
return u1Lamp;
|
|
}
|
|
set
|
|
{
|
|
u1Lamp = value;
|
|
OnPropertyChanged("U1Lamp");
|
|
}
|
|
}
|
|
|
|
private float u2Lamp;
|
|
public float U2Lamp
|
|
{
|
|
get
|
|
{
|
|
return u2Lamp;
|
|
}
|
|
set
|
|
{
|
|
u2Lamp = value;
|
|
OnPropertyChanged("U2Lamp");
|
|
}
|
|
}
|
|
|
|
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;
|
|
currentOperation.StatusChanged += OnCurrentOperationStatusChanged;
|
|
OnPropertyChanged("OperationStatus");
|
|
}
|
|
}
|
|
|
|
private void OnCurrentOperationStatusChanged()
|
|
{
|
|
OnPropertyChanged("OperationStatus");
|
|
}
|
|
|
|
public string OperationStatus
|
|
{
|
|
get
|
|
{
|
|
if (currentOperation == null) return "MANUAL MODE";
|
|
return currentOperation.Status;
|
|
}
|
|
}
|
|
|
|
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));
|
|
}
|
|
}
|
|
}
|