Skip to content

Commit c9a89a1

Browse files
author
Adriano
committed
First version
1 parent b2dfae0 commit c9a89a1

30 files changed

Lines changed: 7862 additions & 1 deletion

App.config

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<configSections>
4+
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
5+
<section name="esp_tools_gui.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
6+
</sectionGroup>
7+
</configSections>
8+
<startup>
9+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
10+
</startup>
11+
<userSettings>
12+
<esp_tools_gui.Properties.Settings>
13+
<setting name="comport" serializeAs="String">
14+
<value />
15+
</setting>
16+
<setting name="combaud" serializeAs="String">
17+
<value>115200</value>
18+
</setting>
19+
</esp_tools_gui.Properties.Settings>
20+
</userSettings>
21+
</configuration>

App.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace esp_tools_gui
8+
{
9+
class App
10+
{
11+
public static MainPage form;
12+
13+
static void Main(string[] args) {
14+
form = new MainPage();
15+
form.ShowDialog();
16+
}
17+
}
18+
}

ESP32.ico

42.3 KB
Binary file not shown.

MainPage.Designer.cs

Lines changed: 584 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MainPage.cs

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Diagnostics;
6+
using System.Drawing;
7+
using System.IO;
8+
using System.IO.Ports;
9+
using System.Linq;
10+
using System.Management;
11+
using System.Text;
12+
using System.Threading.Tasks;
13+
using System.Windows.Forms;
14+
15+
namespace esp_tools_gui
16+
{
17+
public partial class MainPage : Form
18+
{
19+
private static StringBuilder outStr;
20+
private ToolEfuse efuse;
21+
private ToolTool tool;
22+
private ToolSecure secure;
23+
private ToolPartition partition;
24+
25+
private delegate void SafeCallDelegate(object sender, CustomEventArgs a);
26+
27+
public MainPage()
28+
{
29+
InitializeComponent();
30+
31+
outStr = new StringBuilder();
32+
richTextBox1.Text = "";
33+
34+
efuse = new ToolEfuse();
35+
tool = new ToolTool();
36+
secure = new ToolSecure();
37+
partition = new ToolPartition();
38+
39+
efuse.ConsoleEvent += HandleCustomEvent;
40+
tool.ConsoleEvent += HandleCustomEvent;
41+
secure.ConsoleEvent += HandleCustomEvent;
42+
partition.ConsoleEvent += HandleCustomEvent;
43+
44+
ExpertComboboxTool.SelectedIndex = 0;
45+
}
46+
47+
private void MainPage_Load(object sender, EventArgs e)
48+
{
49+
using (var searcher = new ManagementObjectSearcher("SELECT * FROM WIN32_SerialPort"))
50+
{
51+
string[] portnames = SerialPort.GetPortNames();
52+
var ports2 = searcher.Get().Cast<ManagementBaseObject>().ToList();
53+
var tList = (from n in portnames
54+
join p in ports2 on n equals p["DeviceID"].ToString() into joinedList
55+
from sub in joinedList.DefaultIfEmpty()
56+
select new ComPort{ PortId=n, Info=sub==null?"":sub["Caption"].ToString() }).ToList();
57+
58+
tList.ForEach((t)=> { comboBox1.Items.Add(t); });
59+
}
60+
comboBox1.SelectedIndex = 0;
61+
foreach(ComPort i in comboBox1.Items)
62+
{
63+
if(Properties.Settings.Default.comport == i.ToString())
64+
{
65+
comboBox1.SelectedItem = i;
66+
Tool._com = i.PortId;
67+
break;
68+
}
69+
}
70+
comboBox2.Text = Properties.Settings.Default.combaud;
71+
72+
Tool._baud = Properties.Settings.Default.combaud;
73+
74+
Application.DoEvents();
75+
76+
comboBox1.TextChanged += (s, ev) =>
77+
{
78+
Tool._com = ((s as ComboBox).SelectedItem as ComPort).PortId;
79+
Properties.Settings.Default.comport = (s as ComboBox).Text;
80+
Properties.Settings.Default.Save();
81+
};
82+
comboBox2.TextChanged += (s, ev) =>
83+
{
84+
Tool._baud = Properties.Settings.Default.combaud;
85+
Properties.Settings.Default.combaud = (s as ComboBox).Text;
86+
Properties.Settings.Default.Save();
87+
};
88+
}
89+
90+
public class ComPort
91+
{
92+
public string PortId { get; set; }
93+
public string Info { get; set; }
94+
public override string ToString()
95+
{
96+
if (Info.Length > 1)
97+
{
98+
return PortId + " - " + Info;
99+
}
100+
else
101+
{
102+
return PortId;
103+
}
104+
}
105+
}
106+
107+
private void button1_Click(object sender, EventArgs e)
108+
{
109+
progressBar1.Value = 10;
110+
progressBar1.Visible = true;
111+
tool.Parse("flash_id");
112+
tabControl1.SelectedIndex = 0;
113+
progressBar1.Value = 20;
114+
infoTextboxChipType.Text = tool.ChipType;
115+
infoTextboxChip.Text = tool.Chip;
116+
infoTextboxFeature.Text = tool.Features;
117+
infoTextboxCrystal.Text = tool.Crystal;
118+
infoTextboxMac.Text = tool.MAC;
119+
infoTextboxFlash.Text = tool.Flash;
120+
Application.DoEvents();
121+
tool.Parse("read_flash 0x8000 0x400 temp.bin");
122+
progressBar1.Value = 50;
123+
partitionChart.Series[0].Points.Clear();
124+
partitionListview.Items.Clear();
125+
tabControl1.SelectedIndex++;
126+
foreach (var p in tool.Partitions)
127+
{
128+
var lv = partitionListview.Items.Add(p.Name);
129+
lv.SubItems.Add(p.GetTypeName());
130+
lv.SubItems.Add(p.GetSubTypeName());
131+
lv.SubItems.Add("0x" + p.Offset.ToString("X"));
132+
lv.SubItems.Add(p.GetSize());
133+
lv.SubItems.Add("0x" + p.Flags.ToString("X"));
134+
135+
var point = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0.0, p.Size);
136+
point.AxisLabel = p.Name;
137+
partitionChart.Series[0].Points.Add(point);
138+
}
139+
Application.DoEvents();
140+
efuse.Parse("summary");
141+
progressBar1.Value = 70;
142+
tableLayoutPanel1.RowCount = 11;
143+
tableLayoutPanel1.Controls.Clear();
144+
int row = 0;
145+
tabControl1.Visible = false;
146+
tabControl1.SelectedIndex++;
147+
foreach (var f in efuse.Fuses)
148+
{
149+
if (row > 10) tableLayoutPanel1.RowCount++;
150+
var l = new Label { Text = f.Key + ":", Parent = tableLayoutPanel1, Dock = DockStyle.Fill, BackColor = Color.AliceBlue };
151+
tableLayoutPanel1.SetRow(l, row);
152+
tableLayoutPanel1.SetColumn(l, 0);
153+
tableLayoutPanel1.SetColumnSpan(l, 4);
154+
row++;
155+
foreach (var v in efuse.Fuses[f.Key])
156+
{
157+
if (row > 10) tableLayoutPanel1.RowCount++;
158+
var l2 = new Label { Text = v.Title, Parent = tableLayoutPanel1, Dock = DockStyle.Fill };
159+
tableLayoutPanel1.SetRow(l2, row);
160+
tableLayoutPanel1.SetColumn(l2, 0);
161+
l2 = new Label { Text = v.Description, Parent = tableLayoutPanel1, Dock = DockStyle.Fill };
162+
tableLayoutPanel1.SetRow(l2, row);
163+
tableLayoutPanel1.SetColumn(l2, 1);
164+
var t2 = new TextBox { Text = v.Value, Parent = tableLayoutPanel1, Dock = DockStyle.Fill, ReadOnly=true };
165+
tableLayoutPanel1.SetRow(t2, row);
166+
tableLayoutPanel1.SetColumn(t2, 2);
167+
l2 = new Label { Text = v.ReadWrite, Parent = tableLayoutPanel1, Dock = DockStyle.Fill };
168+
tableLayoutPanel1.SetRow(l2, row);
169+
tableLayoutPanel1.SetColumn(l2, 3);
170+
row++;
171+
}
172+
}
173+
tableLayoutPanel1.RowStyles.Clear();
174+
//for(var k=0;k<tableLayoutPanel1.RowCount;k++)
175+
//{
176+
// tableLayoutPanel1.RowStyles.Add(new RowStyle { Height = 20, SizeType = SizeType.Absolute });
177+
//}
178+
tabControl1.Visible = true;
179+
Application.DoEvents();
180+
// todo: read something...
181+
progressBar1.Value = 100;
182+
Application.DoEvents();
183+
progressBar1.Visible = false;
184+
}
185+
186+
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
187+
{
188+
if(e.KeyChar == '\r')
189+
{
190+
switch(ExpertComboboxTool.Text)
191+
{
192+
case "esptool": tool.Execute((sender as TextBox).Text); break;
193+
case "espefuse": efuse.Execute((sender as TextBox).Text); break;
194+
case "espsecure": secure.Execute((sender as TextBox).Text); break;
195+
case "gen_esp32part": partition.Execute((sender as TextBox).Text); break;
196+
}
197+
}
198+
}
199+
200+
private void textBox2_TextChanged(object sender, EventArgs e)
201+
{
202+
203+
}
204+
void HandleCustomEvent(object sender, CustomEventArgs a)
205+
{
206+
if (richTextBox1.InvokeRequired)
207+
{
208+
this.BeginInvoke(new SafeCallDelegate(HandleCustomEvent), new object[] { sender, a });
209+
return;
210+
}
211+
if (a.input.Length > 0)
212+
{
213+
string txt = " > " + a.input + "\r\n";
214+
richTextBox1.SelectionColor = Color.White;
215+
richTextBox1.AppendText(txt);
216+
richTextBox1.SelectionColor = richTextBox1.ForeColor;
217+
richTextBox1.ScrollToCaret();
218+
}
219+
if(a.error.Length > 0)
220+
{
221+
string txt = " [E] " + a.error + "\r\n";
222+
richTextBox1.SelectionColor = Color.LightCoral;
223+
richTextBox1.AppendText(txt);
224+
richTextBox1.SelectionColor = richTextBox1.ForeColor;
225+
richTextBox1.ScrollToCaret();
226+
}
227+
if(a.output.Length > 0)
228+
{
229+
string txt = a.output + "\r\n";
230+
richTextBox1.AppendText(txt);
231+
richTextBox1.ScrollToCaret();
232+
}
233+
}
234+
}
235+
236+
public class CustomEventArgs
237+
{
238+
public string input { get; set; } = "";
239+
public string output { get; set; } = "";
240+
public string error { get; set; } = "";
241+
}
242+
}

0 commit comments

Comments
 (0)