From 4af81a275e71af770a4f47da30e6fecc5895c74b Mon Sep 17 00:00:00 2001 From: Rr42 Date: Sun, 18 Mar 2018 19:21:49 +0530 Subject: [PATCH 01/14] Test commit --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 3789b5f..81149db 100644 --- a/README.rst +++ b/README.rst @@ -1,3 +1,4 @@ +Test Goal of this project ====== This project is a part of FOSSEE fellowship project. For more info visit https://fossee.in/fellowship. From 2d3377ecb73709275641db56809d8fdd86a569ac Mon Sep 17 00:00:00 2001 From: Rr42 Date: Sun, 18 Mar 2018 19:24:18 +0530 Subject: [PATCH 02/14] Test Commit --- README.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/README.rst b/README.rst index 81149db..3789b5f 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,3 @@ -Test Goal of this project ====== This project is a part of FOSSEE fellowship project. For more info visit https://fossee.in/fellowship. From 56b502f2042405588ae0a52ffddd43980ac555ac Mon Sep 17 00:00:00 2001 From: Rr42 Date: Sun, 1 Apr 2018 22:56:03 +0530 Subject: [PATCH 03/14] Added SPDT to Advanced simulation dialogue. --- ldmicro/Makefile | 3 +- ldmicro/components/componentfunctions.h | 6 + ldmicro/components/componentimages.h | 9 +- ldmicro/components/components.cpp | 17 ++ ldmicro/components/componentstructs.h | 13 +- ldmicro/components/spdt.cpp | 232 ++++++++++++++++++ ldmicro/img/{dpdt_switch_1.png => dpdt_1.png} | Bin ldmicro/img/{dpdt_switch_2.png => dpdt_2.png} | Bin ldmicro/img/{dpst_switch_1.png => dpst_1.png} | Bin ldmicro/img/{dpst_switch_2.png => dpst_2.png} | Bin ldmicro/img/{spdt_switch_1.png => spdt_1.png} | Bin ldmicro/img/{spdt_switch_2.png => spdt_2.png} | Bin ldmicro/ldmicro.rc | 4 +- 13 files changed, 278 insertions(+), 6 deletions(-) create mode 100644 ldmicro/components/spdt.cpp rename ldmicro/img/{dpdt_switch_1.png => dpdt_1.png} (100%) rename ldmicro/img/{dpdt_switch_2.png => dpdt_2.png} (100%) rename ldmicro/img/{dpst_switch_1.png => dpst_1.png} (100%) rename ldmicro/img/{dpst_switch_2.png => dpst_2.png} (100%) rename ldmicro/img/{spdt_switch_1.png => spdt_1.png} (100%) rename ldmicro/img/{spdt_switch_2.png => spdt_2.png} (100%) diff --git a/ldmicro/Makefile b/ldmicro/Makefile index 03d533b..df86088 100644 --- a/ldmicro/Makefile +++ b/ldmicro/Makefile @@ -44,7 +44,8 @@ LDOBJS = $(OBJDIR)\ldmicro.obj \ COMPOBJS = $(OBJDIR)\components.obj \ $(OBJDIR)\switch.obj \ - $(OBJDIR)\relay.obj + $(OBJDIR)\relay.obj \ + $(OBJDIR)\spdt.obj HELPOBJ = $(OBJDIR)\helptext.obj diff --git a/ldmicro/components/componentfunctions.h b/ldmicro/components/componentfunctions.h index 9da4bfb..0ba3d18 100644 --- a/ldmicro/components/componentfunctions.h +++ b/ldmicro/components/componentfunctions.h @@ -23,22 +23,28 @@ BOOL ProcessDialogWindow(void); /*Initialization Functions*/ int InitSwitch(void* ComponentAddress); int InitRelay(void* ComponentAddress); +int InitSpdt(void* ComponentAddress); /*Event Handlers*/ void HandleSwitchEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, void* ImageLocation, UINT ImageId, HWND* h); void HandleRelayEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, void* ImageLocation, UINT ImageId, HWND* h); +void HandleSpdtEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, + void* ImageLocation, UINT ImageId, HWND* h); /*Request Handlers*/ double SwitchVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, double Volt, int Source, void* ImageLocation); double RelayVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, double Volt, int Source, void* ImageLocation); +double SpdtVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, + double Volt, int Source, void* ImageLocation); /*Program Reference Functions*/ void SetSwitchIds(int*, void*); void SetRelayIds(int*, void*); +void SetSpdtIds(int*, void*); // Relay Functions diff --git a/ldmicro/components/componentimages.h b/ldmicro/components/componentimages.h index 5c71ae6..41dd99f 100644 --- a/ldmicro/components/componentimages.h +++ b/ldmicro/components/componentimages.h @@ -5,16 +5,20 @@ #define SWITCH_DISCONNECTED 8001 #define RELAY_NC 8002 #define RELAY_NO 8003 +#define SPDT_1 8004 +#define SPDT_2 8005 + #ifndef RC_INVOKED //Used to hide code from resource file(Guess) -#define TOTAL_COMPONENTS 2 +#define TOTAL_COMPONENTS 3 #define COMPONENT_NAME_MAX_LENGTH 50 // Try to keep ComponentID's between 6000 - 6999 #define COMPONENT_SWITCH 6000 #define COMPONENT_RELAY 6001 +#define COMPONENT_SPDT 6002 #define MAX_PIN_COUNT 10 @@ -32,7 +36,8 @@ void SetImage(int Component, void *il); static ComponentData rgCompData[TOTAL_COMPONENTS] = { {0, COMPONENT_SWITCH, TEXT("Switch"), 2, {"Input:", "Output:"}}, - {1, COMPONENT_RELAY, TEXT("Relay"), 5, {"Coil1:", "Coil2:", "NO:", "COM:", "NC:"}} + {1, COMPONENT_RELAY, TEXT("Relay"), 5, {"Coil1:", "Coil2:", "NO:", "COM:", "NC:"}}, + {2, COMPONENT_SPDT, TEXT("Spdt"), 3, {"Input:", "Output1:", "Output2:"}} }; #endif diff --git a/ldmicro/components/components.cpp b/ldmicro/components/components.cpp index 7a27823..692ca2e 100644 --- a/ldmicro/components/components.cpp +++ b/ldmicro/components/components.cpp @@ -48,6 +48,9 @@ size_t GetStructSize(int ComponentId) break; case COMPONENT_RELAY: return sizeof(RelayStruct); + break; + case COMPONENT_SPDT: + return sizeof(SpdtStruct); break; } return (size_t)-1; @@ -64,6 +67,9 @@ int InitializeComponentProperties(void *ComponentAddress, int ComponentId) case COMPONENT_RELAY: return InitRelay(ComponentAddress); break; + case COMPONENT_SPDT: + return InitSpdt(ComponentAddress); + break; } return 0; } @@ -81,6 +87,10 @@ double VoltSet(void* ComponentAddress, BOOL SimulationStarted, int ImageType, in break; case COMPONENT_RELAY: return RelayVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); + break; + case COMPONENT_SPDT: + return SpdtVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); + break; } return Volt; } @@ -97,6 +107,10 @@ void SetPinIds(int Index, void *PinName,int ComponentId, void *ComponentAddres break; case COMPONENT_RELAY: SetRelayIds(PinIds,ComponentAddress); + break; + case COMPONENT_SPDT: + SetSpdtIds(PinIds, ComponentAddress); + break; } } } @@ -125,6 +139,9 @@ int NotifyComponent(void *ComponentAddress, void *PinName, int ComponentId, HandleRelayEvent(ComponentAddress, Event, SimulationStarted, ImageLocation, ImageId, h); // return InitRelay(ComponentAddress); break; + case COMPONENT_SPDT: + HandleSpdtEvent(ComponentAddress, Event, SimulationStarted, ImageLocation, ImageId, h); + break; } // return voltage return 0; diff --git a/ldmicro/components/componentstructs.h b/ldmicro/components/componentstructs.h index a7baca5..214fb4f 100644 --- a/ldmicro/components/componentstructs.h +++ b/ldmicro/components/componentstructs.h @@ -24,9 +24,18 @@ typedef struct RelayStructTag double CoilVolt2; //Voltage at input pin double COMVolt; //Voltage at COM pin double NOVolt; //Voltage at NO pin - double NCVolt; - int PinId[5]; //Voltage at NC pin + double NCVolt; //Voltage at NC pin + int PinId[5]; }RelayStruct; +typedef struct SpdtStructTag +{ + int id; + int image; + BOOL NO1; //Whether Output 1 is connected + double Volt[3]; // Voltage at Input, Output1, Output2 respectively + int PinId[3]; +}SpdtStruct; + #endif diff --git a/ldmicro/components/spdt.cpp b/ldmicro/components/spdt.cpp new file mode 100644 index 0000000..f560134 --- /dev/null +++ b/ldmicro/components/spdt.cpp @@ -0,0 +1,232 @@ +///Includes +#include +#include +//#include +#include +#include + +#include "componentstructs.h" +#include "componentfunctions.h" +#include "componentimages.h" +#include "components.h" + +///Window handles +static HWND StateOut1; +static HWND StateOut2; +HWND* SettingsDialog; + +///Global variables +enum SPDT_Pins {in = 0, out1, out2}; + +///Function definitions +void SetSpdtIds(int* id, void* ComponentAddress) +{ + SpdtStruct* s = (SpdtStruct*)ComponentAddress; + s->PinId[in] = *id++; + s->PinId[out1] = *id++; + s->PinId[out2] = *id++; + +} + +int InitSpdt(void * ComponentAddress) +{ + SpdtStruct* s = (SpdtStruct*)ComponentAddress; + s->image = SPDT_1; + s->NO1 = TRUE; + s->Volt[in] = V_OPEN; + s->Volt[out1] = V_OPEN; + s->Volt[out2] = V_OPEN; + + return SPDT_1; +} + +void MakeSettingsDialog() +{ + HWND InitOut = CreateWindowEx(0, WC_BUTTON, ("Initial output"), + WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, + 7, 3, 120, 65, *SettingsDialog, NULL, NULL, NULL); + FontNice(InitOut); + + StateOut1 = CreateWindowEx(0, WC_BUTTON, ("Output 1"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, + 16, 21, 100, 20, *SettingsDialog, NULL, NULL, NULL); + FontNice(StateOut1); + + StateOut2 = CreateWindowEx(0, WC_BUTTON, ("Output 2"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, + 16, 41, 100, 20, *SettingsDialog, NULL, NULL, NULL); + FontNice(StateOut2); +} + +void LoadSettings(SpdtStruct* s) +{ + if (s->NO1) + Button_SetCheck(StateOut1, BST_CHECKED); + else + Button_SetCheck(StateOut2, BST_CHECKED); +} + +BOOL SaveSettings(SpdtStruct* s, void* ImageLocation) +{ + BOOL NState1; + if (Button_GetState(StateOut1) == BST_CHECKED) + NState1 = TRUE; + else if (Button_GetState(StateOut2) == BST_CHECKED) + NState1 = FALSE; + else + { + MessageBox(*SettingsDialog, + ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); + return FALSE; + } + + s->NO1 = NState1; + + if (NState1) + s->image = SPDT_1; + else + s->image = SPDT_2; + + SetImage(s->image, ImageLocation); + RefreshImages(); + + return TRUE; +} + +void SpdtSettingsDialog(void* ComponentAddress, void* ImageLocation) +{ + SpdtStruct* s = (SpdtStruct*)ComponentAddress; + BOOL exitStatus; + + //Create dialog window instance + SettingsDialog = CreateDialogWindow("SPDT Settings Dialog", 100, 100, 263, 145, STYLE_VERTICAL); + + //Make the settings dialog + MakeSettingsDialog(); + + //Load settings + LoadSettings(s); + + //Show dialog window + ShowDialogWindow(); + + exitStatus = ProcessDialogWindow(); + while (exitStatus == FALSE) + { + exitStatus = SaveSettings(s, ImageLocation); + if (exitStatus == TRUE) + { + //MessageBox(*SettingsDialog, + // ("Saved"), ("Mouse click"), MB_OK | MB_ICONWARNING); + break; + } + else + { + exitStatus = TRUE; + exitStatus = ProcessDialogWindow(); + } + } + + DestroyWindow(*SettingsDialog); + +} + +//Dynamically check and equalise the voltage on all pins that are connected to SPDT at runtime +double EqualiseRuntimeVoltage(void* ComponentAdderss, int index = 0) +{ + SpdtStruct* s = (SpdtStruct*)ComponentAdderss; + + ///Check if input and output 1 are connected + if (s->NO1) + { + ///If the input pin is connected to output 1 then output 2 will be open + s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, V_OPEN); + + ///Get voltages at the connected pins + double volt1 = VoltRequest(s->PinId[0], ComponentAdderss); + double volt2 = VoltRequest(s->PinId[out1], ComponentAdderss); + + ///If either pin is grounded then all pins are set to GND + if (volt1 == GND || volt2 == GND) + { + s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, GND); + s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, GND); + } + ///If no pin is grounded then all pins are set to the max voltage of the pins + else + { + s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, max(volt1, volt2)); + s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, max(volt1, volt2)); + } + } + ///If input and output 2 are connected + else + { + ///If the input pin is connected to output 2 then output 1 will be open + s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, V_OPEN); + + ///Get voltages at the connected pins + double volt1 = VoltRequest(s->PinId[0], ComponentAdderss); + double volt2 = VoltRequest(s->PinId[out2], ComponentAdderss); + + ///If either pin is grounded then all pins are set to GND (Static event) + if (volt1 == GND || volt2 == GND) + { + s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, GND); + s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, GND); + } + ///If no pin is grounded then all pins are set to the max voltage of the pins (Dynamic event) + else + { + s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, max(volt1, volt2)); + s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, max(volt1, volt2)); + } + } + + return s->Volt[index]; +} + +double SpdtVoltChanged(void * ComponentAddress, BOOL SimulationStarted, int index, double Volt, int Source, void * ImageLocation) +{ + if (SimulationStarted) + return EqualiseRuntimeVoltage(ComponentAddress, index); + + return Volt; +} + +void ToggleState(SpdtStruct* s, void* ImageLocation) +{ + s->image = (s->image == SPDT_1) ? SPDT_2 : SPDT_1; + SetImage(s->image, ImageLocation); + RefreshImages(); +} + +void HandleSpdtEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, void * ImageLocation, UINT ImageId, HWND * h) +{ + SpdtStruct* s = (SpdtStruct*)ComponentAddress; + + if (SimulationStarted) + { + switch (Event) + { + case EVENT_MOUSE_CLICK: + ToggleState(s, ImageLocation); + EqualiseRuntimeVoltage(ComponentAddress); + break; + default: + break; + } + } + else + { + switch (Event) + { + case EVENT_MOUSE_DBLCLICK: + SpdtSettingsDialog(ComponentAddress, ImageLocation); + break; + default: + break; + } + } + +} \ No newline at end of file diff --git a/ldmicro/img/dpdt_switch_1.png b/ldmicro/img/dpdt_1.png similarity index 100% rename from ldmicro/img/dpdt_switch_1.png rename to ldmicro/img/dpdt_1.png diff --git a/ldmicro/img/dpdt_switch_2.png b/ldmicro/img/dpdt_2.png similarity index 100% rename from ldmicro/img/dpdt_switch_2.png rename to ldmicro/img/dpdt_2.png diff --git a/ldmicro/img/dpst_switch_1.png b/ldmicro/img/dpst_1.png similarity index 100% rename from ldmicro/img/dpst_switch_1.png rename to ldmicro/img/dpst_1.png diff --git a/ldmicro/img/dpst_switch_2.png b/ldmicro/img/dpst_2.png similarity index 100% rename from ldmicro/img/dpst_switch_2.png rename to ldmicro/img/dpst_2.png diff --git a/ldmicro/img/spdt_switch_1.png b/ldmicro/img/spdt_1.png similarity index 100% rename from ldmicro/img/spdt_switch_1.png rename to ldmicro/img/spdt_1.png diff --git a/ldmicro/img/spdt_switch_2.png b/ldmicro/img/spdt_2.png similarity index 100% rename from ldmicro/img/spdt_switch_2.png rename to ldmicro/img/spdt_2.png diff --git a/ldmicro/ldmicro.rc b/ldmicro/ldmicro.rc index 46c3de1..502d8af 100644 --- a/ldmicro/ldmicro.rc +++ b/ldmicro/ldmicro.rc @@ -10,4 +10,6 @@ RELAY_NC PNG "img\\relay_nc.png" RELAY_NO PNG "img\\relay_no.png" SWITCH_CONNECTED PNG "img\\switch_connected.png" -SWITCH_DISCONNECTED PNG "img\\switch_disconnected.png" \ No newline at end of file +SWITCH_DISCONNECTED PNG "img\\switch_disconnected.png" +SPDT_1 PNG "img\\spdt_1.png" +SPDT_2 PNG "img\\spdt_2.png" \ No newline at end of file From 69d99f289b65c46173900408498d783277112364 Mon Sep 17 00:00:00 2001 From: Rr42 Date: Mon, 2 Apr 2018 13:58:09 +0530 Subject: [PATCH 04/14] Minor Changes --- ldmicro/components/spdt.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ldmicro/components/spdt.cpp b/ldmicro/components/spdt.cpp index f560134..c0bf8b6 100644 --- a/ldmicro/components/spdt.cpp +++ b/ldmicro/components/spdt.cpp @@ -14,7 +14,7 @@ static HWND StateOut1; static HWND StateOut2; HWND* SettingsDialog; - + ///Global variables enum SPDT_Pins {in = 0, out1, out2}; @@ -115,11 +115,7 @@ void SpdtSettingsDialog(void* ComponentAddress, void* ImageLocation) { exitStatus = SaveSettings(s, ImageLocation); if (exitStatus == TRUE) - { - //MessageBox(*SettingsDialog, - // ("Saved"), ("Mouse click"), MB_OK | MB_ICONWARNING); break; - } else { exitStatus = TRUE; @@ -197,6 +193,7 @@ double SpdtVoltChanged(void * ComponentAddress, BOOL SimulationStarted, int inde void ToggleState(SpdtStruct* s, void* ImageLocation) { s->image = (s->image == SPDT_1) ? SPDT_2 : SPDT_1; + s->NO1 = (s->NO1 == TRUE) ? FALSE : TRUE; SetImage(s->image, ImageLocation); RefreshImages(); } From ced427cf5f59bf70a9b760ce05e8826b20ac58a8 Mon Sep 17 00:00:00 2001 From: Rr42 Date: Mon, 2 Apr 2018 14:21:27 +0530 Subject: [PATCH 05/14] Added DPST component to Advanced simulation. --- ldmicro/Makefile | 5 +-- ldmicro/components/componentfunctions.h | 6 ++++ ldmicro/components/componentimages.h | 9 +++-- ldmicro/components/components.cpp | 15 ++++++++ ldmicro/components/componentstructs.h | 9 +++++ ldmicro/components/dpst.cpp | 46 +++++++++++++++++++++++++ ldmicro/components/switch.cpp | 3 +- ldmicro/ldmicro.rc | 4 ++- 8 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 ldmicro/components/dpst.cpp diff --git a/ldmicro/Makefile b/ldmicro/Makefile index df86088..a9bdcb5 100644 --- a/ldmicro/Makefile +++ b/ldmicro/Makefile @@ -45,7 +45,8 @@ LDOBJS = $(OBJDIR)\ldmicro.obj \ COMPOBJS = $(OBJDIR)\components.obj \ $(OBJDIR)\switch.obj \ $(OBJDIR)\relay.obj \ - $(OBJDIR)\spdt.obj + $(OBJDIR)\spdt.obj \ + $(OBJDIR)\dpst.obj HELPOBJ = $(OBJDIR)\helptext.obj @@ -77,7 +78,7 @@ all: $(OBJDIR)/ldmicro.exe $(OBJDIR)/ldinterpret.exe clean: rm -rf $(LDOBJS) $(COMPOBJS) $(CLEANOBJ) - rmdir reg\results + rmdir reg\results lang.cpp: $(OBJDIR)/lang-tables.h diff --git a/ldmicro/components/componentfunctions.h b/ldmicro/components/componentfunctions.h index 0ba3d18..37df62b 100644 --- a/ldmicro/components/componentfunctions.h +++ b/ldmicro/components/componentfunctions.h @@ -24,6 +24,7 @@ BOOL ProcessDialogWindow(void); int InitSwitch(void* ComponentAddress); int InitRelay(void* ComponentAddress); int InitSpdt(void* ComponentAddress); +int InitDpst(void* ComponentAddress); /*Event Handlers*/ void HandleSwitchEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, @@ -32,6 +33,8 @@ void HandleRelayEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, void* ImageLocation, UINT ImageId, HWND* h); void HandleSpdtEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, void* ImageLocation, UINT ImageId, HWND* h); +void HandleDpstEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, + void* ImageLocation, UINT ImageId, HWND* h); /*Request Handlers*/ double SwitchVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, @@ -40,11 +43,14 @@ double RelayVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int inde double Volt, int Source, void* ImageLocation); double SpdtVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, double Volt, int Source, void* ImageLocation); +double DpstVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, + double Volt, int Source, void* ImageLocation); /*Program Reference Functions*/ void SetSwitchIds(int*, void*); void SetRelayIds(int*, void*); void SetSpdtIds(int*, void*); +void SetDpstIds(int*, void*); // Relay Functions diff --git a/ldmicro/components/componentimages.h b/ldmicro/components/componentimages.h index 41dd99f..8b7ec3c 100644 --- a/ldmicro/components/componentimages.h +++ b/ldmicro/components/componentimages.h @@ -7,11 +7,14 @@ #define RELAY_NO 8003 #define SPDT_1 8004 #define SPDT_2 8005 +#define DPST_1 8006 +#define DPST_2 8007 + #ifndef RC_INVOKED //Used to hide code from resource file(Guess) -#define TOTAL_COMPONENTS 3 +#define TOTAL_COMPONENTS 4 #define COMPONENT_NAME_MAX_LENGTH 50 // Try to keep ComponentID's between 6000 - 6999 @@ -19,6 +22,7 @@ #define COMPONENT_SWITCH 6000 #define COMPONENT_RELAY 6001 #define COMPONENT_SPDT 6002 +#define COMPONENT_DPST 6003 #define MAX_PIN_COUNT 10 @@ -37,7 +41,8 @@ void SetImage(int Component, void *il); static ComponentData rgCompData[TOTAL_COMPONENTS] = { {0, COMPONENT_SWITCH, TEXT("Switch"), 2, {"Input:", "Output:"}}, {1, COMPONENT_RELAY, TEXT("Relay"), 5, {"Coil1:", "Coil2:", "NO:", "COM:", "NC:"}}, - {2, COMPONENT_SPDT, TEXT("Spdt"), 3, {"Input:", "Output1:", "Output2:"}} + {2, COMPONENT_SPDT, TEXT("SPDT"), 3, {"Input:", "Output1:", "Output2:"}}, + {3, COMPONENT_DPST, TEXT("DPST"), 4, {"Input1:","Input2:","Output1:","Output2:"}} }; #endif diff --git a/ldmicro/components/components.cpp b/ldmicro/components/components.cpp index 692ca2e..b70ee9e 100644 --- a/ldmicro/components/components.cpp +++ b/ldmicro/components/components.cpp @@ -52,6 +52,9 @@ size_t GetStructSize(int ComponentId) case COMPONENT_SPDT: return sizeof(SpdtStruct); break; + case COMPONENT_DPST: + return sizeof(DpstStruct); + break; } return (size_t)-1; } @@ -70,6 +73,9 @@ int InitializeComponentProperties(void *ComponentAddress, int ComponentId) case COMPONENT_SPDT: return InitSpdt(ComponentAddress); break; + case COMPONENT_DPST: + return InitDpst(ComponentAddress); + break; } return 0; } @@ -91,6 +97,9 @@ double VoltSet(void* ComponentAddress, BOOL SimulationStarted, int ImageType, in case COMPONENT_SPDT: return SpdtVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); break; + case COMPONENT_DPST: + return DpstVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); + break; } return Volt; } @@ -111,6 +120,9 @@ void SetPinIds(int Index, void *PinName,int ComponentId, void *ComponentAddres case COMPONENT_SPDT: SetSpdtIds(PinIds, ComponentAddress); break; + case COMPONENT_DPST: + SetDpstIds(PinIds, ComponentAddress); + break; } } } @@ -142,6 +154,9 @@ int NotifyComponent(void *ComponentAddress, void *PinName, int ComponentId, case COMPONENT_SPDT: HandleSpdtEvent(ComponentAddress, Event, SimulationStarted, ImageLocation, ImageId, h); break; + case COMPONENT_DPST: + HandleDpstEvent(ComponentAddress, Event, SimulationStarted, ImageLocation, ImageId, h); + break; } // return voltage return 0; diff --git a/ldmicro/components/componentstructs.h b/ldmicro/components/componentstructs.h index 214fb4f..8ac3e5a 100644 --- a/ldmicro/components/componentstructs.h +++ b/ldmicro/components/componentstructs.h @@ -38,4 +38,13 @@ typedef struct SpdtStructTag int PinId[3]; }SpdtStruct; +typedef struct DpstStructTag +{ + int id; + int image; + BOOL NO; //Whether the inputs and outputs are disconnected (Open) + double Volt[4]; // Voltage at Input, Output1, Output2 respectively + int PinId[4]; +}DpstStruct; + #endif diff --git a/ldmicro/components/dpst.cpp b/ldmicro/components/dpst.cpp new file mode 100644 index 0000000..e2d1bee --- /dev/null +++ b/ldmicro/components/dpst.cpp @@ -0,0 +1,46 @@ +///Includes +#include +#include +//#include +#include +#include + +#include "componentstructs.h" +#include "componentfunctions.h" +#include "componentimages.h" +#include "components.h" + +///Global variables +enum DPST_Pins { in1 = 0, in2, out1, out2 }; + + +int InitDpst(void * ComponentAddress) +{ + DpstStruct* d = (DpstStruct*)ComponentAddress; + d->image = DPST_1; + d->NO = FALSE; + d->Volt[in1] = V_OPEN; + d->Volt[in2] = V_OPEN; + d->Volt[out1] = V_OPEN; + d->Volt[out2] = V_OPEN; + + return DPST_1; +} + +void HandleDpstEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, void * ImageLocation, UINT ImageId, HWND * h) +{ +} + +double DpstVoltChanged(void * ComponentAddress, BOOL SimulationStarted, int index, double Volt, int Source, void * ImageLocation) +{ + return 0.0; +} + +void SetDpstIds(int* id, void* ComponentAddress) +{ + DpstStruct* d = (DpstStruct*)ComponentAddress; + d->PinId[in1] = *id++; + d->PinId[in2] = *id++; + d->PinId[out1] = *id++; + d->PinId[out2] = *id++; +} \ No newline at end of file diff --git a/ldmicro/components/switch.cpp b/ldmicro/components/switch.cpp index 7e1bf57..ea74076 100644 --- a/ldmicro/components/switch.cpp +++ b/ldmicro/components/switch.cpp @@ -126,6 +126,7 @@ BOOL SaveSwitchDialog(SwitchStruct* Data) ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); return FALSE; } + if(Edit_GetText(NameTextbox, (LPSTR)&temp, 15) < 1) { MessageBox(*SwitchDialog, @@ -185,7 +186,7 @@ int InitSwitch(void* ComponentAddress) temp->Volt[0] = V_OPEN; temp->Volt[1] = V_OPEN; - return SWITCH_DISCONNECTED; + return SWITCH_DISCONNECTED; } void UpdateValues(SwitchStruct* Switch, void* ComponentAddress) diff --git a/ldmicro/ldmicro.rc b/ldmicro/ldmicro.rc index 502d8af..474a990 100644 --- a/ldmicro/ldmicro.rc +++ b/ldmicro/ldmicro.rc @@ -12,4 +12,6 @@ RELAY_NO PNG "img\\relay_no.png" SWITCH_CONNECTED PNG "img\\switch_connected.png" SWITCH_DISCONNECTED PNG "img\\switch_disconnected.png" SPDT_1 PNG "img\\spdt_1.png" -SPDT_2 PNG "img\\spdt_2.png" \ No newline at end of file +SPDT_2 PNG "img\\spdt_2.png" +DPST_1 PNG "img\\dpst_1.png" +DPST_2 PNG "img\\dpst_2.png" From 2531264758d6e6c40273f9212e5e8cccab3df2e0 Mon Sep 17 00:00:00 2001 From: Rr42 Date: Mon, 2 Apr 2018 16:31:23 +0530 Subject: [PATCH 06/14] Resolved function resolution and linker issue. --- ldmicro/Makefile | 1 - ldmicro/components/dpst.cpp | 153 +++++++++++++++++++++++++++++++++--- ldmicro/components/spdt.cpp | 27 +++---- 3 files changed, 157 insertions(+), 24 deletions(-) diff --git a/ldmicro/Makefile b/ldmicro/Makefile index a9bdcb5..11ba1ce 100644 --- a/ldmicro/Makefile +++ b/ldmicro/Makefile @@ -48,7 +48,6 @@ COMPOBJS = $(OBJDIR)\components.obj \ $(OBJDIR)\spdt.obj \ $(OBJDIR)\dpst.obj - HELPOBJ = $(OBJDIR)\helptext.obj CLEANOBJ = $(OBJDIR)\helptext.cpp \ diff --git a/ldmicro/components/dpst.cpp b/ldmicro/components/dpst.cpp index e2d1bee..832d5ac 100644 --- a/ldmicro/components/dpst.cpp +++ b/ldmicro/components/dpst.cpp @@ -10,10 +10,15 @@ #include "componentimages.h" #include "components.h" +///Window handles +static HWND State1; +static HWND State2; +HWND* SettingsDialogDPST; + ///Global variables enum DPST_Pins { in1 = 0, in2, out1, out2 }; - +///Function definitions int InitDpst(void * ComponentAddress) { DpstStruct* d = (DpstStruct*)ComponentAddress; @@ -27,20 +32,150 @@ int InitDpst(void * ComponentAddress) return DPST_1; } -void HandleDpstEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, void * ImageLocation, UINT ImageId, HWND * h) +void SetDpstIds(int* id, void* ComponentAddress) { + DpstStruct* d = (DpstStruct*)ComponentAddress; + d->PinId[in1] = *id++; + d->PinId[in2] = *id++; + d->PinId[out1] = *id++; + d->PinId[out2] = *id++; } -double DpstVoltChanged(void * ComponentAddress, BOOL SimulationStarted, int index, double Volt, int Source, void * ImageLocation) +void MakeSettingsDialogDPST() { - return 0.0; + HWND InitOut = CreateWindowEx(0, WC_BUTTON, ("Initial output state"), + WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, + 7, 3, 120, 65, *SettingsDialogDPST, NULL, NULL, NULL); + FontNice(InitOut); + + State1 = CreateWindowEx(0, WC_BUTTON, ("State 1"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, + 16, 21, 100, 20, *SettingsDialogDPST, NULL, NULL, NULL); + FontNice(State1); + + State2 = CreateWindowEx(0, WC_BUTTON, ("State 2"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, + 16, 41, 100, 20, *SettingsDialogDPST, NULL, NULL, NULL); + FontNice(State2); } -void SetDpstIds(int* id, void* ComponentAddress) +void LoadSettings(DpstStruct* d) +{ + if (!d->NO) + Button_SetCheck(State1, BST_CHECKED); + else + Button_SetCheck(State2, BST_CHECKED); +} + +BOOL SaveSettings(DpstStruct* d, void* ImageLocation) +{ + BOOL NState; + if (Button_GetState(State1) == BST_CHECKED) + NState = TRUE; + else if (Button_GetState(State2) == BST_CHECKED) + NState = FALSE; + else + { + MessageBox(*SettingsDialogDPST, + ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); + return FALSE; + } + + d->NO = !NState; + + if (NState) + d->image = DPST_1; + else + d->image = DPST_2; + + SetImage(d->image, ImageLocation); + RefreshImages(); + + return TRUE; +} + +void DpstSettingsDialog(void* ComponentAddress, void* ImageLocation) { DpstStruct* d = (DpstStruct*)ComponentAddress; - d->PinId[in1] = *id++; - d->PinId[in2] = *id++; - d->PinId[out1] = *id++; - d->PinId[out2] = *id++; + BOOL exitStatus; + + //Create dialog window instance + SettingsDialogDPST = CreateDialogWindow("SPDT Settings Dialog", 100, 100, 263, 145, STYLE_VERTICAL); + + //Make the settings dialog + MakeSettingsDialogDPST(); + + //Load settings + LoadSettings(d); + + //Show dialog window + ShowDialogWindow(); + + exitStatus = ProcessDialogWindow(); + while (exitStatus == FALSE) + { + exitStatus = SaveSettings(d, ImageLocation); + if (exitStatus == TRUE) + break; + else + { + exitStatus = TRUE; + exitStatus = ProcessDialogWindow(); + } + } + + DestroyWindow(*SettingsDialogDPST); +} + + +//Dynamically check and equalise the voltage on all pins that are connected to DPST at runtime +double EqualiseRuntimeVoltageDPST(void* ComponentAdderss, int index = 0) +{ + return 0; //Edit!!! +} + + +void ToggleState(DpstStruct* d, void* ImageLocation) +{ + d->image = (d->image == DPST_1) ? DPST_2 : DPST_1; + d->NO = (d->NO == TRUE) ? FALSE : TRUE; + SetImage(d->image, ImageLocation); + RefreshImages(); +} + +void HandleDpstEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, void * ImageLocation, UINT ImageId, HWND * h) +{ + DpstStruct* d = (DpstStruct*)ComponentAddress; + + if (SimulationStarted) + { + switch (Event) + { + case EVENT_MOUSE_CLICK: + ToggleState(d, ImageLocation); + EqualiseRuntimeVoltageDPST(ComponentAddress); + break; + default: + break; + } + } + else + { + switch (Event) + { + case EVENT_MOUSE_DBLCLICK: + DpstSettingsDialog(ComponentAddress, ImageLocation); + break; + default: + break; + } + } +} + +double DpstVoltChanged(void * ComponentAddress, BOOL SimulationStarted, int index, double Volt, int Source, void * ImageLocation) +{ + if (SimulationStarted) + return EqualiseRuntimeVoltageDPST(ComponentAddress, index); + + return Volt; } \ No newline at end of file diff --git a/ldmicro/components/spdt.cpp b/ldmicro/components/spdt.cpp index c0bf8b6..4393341 100644 --- a/ldmicro/components/spdt.cpp +++ b/ldmicro/components/spdt.cpp @@ -13,7 +13,7 @@ ///Window handles static HWND StateOut1; static HWND StateOut2; -HWND* SettingsDialog; +HWND* SettingsDialogSPDT; ///Global variables enum SPDT_Pins {in = 0, out1, out2}; @@ -40,21 +40,21 @@ int InitSpdt(void * ComponentAddress) return SPDT_1; } -void MakeSettingsDialog() +void MakeSettingsDialogSPDT() { HWND InitOut = CreateWindowEx(0, WC_BUTTON, ("Initial output"), WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, - 7, 3, 120, 65, *SettingsDialog, NULL, NULL, NULL); + 7, 3, 120, 65, *SettingsDialogSPDT, NULL, NULL, NULL); FontNice(InitOut); StateOut1 = CreateWindowEx(0, WC_BUTTON, ("Output 1"), WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, - 16, 21, 100, 20, *SettingsDialog, NULL, NULL, NULL); + 16, 21, 100, 20, *SettingsDialogSPDT, NULL, NULL, NULL); FontNice(StateOut1); StateOut2 = CreateWindowEx(0, WC_BUTTON, ("Output 2"), WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 41, 100, 20, *SettingsDialog, NULL, NULL, NULL); + 16, 41, 100, 20, *SettingsDialogSPDT, NULL, NULL, NULL); FontNice(StateOut2); } @@ -75,7 +75,7 @@ BOOL SaveSettings(SpdtStruct* s, void* ImageLocation) NState1 = FALSE; else { - MessageBox(*SettingsDialog, + MessageBox(*SettingsDialogSPDT, ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); return FALSE; } @@ -99,10 +99,10 @@ void SpdtSettingsDialog(void* ComponentAddress, void* ImageLocation) BOOL exitStatus; //Create dialog window instance - SettingsDialog = CreateDialogWindow("SPDT Settings Dialog", 100, 100, 263, 145, STYLE_VERTICAL); + SettingsDialogSPDT = CreateDialogWindow("SPDT Settings Dialog", 100, 100, 263, 145, STYLE_VERTICAL); //Make the settings dialog - MakeSettingsDialog(); + MakeSettingsDialogSPDT(); //Load settings LoadSettings(s); @@ -123,12 +123,12 @@ void SpdtSettingsDialog(void* ComponentAddress, void* ImageLocation) } } - DestroyWindow(*SettingsDialog); + DestroyWindow(*SettingsDialogSPDT); } //Dynamically check and equalise the voltage on all pins that are connected to SPDT at runtime -double EqualiseRuntimeVoltage(void* ComponentAdderss, int index = 0) +double EqualiseRuntimeVoltageSPDT(void* ComponentAdderss, int index = 0) { SpdtStruct* s = (SpdtStruct*)ComponentAdderss; @@ -185,7 +185,7 @@ double EqualiseRuntimeVoltage(void* ComponentAdderss, int index = 0) double SpdtVoltChanged(void * ComponentAddress, BOOL SimulationStarted, int index, double Volt, int Source, void * ImageLocation) { if (SimulationStarted) - return EqualiseRuntimeVoltage(ComponentAddress, index); + return EqualiseRuntimeVoltageSPDT(ComponentAddress, index); return Volt; } @@ -208,7 +208,7 @@ void HandleSpdtEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, { case EVENT_MOUSE_CLICK: ToggleState(s, ImageLocation); - EqualiseRuntimeVoltage(ComponentAddress); + EqualiseRuntimeVoltageSPDT(ComponentAddress); break; default: break; @@ -224,6 +224,5 @@ void HandleSpdtEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, default: break; } - } - + } } \ No newline at end of file From c21ef62e6f2f4d59188c0eaa5365e55007a8831d Mon Sep 17 00:00:00 2001 From: Rr42 Date: Mon, 2 Apr 2018 17:13:32 +0530 Subject: [PATCH 07/14] Added DPDT component to Advanced simulation. --- ldmicro/Makefile | 3 +- ldmicro/components/componentfunctions.h | 6 + ldmicro/components/componentimages.h | 8 +- ldmicro/components/components.cpp | 15 ++ ldmicro/components/componentstructs.h | 11 +- ldmicro/components/dpdt.cpp | 184 ++++++++++++++++++++++++ ldmicro/components/dpst.cpp | 2 - ldmicro/img/dpdt_1.png | Bin 1437 -> 1443 bytes ldmicro/img/dpdt_2.png | Bin 1443 -> 1437 bytes ldmicro/ldmicro.rc | 2 + 10 files changed, 225 insertions(+), 6 deletions(-) create mode 100644 ldmicro/components/dpdt.cpp diff --git a/ldmicro/Makefile b/ldmicro/Makefile index 11ba1ce..3bc6257 100644 --- a/ldmicro/Makefile +++ b/ldmicro/Makefile @@ -46,7 +46,8 @@ COMPOBJS = $(OBJDIR)\components.obj \ $(OBJDIR)\switch.obj \ $(OBJDIR)\relay.obj \ $(OBJDIR)\spdt.obj \ - $(OBJDIR)\dpst.obj + $(OBJDIR)\dpst.obj \ + $(OBJDIR)\dpdt.obj HELPOBJ = $(OBJDIR)\helptext.obj diff --git a/ldmicro/components/componentfunctions.h b/ldmicro/components/componentfunctions.h index 37df62b..916bf00 100644 --- a/ldmicro/components/componentfunctions.h +++ b/ldmicro/components/componentfunctions.h @@ -25,6 +25,7 @@ int InitSwitch(void* ComponentAddress); int InitRelay(void* ComponentAddress); int InitSpdt(void* ComponentAddress); int InitDpst(void* ComponentAddress); +int InitDpdt(void* ComponentAddress); /*Event Handlers*/ void HandleSwitchEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, @@ -35,6 +36,8 @@ void HandleSpdtEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, void* ImageLocation, UINT ImageId, HWND* h); void HandleDpstEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, void* ImageLocation, UINT ImageId, HWND* h); +void HandleDpdtEvent(void* ComponentAddress, int Event, BOOL SimulationStarted, + void* ImageLocation, UINT ImageId, HWND* h); /*Request Handlers*/ double SwitchVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, @@ -45,12 +48,15 @@ double SpdtVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index double Volt, int Source, void* ImageLocation); double DpstVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, double Volt, int Source, void* ImageLocation); +double DpdtVoltChanged(void* ComponentAddress, BOOL SimulationStarted, int index, + double Volt, int Source, void* ImageLocation); /*Program Reference Functions*/ void SetSwitchIds(int*, void*); void SetRelayIds(int*, void*); void SetSpdtIds(int*, void*); void SetDpstIds(int*, void*); +void SetDpdtIds(int*, void*); // Relay Functions diff --git a/ldmicro/components/componentimages.h b/ldmicro/components/componentimages.h index 8b7ec3c..27ef6ce 100644 --- a/ldmicro/components/componentimages.h +++ b/ldmicro/components/componentimages.h @@ -9,12 +9,14 @@ #define SPDT_2 8005 #define DPST_1 8006 #define DPST_2 8007 +#define DPDT_1 8008 +#define DPDT_2 8009 #ifndef RC_INVOKED //Used to hide code from resource file(Guess) -#define TOTAL_COMPONENTS 4 +#define TOTAL_COMPONENTS 5 #define COMPONENT_NAME_MAX_LENGTH 50 // Try to keep ComponentID's between 6000 - 6999 @@ -23,6 +25,7 @@ #define COMPONENT_RELAY 6001 #define COMPONENT_SPDT 6002 #define COMPONENT_DPST 6003 +#define COMPONENT_DPDT 6004 #define MAX_PIN_COUNT 10 @@ -42,7 +45,8 @@ static ComponentData rgCompData[TOTAL_COMPONENTS] = { {0, COMPONENT_SWITCH, TEXT("Switch"), 2, {"Input:", "Output:"}}, {1, COMPONENT_RELAY, TEXT("Relay"), 5, {"Coil1:", "Coil2:", "NO:", "COM:", "NC:"}}, {2, COMPONENT_SPDT, TEXT("SPDT"), 3, {"Input:", "Output1:", "Output2:"}}, - {3, COMPONENT_DPST, TEXT("DPST"), 4, {"Input1:","Input2:","Output1:","Output2:"}} + {3, COMPONENT_DPST, TEXT("DPST"), 4, {"Input1:", "Input2:", "Output1:", "Output2:"}}, + {4, COMPONENT_DPDT, TEXT("DPDT"), 6, {"Input1:", "Input2:", "Output11:", "Output12:", "Output21:", "Output22:"}} }; #endif diff --git a/ldmicro/components/components.cpp b/ldmicro/components/components.cpp index b70ee9e..632f136 100644 --- a/ldmicro/components/components.cpp +++ b/ldmicro/components/components.cpp @@ -55,6 +55,9 @@ size_t GetStructSize(int ComponentId) case COMPONENT_DPST: return sizeof(DpstStruct); break; + case COMPONENT_DPDT: + return sizeof(DpdtStruct); + break; } return (size_t)-1; } @@ -76,6 +79,9 @@ int InitializeComponentProperties(void *ComponentAddress, int ComponentId) case COMPONENT_DPST: return InitDpst(ComponentAddress); break; + case COMPONENT_DPDT: + return InitDpdt(ComponentAddress); + break; } return 0; } @@ -100,6 +106,9 @@ double VoltSet(void* ComponentAddress, BOOL SimulationStarted, int ImageType, in case COMPONENT_DPST: return DpstVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); break; + case COMPONENT_DPDT: + return DpdtVoltChanged(ComponentAddress, SimulationStarted, Index, Volt, Source, ImageLocation); + break; } return Volt; } @@ -123,6 +132,9 @@ void SetPinIds(int Index, void *PinName,int ComponentId, void *ComponentAddres case COMPONENT_DPST: SetDpstIds(PinIds, ComponentAddress); break; + case COMPONENT_DPDT: + SetDpdtIds(PinIds, ComponentAddress); + break; } } } @@ -157,6 +169,9 @@ int NotifyComponent(void *ComponentAddress, void *PinName, int ComponentId, case COMPONENT_DPST: HandleDpstEvent(ComponentAddress, Event, SimulationStarted, ImageLocation, ImageId, h); break; + case COMPONENT_DPDT: + HandleDpdtEvent(ComponentAddress, Event, SimulationStarted, ImageLocation, ImageId, h); + break; } // return voltage return 0; diff --git a/ldmicro/components/componentstructs.h b/ldmicro/components/componentstructs.h index 8ac3e5a..87bba27 100644 --- a/ldmicro/components/componentstructs.h +++ b/ldmicro/components/componentstructs.h @@ -43,8 +43,17 @@ typedef struct DpstStructTag int id; int image; BOOL NO; //Whether the inputs and outputs are disconnected (Open) - double Volt[4]; // Voltage at Input, Output1, Output2 respectively + double Volt[4]; // Voltage at Input1, Input2, Output1, Output2 respectively int PinId[4]; }DpstStruct; +typedef struct DpdtStructTag +{ + int id; + int image; + BOOL NS1; //Whether the inputs and outputs are connected in state 1 + double Volt[6]; // Voltage at Input1, Input2, Output11, Output12, Output21, Output22 respectively + int PinId[6]; +}DpdtStruct; + #endif diff --git a/ldmicro/components/dpdt.cpp b/ldmicro/components/dpdt.cpp new file mode 100644 index 0000000..afe9840 --- /dev/null +++ b/ldmicro/components/dpdt.cpp @@ -0,0 +1,184 @@ +///Includes +#include +#include +//#include +#include +#include + +#include "componentstructs.h" +#include "componentfunctions.h" +#include "componentimages.h" +#include "components.h" + +///Window handles +static HWND DPDTState1; +static HWND DPDTState2; +HWND* SettingsDialogDPDT; + +///Global variables +enum DPDT_Pins { in1 = 0, in2, out11, out12, out21, out22 }; + +///Function definitions +int InitDpdt(void * ComponentAddress) +{ + DpdtStruct* d = (DpdtStruct*)ComponentAddress; + d->image = DPDT_1; + d->NS1 = TRUE; + d->Volt[in1] = V_OPEN; + d->Volt[in2] = V_OPEN; + d->Volt[out11] = V_OPEN; + d->Volt[out12] = V_OPEN; + d->Volt[out21] = V_OPEN; + d->Volt[out22] = V_OPEN; + + return DPDT_1; +} + +void SetDpdtIds(int* id, void* ComponentAddress) +{ + DpdtStruct* d = (DpdtStruct*)ComponentAddress; + d->PinId[in1] = *id++; + d->PinId[in2] = *id++; + d->PinId[out11] = *id++; + d->PinId[out12] = *id++; + d->PinId[out21] = *id++; + d->PinId[out22] = *id++; +} + +void MakeSettingsDialogDPDT() +{ + HWND InitOut = CreateWindowEx(0, WC_BUTTON, ("Initial output state"), + WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, + 7, 3, 120, 65, *SettingsDialogDPDT, NULL, NULL, NULL); + FontNice(InitOut); + + DPDTState1 = CreateWindowEx(0, WC_BUTTON, ("State 1"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, + 16, 21, 100, 20, *SettingsDialogDPDT, NULL, NULL, NULL); + FontNice(DPDTState1); + + DPDTState2 = CreateWindowEx(0, WC_BUTTON, ("State 2"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, + 16, 41, 100, 20, *SettingsDialogDPDT, NULL, NULL, NULL); + FontNice(DPDTState2); +} + +void LoadSettings(DpdtStruct* d) +{ + if (d->NS1) + Button_SetCheck(DPDTState1, BST_CHECKED); + else + Button_SetCheck(DPDTState2, BST_CHECKED); +} + +BOOL SaveSettings(DpdtStruct* d, void* ImageLocation) +{ + BOOL NState; + if (Button_GetState(DPDTState1) == BST_CHECKED) + NState = TRUE; + else if (Button_GetState(DPDTState2) == BST_CHECKED) + NState = FALSE; + else + { + MessageBox(*SettingsDialogDPDT, + ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); + return FALSE; + } + + d->NS1 = NState; + + if (NState) + d->image = DPDT_1; + else + d->image = DPDT_2; + + SetImage(d->image, ImageLocation); + RefreshImages(); + + return TRUE; +} + +void DpdtSettingsDialog(void* ComponentAddress, void* ImageLocation) +{ + DpdtStruct* d = (DpdtStruct*)ComponentAddress; + BOOL exitStatus; + + //Create dialog window instance + SettingsDialogDPDT = CreateDialogWindow("SPDT Settings Dialog", 100, 100, 263, 145, STYLE_VERTICAL); + + //Make the settings dialog + MakeSettingsDialogDPDT(); + + //Load settings + LoadSettings(d); + + //Show dialog window + ShowDialogWindow(); + + exitStatus = ProcessDialogWindow(); + while (exitStatus == FALSE) + { + exitStatus = SaveSettings(d, ImageLocation); + if (exitStatus == TRUE) + break; + else + { + exitStatus = TRUE; + exitStatus = ProcessDialogWindow(); + } + } + + DestroyWindow(*SettingsDialogDPDT); +} + +//Dynamically check and equalise the voltage on all pins that are connected to DPST at runtime +double EqualiseRuntimeVoltageDPDT(void* ComponentAdderss, int index = 0) +{ + return 0; //Edit!!! +} + +void ToggleState(DpdtStruct* d, void* ImageLocation) +{ + d->image = (d->image == DPDT_1) ? DPDT_2 : DPDT_1; + d->NS1 = (d->NS1 == TRUE) ? FALSE : TRUE; + SetImage(d->image, ImageLocation); + RefreshImages(); +} + +void HandleDpdtEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, void * ImageLocation, UINT ImageId, HWND * h) +{ + DpdtStruct* d = (DpdtStruct*)ComponentAddress; + + if (SimulationStarted) + { + switch (Event) + { + case EVENT_MOUSE_CLICK: + ToggleState(d, ImageLocation); + EqualiseRuntimeVoltageDPDT(ComponentAddress); + break; + default: + break; + } + } + else + { + switch (Event) + { + case EVENT_MOUSE_DBLCLICK: + DpdtSettingsDialog(ComponentAddress, ImageLocation); + break; + default: + break; + } + } +} + +double DpdtVoltChanged(void * ComponentAddress, BOOL SimulationStarted, int index, double Volt, int Source, void * ImageLocation) +{ + + if (SimulationStarted) + return EqualiseRuntimeVoltageDPDT(ComponentAddress, index); + + return Volt; +} \ No newline at end of file diff --git a/ldmicro/components/dpst.cpp b/ldmicro/components/dpst.cpp index 832d5ac..e3b7f48 100644 --- a/ldmicro/components/dpst.cpp +++ b/ldmicro/components/dpst.cpp @@ -127,14 +127,12 @@ void DpstSettingsDialog(void* ComponentAddress, void* ImageLocation) DestroyWindow(*SettingsDialogDPST); } - //Dynamically check and equalise the voltage on all pins that are connected to DPST at runtime double EqualiseRuntimeVoltageDPST(void* ComponentAdderss, int index = 0) { return 0; //Edit!!! } - void ToggleState(DpstStruct* d, void* ImageLocation) { d->image = (d->image == DPST_1) ? DPST_2 : DPST_1; diff --git a/ldmicro/img/dpdt_1.png b/ldmicro/img/dpdt_1.png index 56c61a85427440f6e22ec16a20076e19b4580a90..17ff18d2fbadd22f0f6f0521ea7a092437ca3cd3 100644 GIT binary patch delta 1350 zcmV-M1-bg23!@8=Zhs(2L_t(|obB9SsAg3e$MMfIGc}?nH7TftWtnE9PDjlcD94N> z@ItAZD6fQIF#lj`bP+>;gdi`(B!wUhB`iWJ$}TL_u@sLvqb3;r6aS({p_VC`^?0$) zbdGaoPH)25Yvo#BIK1%gb@4m<%iinVYd!mk%rt0+HMIi_UVq6D(ilTXV+(L z8OC0ZD`eie>baKC*Bp}hcRVHHv=zri9ED?*+t#G?C8Tf;t`PCgJsyoX5ZB@}GXF7U zFnSb{`LH78MeB2Pbw$>Hryri#fs_n%4=Z z-fQs+IDY~USiAxr(A+=r>WJj?wL|R2srU#U$CdaX4#RzRO~RSKs~2x|S%-sbhuDn` z3!ewz&p21+L-pcJON+OxeQ_q{Yi_01qCFv<)8Eob;|w8n|2YsKpG3W?aLJWy`Lb@&*r!GV|;aer#HXx;tFiZ}>2<7}C~+Qac9@dJEH z=DicA>r%*f@qL*$tT5*NxEd!-y(rn&Eh}OlylX`nkU6ic7H^s&)>3+#)Hh+)+t3c2 zC*s!Ci?f{GgzT?u)y~56ioi+hvU(G;6JMEe?6J5|=B=w2XE}Y%A(>AjMI5){xbjPE zvw!kjGAVrtDV&FIEmScsCt@wWi7&}~ZpvWvC?scA-jlpJGNm?DXI?q7GINjSG8E(3Rz0Tx>l-EhLFbSZw_gkA*3;ekj5B78e<4) zj3J~khLFY>LK--&nqP2L(1#VFXAE` zg9{WXw}?2aTD0yK7bD(=AL8Q+U4M2zeh_ZNB{kkv?@`E&xNOC}@`$5xgVHZ+(rylY z-LlHI?VJ8<;X>wblr~Ot6Qp_ty-n(K`1Ooq@4+?^lkOh&CS>jZF!m+9-sqRLihqcl~-wb2FgR5lTzUsM_(AON2`8PZ(V#|u-N@JQ6l)}16=}SmqE50G(&^;b4SJAg| zevO7S{RzqZgVNFZXClrPQQp&!I9$Y5+=1(A^z5a#IbHleAi9CtS{CMu^Xo-C;bV09UstHzpP2u zYGz>l!sovDlhH4$G7;->I_{SFNbNXN)1Hvd>2K+zafXn_7(yDOw;jVpMqO4zjJm9b z76r(PyF-BchlZ?8orr3L3)*D5fY1Cy^B0pk-B4#rV zQObgL;PO$IHTVzx-Le{I2x*KVq%nq&#u!2xV+d)CA*3;02F0Q84R`|+1^@s607*qo IM6N<$f)hxd1ONa4 delta 1344 zcmV-G1;6^E3!Mv)Zhsm{L_t(|obB9QsHIgM$MMg9W@^+lEe%EmM=W0kG&yS4M0rXf zgf5f_Wxkm@_)QlNY_2pjHqHYMO5-|1Q>+ zIdjfwx25*;tX%60n+^L}7eDy2*4odr{?9)$Q>Px*jUAw~H-BA7Wpp8x(S=k-7g8Br zNM&>(m9b&$0HYD{c3gr}aX6mAz4)%oKaUlw%^4DLCYJCgd_v|HoQ2=umm)qhTD0cw z)Fa-7pW!T-e_7-DTk$J=L*`8br)yHkE!Zw|*OW0w;n!G@`NB}qXl==gH~<@`%7DyA za34+@BGz(R+kezg!b3BTeE?q*v3rhrR?(V}SMjD9$F84z_L*Ot)wH#TM7#w%WS%m^ z*lTfx%)92EYZ-0rA({Wg-$i_6>bQtwae}gJ4N6-=3SYn#BHp>?)rdpzBYaWjOG5^u zMIo7wDpGzS;>#kA6R}RjW)Yvp9r(V?9b?36YY$mY#DD&Zn5{Slk1LN(u9ErJ(PA|# zq*B^jvMQ$wsf;e9GU^l(ahQl0JH{A9^3}0Jtl$)U41dIDv0LVg<3<{e4cIhxh!q@- zz!CT)z9Zr}mH!z#TH59w+So zp8AB$LVr2c`v6Xxe7_lYDl_PInNN(E?!V&yQ^-mp_EYY-7nPZGAnsNK?HKdU`}Ok1 z5VDepjY>7iX_L<;8A3=6ta?t4a#ZZq9W)>{MMcs^!xF`?M)j(RuZue z3%F4ElduU-;3ixm^B-eHtMkTi{%pbb@Hc!4n}4w#iQOVjA1hdUGbG|2xE0%E-m}K_ zV{ik`mHFVn>6#SsQ(PzW`YB`Hi>q*|%vXkrMr%t}#6CEBstm~7jYo0f5V4liS{cxZ zm~|Pt59f=xZGLf9)0&X|F>7h)^NPSh>#|xCazDO4@Aw|4< z>VLTMPi(7F^e`xG2`QY9A5N+mR}--wSL5eS+Pe>Vjff+ayYmI5s5@Z<_wAWu=4uz%eWZF<4cN^B@yS1 z7OlC5ixHdgb9{Ww8sBnScq1+y<6ZR@h1`g5O+71**n;boep!Qdb7*VHD#x~O`;UbS znZHxoI4um2YA;&b)EAVh_gQ!V+eHj|df1wf^{->>E6ST$yVw;Hao_@qZBF@Gx{CJF>y|lK6EN4%v@vS%%Pbn4eqqZ7vS4gF_w`5gL7g8Br zNM+O~q;v>9ebR8IIU>1i><}yXkblx~;Ypl>J6r3QHR!XN8Q3`aUZ)88cJG%pCZ%!A zM{%#r$0on^epyx1`(;&5@0V3My(mC=P%#=ijM1mP4MY$yu=0000_Wxkm@_)QlNY_2pjHqHYMO5-|1Q>+ zIdjfwx25*;tX%60n+^L}7eDy2*4odr{?9)$Q>Px*jUAw~H-BA7Wpp8x(S=k-7g8Br zNM&>(m9b&$0HYD{c3gr}aX6mAz4)%oKaUlw%^4DLCYJCgd_v|HoQ2=umm)qhTD0cw z)Fa-7pW!T-e_7-DTk$J=L*`8br)yHkE!Zw|*OW0w;n!G@`NB}qXl==gH~<@`%7DyA za34+@BGz(R+kezg!b3BTeE?q*v3rhrR?(V}SMjD9$F84z_L*Ot)wH#TM7#w%WS%m^ z*lTfx%)92EYZ-0rA({Wg-$i_6>bQtwae}gJ4N6-=3SYn#BHp>?)rdpzBYaWjOG5^u zMIo7wDpGzS;>#kA6R}RjW)Yvp9r(V?9b?36YY$mY#DD&Zn5{Slk1LN(u9ErJ(PA|# zq*B^jvMQ$wsf;e9GU^l(ahQl0JH{A9^3}0Jtl$)U41dIDv0LVg<3<{e4cIhxh!q@- zz!CT)z9Zr}mH!z#TH59w+So zp8AB$LVr2c`v6Xxe7_lYDl_PInNN(E?!V&yQ^-mp_EYY-7nPZGAnsNK?HKdU`}Ok1 z5VDepjY>7iX_L<;8A3=6ta?t4a#ZZq9W)>{MMcs^!xF`?M)j(RuZue z3%F4ElduU-;3ixm^B-eHtMkTi{%pbb@Hc!4n}4w#iQOVjA1hdUGbG|2xE0%E-m}K_ zV{ik`mHFVn>6#SsQ(PzW`YB`Hi>q*|%vXkrMr%t}#6CEBstm~7jYo0f5V4liS{cxZ zm~|Pt59f=xZGLf9)0&X|F>7h)^NPSh>#|xCazDO4@Aw|4< z>VLTMPi(7F^e`xG2`QY9A5N+mR}--wSL5eS+Pe>Vjff+ayYmI5s5@Z<_wAWu=4uz%eWZF<4cN^B@yS1 z7OlC5ixHdgb9{Ww8sBnScq1+y<6ZR@h1`g5O+71**n;boep!Qdb7*VHD#x~O`;UbS znZHxoI4um2YA;&b)EAVh_gQ!V+eHj|df1wf^{->>E6ST$yVw;Hao_@qZBF@Gx{CJF>y|lK6EN4%v@vS%%Pbn4eqqZ7vS4gF_w`5gL7g8Br zNM+O~q;v>9ebR8IIU>1i><}yXkblx~;Ypl>J6r3QHR!XN8Q3`aUZ)88cJG%pCZ%!A zM{%#r$0on^epyx1`(;&5@0V3My(mC=P%#=ijM1mP4MY$yu=0000 z@ItAZD6fQIF#lj`bP+>;gdi`(B!wUhB`iWJ$}TL_u@sLvqb3;r6aS({p_VC`^?0$) zbdGaoPH)25Yvo#BIK1%gb@4m<%iinVYd!mk%rt0+HMIi_UVq6D(ilTXV+(L z8OC0ZD`eie>baKC*Bp}hcRVHHv=zri9ED?*+t#G?C8Tf;t`PCgJsyoX5ZB@}GXF7U zFnSb{`LH78MeB2Pbw$>Hryri#fs_n%4=Z z-fQs+IDY~USiAxr(A+=r>WJj?wL|R2srU#U$CdaX4#RzRO~RSKs~2x|S%-sbhuDn` z3!ewz&p21+L-pcJON+OxeQ_q{Yi_01qCFv<)8Eob;|w8n|2YsKpG3W?aLJWy`Lb@&*r!GV|;aer#HXx;tFiZ}>2<7}C~+Qac9@dJEH z=DicA>r%*f@qL*$tT5*NxEd!-y(rn&Eh}OlylX`nkU6ic7H^s&)>3+#)Hh+)+t3c2 zC*s!Ci?f{GgzT?u)y~56ioi+hvU(G;6JMEe?6J5|=B=w2XE}Y%A(>AjMI5){xbjPE zvw!kjGAVrtDV&FIEmScsCt@wWi7&}~ZpvWvC?scA-jlpJGNm?DXI?q7GINjSG8E(3Rz0Tx>l-EhLFbSZw_gkA*3;ekj5B78e<4) zj3J~khLFY>LK--&nqP2L(1#VFXAE` zg9{WXw}?2aTD0yK7bD(=AL8Q+U4M2zeh_ZNB{kkv?@`E&xNOC}@`$5xgVHZ+(rylY z-LlHI?VJ8<;X>wblr~Ot6Qp_ty-n(K`1Ooq@4+?^lkOh&CS>jZF!m+9-sqRLihqcl~-wb2FgR5lTzUsM_(AON2`8PZ(V#|u-N@JQ6l)}16=}SmqE50G(&^;b4SJAg| zevO7S{RzqZgVNFZXClrPQQp&!I9$Y5+=1(A^z5a#IbHleAi9CtS{CMu^Xo-C;bV09UstHzpP2u zYGz>l!sovDlhH4$G7;->I_{SFNbNXN)1Hvd>2K+zafXn_7(yDOw;jVpMqO4zjJm9b z76r(PyF-BchlZ?8orr3L3)*D5fY1Cy^B0pk-B4#rV zQObgL;PO$IHTVzx-Le{I2x*KVq%nq&#u!2xV+d)CA*3;02F0Q84R`|+1^@s607*qo IM6N<$f)hxd1ONa4 diff --git a/ldmicro/ldmicro.rc b/ldmicro/ldmicro.rc index 474a990..952b087 100644 --- a/ldmicro/ldmicro.rc +++ b/ldmicro/ldmicro.rc @@ -15,3 +15,5 @@ SPDT_1 PNG "img\\spdt_1.png" SPDT_2 PNG "img\\spdt_2.png" DPST_1 PNG "img\\dpst_1.png" DPST_2 PNG "img\\dpst_2.png" +DPDT_1 PNG "img\\dpdt_1.png" +DPDT_2 PNG "img\\dpdt_2.png" From cd6a0f22a4546af344d932556993415929032972 Mon Sep 17 00:00:00 2001 From: Rr42 Date: Mon, 2 Apr 2018 23:18:12 +0530 Subject: [PATCH 08/14] Added functionality for DPST component. SPDT and DPST functionality tested and finalised. --- ldmicro/components/dpdt.cpp | 7 ++++- ldmicro/components/dpst.cpp | 51 ++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/ldmicro/components/dpdt.cpp b/ldmicro/components/dpdt.cpp index afe9840..692d6e7 100644 --- a/ldmicro/components/dpdt.cpp +++ b/ldmicro/components/dpdt.cpp @@ -134,7 +134,11 @@ void DpdtSettingsDialog(void* ComponentAddress, void* ImageLocation) //Dynamically check and equalise the voltage on all pins that are connected to DPST at runtime double EqualiseRuntimeVoltageDPDT(void* ComponentAdderss, int index = 0) { - return 0; //Edit!!! + DpdtStruct* d = (DpdtStruct*)ComponentAdderss; + + //To be finished + + return d->Volt[index]; } void ToggleState(DpdtStruct* d, void* ImageLocation) @@ -147,6 +151,7 @@ void ToggleState(DpdtStruct* d, void* ImageLocation) void HandleDpdtEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, void * ImageLocation, UINT ImageId, HWND * h) { + DpdtStruct* d = (DpdtStruct*)ComponentAddress; if (SimulationStarted) diff --git a/ldmicro/components/dpst.cpp b/ldmicro/components/dpst.cpp index e3b7f48..f3640a5 100644 --- a/ldmicro/components/dpst.cpp +++ b/ldmicro/components/dpst.cpp @@ -130,7 +130,56 @@ void DpstSettingsDialog(void* ComponentAddress, void* ImageLocation) //Dynamically check and equalise the voltage on all pins that are connected to DPST at runtime double EqualiseRuntimeVoltageDPST(void* ComponentAdderss, int index = 0) { - return 0; //Edit!!! + DpstStruct* d = (DpstStruct*)ComponentAdderss; + + ///Check if the switch is open + if (d->NO) + { + ///If switch is open then all terminals will be floating/open + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); + d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); + d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); + } + ///If the switch is connected + else + { + double Vin = VoltRequest(d->PinId[in1], ComponentAdderss); + double Vout = VoltRequest(d->PinId[out1], ComponentAdderss); + + ///Equalise voltage for input 1 output 1 pair + ///If either pin is grounded then all pins are set to GND (Static event) + if (Vin == GND || Vout == GND) + { + d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, GND); + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, GND); + } + ///If no pin is grounded then all pins are set to the max voltage of the pins (Dynamic event) + else + { + d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, max(Vin, Vout)); + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, max(Vin, Vout)); + } + + Vin = VoltRequest(d->PinId[in1], ComponentAdderss); + Vout = VoltRequest(d->PinId[out1], ComponentAdderss); + + ///Equalise voltage for input 2 output 2 pair + ///If either pin is grounded then all pins are set to GND (Static event) + if (Vin == GND || Vout == GND) + { + d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, GND); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, GND); + } + ///If no pin is grounded then all pins are set to the max voltage of the pins (Dynamic event) + else + { + d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, max(Vin, Vout)); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, max(Vin, Vout)); + } + } + + return d->Volt[index]; } void ToggleState(DpstStruct* d, void* ImageLocation) From 809373f141974d13c38292ae9ed256e169fc2f12 Mon Sep 17 00:00:00 2001 From: Rr42 Date: Tue, 3 Apr 2018 22:02:11 +0530 Subject: [PATCH 09/14] Added functionality to DPDT component. --- ldmicro/components/dpdt.cpp | 83 ++++++++++++++++++++++++++++++++++++- ldmicro/components/spdt.cpp | 2 +- 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/ldmicro/components/dpdt.cpp b/ldmicro/components/dpdt.cpp index 692d6e7..132c804 100644 --- a/ldmicro/components/dpdt.cpp +++ b/ldmicro/components/dpdt.cpp @@ -136,7 +136,88 @@ double EqualiseRuntimeVoltageDPDT(void* ComponentAdderss, int index = 0) { DpdtStruct* d = (DpdtStruct*)ComponentAdderss; - //To be finished + ///Check if DPDT switch is in state 1; i.e Input 1 is connected to output11, Input 2 is connected to output21 + if (d->NS1) + { + ///If DPDT switch is in state 1 then output12 and output22 will be floating/open + d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, V_OPEN); + d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, V_OPEN); + + ///Get voltages at the connected pins + double Vin = VoltRequest(d->PinId[in1], ComponentAdderss); + double Vout = VoltRequest(d->PinId[out11], ComponentAdderss); + + ///Set 1: input 1, output11, output12 + ///If either pin is grounded then all pins are set to GND + if (Vin == GND || Vout == GND) + { + d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, GND); + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, GND); + } + ///If no pin is grounded then all pins are set to the max voltage of the pins + else + { + d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, max(Vin, Vout)); + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, max(Vin, Vout)); + } + + Vin = VoltRequest(d->PinId[in2], ComponentAdderss); + Vout = VoltRequest(d->PinId[out21], ComponentAdderss); + ///Set 2: input 2, output21, output22 + ///If either pin is grounded then all pins are set to GND + if (Vin == GND || Vout == GND) + { + d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, GND); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, GND); + } + ///If no pin is grounded then all pins are set to the max voltage of the pins + else + { + d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, max(Vin, Vout)); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, max(Vin, Vout)); + } + } + ///Check if DPDT switch is in state 2; i.e Input 1 is connected to output12, Input 2 is connected to output22 + else + { + ///If DPDT switch is in state 2 then output11 and output21 will be floating/open + d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, V_OPEN); + d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, V_OPEN); + + ///Get voltages at the connected pins + double Vin = VoltRequest(d->PinId[in1], ComponentAdderss); + double Vout = VoltRequest(d->PinId[out12], ComponentAdderss); + + ///Set 1: input 1, output11, output12 + ///If either pin is grounded then all pins are set to GND + if (Vin == GND || Vout == GND) + { + d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, GND); + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, GND); + } + ///If no pin is grounded then all pins are set to the max voltage of the pins + else + { + d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, max(Vin, Vout)); + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, max(Vin, Vout)); + } + + Vin = VoltRequest(d->PinId[in2], ComponentAdderss); + Vout = VoltRequest(d->PinId[out22], ComponentAdderss); + ///Set 2: input 2, output21, output22 + ///If either pin is grounded then all pins are set to GND + if (Vin == GND || Vout == GND) + { + d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, GND); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, GND); + } + ///If no pin is grounded then all pins are set to the max voltage of the pins + else + { + d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, max(Vin, Vout)); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, max(Vin, Vout)); + } + } return d->Volt[index]; } diff --git a/ldmicro/components/spdt.cpp b/ldmicro/components/spdt.cpp index 4393341..fd4a837 100644 --- a/ldmicro/components/spdt.cpp +++ b/ldmicro/components/spdt.cpp @@ -139,7 +139,7 @@ double EqualiseRuntimeVoltageSPDT(void* ComponentAdderss, int index = 0) s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, V_OPEN); ///Get voltages at the connected pins - double volt1 = VoltRequest(s->PinId[0], ComponentAdderss); + double volt1 = VoltRequest(s->PinId[in], ComponentAdderss); double volt2 = VoltRequest(s->PinId[out1], ComponentAdderss); ///If either pin is grounded then all pins are set to GND From a1bdbc1cbe9b446fb79748f903ac3cf0e1bb79db Mon Sep 17 00:00:00 2001 From: Rr42 Date: Wed, 4 Apr 2018 11:54:50 +0530 Subject: [PATCH 10/14] Added temporary functionality to SPDT component. Fixed bugs in DPST component. --- ldmicro/components/componentstructs.h | 3 +- ldmicro/components/dpst.cpp | 29 +++++++++++-- ldmicro/components/spdt.cpp | 61 ++++++++++++++++++++++----- 3 files changed, 77 insertions(+), 16 deletions(-) diff --git a/ldmicro/components/componentstructs.h b/ldmicro/components/componentstructs.h index 87bba27..9087c7a 100644 --- a/ldmicro/components/componentstructs.h +++ b/ldmicro/components/componentstructs.h @@ -33,8 +33,9 @@ typedef struct SpdtStructTag { int id; int image; + BOOL latched; //Whether the swetch is in latch mode or not BOOL NO1; //Whether Output 1 is connected - double Volt[3]; // Voltage at Input, Output1, Output2 respectively + double Volt[3]; //Voltage at Input, Output1, Output2 respectively int PinId[3]; }SpdtStruct; diff --git a/ldmicro/components/dpst.cpp b/ldmicro/components/dpst.cpp index f3640a5..bbdad78 100644 --- a/ldmicro/components/dpst.cpp +++ b/ldmicro/components/dpst.cpp @@ -136,10 +136,31 @@ double EqualiseRuntimeVoltageDPST(void* ComponentAdderss, int index = 0) if (d->NO) { ///If switch is open then all terminals will be floating/open - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); - d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); - d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); + switch (index) + { + case in1: + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); + d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); + d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); + break; + case in2: + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); + d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); + d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); + break; + case out1: + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); + d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); + break; + case out2: + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); + d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); + break; + default: + break; + } } ///If the switch is connected else diff --git a/ldmicro/components/spdt.cpp b/ldmicro/components/spdt.cpp index fd4a837..c8406d6 100644 --- a/ldmicro/components/spdt.cpp +++ b/ldmicro/components/spdt.cpp @@ -13,6 +13,8 @@ ///Window handles static HWND StateOut1; static HWND StateOut2; +static HWND ModeLatched; +static HWND ModeTemp; HWND* SettingsDialogSPDT; ///Global variables @@ -25,13 +27,13 @@ void SetSpdtIds(int* id, void* ComponentAddress) s->PinId[in] = *id++; s->PinId[out1] = *id++; s->PinId[out2] = *id++; - } int InitSpdt(void * ComponentAddress) { SpdtStruct* s = (SpdtStruct*)ComponentAddress; s->image = SPDT_1; + s->latched = TRUE; s->NO1 = TRUE; s->Volt[in] = V_OPEN; s->Volt[out1] = V_OPEN; @@ -42,24 +44,45 @@ int InitSpdt(void * ComponentAddress) void MakeSettingsDialogSPDT() { - HWND InitOut = CreateWindowEx(0, WC_BUTTON, ("Initial output"), + ///Switch action mode + HWND InitLatched = CreateWindowEx(0, WC_BUTTON, ("Action mode"), WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, 7, 3, 120, 65, *SettingsDialogSPDT, NULL, NULL, NULL); + FontNice(InitLatched); + + ModeLatched = CreateWindowEx(0, WC_BUTTON, ("Latched"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, + 16, 21, 100, 20, *SettingsDialogSPDT, NULL, NULL, NULL); + FontNice(ModeLatched); + + ModeTemp = CreateWindowEx(0, WC_BUTTON, ("Temporary"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, + 16, 41, 100, 20, *SettingsDialogSPDT, NULL, NULL, NULL); + FontNice(ModeTemp); + + ///Switch initial status + HWND InitOut = CreateWindowEx(0, WC_BUTTON, ("Initial output"), + WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, + 140, 3, 120, 65, *SettingsDialogSPDT, NULL, NULL, NULL); FontNice(InitOut); StateOut1 = CreateWindowEx(0, WC_BUTTON, ("Output 1"), WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, - 16, 21, 100, 20, *SettingsDialogSPDT, NULL, NULL, NULL); + 149, 21, 100, 20, *SettingsDialogSPDT, NULL, NULL, NULL); FontNice(StateOut1); StateOut2 = CreateWindowEx(0, WC_BUTTON, ("Output 2"), WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 41, 100, 20, *SettingsDialogSPDT, NULL, NULL, NULL); + 149, 41, 100, 20, *SettingsDialogSPDT, NULL, NULL, NULL); FontNice(StateOut2); } void LoadSettings(SpdtStruct* s) { + if (s->latched) + Button_SetCheck(ModeLatched, BST_CHECKED); + else + Button_SetCheck(ModeTemp, BST_CHECKED); if (s->NO1) Button_SetCheck(StateOut1, BST_CHECKED); else @@ -67,12 +90,22 @@ void LoadSettings(SpdtStruct* s) } BOOL SaveSettings(SpdtStruct* s, void* ImageLocation) -{ - BOOL NState1; +{ + if (Button_GetState(ModeLatched) == BST_CHECKED) + s->latched = TRUE; + else if (Button_GetState(ModeTemp) == BST_CHECKED) + s->latched = FALSE; + else + { + MessageBox(*SettingsDialogSPDT, + ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); + return FALSE; + } + if (Button_GetState(StateOut1) == BST_CHECKED) - NState1 = TRUE; + s->NO1 = TRUE; else if (Button_GetState(StateOut2) == BST_CHECKED) - NState1 = FALSE; + s->NO1 = FALSE; else { MessageBox(*SettingsDialogSPDT, @@ -80,9 +113,8 @@ BOOL SaveSettings(SpdtStruct* s, void* ImageLocation) return FALSE; } - s->NO1 = NState1; - if (NState1) + if (s->NO1) s->image = SPDT_1; else s->image = SPDT_2; @@ -206,10 +238,17 @@ void HandleSpdtEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, { switch (Event) { - case EVENT_MOUSE_CLICK: + case EVENT_MOUSE_DOWN: ToggleState(s, ImageLocation); EqualiseRuntimeVoltageSPDT(ComponentAddress); break; + case EVENT_MOUSE_UP: + if (!s->latched) + { + ToggleState(s, ImageLocation); + EqualiseRuntimeVoltageSPDT(ComponentAddress); + } + break; default: break; } From 145c0d5bd368decad6540a51515f087b1cdb936f Mon Sep 17 00:00:00 2001 From: Rr42 Date: Wed, 4 Apr 2018 18:32:41 +0530 Subject: [PATCH 11/14] Fixed bugs in SPDT component, added latching option --- ldmicro/components/componentstructs.h | 1 + ldmicro/components/dpdt.cpp | 32 ++++++- ldmicro/components/dpst.cpp | 110 +++++++++++++++-------- ldmicro/components/spdt.cpp | 120 +++++++++++++++++++++++++- 4 files changed, 217 insertions(+), 46 deletions(-) diff --git a/ldmicro/components/componentstructs.h b/ldmicro/components/componentstructs.h index 9087c7a..d840147 100644 --- a/ldmicro/components/componentstructs.h +++ b/ldmicro/components/componentstructs.h @@ -43,6 +43,7 @@ typedef struct DpstStructTag { int id; int image; + BOOL latched; //Whether the swetch is in latch mode or not BOOL NO; //Whether the inputs and outputs are disconnected (Open) double Volt[4]; // Voltage at Input1, Input2, Output1, Output2 respectively int PinId[4]; diff --git a/ldmicro/components/dpdt.cpp b/ldmicro/components/dpdt.cpp index 132c804..4441f26 100644 --- a/ldmicro/components/dpdt.cpp +++ b/ldmicro/components/dpdt.cpp @@ -140,8 +140,8 @@ double EqualiseRuntimeVoltageDPDT(void* ComponentAdderss, int index = 0) if (d->NS1) { ///If DPDT switch is in state 1 then output12 and output22 will be floating/open - d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, V_OPEN); - d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, V_OPEN); + //d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, V_OPEN); + //d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, V_OPEN); ///Get voltages at the connected pins double Vin = VoltRequest(d->PinId[in1], ComponentAdderss); @@ -154,6 +154,12 @@ double EqualiseRuntimeVoltageDPDT(void* ComponentAdderss, int index = 0) d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, GND); d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, GND); } + ///If Vin is set as open + else if (Vin == V_OPEN) + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, Vout); + ///If Vout is set as open + else if (Vout == V_OPEN) + d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, Vin); ///If no pin is grounded then all pins are set to the max voltage of the pins else { @@ -170,6 +176,12 @@ double EqualiseRuntimeVoltageDPDT(void* ComponentAdderss, int index = 0) d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, GND); d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, GND); } + ///If Vin is set as open + else if (Vin == V_OPEN) + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, Vout); + ///If Vout is set as open + else if (Vout == V_OPEN) + d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, Vin); ///If no pin is grounded then all pins are set to the max voltage of the pins else { @@ -181,8 +193,8 @@ double EqualiseRuntimeVoltageDPDT(void* ComponentAdderss, int index = 0) else { ///If DPDT switch is in state 2 then output11 and output21 will be floating/open - d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, V_OPEN); - d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, V_OPEN); + //d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, V_OPEN); + //d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, V_OPEN); ///Get voltages at the connected pins double Vin = VoltRequest(d->PinId[in1], ComponentAdderss); @@ -195,6 +207,12 @@ double EqualiseRuntimeVoltageDPDT(void* ComponentAdderss, int index = 0) d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, GND); d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, GND); } + ///If Vin is set as open + else if (Vin == V_OPEN) + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, Vout); + ///If Vout is set as open + else if (Vout == V_OPEN) + d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, Vin); ///If no pin is grounded then all pins are set to the max voltage of the pins else { @@ -211,6 +229,12 @@ double EqualiseRuntimeVoltageDPDT(void* ComponentAdderss, int index = 0) d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, GND); d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, GND); } + ///If Vin is set as open + else if (Vin == V_OPEN) + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, Vout); + ///If Vout is set as open + else if (Vout == V_OPEN) + d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, Vin); ///If no pin is grounded then all pins are set to the max voltage of the pins else { diff --git a/ldmicro/components/dpst.cpp b/ldmicro/components/dpst.cpp index bbdad78..80291f1 100644 --- a/ldmicro/components/dpst.cpp +++ b/ldmicro/components/dpst.cpp @@ -13,6 +13,8 @@ ///Window handles static HWND State1; static HWND State2; +static HWND ModeLatchedDPST; +static HWND ModeTempDPST; HWND* SettingsDialogDPST; ///Global variables @@ -24,6 +26,7 @@ int InitDpst(void * ComponentAddress) DpstStruct* d = (DpstStruct*)ComponentAddress; d->image = DPST_1; d->NO = FALSE; + d->latched = TRUE; d->Volt[in1] = V_OPEN; d->Volt[in2] = V_OPEN; d->Volt[out1] = V_OPEN; @@ -43,24 +46,47 @@ void SetDpstIds(int* id, void* ComponentAddress) void MakeSettingsDialogDPST() { - HWND InitOut = CreateWindowEx(0, WC_BUTTON, ("Initial output state"), + ///Switch action mode + HWND InitLatched = CreateWindowEx(0, WC_BUTTON, ("Action mode"), WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, 7, 3, 120, 65, *SettingsDialogDPST, NULL, NULL, NULL); + FontNice(InitLatched); + + ModeLatchedDPST = CreateWindowEx(0, WC_BUTTON, ("Latched"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, + 16, 21, 100, 20, *SettingsDialogDPST, NULL, NULL, NULL); + FontNice(ModeLatchedDPST); + + ModeTempDPST = CreateWindowEx(0, WC_BUTTON, ("Temporary"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, + 16, 41, 100, 20, *SettingsDialogDPST, NULL, NULL, NULL); + FontNice(ModeTempDPST); + + ///Switch initial status + HWND InitOut = CreateWindowEx(0, WC_BUTTON, ("Initial output state"), + WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, + 140, 3, 120, 65, *SettingsDialogDPST, NULL, NULL, NULL); FontNice(InitOut); State1 = CreateWindowEx(0, WC_BUTTON, ("State 1"), WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, - 16, 21, 100, 20, *SettingsDialogDPST, NULL, NULL, NULL); + 149, 21, 100, 20, *SettingsDialogDPST, NULL, NULL, NULL); FontNice(State1); State2 = CreateWindowEx(0, WC_BUTTON, ("State 2"), WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 41, 100, 20, *SettingsDialogDPST, NULL, NULL, NULL); + 149, 41, 100, 20, *SettingsDialogDPST, NULL, NULL, NULL); FontNice(State2); } void LoadSettings(DpstStruct* d) { + + if (d->latched) + Button_SetCheck(ModeLatchedDPST, BST_CHECKED); + else + Button_SetCheck(ModeTempDPST, BST_CHECKED); + if (!d->NO) Button_SetCheck(State1, BST_CHECKED); else @@ -68,12 +94,22 @@ void LoadSettings(DpstStruct* d) } BOOL SaveSettings(DpstStruct* d, void* ImageLocation) -{ - BOOL NState; +{ + if (Button_GetState(ModeLatchedDPST) == BST_CHECKED) + d->latched = TRUE; + else if (Button_GetState(ModeTempDPST) == BST_CHECKED) + d->latched = FALSE; + else + { + MessageBox(*SettingsDialogDPST, + ("Incomplete"), ("Warning"), MB_OK | MB_ICONWARNING); + return FALSE; + } + if (Button_GetState(State1) == BST_CHECKED) - NState = TRUE; + d->NO = FALSE; else if (Button_GetState(State2) == BST_CHECKED) - NState = FALSE; + d->NO = TRUE; else { MessageBox(*SettingsDialogDPST, @@ -81,9 +117,7 @@ BOOL SaveSettings(DpstStruct* d, void* ImageLocation) return FALSE; } - d->NO = !NState; - - if (NState) + if (!d->NO) d->image = DPST_1; else d->image = DPST_2; @@ -136,31 +170,12 @@ double EqualiseRuntimeVoltageDPST(void* ComponentAdderss, int index = 0) if (d->NO) { ///If switch is open then all terminals will be floating/open - switch (index) - { - case in1: - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); - d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); - d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); - break; - case in2: - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); - d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); - d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); - break; - case out1: - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); - d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); - break; - case out2: - d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); - d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); - d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); - break; - default: - break; - } + /* + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); + d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); + d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); + */ } ///If the switch is connected else @@ -175,6 +190,12 @@ double EqualiseRuntimeVoltageDPST(void* ComponentAdderss, int index = 0) d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, GND); d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, GND); } + ///If Vin is set as open + else if (Vin == V_OPEN) + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, Vout); + ///If Vout is set as open + else if (Vout == V_OPEN) + d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, Vin); ///If no pin is grounded then all pins are set to the max voltage of the pins (Dynamic event) else { @@ -182,8 +203,8 @@ double EqualiseRuntimeVoltageDPST(void* ComponentAdderss, int index = 0) d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, max(Vin, Vout)); } - Vin = VoltRequest(d->PinId[in1], ComponentAdderss); - Vout = VoltRequest(d->PinId[out1], ComponentAdderss); + Vin = VoltRequest(d->PinId[in2], ComponentAdderss); + Vout = VoltRequest(d->PinId[out2], ComponentAdderss); ///Equalise voltage for input 2 output 2 pair ///If either pin is grounded then all pins are set to GND (Static event) @@ -192,6 +213,12 @@ double EqualiseRuntimeVoltageDPST(void* ComponentAdderss, int index = 0) d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, GND); d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, GND); } + ///If Vin is set as open + else if (Vin == V_OPEN) + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, Vout); + ///If Vout is set as open + else if (Vout == V_OPEN) + d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, Vin); ///If no pin is grounded then all pins are set to the max voltage of the pins (Dynamic event) else { @@ -219,10 +246,17 @@ void HandleDpstEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, { switch (Event) { - case EVENT_MOUSE_CLICK: + case EVENT_MOUSE_DOWN: ToggleState(d, ImageLocation); EqualiseRuntimeVoltageDPST(ComponentAddress); break; + case EVENT_MOUSE_UP: + if (!d->latched) + { + ToggleState(d, ImageLocation); + EqualiseRuntimeVoltageDPST(ComponentAddress); + } + break; default: break; } diff --git a/ldmicro/components/spdt.cpp b/ldmicro/components/spdt.cpp index c8406d6..551d145 100644 --- a/ldmicro/components/spdt.cpp +++ b/ldmicro/components/spdt.cpp @@ -160,7 +160,7 @@ void SpdtSettingsDialog(void* ComponentAddress, void* ImageLocation) } //Dynamically check and equalise the voltage on all pins that are connected to SPDT at runtime -double EqualiseRuntimeVoltageSPDT(void* ComponentAdderss, int index = 0) +void EqualiseStaticVoltageSPDT(void* ComponentAdderss) { SpdtStruct* s = (SpdtStruct*)ComponentAdderss; @@ -180,6 +180,12 @@ double EqualiseRuntimeVoltageSPDT(void* ComponentAdderss, int index = 0) s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, GND); s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, GND); } + ///If volt1 is set as open + else if (volt1 == V_OPEN) + s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, volt2); + ///If volt2 is set as open + else if (volt2 == V_OPEN) + s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, volt1); ///If no pin is grounded then all pins are set to the max voltage of the pins else { @@ -203,6 +209,112 @@ double EqualiseRuntimeVoltageSPDT(void* ComponentAdderss, int index = 0) s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, GND); s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, GND); } + ///If volt1 is set as open + else if (volt1 == V_OPEN) + s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, volt2); + ///If volt2 is set as open + else if (volt2 == V_OPEN) + s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, volt1); + ///If no pin is grounded then all pins are set to the max voltage of the pins (Dynamic event) + else + { + s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, max(volt1, volt2)); + s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, max(volt1, volt2)); + } + } +} + +//Dynamically check and equalise the voltage on all pins that are connected to SPDT at runtime +double EqualiseRuntimeVoltageSPDT(void* ComponentAdderss, int index, double volt) +{ + SpdtStruct* s = (SpdtStruct*)ComponentAdderss; + + ///Check if input and output 1 are connected + if (s->NO1) + { + if (index == out2) + s->Volt[index] = V_OPEN; + else + ///If the input pin is connected to output 1 then output 2 will be open + s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, V_OPEN); + + ///Get voltages at the connected pins + double volt1; + double volt2; + + if (index == in) + { + volt1 = volt; + volt2 = VoltRequest(s->PinId[out1], ComponentAdderss); + } + else if (index == out1) + { + volt1 = VoltRequest(s->PinId[in], ComponentAdderss); + volt2 = volt; + } + else + { + volt1 = VoltRequest(s->PinId[in], ComponentAdderss); + volt2 = VoltRequest(s->PinId[out1], ComponentAdderss); + } + + ///If either pin is grounded then all pins are set to GND + if (volt1 == GND || volt2 == GND) + { + s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, GND); + s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, GND); + } + ///If volt1 is set as open + else if (volt1 == V_OPEN) + s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, volt2); + ///If volt2 is set as open + else if (volt2 == V_OPEN) + s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, volt1); + ///If no pin is grounded then all pins are set to the max voltage of the pins + else + { + s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, max(volt1, volt2)); + s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, max(volt1, volt2)); + } + } + ///If input and output 2 are connected + else + { + ///If the input pin is connected to output 2 then output 1 will be open + s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, V_OPEN); + + ///Get voltages at the connected pins + double volt1; + double volt2; + + if (index == in) + { + volt1 = volt; + volt2 = VoltRequest(s->PinId[out2], ComponentAdderss); + } + else if (index == out1) + { + volt1 = VoltRequest(s->PinId[in], ComponentAdderss); + volt2 = volt; + } + else + { + volt1 = VoltRequest(s->PinId[in], ComponentAdderss); + volt2 = VoltRequest(s->PinId[out2], ComponentAdderss); + } + + ///If either pin is grounded then all pins are set to GND (Static event) + if (volt1 == GND || volt2 == GND) + { + s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, GND); + s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, GND); + } + ///If volt1 is set as open + else if (volt1 == V_OPEN) + s->Volt[in] = VoltChange(s->PinId[in], in, ComponentAdderss, volt2); + ///If volt2 is set as open + else if (volt2 == V_OPEN) + s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, volt1); ///If no pin is grounded then all pins are set to the max voltage of the pins (Dynamic event) else { @@ -217,7 +329,7 @@ double EqualiseRuntimeVoltageSPDT(void* ComponentAdderss, int index = 0) double SpdtVoltChanged(void * ComponentAddress, BOOL SimulationStarted, int index, double Volt, int Source, void * ImageLocation) { if (SimulationStarted) - return EqualiseRuntimeVoltageSPDT(ComponentAddress, index); + return EqualiseRuntimeVoltageSPDT(ComponentAddress, index, Volt); return Volt; } @@ -240,13 +352,13 @@ void HandleSpdtEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, { case EVENT_MOUSE_DOWN: ToggleState(s, ImageLocation); - EqualiseRuntimeVoltageSPDT(ComponentAddress); + EqualiseStaticVoltageSPDT(ComponentAddress); break; case EVENT_MOUSE_UP: if (!s->latched) { ToggleState(s, ImageLocation); - EqualiseRuntimeVoltageSPDT(ComponentAddress); + EqualiseStaticVoltageSPDT(ComponentAddress); } break; default: From 2e79230b5e7e5a717ee2fd756b3588815627a1c1 Mon Sep 17 00:00:00 2001 From: Rr42 Date: Wed, 4 Apr 2018 20:16:11 +0530 Subject: [PATCH 12/14] Fixed bugs in DPDT, added latching functionality to DPST. --- ldmicro/components/dpdt.cpp | 219 ++++++++++++++++++++++++++++++++++-- ldmicro/components/dpst.cpp | 139 +++++++++++++++++++++-- ldmicro/components/spdt.cpp | 10 +- 3 files changed, 346 insertions(+), 22 deletions(-) diff --git a/ldmicro/components/dpdt.cpp b/ldmicro/components/dpdt.cpp index 4441f26..ab857ea 100644 --- a/ldmicro/components/dpdt.cpp +++ b/ldmicro/components/dpdt.cpp @@ -132,7 +132,7 @@ void DpdtSettingsDialog(void* ComponentAddress, void* ImageLocation) } //Dynamically check and equalise the voltage on all pins that are connected to DPST at runtime -double EqualiseRuntimeVoltageDPDT(void* ComponentAdderss, int index = 0) +double EqualiseRuntimeVoltageDPDT(void* ComponentAdderss, int index, double volt) { DpdtStruct* d = (DpdtStruct*)ComponentAdderss; @@ -140,8 +140,211 @@ double EqualiseRuntimeVoltageDPDT(void* ComponentAdderss, int index = 0) if (d->NS1) { ///If DPDT switch is in state 1 then output12 and output22 will be floating/open - //d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, V_OPEN); - //d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, V_OPEN); + if (index == out12) + { + d->Volt[out12] = V_OPEN; + d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, V_OPEN); + } + else if (index == out22) + { + d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, V_OPEN); + d->Volt[out22] = V_OPEN; + } + else + { + d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, V_OPEN); + d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, V_OPEN); + } + + double Vin; + double Vout; + + ///Get voltages at the connected pins + if (index == in1) + { + Vin = volt; + Vout = VoltRequest(d->PinId[out11], ComponentAdderss); + } + else if (index == out11) + { + Vin = VoltRequest(d->PinId[in1], ComponentAdderss); + Vout = volt; + } + else + { + Vin = VoltRequest(d->PinId[in1], ComponentAdderss); + Vout = VoltRequest(d->PinId[out11], ComponentAdderss); + } + + ///Set 1: input 1, output11, output12 + ///If either pin is grounded then all pins are set to GND + if (Vin == GND || Vout == GND) + { + d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, GND); + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, GND); + } + ///If Vin is set as open + else if (Vin == V_OPEN) + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, Vout); + ///If Vout is set as open + else if (Vout == V_OPEN) + d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, Vin); + ///If no pin is grounded then all pins are set to the max voltage of the pins + else + { + d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, max(Vin, Vout)); + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, max(Vin, Vout)); + } + + ///Get voltages at the connected pins + if (index == in2) + { + Vin = volt; + Vout = VoltRequest(d->PinId[out21], ComponentAdderss); + } + else if (index == out21) + { + Vin = VoltRequest(d->PinId[in2], ComponentAdderss); + Vout = volt; + } + else + { + Vin = VoltRequest(d->PinId[in2], ComponentAdderss); + Vout = VoltRequest(d->PinId[out21], ComponentAdderss); + } + + ///Set 2: input 2, output21, output22 + ///If either pin is grounded then all pins are set to GND + if (Vin == GND || Vout == GND) + { + d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, GND); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, GND); + } + ///If Vin is set as open + else if (Vin == V_OPEN) + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, Vout); + ///If Vout is set as open + else if (Vout == V_OPEN) + d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, Vin); + ///If no pin is grounded then all pins are set to the max voltage of the pins + else + { + d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, max(Vin, Vout)); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, max(Vin, Vout)); + } + } + ///Check if DPDT switch is in state 2; i.e Input 1 is connected to output12, Input 2 is connected to output22 + else + { + ///If DPDT switch is in state 2 then output11 and output21 will be floating/open + if (index == out11) + { + d->Volt[out11] = V_OPEN; + d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, V_OPEN); + } + else if (index == out21) + { + d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, V_OPEN); + d->Volt[out21] = V_OPEN; + } + else + { + d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, V_OPEN); + d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, V_OPEN); + } + + double Vin; + double Vout; + + ///Get voltages at the connected pins + if (index == in1) + { + Vin = volt; + Vout = VoltRequest(d->PinId[out12], ComponentAdderss); + } + else if (index == out12) + { + Vin = VoltRequest(d->PinId[in1], ComponentAdderss); + Vout = volt; + } + else + { + Vin = VoltRequest(d->PinId[in1], ComponentAdderss); + Vout = VoltRequest(d->PinId[out12], ComponentAdderss); + } + + ///Set 1: input 1, output11, output12 + ///If either pin is grounded then all pins are set to GND + if (Vin == GND || Vout == GND) + { + d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, GND); + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, GND); + } + ///If Vin is set as open + else if (Vin == V_OPEN) + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, Vout); + ///If Vout is set as open + else if (Vout == V_OPEN) + d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, Vin); + ///If no pin is grounded then all pins are set to the max voltage of the pins + else + { + d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, max(Vin, Vout)); + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, max(Vin, Vout)); + } + + ///Get voltages at the connected pins + if (index == in2) + { + Vin = volt; + Vout = VoltRequest(d->PinId[out22], ComponentAdderss); + } + else if (index == out22) + { + Vin = VoltRequest(d->PinId[in2], ComponentAdderss); + Vout = volt; + } + else + { + Vin = VoltRequest(d->PinId[in2], ComponentAdderss); + Vout = VoltRequest(d->PinId[out22], ComponentAdderss); + } + + ///Set 2: input 2, output21, output22 + ///If either pin is grounded then all pins are set to GND + if (Vin == GND || Vout == GND) + { + d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, GND); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, GND); + } + ///If Vin is set as open + else if (Vin == V_OPEN) + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, Vout); + ///If Vout is set as open + else if (Vout == V_OPEN) + d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, Vin); + ///If no pin is grounded then all pins are set to the max voltage of the pins + else + { + d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, max(Vin, Vout)); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, max(Vin, Vout)); + } + } + + return d->Volt[index]; +} + +//Perform a static check and equalise the voltage on all pins that are connected to DPST at runtime +void EqualiseStaticVoltageDPDT(void* ComponentAdderss) +{ + DpdtStruct* d = (DpdtStruct*)ComponentAdderss; + + ///Check if DPDT switch is in state 1; i.e Input 1 is connected to output11, Input 2 is connected to output21 + if (d->NS1) + { + ///If DPDT switch is in state 1 then output12 and output22 will be floating/open + d->Volt[out12] = VoltChange(d->PinId[out12], out12, ComponentAdderss, V_OPEN); + d->Volt[out22] = VoltChange(d->PinId[out22], out22, ComponentAdderss, V_OPEN); ///Get voltages at the connected pins double Vin = VoltRequest(d->PinId[in1], ComponentAdderss); @@ -193,8 +396,8 @@ double EqualiseRuntimeVoltageDPDT(void* ComponentAdderss, int index = 0) else { ///If DPDT switch is in state 2 then output11 and output21 will be floating/open - //d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, V_OPEN); - //d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, V_OPEN); + d->Volt[out11] = VoltChange(d->PinId[out11], out11, ComponentAdderss, V_OPEN); + d->Volt[out21] = VoltChange(d->PinId[out21], out21, ComponentAdderss, V_OPEN); ///Get voltages at the connected pins double Vin = VoltRequest(d->PinId[in1], ComponentAdderss); @@ -242,8 +445,6 @@ double EqualiseRuntimeVoltageDPDT(void* ComponentAdderss, int index = 0) d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, max(Vin, Vout)); } } - - return d->Volt[index]; } void ToggleState(DpdtStruct* d, void* ImageLocation) @@ -265,7 +466,7 @@ void HandleDpdtEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, { case EVENT_MOUSE_CLICK: ToggleState(d, ImageLocation); - EqualiseRuntimeVoltageDPDT(ComponentAddress); + EqualiseStaticVoltageDPDT(ComponentAddress); break; default: break; @@ -288,7 +489,7 @@ double DpdtVoltChanged(void * ComponentAddress, BOOL SimulationStarted, int inde { if (SimulationStarted) - return EqualiseRuntimeVoltageDPDT(ComponentAddress, index); + return EqualiseRuntimeVoltageDPDT(ComponentAddress, index, Volt); return Volt; } \ No newline at end of file diff --git a/ldmicro/components/dpst.cpp b/ldmicro/components/dpst.cpp index 80291f1..5aa8e70 100644 --- a/ldmicro/components/dpst.cpp +++ b/ldmicro/components/dpst.cpp @@ -162,7 +162,7 @@ void DpstSettingsDialog(void* ComponentAddress, void* ImageLocation) } //Dynamically check and equalise the voltage on all pins that are connected to DPST at runtime -double EqualiseRuntimeVoltageDPST(void* ComponentAdderss, int index = 0) +double EqualiseRuntimeVoltageDPST(void* ComponentAdderss, int index, double volt) { DpstStruct* d = (DpstStruct*)ComponentAdderss; @@ -170,12 +170,137 @@ double EqualiseRuntimeVoltageDPST(void* ComponentAdderss, int index = 0) if (d->NO) { ///If switch is open then all terminals will be floating/open - /* + switch (index) + { + case in1: + d->Volt[in1] = V_OPEN; + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); + d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); + d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); + break; + case in2: + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); + d->Volt[in2] = V_OPEN; + d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); + d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); + case out1: + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); + d->Volt[out1] = V_OPEN; + d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); + break; + case out2: + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); + d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); + d->Volt[out2] = V_OPEN; + break; + default: + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); + d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); + d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); + break; + } + } + ///If the switch is connected + else + { + double Vin; + double Vout; + + ///Get voltages at the connected pins + if (index == in1) + { + Vin = volt; + Vout = VoltRequest(d->PinId[out1], ComponentAdderss); + } + else if (index == out1) + { + Vin = VoltRequest(d->PinId[in1], ComponentAdderss); + Vout = volt; + } + else + { + Vin = VoltRequest(d->PinId[in1], ComponentAdderss); + Vout = VoltRequest(d->PinId[out1], ComponentAdderss); + } + + ///Equalise voltage for input 1 output 1 pair + ///If either pin is grounded then all pins are set to GND (Static event) + if (Vin == GND || Vout == GND) + { + d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, GND); + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, GND); + } + ///If Vin is set as open + else if (Vin == V_OPEN) + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, Vout); + ///If Vout is set as open + else if (Vout == V_OPEN) + d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, Vin); + ///If no pin is grounded then all pins are set to the max voltage of the pins (Dynamic event) + else + { + d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, max(Vin, Vout)); + d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, max(Vin, Vout)); + } + + ///Get voltages at the connected pins + if (index == in2) + { + Vin = volt; + Vout = VoltRequest(d->PinId[out2], ComponentAdderss); + } + else if (index == out2) + { + Vin = VoltRequest(d->PinId[in2], ComponentAdderss); + Vout = volt; + } + else + { + Vin = VoltRequest(d->PinId[in2], ComponentAdderss); + Vout = VoltRequest(d->PinId[out2], ComponentAdderss); + } + + ///Equalise voltage for input 2 output 2 pair + ///If either pin is grounded then all pins are set to GND (Static event) + if (Vin == GND || Vout == GND) + { + d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, GND); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, GND); + } + ///If Vin is set as open + else if (Vin == V_OPEN) + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, Vout); + ///If Vout is set as open + else if (Vout == V_OPEN) + d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, Vin); + ///If no pin is grounded then all pins are set to the max voltage of the pins (Dynamic event) + else + { + d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, max(Vin, Vout)); + d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, max(Vin, Vout)); + } + } + + return d->Volt[index]; +} + +//Perform a static check and equalise the voltage on all pins that are connected to DPST at runtime +void EqualiseStaticVoltageDPST(void* ComponentAdderss) +{ + DpstStruct* d = (DpstStruct*)ComponentAdderss; + + ///Check if the switch is open + if (d->NO) + { + ///If switch is open then all terminals will be floating/open d->Volt[in1] = VoltChange(d->PinId[in1], in1, ComponentAdderss, V_OPEN); d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, V_OPEN); d->Volt[out1] = VoltChange(d->PinId[out1], out1, ComponentAdderss, V_OPEN); d->Volt[out2] = VoltChange(d->PinId[out2], out2, ComponentAdderss, V_OPEN); - */ + } ///If the switch is connected else @@ -226,8 +351,6 @@ double EqualiseRuntimeVoltageDPST(void* ComponentAdderss, int index = 0) d->Volt[in2] = VoltChange(d->PinId[in2], in2, ComponentAdderss, max(Vin, Vout)); } } - - return d->Volt[index]; } void ToggleState(DpstStruct* d, void* ImageLocation) @@ -248,13 +371,13 @@ void HandleDpstEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, { case EVENT_MOUSE_DOWN: ToggleState(d, ImageLocation); - EqualiseRuntimeVoltageDPST(ComponentAddress); + EqualiseStaticVoltageDPST(ComponentAddress); break; case EVENT_MOUSE_UP: if (!d->latched) { ToggleState(d, ImageLocation); - EqualiseRuntimeVoltageDPST(ComponentAddress); + EqualiseStaticVoltageDPST(ComponentAddress); } break; default: @@ -277,7 +400,7 @@ void HandleDpstEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, double DpstVoltChanged(void * ComponentAddress, BOOL SimulationStarted, int index, double Volt, int Source, void * ImageLocation) { if (SimulationStarted) - return EqualiseRuntimeVoltageDPST(ComponentAddress, index); + return EqualiseRuntimeVoltageDPST(ComponentAddress, index, Volt); return Volt; } \ No newline at end of file diff --git a/ldmicro/components/spdt.cpp b/ldmicro/components/spdt.cpp index 551d145..9baa407 100644 --- a/ldmicro/components/spdt.cpp +++ b/ldmicro/components/spdt.cpp @@ -159,7 +159,7 @@ void SpdtSettingsDialog(void* ComponentAddress, void* ImageLocation) } -//Dynamically check and equalise the voltage on all pins that are connected to SPDT at runtime +//Perform a static check and equalise the voltage on all pins that are connected to SPDT at runtime void EqualiseStaticVoltageSPDT(void* ComponentAdderss) { SpdtStruct* s = (SpdtStruct*)ComponentAdderss; @@ -232,16 +232,16 @@ double EqualiseRuntimeVoltageSPDT(void* ComponentAdderss, int index, double volt ///Check if input and output 1 are connected if (s->NO1) { + ///If the input pin is connected to output 1 then output 2 will be open if (index == out2) - s->Volt[index] = V_OPEN; + s->Volt[out2] = V_OPEN; else - ///If the input pin is connected to output 1 then output 2 will be open s->Volt[out2] = VoltChange(s->PinId[out2], out2, ComponentAdderss, V_OPEN); - ///Get voltages at the connected pins double volt1; double volt2; + ///Get voltages at the connected pins if (index == in) { volt1 = volt; @@ -283,10 +283,10 @@ double EqualiseRuntimeVoltageSPDT(void* ComponentAdderss, int index, double volt ///If the input pin is connected to output 2 then output 1 will be open s->Volt[out1] = VoltChange(s->PinId[out1], out1, ComponentAdderss, V_OPEN); - ///Get voltages at the connected pins double volt1; double volt2; + ///Get voltages at the connected pins if (index == in) { volt1 = volt; From 75249b08d469e081323e7454ef532e941bee8459 Mon Sep 17 00:00:00 2001 From: Rr42 Date: Wed, 4 Apr 2018 21:07:42 +0530 Subject: [PATCH 13/14] Added latching functionality to DPDT component. Bugs when using temporary latch during dynamic simulation. Note: similar bug is found in the allready given Switch component. --- ldmicro/components/componentstructs.h | 1 + ldmicro/components/dpdt.cpp | 53 ++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/ldmicro/components/componentstructs.h b/ldmicro/components/componentstructs.h index d840147..76dadda 100644 --- a/ldmicro/components/componentstructs.h +++ b/ldmicro/components/componentstructs.h @@ -53,6 +53,7 @@ typedef struct DpdtStructTag { int id; int image; + BOOL latched; //Whether the swetch is in latch mode or not BOOL NS1; //Whether the inputs and outputs are connected in state 1 double Volt[6]; // Voltage at Input1, Input2, Output11, Output12, Output21, Output22 respectively int PinId[6]; diff --git a/ldmicro/components/dpdt.cpp b/ldmicro/components/dpdt.cpp index ab857ea..09aa245 100644 --- a/ldmicro/components/dpdt.cpp +++ b/ldmicro/components/dpdt.cpp @@ -13,6 +13,8 @@ ///Window handles static HWND DPDTState1; static HWND DPDTState2; +static HWND ModeLatchedDPDT; +static HWND ModeTempDPDT; HWND* SettingsDialogDPDT; ///Global variables @@ -24,6 +26,7 @@ int InitDpdt(void * ComponentAddress) DpdtStruct* d = (DpdtStruct*)ComponentAddress; d->image = DPDT_1; d->NS1 = TRUE; + d->latched = TRUE; d->Volt[in1] = V_OPEN; d->Volt[in2] = V_OPEN; d->Volt[out11] = V_OPEN; @@ -47,24 +50,45 @@ void SetDpdtIds(int* id, void* ComponentAddress) void MakeSettingsDialogDPDT() { - HWND InitOut = CreateWindowEx(0, WC_BUTTON, ("Initial output state"), + ///Switch action mode + HWND InitLatched = CreateWindowEx(0, WC_BUTTON, ("Action mode"), WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, 7, 3, 120, 65, *SettingsDialogDPDT, NULL, NULL, NULL); + FontNice(InitLatched); + + ModeLatchedDPDT = CreateWindowEx(0, WC_BUTTON, ("Latched"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, + 16, 21, 100, 20, *SettingsDialogDPDT, NULL, NULL, NULL); + FontNice(ModeLatchedDPDT); + + ModeTempDPDT = CreateWindowEx(0, WC_BUTTON, ("Temporary"), + WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, + 16, 41, 100, 20, *SettingsDialogDPDT, NULL, NULL, NULL); + FontNice(ModeTempDPDT); + + ///Switch initial status + HWND InitOut = CreateWindowEx(0, WC_BUTTON, ("Initial output state"), + WS_CHILD | BS_GROUPBOX | WS_VISIBLE | WS_TABSTOP, + 140, 3, 120, 65, *SettingsDialogDPDT, NULL, NULL, NULL); FontNice(InitOut); DPDTState1 = CreateWindowEx(0, WC_BUTTON, ("State 1"), WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE | WS_GROUP, - 16, 21, 100, 20, *SettingsDialogDPDT, NULL, NULL, NULL); + 149, 21, 100, 20, *SettingsDialogDPDT, NULL, NULL, NULL); FontNice(DPDTState1); DPDTState2 = CreateWindowEx(0, WC_BUTTON, ("State 2"), WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE, - 16, 41, 100, 20, *SettingsDialogDPDT, NULL, NULL, NULL); + 149, 41, 100, 20, *SettingsDialogDPDT, NULL, NULL, NULL); FontNice(DPDTState2); } void LoadSettings(DpdtStruct* d) { + if (d->latched) + Button_SetCheck(ModeLatchedDPDT, BST_CHECKED); + else + Button_SetCheck(ModeTempDPDT, BST_CHECKED); if (d->NS1) Button_SetCheck(DPDTState1, BST_CHECKED); else @@ -73,11 +97,15 @@ void LoadSettings(DpdtStruct* d) BOOL SaveSettings(DpdtStruct* d, void* ImageLocation) { - BOOL NState; + if (Button_GetState(ModeLatchedDPDT) == BST_CHECKED) + d->latched = TRUE; + else + d->latched = FALSE; + if (Button_GetState(DPDTState1) == BST_CHECKED) - NState = TRUE; + d->NS1 = TRUE; else if (Button_GetState(DPDTState2) == BST_CHECKED) - NState = FALSE; + d->NS1 = FALSE; else { MessageBox(*SettingsDialogDPDT, @@ -85,9 +113,7 @@ BOOL SaveSettings(DpdtStruct* d, void* ImageLocation) return FALSE; } - d->NS1 = NState; - - if (NState) + if (d->NS1) d->image = DPDT_1; else d->image = DPDT_2; @@ -464,10 +490,17 @@ void HandleDpdtEvent(void * ComponentAddress, int Event, BOOL SimulationStarted, { switch (Event) { - case EVENT_MOUSE_CLICK: + case EVENT_MOUSE_DOWN: ToggleState(d, ImageLocation); EqualiseStaticVoltageDPDT(ComponentAddress); break; + case EVENT_MOUSE_UP: + if (!d->latched) + { + ToggleState(d, ImageLocation); + EqualiseStaticVoltageDPDT(ComponentAddress); + } + break; default: break; } From 1634ac052f53bfb4d0a948fb107ebdfa9283533f Mon Sep 17 00:00:00 2001 From: Rr42 Date: Wed, 4 Apr 2018 23:50:47 +0530 Subject: [PATCH 14/14] Added file description headers. --- ldmicro/components/dpdt.cpp | 11 +++++++++++ ldmicro/components/dpst.cpp | 11 +++++++++++ ldmicro/components/spdt.cpp | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/ldmicro/components/dpdt.cpp b/ldmicro/components/dpdt.cpp index 09aa245..c04c901 100644 --- a/ldmicro/components/dpdt.cpp +++ b/ldmicro/components/dpdt.cpp @@ -1,3 +1,14 @@ +/* DPDT component file +* Code version: 2.0 +* Version description: Adds latching functionality to component +* Version steability: +* GUI -> Stable +* Functionality -> No known bugs. +* Bugs: +* 1. - +* +*/ + ///Includes #include #include diff --git a/ldmicro/components/dpst.cpp b/ldmicro/components/dpst.cpp index 5aa8e70..d806dbb 100644 --- a/ldmicro/components/dpst.cpp +++ b/ldmicro/components/dpst.cpp @@ -1,3 +1,14 @@ +/* DPST component file +* Code version: 2.1 +* Version description: Fixes minor bugs in v2.0 +* Version steability: +* GUI -> Stable +* Functionality -> Bugs found. +* Bugs: +* 1. Voltages dont load properly during simulation when the "Switch" component controls input pin of the DPST component. +* +*/ + ///Includes #include #include diff --git a/ldmicro/components/spdt.cpp b/ldmicro/components/spdt.cpp index 9baa407..e30a732 100644 --- a/ldmicro/components/spdt.cpp +++ b/ldmicro/components/spdt.cpp @@ -1,3 +1,14 @@ +/* SPDT component file +* Code version: 2.0 +* Version description: Adds latching functionality to component +* Version steability: +* GUI -> Stable +* Functionality -> No known bugs. +* Bugs: +* 1. - +* +*/ + ///Includes #include #include