superstar_v2/PrimaryFormParts/PrimaryForm.ToggleLight.cs

275 lines
12 KiB
C#
Raw Normal View History

2025-04-07 16:54:10 +08:00
using System.IO;
2025-04-07 16:54:10 +08:00
namespace DualScreenDemo
{
2025-08-06 10:47:43 +08:00
public partial class PrimaryForm : Form
2025-04-07 16:54:10 +08:00
{
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
private Button btnTurnOn;
2025-08-07 16:13:57 +08:00
//private Button btnTurnOff;
2025-04-07 16:54:10 +08:00
private Button btnBright;
private Button btnRomantic;
private Button btnAuto;
private Button btnColorTuning;
private Button btnSoft;
private Button btnDynamic;
private Button btnDeskLamp;
private Button btnStageLight;
private Button btnShelfLight;
private Button btnWallLight;
private Button btnBrightnessUp1;
private Button btnBrightnessDown1;
private Button btnBrightnessUp2;
private Button btnBrightnessDown2;
2025-08-06 10:47:43 +08:00
private int OnOffState;
2025-04-07 16:54:10 +08:00
private PictureBox pictureBoxToggleLight;
2025-08-07 17:17:02 +08:00
//private PictureBox Brightness1;
//private PictureBox Brightness2;
2025-04-07 16:54:10 +08:00
private void InitializeButtonsForPictureBoxToggleLight()
{
2025-08-13 09:48:25 +08:00
var data=LoadBtnConfigData();
2025-08-06 10:47:43 +08:00
btnTurnOn = new Button { Text = "" };
ConfigureButton(btnTurnOn, 29, 45, 250, 67,
2025-08-13 09:48:25 +08:00
new Bitmap(Path.Combine(serverPath, data["LightControl"]["OnOff"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["OnOff"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["OnOff"])),
2025-04-07 16:54:10 +08:00
null);
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
btnTurnOn.Click += (sender, e) =>
{
2025-08-06 10:47:43 +08:00
if (OnOffState == 1)
2025-04-07 16:54:10 +08:00
{
2025-08-06 10:47:43 +08:00
SendCommandThroughSerialPort("a2 dc a4");
Console.WriteLine("light off");
OnOffState = 0;
}
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen && OnOffState!=1)
{
2025-04-07 16:54:10 +08:00
byte[] commandBytes = new byte[] { 0xA2, 0xDB, 0xA4 };
2025-08-06 10:47:43 +08:00
Console.WriteLine("light on");
2025-04-07 16:54:10 +08:00
SerialPortManager.mySerialPort.Write(commandBytes, 0, commandBytes.Length);
2025-08-06 10:47:43 +08:00
OnOffState = 1;
2025-04-07 16:54:10 +08:00
}
else
{
MessageBox.Show("Serial port is not open. Cannot send track correction command.");
}
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
};
2025-08-06 10:47:43 +08:00
//btnTurnOff = new Button { Text = "" };
//ConfigureButton(btnTurnOff, 753, 411, 122, 62,
// resizedNormalStateImageForLightControl, resizedNormalStateImageForLightControl, resizedNormalStateImageForLightControl,
// (sender, e) => SendCommandThroughSerialPort("a2 dc a4"));
2025-04-07 16:54:10 +08:00
btnBright = new Button{ Text = "" };
2025-08-06 10:47:43 +08:00
ConfigureButton(btnBright, 295, 45, 118, 65,
2025-08-13 09:48:25 +08:00
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Brightness"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Brightness"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Brightness"])),
2025-04-07 16:54:10 +08:00
null);
btnBright.Click += (sender, e) =>
{
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
{
byte[] commandBytes = new byte[] { 0xA2, 0xD5, 0xA4 };
SerialPortManager.mySerialPort.Write(commandBytes, 0, commandBytes.Length);
}
else
{
MessageBox.Show("Serial port is not open. Cannot send track correction command.");
}
};
2025-08-06 10:47:43 +08:00
btnRomantic = new Button{ Text = "" };
ConfigureButton(btnRomantic, 430, 45, 118, 65,
2025-08-13 16:42:22 +08:00
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Romantic"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Romantic"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Romantic"])),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 d7 a4"));
2025-08-06 10:47:43 +08:00
btnAuto = new Button{ Text = "" };
ConfigureButton(btnAuto, 430, 125, 118, 65,
2025-08-13 16:42:22 +08:00
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Auto"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Auto"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Auto"])),
2025-04-07 16:54:10 +08:00
null);
2025-08-06 10:47:43 +08:00
btnColorTuning = new Button{ Text = "" };
ConfigureButton(btnColorTuning, 430, 203, 118, 65,
2025-08-13 16:42:22 +08:00
new Bitmap(Path.Combine(serverPath, data["LightControl"]["ColorTune"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["ColorTune"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["ColorTune"])),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 75 a4"));
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
2025-08-06 10:47:43 +08:00
btnSoft = new Button{ Text = "" };
ConfigureButton(btnSoft, 295, 125, 118, 65,
2025-08-13 16:42:22 +08:00
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Soft"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Soft"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Soft"])),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 d6 a4"));
2025-08-06 10:47:43 +08:00
btnDynamic = new Button{ Text = "" };
ConfigureButton(btnDynamic, 295, 203, 118, 65,
2025-08-13 16:42:22 +08:00
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Dynamic"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Dynamic"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Dynamic"])),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 d8 a4"));
2025-08-06 10:47:43 +08:00
btnDeskLamp = new Button{ Text = "" };
ConfigureButton(btnDeskLamp, 430, 283, 118, 65,
2025-08-13 16:42:22 +08:00
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Lamp"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Lamp"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["Lamp"])),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 fb a4"));
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
btnStageLight = new Button{ Text = "" };
2025-08-06 10:47:43 +08:00
ConfigureButton(btnStageLight, 295, 283, 118, 65,
2025-08-13 16:42:22 +08:00
new Bitmap(Path.Combine(serverPath, data["LightControl"]["StageLight"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["StageLight"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["StageLight"])),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 fa a4"));
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
btnShelfLight = new Button{ Text = "" };
2025-08-06 10:47:43 +08:00
ConfigureButton(btnShelfLight, 163, 283, 118, 65,
2025-08-13 16:42:22 +08:00
new Bitmap(Path.Combine(serverPath, data["LightControl"]["ShelfLight"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["ShelfLight"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["ShelfLight"])),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 f9 a4"));
2025-08-06 10:47:43 +08:00
btnWallLight = new Button{ Text = "" };
ConfigureButton(btnWallLight, 29, 283, 118, 65,
2025-08-13 16:42:22 +08:00
new Bitmap(Path.Combine(serverPath, data["LightControl"]["WallLight"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["WallLight"])),
new Bitmap(Path.Combine(serverPath, data["LightControl"]["WallLight"])),
2025-04-07 16:54:10 +08:00
(sender, e) => SendCommandThroughSerialPort("a2 f8 a4"));
2025-08-06 10:47:43 +08:00
2025-08-07 17:17:02 +08:00
//Brightness1 = new PictureBox { };
//Brightness1.BackgroundImage = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\3.介面\\燈光控制_桌燈調光.png"));
//Brightness1.BackgroundImageLayout = ImageLayout.Stretch;
//Brightness1.Size = new Size(155, 172);
//Brightness1.Location = new Point(38, 151);
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
btnBrightnessUp1 = new Button{ Text = "" };
2025-08-07 17:17:02 +08:00
ConfigureTransButton(btnBrightnessUp1, 30, 125, 118, 65, null);
2025-04-07 16:54:10 +08:00
btnBrightnessUp1.MouseDown += (sender, e) =>
{
lightControlTimer.Tag = "a2 d9 a4";
2025-08-07 17:17:02 +08:00
lightControlTimer.Start();
2025-04-07 16:54:10 +08:00
};
2025-08-07 17:17:02 +08:00
//btnBrightnessUp1.BackColor = Color.Red;
2025-04-07 16:54:10 +08:00
btnBrightnessUp1.MouseUp += (sender, e) =>
{
lightControlTimer.Stop();
};
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
btnBrightnessDown1 = new Button{ Text = "" };
2025-08-07 17:17:02 +08:00
ConfigureTransButton(btnBrightnessDown1, 30, 203, 118, 65, null);
2025-04-07 16:54:10 +08:00
btnBrightnessDown1.MouseDown += (sender, e) => { lightControlTimer.Tag = "a2 da a4"; lightControlTimer.Start(); };
btnBrightnessDown1.MouseUp += (sender, e) => { lightControlTimer.Stop(); };
2025-08-07 17:17:02 +08:00
//btnBrightnessDown1.BackColor = Color.Red;
2025-08-06 10:47:43 +08:00
2025-08-07 17:17:02 +08:00
//Brightness2 = new PictureBox { };
//Brightness2.BackgroundImage = new Bitmap(Path.Combine(serverPath, "themes\\superstar\\button\\3.介面\\燈光控制_層板調光.png"));
//Brightness2.BackgroundImageLayout = ImageLayout.Stretch;
//Brightness2.Size = new Size(155, 172);
//Brightness2.Location = new Point(216, 151);
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
btnBrightnessUp2 = new Button{ Text = "" };
2025-08-07 17:17:02 +08:00
ConfigureTransButton(btnBrightnessUp2, 163, 125, 118, 65, null);
btnBrightnessUp2.MouseDown += (sender, e) => { lightControlTimer.Tag = "a2 f6 a4"; lightControlTimer.Start(); };
2025-04-07 16:54:10 +08:00
btnBrightnessUp2.MouseUp += (sender, e) => { lightControlTimer.Stop(); };
2025-08-06 10:47:43 +08:00
2025-04-07 16:54:10 +08:00
btnBrightnessDown2 = new Button{ Text = "" };
2025-08-07 17:17:02 +08:00
ConfigureTransButton(btnBrightnessDown2, 163, 203, 118, 65, null);
2025-04-07 16:54:10 +08:00
btnBrightnessDown2.MouseDown += (sender, e) => { lightControlTimer.Tag = "a2 f7 a4"; lightControlTimer.Start(); };
btnBrightnessDown2.MouseUp += (sender, e) => { lightControlTimer.Stop(); };
2025-08-06 10:47:43 +08:00
pictureBoxToggleLight.Controls.Add(btnTurnOn);
pictureBoxToggleLight.Controls.Add(btnBright);
pictureBoxToggleLight.Controls.Add(btnRomantic);
pictureBoxToggleLight.Controls.Add(btnAuto);
pictureBoxToggleLight.Controls.Add(btnColorTuning);
pictureBoxToggleLight.Controls.Add(btnSoft);
pictureBoxToggleLight.Controls.Add(btnDynamic);
pictureBoxToggleLight.Controls.Add(btnDeskLamp);
pictureBoxToggleLight.Controls.Add(btnStageLight);
pictureBoxToggleLight.Controls.Add(btnShelfLight);
pictureBoxToggleLight.Controls.Add(btnWallLight);
2025-08-07 17:17:02 +08:00
//Brightness1.Controls.Add(btnBrightnessUp1);
//Brightness1.Controls.Add(btnBrightnessDown1);
//Brightness2.Controls.Add(btnBrightnessUp2);
//Brightness2.Controls.Add(btnBrightnessDown2);
pictureBoxToggleLight.Controls.Add(btnBrightnessUp1);
pictureBoxToggleLight.Controls.Add(btnBrightnessDown1);
pictureBoxToggleLight.Controls.Add(btnBrightnessUp2);
pictureBoxToggleLight.Controls.Add(btnBrightnessDown2);
//pictureBoxToggleLight.Controls.Add(Brightness1);
//pictureBoxToggleLight.Controls.Add(Brightness2);
2025-04-07 16:54:10 +08:00
}
private void ToggleLightButton_Click(object sender, EventArgs e)
{
CloseUI(pictureBoxSceneSoundEffects);
CloseUI(pictureBoxQRCode);
2025-04-07 16:54:10 +08:00
if (!pictureBoxToggleLight.Visible)
{
2025-08-13 16:42:22 +08:00
var data = LoadBtnConfigData();
2025-08-06 10:47:43 +08:00
pictureBoxToggleLight.Size = new Size(630, 379);
pictureBoxToggleLight.Location = new Point(628, 359);
ResizeAndPositionPictureBox(pictureBoxToggleLight, 628, 359, 570, 359);
2025-08-13 16:42:22 +08:00
pictureBoxToggleLight.BackgroundImage = new Bitmap(Path.Combine(serverPath, data["LightControl"]["LightControlBaseUI"]));
2025-08-06 10:47:43 +08:00
pictureBoxToggleLight.BackgroundImageLayout = ImageLayout.Stretch;
pictureBoxToggleLight.BringToFront();
SetUIVisible(pictureBoxToggleLight);
2025-04-07 16:54:10 +08:00
}
else
{
2025-08-06 10:47:43 +08:00
CloseUI(pictureBoxToggleLight);
2025-04-07 16:54:10 +08:00
}
2025-08-06 10:47:43 +08:00
if (pictureBoxQRCode != null)
2025-04-07 16:54:10 +08:00
{
2025-08-06 10:47:43 +08:00
pictureBoxQRCode.Visible = false;
//closeQRCodeButton.Visible = false;
2025-04-07 16:54:10 +08:00
}
}
private void SetPictureBoxToggleLightAndButtonsVisibility(bool isVisible)
{
if (isVisible) SetUIVisible(pictureBoxToggleLight);
else CloseUI(pictureBoxToggleLight);
2025-04-07 16:54:10 +08:00
}
}
}