98 lines
3.2 KiB
C#
98 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.IO;
|
|
|
|
namespace TinyFPGA_VisualProgrammer
|
|
{
|
|
public partial class Programmer : Form
|
|
{
|
|
SerialController sController = null;
|
|
TinyProg TProg = null;
|
|
|
|
public Programmer()
|
|
{
|
|
InitializeComponent();
|
|
fileSelectDialog.InitialDirectory = Path.GetDirectoryName(Application.ExecutablePath);
|
|
this.AllowDrop = true;
|
|
this.DragEnter += new DragEventHandler(Programmer_DragEnter);
|
|
this.DragDrop += new DragEventHandler(Programmer_DragDrop);
|
|
|
|
sController = new SerialController();
|
|
TProg = new TinyProg(sController);
|
|
if (sController.sPortsList != null && sController.sPortsList.Count > 0)
|
|
{
|
|
foreach (string s in sController.sPortsList)
|
|
serialPortList.Items.Add(s);
|
|
|
|
serialPortList.SelectedIndex = serialPortList.Items.Count - 1;
|
|
}
|
|
}
|
|
|
|
void Programmer_DragEnter(object sender, DragEventArgs e)
|
|
{
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
|
|
}
|
|
|
|
void Programmer_DragDrop(object sender, DragEventArgs e)
|
|
{
|
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
|
//if(Path.GetExtension(files.First()) == "hex")
|
|
fileLocationTextBox.Text = files.First();
|
|
fileSelectDialog.FileName = files.First();
|
|
launchProgramBtn.Enabled = true;
|
|
}
|
|
|
|
private void fileExpSelect_Click(object sender, EventArgs e)
|
|
{
|
|
fileSelectDialog.ShowDialog();
|
|
}
|
|
|
|
private void fileSelectDialog_FileOk(object sender, CancelEventArgs e)
|
|
{
|
|
fileLocationTextBox.Text = fileSelectDialog.FileName;
|
|
launchProgramBtn.Enabled = true;
|
|
}
|
|
|
|
private void connectBtn_Click(object sender, EventArgs e)
|
|
{
|
|
connectBtn.Enabled = false;
|
|
|
|
if (sController.GetPortOpened())
|
|
{
|
|
sController.ClosePort();
|
|
connectBtn.Text = "Connect";
|
|
statusLabel.Text = "--";
|
|
}
|
|
else
|
|
{
|
|
sController.comPortName = serialPortList.SelectedItem.ToString();
|
|
sController.OpenPort();
|
|
if (sController.GetPortOpened())
|
|
TProg.CheckTinyPresence();
|
|
if (TProg.TinyFPGAIsConnected)
|
|
statusLabel.Text = TProg.GetBoardData().name + " v" + TProg.GetBoardData().hver + " found.";
|
|
else
|
|
statusLabel.Text = "No TinyFPGA found.";
|
|
connectBtn.Text = "Disconnect";
|
|
}
|
|
|
|
connectBtn.Enabled = true;
|
|
}
|
|
|
|
private void serialPortList_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (serialPortList.SelectedItem.ToString().Length > 0)
|
|
connectBtn.Enabled = true;
|
|
else
|
|
connectBtn.Enabled = false;
|
|
}
|
|
}
|
|
}
|