96 lines
2.9 KiB
C#
96 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.IO.Ports;
|
|
using RGBController2.Boards;
|
|
using System.ComponentModel;
|
|
using RGBController2.ViewModels.LightingModes;
|
|
|
|
namespace RGBController2.ViewModels.Tabs
|
|
{
|
|
public class ArduinoTab : Tab, INotifyPropertyChanged
|
|
{
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
private enum LightingModes
|
|
{
|
|
StaticMode = 0,
|
|
AnimationMode,
|
|
QuakeMode
|
|
}
|
|
|
|
private ArduinoBoard _arduinoBoard;
|
|
|
|
private string[] _availablePorts;
|
|
public string[] AvailablePorts
|
|
{
|
|
get { return _availablePorts; }
|
|
set { _availablePorts = value; }
|
|
}
|
|
|
|
private string _conntectionStatus;
|
|
public string ConnectionStatus
|
|
{
|
|
get { return _conntectionStatus; }
|
|
set { _conntectionStatus = value; }
|
|
}
|
|
|
|
private string _selectedPort;
|
|
public string SelectedPort
|
|
{
|
|
get { return _selectedPort; }
|
|
set
|
|
{
|
|
if (value != _selectedPort)
|
|
{
|
|
_selectedPort = value;
|
|
// Connect to the port here
|
|
_arduinoBoard = new ArduinoBoard(_selectedPort);
|
|
if (_arduinoBoard.Connected)
|
|
{
|
|
ConnectionStatus = "Device Connected";
|
|
// Set the page to static lighting mode to allow the user to change the
|
|
// lighting mode now that we are connected to the arduino
|
|
SelectedLightingMode = new StaticViewModel(_arduinoBoard);
|
|
OnPropertyChanged(nameof(SelectedLightingMode));
|
|
}
|
|
else
|
|
ConnectionStatus = "Failed to Connect";
|
|
OnPropertyChanged(nameof(ConnectionStatus));
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
private LightingModes _lightingMode;
|
|
public int LightingMode
|
|
{
|
|
get { return (int)_lightingMode; }
|
|
set { _lightingMode = (LightingModes) value; }
|
|
}
|
|
|
|
public ArduinoTab(string name)
|
|
{
|
|
TabType = tabType.Arduino;
|
|
Name = name;
|
|
ConnectionStatus = "Device Disconnected";
|
|
_selectedPort = "";
|
|
|
|
// Get a list of the available com ports
|
|
string[] ports = SerialPort.GetPortNames();
|
|
_availablePorts = ports;
|
|
|
|
// This is a temporary viewmodel that is used before the user has connected to a device
|
|
SelectedLightingMode = new InformationViewModel();
|
|
}
|
|
|
|
protected void OnPropertyChanged(string propertyName)
|
|
{
|
|
if (PropertyChanged != null)
|
|
{
|
|
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
}
|
|
}
|
|
}
|