89 lines
1.5 KiB
C#
89 lines
1.5 KiB
C#
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;
|
|
}
|
|
}
|
|
|
|
public float iAcc;
|
|
public string IAcc
|
|
{
|
|
get
|
|
{
|
|
return string.Format("{0,8:0.0000}", iAcc);
|
|
}
|
|
}
|
|
|
|
public float uAcc;
|
|
public string UAcc
|
|
{
|
|
get
|
|
{
|
|
return string.Format("{0,8:0.0000}", uAcc);
|
|
}
|
|
}
|
|
|
|
public float iLamp;
|
|
public string ILamp
|
|
{
|
|
get
|
|
{
|
|
return string.Format("{0,8:0.0000}", iLamp);
|
|
}
|
|
}
|
|
|
|
public float uLamp;
|
|
public string ULamp
|
|
{
|
|
get
|
|
{
|
|
return string.Format("{0,8:0.0000}", uLamp);
|
|
}
|
|
}
|
|
|
|
public bool isConnected;
|
|
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 void FillPorts()
|
|
{
|
|
ports = new List<string>(SerialPort.GetPortNames());
|
|
}
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
public void OnPropertyChanged(string propertyName)
|
|
{
|
|
PropertyChangedEventHandler handler = PropertyChanged;
|
|
if (handler == null) return;
|
|
handler(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
}
|
|
}
|