-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFlashAndConfig.cs
More file actions
125 lines (121 loc) · 5.61 KB
/
FlashAndConfig.cs
File metadata and controls
125 lines (121 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using static ZeDMD_Updater2.Esp32Device;
namespace ZeDMD_Updater2
{
internal static class FlashAndConfig
{
public static void HardReboot(Esp32Device zd)
{
string devtype = "esp32";
if (zd.isS3 || zd.isLilygo) devtype = "esp32s3";
ProcessStartInfo processStartInfo = new ProcessStartInfo("esptool.exe", "--no-stub --chip " + devtype + " --port COM" + zd.ComId.ToString() + " flash_id");
using (Process process = new Process())
{
process.StartInfo = processStartInfo;
process.Start();
process.WaitForExit(); // Wait for the process to complete
}
}
public static bool FlashEsp32(Esp32Device zd, string filePath)
{
string devtype = "esp32";
if (zd.isS3 || zd.isLilygo) devtype = "esp32s3";
string commands = "--chip " + devtype + " --port COM" + zd.ComId.ToString() + " write_flash 0x0 \"" + filePath + "\"";
ProcessStartInfo processStartInfo = new ProcessStartInfo("esptool.exe", commands);
using (Process process = new Process())
{
process.StartInfo = processStartInfo;
process.Start();
process.WaitForExit(); // Wait for the process to complete
int exitCode = process.ExitCode;
if (exitCode != 0)
{
MessageBox.Show("The flashing failed. ESP32 are known to have an issue while flashing at connection time, retry pushing the ESP32 'BOOT' button during the connection", "Failed");
return false;
}
Thread.Sleep(1500);
HardReboot(zd);
return true;
}
}
private static string logBox;
private static void LogHandler(string format, IntPtr args, IntPtr pUserData)
{
logBox += Marshal.PtrToStringAnsi(Esp32Device.ZeDMD_FormatLogMessage(format, args, pUserData)) + "\r\n";
}
public static bool SetZeDmdParameters(Esp32Device device, int brightness, int rgborder, int panelclockphase, int paneldriver,
int paneli2sspeed, int panellatchblanking, int panelminrefresh, int transport, int udpdelay, int usbpackagesize,
string wifissid, string wifipassword, int yoffset, ref string logres, bool muted)
{
IntPtr _pZeDMD = IntPtr.Zero;
_pZeDMD = ZeDMD_GetInstance();
GCHandle handle;
ZeDMD_LogCallback callbackDelegate = new ZeDMD_LogCallback(LogHandler);
if (!muted)
{
logBox = "=== Setting ZeDMD Parameters ===\r\n";
// create an instance
// Keep a reference to the delegate to prevent GC from collecting it
handle = GCHandle.Alloc(callbackDelegate);
ZeDMD_SetLogCallback(_pZeDMD, callbackDelegate, IntPtr.Zero);
}
bool openOK = false;
if (device.isWifi) openOK = ZeDMD_OpenDefaultWiFi(_pZeDMD);
else
{
string comport = @"COM" + device.ComId.ToString();
ZeDMD_SetDevice(_pZeDMD, comport);
openOK = ZeDMD_Open(_pZeDMD);
}
if (openOK)
{
ZeDMD_SetBrightness(_pZeDMD, (byte)brightness);
ZeDMD_SetRGBOrder(_pZeDMD, (byte)rgborder);
ZeDMD_SetPanelClockPhase(_pZeDMD, (byte)panelclockphase);
ZeDMD_SetPanelDriver(_pZeDMD, (byte)paneldriver);
ZeDMD_SetPanelI2sSpeed(_pZeDMD, (byte)paneli2sspeed);
ZeDMD_SetPanelLatchBlanking(_pZeDMD, (byte)panellatchblanking);
ZeDMD_SetPanelMinRefreshRate(_pZeDMD, (byte)panelminrefresh);
ZeDMD_SetTransport(_pZeDMD, (byte)transport);
ZeDMD_SetUdpDelay(_pZeDMD, (byte)udpdelay);
ZeDMD_SetUsbPackageSize(_pZeDMD, (ushort)usbpackagesize);
ZeDMD_SetYOffset(_pZeDMD, (byte)yoffset);
if (wifissid != "")
{
ZeDMD_SetWiFiSSID(_pZeDMD, wifissid);
ZeDMD_SetWiFiPassword(_pZeDMD, wifipassword);
//Esp32Device.ZeDMD_SetWiFiPort(_pZeDMD, 3333);
}
ZeDMD_SaveSettings(_pZeDMD);
ZeDMD_Reset(_pZeDMD);
ZeDMD_Close(_pZeDMD);
device.Brightness = brightness;
device.RgbOrder = rgborder;
device.PanelClockPhase = panelclockphase;
device.PanelDriver = paneldriver;
device.PanelI2SSpeed = paneli2sspeed;
device.PanelLatchBlanking = panellatchblanking;
device.PanelMinRefreshRate = panelminrefresh;
if (transport == 1 || transport == 2) device.isWifi = true;
else device.isWifi = false;
device.UdpDelay = udpdelay;
device.UsbPacketSize = usbpackagesize;
device.YOffset = yoffset;
device.SSID = wifissid;
}
else
{
MessageBox.Show("Unable to Open the device on COM" + device.ComId.ToString() + " to set the parameters");
logBox += "Unable to Open the device on COM" + device.ComId.ToString() + " to set the parameters\r\n";
logres = logBox;
return false;
}
logres = logBox;
return true;
}
}
}