Skip to content

Commit

Permalink
Fixes to menus.
Browse files Browse the repository at this point in the history
  • Loading branch information
julihirn committed Sep 4, 2023
1 parent 0367e02 commit 5624f41
Show file tree
Hide file tree
Showing 52 changed files with 5,110 additions and 517 deletions.
Binary file modified .vs/ProjectEvaluation/serial monitor.metadata.v5.1
Binary file not shown.
Binary file modified .vs/ProjectEvaluation/serial monitor.projects.v5.1
Binary file not shown.
Binary file modified .vs/Serial Monitor/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/Serial Monitor/v17/.futdcache.v2
Binary file not shown.
Binary file modified .vs/Serial Monitor/v17/.suo
Binary file not shown.
21 changes: 21 additions & 0 deletions Serial Monitor/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@
<setting name="DEF_INT_BaudRate" serializeAs="String">
<value>9600</value>
</setting>
<setting name="THM_COL_TabSelectedColor" serializeAs="String">
<value>100, 128, 128, 128</value>
</setting>
<setting name="THM_COL_TabSelectedBorderColor" serializeAs="String">
<value>100, 128, 128, 128</value>
</setting>
<setting name="THM_COL_TabSelectedForeColor" serializeAs="String">
<value>White</value>
</setting>
<setting name="THM_COL_ColumnSeperatorColor" serializeAs="String">
<value>64, 64, 64</value>
</setting>
<setting name="THM_COL_SecondaryForeColor" serializeAs="String">
<value>Silver</value>
</setting>
<setting name="THM_COL_SelectedShadowColor" serializeAs="String">
<value>Black</value>
</setting>
<setting name="THM_COL_ButtonChecked" serializeAs="String">
<value>70, 70, 70</value>
</setting>
</Serial_Monitor.Properties.Settings>
</userSettings>
</configuration>
63 changes: 63 additions & 0 deletions Serial Monitor/Classes/Button Commands/BtnCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Serial_Monitor.Classes.Button_Commands {
public class BtnCommand {
public BtnCommand() {
isSet = false;
}
CommandType commandType = CommandType.NoAssignedCommand;
public CommandType Type {
get { return commandType; }
set {
commandType = value;
isEdited = true;
}
}
public void SetValue(CommandType Type, string CommandLine, string Channel) {
isSet = true;
commandType = Type;
this.commandLine = CommandLine;
this.channel = Channel;
}
public void Reset() {
isSet = false;
isEdited = false;
commandType = CommandType.NoAssignedCommand;
commandLine = "";
}
string commandLine = "";
public string CommandLine {
get { return commandLine; }
set {
commandLine = value;
isEdited = true;
}
}
string channel = "";
public string Channel {
get { return channel; }
set {
channel = value;
isEdited = true;
}
}
private bool isEdited = false;
public bool IsEdited {
get { return isEdited; }
}
private bool isSet = false;
public bool IsSet {
get { return isSet; }
}
}
public enum CommandType {
NoAssignedCommand = 0x00,
SendString = 0x01,
SendText = 0x02,
ExecuteProgram = 0x04
}
}
21 changes: 20 additions & 1 deletion Serial Monitor/Classes/EnumManager.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
using System;
using Serial_Monitor.Classes.Button_Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Serial_Monitor.Classes {
public static class EnumManager {
public static CommandType StringToCommandType(string Input) {
if (Input.ToUpper() == "NONE") { return CommandType.NoAssignedCommand; }
else if (Input.ToUpper() == "SENDSTR") { return CommandType.SendString; }
else if (Input.ToUpper() == "SENDTXT") { return CommandType.SendText; }
else if (Input.ToUpper() == "EXECMD") { return CommandType.ExecuteProgram; }
else {
return CommandType.NoAssignedCommand;
}
}
public static string CommandTypeToString(CommandType Input) {
if (Input == CommandType.NoAssignedCommand) { return "NONE"; }
else if (Input == CommandType.SendString) { return "SENDSTR"; }
else if (Input == CommandType.SendText) { return "SENDTXT"; }
else if (Input == CommandType.ExecuteProgram) { return "EXECMD"; }
else {
return "NONE";
}
}
public static System.IO.Ports.StopBits StringToStopBits(string Input) {
if (Input == "0") { return System.IO.Ports.StopBits.None; }
else if (Input == "1") { return System.IO.Ports.StopBits.One; }
Expand Down
35 changes: 28 additions & 7 deletions Serial Monitor/Classes/ProgramManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,29 @@ public static void RunFromStart() {
ProgramManager.ProgramStep = 0;
ProgramManager.ProgramState = StepEnumerations.StepState.Running;
}
public static void RunFromStart(string ProgramName) {
public static void RunFromStart(string ProgramName, bool UseProgramCommand = true) {
bool ProgramFound = false;
if (ProgramName.Length > 0) {
bool Resulted = false;
string ProName = "";
foreach (ProgramObject PrgObj in Programs) {
if (PrgObj.Name == ProgramName) {
CurrentProgram = PrgObj;
ProgramFound = true;
ProName = PrgObj.Name;
if (MainInstance != null) { MainInstance.MethodSetRunText(PrgObj.Name); }
break;
if (UseProgramCommand == true) {
if (PrgObj.Name == ProgramName) {
CurrentProgram = PrgObj;
ProgramFound = true;
ProName = PrgObj.Name;
if (MainInstance != null) { MainInstance.MethodSetRunText(PrgObj.Name); }
break;
}
}
else {
if (PrgObj.Command == ProgramName) {
CurrentProgram = PrgObj;
ProgramFound = true;
ProName = PrgObj.Name;
if (MainInstance != null) { MainInstance.MethodSetRunText(PrgObj.Name); }
break;
}
}
}
if (Resulted == true) {
Expand Down Expand Up @@ -686,5 +697,15 @@ public static void CommandLine(StepEnumerations.StepExecutable StepChange) {
}
}
#endregion
#region Program Command Connectivity
public static void ExecuteProgram(string ProgramCommand) {
if (ProgramCommand.Trim(' ') == "") { return; }
ProgramState = StepEnumerations.StepState.Paused;
RunFromStart(ProgramCommand, false);
CleanProgramData();
SetupProgram();
NoStepProgramIncrement = true;
}
#endregion
}
}
1 change: 1 addition & 0 deletions Serial Monitor/Classes/ProgramObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public string Name {
ProgramManager.ProgramNameChange(this);
}
}
public int UntitledProgramNmber = -1;
private string command = "";
public string Command {
get { return command; }
Expand Down
76 changes: 62 additions & 14 deletions Serial Monitor/Classes/ProjectManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Handlers;
using ODModules;
using Serial_Monitor.Classes.Button_Commands;
using Serial_Monitor.Classes.Step_Programs;
using System;
using System.Collections.Generic;
Expand All @@ -14,12 +15,44 @@
namespace Serial_Monitor.Classes {
public static class ProjectManager {
public static List<KeypadButton> Buttons = new List<KeypadButton>();

private const int MaximumButtons = 20;
public static void SetKeypadButton(int Index, string CmdType, string CmcLine, string DisplayText, string Channel) {
if (Buttons.Count == MaximumButtons) {
if (Index < MaximumButtons) {
KeypadButton Btn = Buttons[Index];
object? TagData = Btn.Tag;
if (TagData != null) {
if (TagData.GetType() == typeof(BtnCommand)) {
Btn.Text = DisplayText;
BtnCommand Data = (BtnCommand)TagData;
Data.SetValue(EnumManager.StringToCommandType(CmdType), CmcLine, Channel);
}
}
}
}
}
public static void ClearKeypadButtons() {
for (int i = 0; i < Buttons.Count; i++) {
object? TagData = Buttons[i].Tag;
if (TagData != null) {
if (TagData.GetType() == typeof(BtnCommand)) {
Buttons[i].Text = "";
BtnCommand Data = (BtnCommand)TagData;
Data.Reset();
}
}
}
}
public static void LoadGenericKeypadButtons() {
for (int i = 0; i < MaximumButtons; i++) {
BtnCommand Cmd = new BtnCommand();
KeypadButton kBtn = new KeypadButton();
kBtn.Tag = Cmd;
Buttons.Add(kBtn);
}
}
public static event FileOpenedHandler? ProgramNameChanged;
public delegate void FileOpenedHandler(string Address);
public static void ClearKeypad() {
Buttons.Clear();
}
public static void WriteFile(string FileAddress) {
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
Expand Down Expand Up @@ -89,12 +122,21 @@ public static void WriteFile(string FileAddress) {
Sw.WriteLine("-- Keypad Buttons");
int Cnt = 0;
foreach (KeypadButton Btn in Buttons) {
Sw.WriteLine(StringHandler.AddTabs(1, "def,parm:KBTN_" + Cnt.ToString() + "{"));
Sw.WriteLine(StringHandler.AddTabs(2, "def,str:Text=" + StringHandler.EncapsulateString(Btn.Text)));
Sw.WriteLine(StringHandler.AddTabs(2, "def,str:Command=" + StringHandler.EncapsulateString(Btn.Command)));
if (Btn.Tag != null) {
if (Btn.Tag.GetType() == typeof(BtnCommand)) {
BtnCommand CmdSet = (BtnCommand)Btn.Tag;
if ((CmdSet.IsSet == true) || (CmdSet.IsEdited == true)) {
Sw.WriteLine(StringHandler.AddTabs(1, "def,parm:KBTN_" + Cnt.ToString() + "{"));
Sw.WriteLine(StringHandler.AddTabs(2, "def,str:Text=" + StringHandler.EncapsulateString(Btn.Text)));
Sw.WriteLine(StringHandler.AddTabs(2, "def,str:Command=" + StringHandler.EncapsulateString(CmdSet.CommandLine)));
Sw.WriteLine(StringHandler.AddTabs(2, "def,str:Type=" + StringHandler.EncapsulateString(EnumManager.CommandTypeToString(CmdSet.Type))));
Sw.WriteLine(StringHandler.AddTabs(2, "def,str:Channel=" + StringHandler.EncapsulateString(CmdSet.Channel)));

Sw.WriteLine(StringHandler.AddTabs(2, "}"));
Sw.WriteLine(StringHandler.AddTabs(1, "}"));
Sw.WriteLine(StringHandler.AddTabs(2, "}"));
Sw.WriteLine(StringHandler.AddTabs(1, "}"));
}
}
}
Cnt++;
}
}
Expand Down Expand Up @@ -156,9 +198,15 @@ public static void ReadSMPFile(string FileAddress, SerialManager.CommandProcesse
SystemManager.SerialManagers.Add(Sm);
}
else if (ParameterName.StartsWith("KBTN")) {
KeypadButton KButton = new KeypadButton();
KButton.Text = DocumentHandler.GetStringVariable(DocumentHandler.PARM[i], "Text", "");
Buttons.Add(KButton);
if (ParameterName.Split('_').Length == 2) {
string IndexStr = ParameterName.Split('_')[1];
int Index = 0; int.TryParse(IndexStr, out Index);
string ButtonText = DocumentHandler.GetStringVariable(DocumentHandler.PARM[i], "Text", "");
string CommandText = DocumentHandler.GetStringVariable(DocumentHandler.PARM[i], "Command", "");
string CommandType = DocumentHandler.GetStringVariable(DocumentHandler.PARM[i], "Type", "NONE");
string CommandChannel = DocumentHandler.GetStringVariable(DocumentHandler.PARM[i], "Channel", "");
SetKeypadButton(Index, CommandType, CommandText, ButtonText, CommandChannel);
}
}
else if (ParameterName.StartsWith("STEP")) {
if (CurrentProgramIndex > 0) {
Expand Down Expand Up @@ -196,7 +244,7 @@ public static void ReadCMSLFile(string FileAddress, SerialManager.CommandProcess
}
public static StepEnumerations.StepExecutable ExecutableFromLegacyString(string Input) {
Input = Input.ToUpper();
if (Input == "SND") { return StepEnumerations.StepExecutable.SendString;}
if (Input == "SND") { return StepEnumerations.StepExecutable.SendString; }
else if (Input == "STXT") { return StepEnumerations.StepExecutable.SendText; }
else if (Input == "PRNT") { return StepEnumerations.StepExecutable.Print; }
else if (Input == "END") { return StepEnumerations.StepExecutable.Close; }
Expand All @@ -205,7 +253,7 @@ public static StepEnumerations.StepExecutable ExecutableFromLegacyString(string
else if (Input == "CLR") { return StepEnumerations.StepExecutable.Clear; }
else if (Input == "DLY") { return StepEnumerations.StepExecutable.Delay; }
else if (Input == "GOTO") { return StepEnumerations.StepExecutable.GoToLine; }
// else if (Input == "WHEN_TCK") { return StepEnumerations.StepExecutable.GoTo; }
// else if (Input == "WHEN_TCK") { return StepEnumerations.StepExecutable.GoTo; }
else if (Input == "SBYTE") { return StepEnumerations.StepExecutable.SendByte; }
else if (Input == "SWS") { return StepEnumerations.StepExecutable.SwitchSender; }
else { return StepEnumerations.StepExecutable.NoOperation; }
Expand Down
Loading

0 comments on commit 5624f41

Please sign in to comment.