Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ArduinoFrontend/src/app/Libs/General.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class Resistor extends CircuitElement {
} else {
this.value = tmp;
this.updateColors();
window['hideToast']();
}
}
/** Function returns resistence values 10K ohm => 10 */
Expand Down
2 changes: 1 addition & 1 deletion ArduinoFrontend/src/app/Libs/Miscellaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ArduinoFrontend/src/app/Libs/Point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
28 changes: 21 additions & 7 deletions ArduinoFrontend/src/app/Libs/Workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -882,15 +895,15 @@ export class Workspace {
// Hide Property box
window.hideProperties();
} else {
window['showToast']('No Element Selected');
window['showToast']('No Element Selected', true);
}
}

/** Function to copy component fro 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;
Expand Down Expand Up @@ -1126,6 +1139,7 @@ export class Workspace {
Workspace.simulating = false;
Workspace.simulationStopped.emit(true);
callback();
window['hideToast']();
}
/**
* Function to clear the workspace
Expand Down
26 changes: 19 additions & 7 deletions ArduinoFrontend/src/app/Libs/inputs/GasSensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
}
}
2 changes: 1 addition & 1 deletion ArduinoFrontend/src/app/Libs/inputs/TemperatureSensors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions ArduinoFrontend/src/app/Libs/outputs/Display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions ArduinoFrontend/src/app/Libs/outputs/Led.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,18 @@ 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();
} 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 {
window.showToast('LED has burst');
this.fillColor('none');
}

Expand Down
12 changes: 10 additions & 2 deletions ArduinoFrontend/src/app/Libs/outputs/Motors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,18 @@ export class ServoMotor extends CircuitElement {
}

this.nodes[1].addValueListener((v) => {
if (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');
} else if (!isConnected) {
window['showToast']('Please Connect Servo Properly!');
} 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]);
});
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading