Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Led pin connection issues bugfix #467

Merged
merged 8 commits into from
Mar 3, 2023
Merged
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
69 changes: 46 additions & 23 deletions ArduinoFrontend/src/app/Libs/outputs/Led.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export class LED extends CircuitElement {
* If all nodes of element are connected or not
*/
allNodesConnected = false;
/**
* Flag to check if logic function's recursion should be skipped
*/
skipCheck = false;

/**
* LED constructor
Expand Down Expand Up @@ -99,30 +103,48 @@ export class LED extends CircuitElement {
}
/** Simulation Logic */
logic(val: number) {

if (this.prev === val) {
return;
this.skipCheck = true;
}

if (!this.allNodesConnected) {
const arduinoEnd: any = this.getRecArduinov2(this.pinNamedMap['POSITIVE'], 'POSITIVE');
const negativeEnd = this.getRecArduinov2(this.pinNamedMap['NEGATIVE'], 'NEGATIVE');
if (negativeEnd && arduinoEnd) {
if (negativeEnd.hasOwnProperty('label')) {
if (negativeEnd.label === 'GND' || (negativeEnd.value === 0 && arduinoEnd.value > 0)) {
this.allNodesConnected = true;
}
}
}
}
this.prev = val;
// TODO: Run if PWM is not attached
if (this.nodes[0].connectedTo && this.nodes[1].connectedTo && !this.pwmAttached && this.allNodesConnected) {
if (val >= 5) {
this.anim();
} else if (val > 0 && val < 5) {
if (val < 0.1) {
if (this.nodes[0].connectedTo && this.nodes[1].connectedTo) {
if (!this.pwmAttached && this.allNodesConnected) {
if (val >= 5 || this.nodes[0].value === 5) {
this.anim();
} else if (val > 0 && val < 5 || this.nodes[0].value > 0) {
if (val < 0.1) {
this.fillColor('none');
} else {
this.glowWithAlpha(val);
}
} else {
this.fillColor('none');
}
if (val >= 0 && !this.skipCheck) {
this.prev = val;
this.nodes[1].setValue(val, null);
} else {
this.glowWithAlpha(val);
this.skipCheck = false;
return;
}
} else {
this.fillColor('none');
}
if (val >= 0) {
this.nodes[1].setValue(val, null);
}
} else if (this.nodes[0].connectedTo && this.nodes[1].connectedTo && this.pwmAttached && this.allNodesConnected) {
// TODO: Run if PWM is attached
this.glowWithAlpha(this.voltage);
} else if (this.pwmAttached && this.allNodesConnected) {
// TODO: Run if PWM is attached
this.glowWithAlpha(this.voltage);

}
} else {
// TODO: Show Toast
this.handleConnectionError();
Expand Down Expand Up @@ -216,12 +238,11 @@ export class LED extends CircuitElement {
}
}
}
if (arduinoEnd) {
if (arduinoEnd.hasOwnProperty('label')) {
if (arduinoEnd.label === 'GND') {
this.allNodesConnected = true;
}
}
// Check if nodes of LED are connected
if (!negativeEnd || !arduinoEnd) {
// TODO: Show Toast
this.handleConnectionError();
window.showToast('LED is not Connected properly');
}

// do not run addPwm if arduino is not connected
Expand Down Expand Up @@ -261,9 +282,11 @@ export class LED extends CircuitElement {
try {
if (node.connectedTo.start.parent.keyName === 'ArduinoUno') {
// TODO: Return if arduino is connected to start node
this.visitedNodesv2.clear();
return node.connectedTo.start;
} else if (node.connectedTo.end.parent.keyName === 'ArduinoUno') {
// TODO: Return if arduino is connected to end node
this.visitedNodesv2.clear();
return node.connectedTo.end;
} else if (node.connectedTo.start.parent.keyName === 'BreadBoard' && !this.visitedNodesv2.has(node.connectedTo.start.gid)) {
// TODO: Call recursive BreadBoard handler function if node is connected to Breadboard && visited nodes doesn't have node's gid
Expand Down