From 7c8eb4d2dd84248a462098ef2bedb30941b6064f Mon Sep 17 00:00:00 2001 From: kghs-aver Date: Mon, 10 Feb 2025 13:17:56 +0530 Subject: [PATCH 1/5] toast message popup fix --- ArduinoFrontend/src/app/Libs/General.ts | 1 + ArduinoFrontend/src/app/Libs/Miscellaneous.ts | 2 +- ArduinoFrontend/src/app/Libs/Point.ts | 2 +- ArduinoFrontend/src/app/Libs/Workspace.ts | 28 ++++++++++++++----- .../src/app/Libs/inputs/GasSensor.ts | 26 ++++++++++++----- .../src/app/Libs/inputs/TemperatureSensors.ts | 2 +- .../src/app/Libs/outputs/Display.ts | 5 ++++ ArduinoFrontend/src/app/Libs/outputs/Led.ts | 2 ++ .../src/app/Libs/outputs/Motors.ts | 8 +++++- 9 files changed, 58 insertions(+), 18 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/General.ts b/ArduinoFrontend/src/app/Libs/General.ts index 771a4346b..2a5677cba 100644 --- a/ArduinoFrontend/src/app/Libs/General.ts +++ b/ArduinoFrontend/src/app/Libs/General.ts @@ -183,6 +183,7 @@ export class Resistor extends CircuitElement { } else { this.value = tmp; this.updateColors(); + window['hideToast'](); } } /** Function returns resistence values 10K ohm => 10 */ diff --git a/ArduinoFrontend/src/app/Libs/Miscellaneous.ts b/ArduinoFrontend/src/app/Libs/Miscellaneous.ts index 2590d1d80..2df7af37b 100644 --- a/ArduinoFrontend/src/app/Libs/Miscellaneous.ts +++ b/ArduinoFrontend/src/app/Libs/Miscellaneous.ts @@ -84,7 +84,7 @@ export class Label extends CircuitElement { // if text field is empty if (value === '') { // TODO: Show Toast - window['showToast']('Label cannot be empty'); + window['showToast']('Label cannot be empty',true); return; } this.text = value; diff --git a/ArduinoFrontend/src/app/Libs/Point.ts b/ArduinoFrontend/src/app/Libs/Point.ts index b1983ff12..d25971ff4 100644 --- a/ArduinoFrontend/src/app/Libs/Point.ts +++ b/ArduinoFrontend/src/app/Libs/Point.ts @@ -294,7 +294,7 @@ export class Point { if (wire.start && wire.end) { window['scope']['wires'].push(wire); } else { - window['showToast']('Wire was not connected properly !'); + window['showToast']('Wire was not connected properly !',true); } } diff --git a/ArduinoFrontend/src/app/Libs/Workspace.ts b/ArduinoFrontend/src/app/Libs/Workspace.ts index 34870b34e..5b9a5a65b 100644 --- a/ArduinoFrontend/src/app/Libs/Workspace.ts +++ b/ArduinoFrontend/src/app/Libs/Workspace.ts @@ -230,17 +230,30 @@ export class Workspace { const ele = document.getElementById('bubblebox'); ele.style.display = 'none'; }; + // Global flag to track whether the toast is currently visible + window['toastVisible'] = false; // Global Function to show Toast Message - window['showToast'] = (message: string) => { + window['showToast'] = (message: string,autoHide = false) => { const ele = document.getElementById('ToastMessage'); ele.style.display = 'block'; ele.innerText = message; ele.style.padding = '15px 25px 15px 25px'; - setTimeout(() => { - ele.style.display = 'none'; - }, 10000); - + window['toastVisible'] = true; + // Auto-hide the toast after 5 seconds if autoHide is true + if (autoHide) { + setTimeout(() => { + if (window['toastVisible']) { + window['hideToast'](); + } + }, 5000); + } + }; + // Global Function to hide Toast Message + window['hideToast'] = (message: string) => { + const ele = document.getElementById('ToastMessage'); + ele.style.display = 'none'; + window['toastVisible'] = false; // Mark the toast as hidden }; // Global Function to print output in Console window['printConsole'] = (textmsg: string, type: ConsoleType) => { @@ -882,7 +895,7 @@ export class Workspace { // Hide Property box window.hideProperties(); } else { - window['showToast']('No Element Selected'); + window['showToast']('No Element Selected',true); } } @@ -890,7 +903,7 @@ export class Workspace { static copyComponent() { if (window['Selected']) { if (window['Selected'] instanceof Wire) { - window['showToast']('You Can\'t Copy Wire'); + window['showToast']('You Can\'t Copy Wire',true); return; } Workspace.copiedItem = window.Selected; @@ -1126,6 +1139,7 @@ export class Workspace { Workspace.simulating = false; Workspace.simulationStopped.emit(true); callback(); + window['hideToast'](); } /** * Function to clear the workspace diff --git a/ArduinoFrontend/src/app/Libs/inputs/GasSensor.ts b/ArduinoFrontend/src/app/Libs/inputs/GasSensor.ts index f97d2c66a..a36f2f820 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/GasSensor.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/GasSensor.ts @@ -57,7 +57,8 @@ export class MQ2 extends CircuitElement { } else { v = 0; } - if (this.nodes[0].connectedTo && this.nodes[0].value >= 4.9) { + if (this.nodes[0].connectedTo && this.nodes[0].value >= 4.9 && + this.nodes[3].connectedTo && this.nodes[1].connectedTo) { this.nodes[3].setValue(Math.round(v), null); } else { window['showToast']('Please Connect Wires Properly'); @@ -67,6 +68,14 @@ export class MQ2 extends CircuitElement { * Initialize animation for the gas sensor */ initSimulation(): void { + // Check Connection + if ( + !(this.nodes[0].connectedTo && + this.nodes[1].connectedTo && + this.nodes[3].connectedTo) + ) { + window['showToast']('Please Connect Sensor Properly'); + } else { this.elements[1].show(); this.elements.undrag(); let tmp = this.elements[1].attr(); @@ -117,16 +126,19 @@ export class MQ2 extends CircuitElement { x: tmp.x + 164, y: tmp.y + 145 }, Center); + } } /** * Remove line and smoke */ closeSimulation(): void { - this.elements[1].hide(); - this.line.remove(); - this.line = null; - this.elements[1].undrag(); - this.setDragListeners(); - } + if (this.nodes[0].connectedTo && this.nodes[1].connectedTo && this.nodes[3].connectedTo){ + this.elements[1].hide(); + this.line.remove(); + this.line = null; + this.elements[1].undrag(); + this.setDragListeners(); + } +} } diff --git a/ArduinoFrontend/src/app/Libs/inputs/TemperatureSensors.ts b/ArduinoFrontend/src/app/Libs/inputs/TemperatureSensors.ts index a2002d321..df513c1c2 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/TemperatureSensors.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/TemperatureSensors.ts @@ -42,7 +42,7 @@ export class TMP36 extends CircuitElement { setValue(val: number) { if ( this.nodes[0].connectedTo && this.nodes[0].value >= 4.9 && - this.nodes[2].connectedTo + this.nodes[2].connectedTo && this.nodes[1].connectedTo ) { this.nodes[1].setValue(val, null); } else { diff --git a/ArduinoFrontend/src/app/Libs/outputs/Display.ts b/ArduinoFrontend/src/app/Libs/outputs/Display.ts index cbaaffd39..569204b63 100644 --- a/ArduinoFrontend/src/app/Libs/outputs/Display.ts +++ b/ArduinoFrontend/src/app/Libs/outputs/Display.ts @@ -717,6 +717,11 @@ export class LCD16X2 extends CircuitElement { } } } + // If no Arduino is found, show an error and stop + if (!this.arduino) { + window['showToast']('V0 pin is not properly connected to the Arduino.'); + return; + } // Add PWM event on arduino (this.arduino as ArduinoUno).addPWM(connectedPin, this.v0Listener.bind(this)); diff --git a/ArduinoFrontend/src/app/Libs/outputs/Led.ts b/ArduinoFrontend/src/app/Libs/outputs/Led.ts index b3b0d9b61..d3fd482a6 100644 --- a/ArduinoFrontend/src/app/Libs/outputs/Led.ts +++ b/ArduinoFrontend/src/app/Libs/outputs/Led.ts @@ -145,8 +145,10 @@ export class LED extends CircuitElement { this.handleConnectionError(); } else if (current >= 0.02 || pin0Current >= 0.02) { this.anim(); + window.hideToast(); } else if ((current > 0.012 && current < 0.02) || (pin0Current > 0.012)) { this.glowWithAlpha(current); + window.hideToast(); } else { this.fillColor('none'); } diff --git a/ArduinoFrontend/src/app/Libs/outputs/Motors.ts b/ArduinoFrontend/src/app/Libs/outputs/Motors.ts index cddf525dc..a9d79a665 100644 --- a/ArduinoFrontend/src/app/Libs/outputs/Motors.ts +++ b/ArduinoFrontend/src/app/Libs/outputs/Motors.ts @@ -723,8 +723,14 @@ export class ServoMotor extends CircuitElement { } this.nodes[1].addValueListener((v) => { - if (v < 4 || v > 6) { + if (!this.areAllNodesConnected() && (v < 4 || v > 6)) { + window['showToast']('Please Connect Servo Properly! Low Voltage Applied'); + return; + } else if (v < 4 || v > 6) { window['showToast']('Low Voltage Applied'); + } else { + window['showToast']('Please Connect Servo Properly!'); + return; } this.nodes[0].setValue(v, this.nodes[1]); }); From 8bb7d322ea107b2f1f9c5619204c2479d6ce5150 Mon Sep 17 00:00:00 2001 From: kghs-aver Date: Mon, 10 Feb 2025 13:18:40 +0530 Subject: [PATCH 2/5] toast message popup --- .../src/app/componentlist/componentlist.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ArduinoFrontend/src/app/componentlist/componentlist.component.ts b/ArduinoFrontend/src/app/componentlist/componentlist.component.ts index fd64bee06..824575aae 100644 --- a/ArduinoFrontend/src/app/componentlist/componentlist.component.ts +++ b/ArduinoFrontend/src/app/componentlist/componentlist.component.ts @@ -95,7 +95,7 @@ export class ComponentlistComponent implements OnInit { DownloadCSV() { // if no components are present show a toast message if (this.noComponets) { - window.showToast('No Components On Workspace'); + window.showToast('No Components On Workspace',true); return; } // CSV heading From f5a25fc42382063353cc97c1ab926e5365ef7587 Mon Sep 17 00:00:00 2001 From: kghs-aver Date: Mon, 10 Feb 2025 13:26:58 +0530 Subject: [PATCH 3/5] linting fix --- ArduinoFrontend/src/app/Libs/Miscellaneous.ts | 2 +- ArduinoFrontend/src/app/Libs/Point.ts | 2 +- ArduinoFrontend/src/app/Libs/Workspace.ts | 6 +++--- ArduinoFrontend/src/app/Libs/inputs/GasSensor.ts | 2 +- ArduinoFrontend/src/app/Libs/inputs/TemperatureSensors.ts | 2 +- ArduinoFrontend/src/app/Libs/outputs/Display.ts | 8 ++++---- .../src/app/componentlist/componentlist.component.ts | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/Miscellaneous.ts b/ArduinoFrontend/src/app/Libs/Miscellaneous.ts index 2df7af37b..b18e943a6 100644 --- a/ArduinoFrontend/src/app/Libs/Miscellaneous.ts +++ b/ArduinoFrontend/src/app/Libs/Miscellaneous.ts @@ -84,7 +84,7 @@ export class Label extends CircuitElement { // if text field is empty if (value === '') { // TODO: Show Toast - window['showToast']('Label cannot be empty',true); + window['showToast']('Label cannot be empty', true); return; } this.text = value; diff --git a/ArduinoFrontend/src/app/Libs/Point.ts b/ArduinoFrontend/src/app/Libs/Point.ts index d25971ff4..835c5049c 100644 --- a/ArduinoFrontend/src/app/Libs/Point.ts +++ b/ArduinoFrontend/src/app/Libs/Point.ts @@ -294,7 +294,7 @@ export class Point { if (wire.start && wire.end) { window['scope']['wires'].push(wire); } else { - window['showToast']('Wire was not connected properly !',true); + window['showToast']('Wire was not connected properly !', true); } } diff --git a/ArduinoFrontend/src/app/Libs/Workspace.ts b/ArduinoFrontend/src/app/Libs/Workspace.ts index 5b9a5a65b..8096c824e 100644 --- a/ArduinoFrontend/src/app/Libs/Workspace.ts +++ b/ArduinoFrontend/src/app/Libs/Workspace.ts @@ -233,7 +233,7 @@ export class Workspace { // Global flag to track whether the toast is currently visible window['toastVisible'] = false; // Global Function to show Toast Message - window['showToast'] = (message: string,autoHide = false) => { + window['showToast'] = (message: string, autoHide = false) => { const ele = document.getElementById('ToastMessage'); ele.style.display = 'block'; @@ -895,7 +895,7 @@ export class Workspace { // Hide Property box window.hideProperties(); } else { - window['showToast']('No Element Selected',true); + window['showToast']('No Element Selected', true); } } @@ -903,7 +903,7 @@ export class Workspace { static copyComponent() { if (window['Selected']) { if (window['Selected'] instanceof Wire) { - window['showToast']('You Can\'t Copy Wire',true); + window['showToast']('You Can\'t Copy Wire', true); return; } Workspace.copiedItem = window.Selected; diff --git a/ArduinoFrontend/src/app/Libs/inputs/GasSensor.ts b/ArduinoFrontend/src/app/Libs/inputs/GasSensor.ts index a36f2f820..ab7fad0f3 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/GasSensor.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/GasSensor.ts @@ -133,7 +133,7 @@ export class MQ2 extends CircuitElement { * Remove line and smoke */ closeSimulation(): void { - if (this.nodes[0].connectedTo && this.nodes[1].connectedTo && this.nodes[3].connectedTo){ + if (this.nodes[0].connectedTo && this.nodes[1].connectedTo && this.nodes[3].connectedTo) { this.elements[1].hide(); this.line.remove(); this.line = null; diff --git a/ArduinoFrontend/src/app/Libs/inputs/TemperatureSensors.ts b/ArduinoFrontend/src/app/Libs/inputs/TemperatureSensors.ts index df513c1c2..78897b6c4 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/TemperatureSensors.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/TemperatureSensors.ts @@ -42,7 +42,7 @@ export class TMP36 extends CircuitElement { setValue(val: number) { if ( this.nodes[0].connectedTo && this.nodes[0].value >= 4.9 && - this.nodes[2].connectedTo && this.nodes[1].connectedTo + this.nodes[2].connectedTo && this.nodes[1].connectedTo ) { this.nodes[1].setValue(val, null); } else { diff --git a/ArduinoFrontend/src/app/Libs/outputs/Display.ts b/ArduinoFrontend/src/app/Libs/outputs/Display.ts index 569204b63..509ca1ff5 100644 --- a/ArduinoFrontend/src/app/Libs/outputs/Display.ts +++ b/ArduinoFrontend/src/app/Libs/outputs/Display.ts @@ -718,10 +718,10 @@ export class LCD16X2 extends CircuitElement { } } // If no Arduino is found, show an error and stop - if (!this.arduino) { - window['showToast']('V0 pin is not properly connected to the Arduino.'); - return; - } + if (!this.arduino) { + window['showToast']('V0 pin is not properly connected to the Arduino.'); + return; + } // Add PWM event on arduino (this.arduino as ArduinoUno).addPWM(connectedPin, this.v0Listener.bind(this)); diff --git a/ArduinoFrontend/src/app/componentlist/componentlist.component.ts b/ArduinoFrontend/src/app/componentlist/componentlist.component.ts index 824575aae..d1bd8f269 100644 --- a/ArduinoFrontend/src/app/componentlist/componentlist.component.ts +++ b/ArduinoFrontend/src/app/componentlist/componentlist.component.ts @@ -95,7 +95,7 @@ export class ComponentlistComponent implements OnInit { DownloadCSV() { // if no components are present show a toast message if (this.noComponets) { - window.showToast('No Components On Workspace',true); + window.showToast('No Components On Workspace', true); return; } // CSV heading From c1cc831f657a3e558ceb152a4d37c98c5d562d5b Mon Sep 17 00:00:00 2001 From: kghs-aver Date: Sat, 22 Mar 2025 02:55:24 +0530 Subject: [PATCH 4/5] fix led burst message appear error --- ArduinoFrontend/src/app/Libs/outputs/Led.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ArduinoFrontend/src/app/Libs/outputs/Led.ts b/ArduinoFrontend/src/app/Libs/outputs/Led.ts index d3fd482a6..16b4e57cf 100644 --- a/ArduinoFrontend/src/app/Libs/outputs/Led.ts +++ b/ArduinoFrontend/src/app/Libs/outputs/Led.ts @@ -140,6 +140,7 @@ export class LED extends CircuitElement { // TODO: Run if PWM is not attached if (this.nodes[0].connectedTo && this.nodes[1].connectedTo) { if (!this.pwmAttached && this.allNodesConnected) { + console.log('current', current); if (current > 0.03 || pin0Current > 0.03) { window.showToast('LED has burst'); this.handleConnectionError(); @@ -150,6 +151,7 @@ export class LED extends CircuitElement { this.glowWithAlpha(current); window.hideToast(); } else { + window.showToast('LED has burst'); this.fillColor('none'); } From ca12d388503a160b5bc5718f4344f26ad2731b85 Mon Sep 17 00:00:00 2001 From: kghs-aver Date: Tue, 25 Mar 2025 11:42:22 +0530 Subject: [PATCH 5/5] fix for servomoter --- ArduinoFrontend/src/app/Libs/outputs/Motors.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/outputs/Motors.ts b/ArduinoFrontend/src/app/Libs/outputs/Motors.ts index a9d79a665..e650876fc 100644 --- a/ArduinoFrontend/src/app/Libs/outputs/Motors.ts +++ b/ArduinoFrontend/src/app/Libs/outputs/Motors.ts @@ -723,16 +723,18 @@ export class ServoMotor extends CircuitElement { } this.nodes[1].addValueListener((v) => { - if (!this.areAllNodesConnected() && (v < 4 || v > 6)) { + const isConnected = this.areAllNodesConnected(); + const isLowVoltage = v < 4 || v > 6; + if (!isConnected && isLowVoltage) { window['showToast']('Please Connect Servo Properly! Low Voltage Applied'); - return; - } else if (v < 4 || v > 6) { - window['showToast']('Low Voltage Applied'); - } else { + } else if (!isConnected) { window['showToast']('Please Connect Servo Properly!'); - return; + } else if (isLowVoltage) { + window['showToast']('Low Voltage Applied'); + } + if (isConnected && !isLowVoltage) { + this.nodes[0].setValue(v, this.nodes[1]); } - this.nodes[0].setValue(v, this.nodes[1]); }); } /**