Skip to content

Commit

Permalink
Merge pull request frg-fossee#190 from gupta-arpit/bugfix/component_p…
Browse files Browse the repository at this point in the history
…lacement

Components and breadboard bugfix
  • Loading branch information
firuza authored Sep 13, 2020
2 parents ac636c6 + e06c65f commit 046e32a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 22 deletions.
12 changes: 6 additions & 6 deletions ArduinoFrontend/src/app/Libs/General.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,31 +561,31 @@ export class BreadBoard extends CircuitElement {
// Stores set of node which has same y values
const ytemp = {};

for (const node of this.joined) {
for (const node of this.nodes) {
// Add a Node value change listener
node.addValueListener((v, cby, par) => {
if (par.x === par.x && cby.y === par.y) {
node.addValueListener((value, calledBy, parent) => {
if (calledBy.y === parent.y) {
return;
}
if (node.label === '+' || node.label === '-') {
for (const neigh of ytemp[node.y]) {
if (neigh.x !== node.x) {
neigh.setValue(v, neigh);
neigh.setValue(value, neigh);
}
}
} else {
const op = node.label.charCodeAt(0);
if (op >= 102) {
for (const neigh of xtemp[node.x]) {
if (neigh.y !== node.y && neigh.label.charCodeAt(0) >= 102) {
neigh.setValue(v, neigh);
neigh.setValue(value, neigh);
}
}
}
if (op <= 101) {
for (const neigh of xtemp[node.x]) {
if (neigh.y !== node.y && neigh.label.charCodeAt(0) <= 101) {
neigh.setValue(v, neigh);
neigh.setValue(value, neigh);
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions ArduinoFrontend/src/app/Libs/Point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,20 @@ export class Point {
this.soldered = true;
const newClass = `${this.body.node.getAttribute('class')} solder-highlight`;
this.body.node.setAttribute('class', newClass);
if (this.connectCallback) {
this.connectCallback(this);
}
return wire;
}

/**
* Unsolders wire to the point
*/
unsolderWire() {
if (this.connectedTo) {
this.connectedTo.delete();
const wire = this.connectedTo;
if (wire) {
this.setValue(-1, this);
wire.delete();
}
this.soldered = false;
const newClass = this.body.node.getAttribute('class').replace(' solder-highlight', '');
Expand Down
18 changes: 14 additions & 4 deletions ArduinoFrontend/src/app/Libs/outputs/Display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export class LCD16X2 extends CircuitElement {
newDdRamAddress = direction > 0 ? 0x40 : 0x27;
}

this.ddRamAddress = newDdRamAddress;
this.setDdRamAddress(newDdRamAddress);
}

/**
Expand Down Expand Up @@ -394,13 +394,23 @@ export class LCD16X2 extends CircuitElement {
}
}

/**
* Checks if power supply is enough
*/
isPowerSupplyEnough() {
const vcc = this.getVCC();
if (vcc < 3.3 || vcc > 5) {
return false;
}
return true;
}

/**
* event listener for node `E`
* @param newValue new value at the node `E`
*/
eSignalListener(newValue) {
const vcc = this.getVCC();
if (vcc < 3.3 || vcc > 5) {
if (!this.isPowerSupplyEnough()) {
console.log('Not enough power supply.');
return;
}
Expand Down Expand Up @@ -655,6 +665,7 @@ export class LCD16X2 extends CircuitElement {
const v0Pin = this.nodes[2];

if (!v0Pin.connectedTo) {
window['showToast']('V0 pin of the LCD is not connected to power source.');
return;
}

Expand All @@ -667,7 +678,6 @@ export class LCD16X2 extends CircuitElement {
this.arduino = v0Pin.connectedTo.end.parent;
connectedPin = v0Pin.connectedTo.end;
} else {
window['showToast']('Arduino Not Found!');
this.connected = false;
return;
}
Expand Down
8 changes: 7 additions & 1 deletion ArduinoFrontend/src/app/Libs/outputs/LCD/LCDPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ export class LCDPixel {
*/
shift(distance, hidden) {
this.posX += distance;

// if canvas is not set yet, return
if (!this.canvas) {
return;
}

this.canvas.attr({
x: this.posX + this.lcdX
});
Expand Down Expand Up @@ -266,7 +272,7 @@ export class LCDPixel {
* Refreshes the pixel if changes are pending, else does nothing
*/
refresh() {
if (this.changesPending) {
if (this.changesPending && this.canvas) {
this.canvas.attr({
x: this.posX + this.lcdX,
y: this.posY + this.lcdY,
Expand Down
42 changes: 33 additions & 9 deletions ArduinoFrontend/src/app/Libs/outputs/Led.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ export class LED extends CircuitElement {
fill: LED.colors[this.selectedIndex]
});
}
/**
* fills color in the led
* @param color color
*/
fillColor(color) {
this.elements[3].attr({ fill: color });
}
/** Simulation Logic */
logic(val: number) {
// console.log(val);
Expand All @@ -79,21 +86,26 @@ export class LED extends CircuitElement {
if (val >= 5) {
this.anim();
} else {
this.elements[3].attr({ fill: 'none' });
this.fillColor('none');
}
if (val >= 0) {
this.nodes[1].setValue(val, null);
}
} else {
// TODO: Show Toast
this.handleConnectionError();
window.showToast('LED is not Connected properly');
}
}
/**
* Handles connection error
*/
handleConnectionError() {
this.fillColor('none');
}
/** animation caller when start simulation is pressed */
anim() {
this.elements[3].attr({
fill: `r(0.5, 0.5)${LED.glowColors[this.selectedIndex]}`
});
this.fillColor(`r(0.5, 0.5)${LED.glowColors[this.selectedIndex]}`);
}
/**
* Get The Led Name
Expand Down Expand Up @@ -143,7 +155,7 @@ export class LED extends CircuitElement {
/** Function removes all the animations */
closeSimulation(): void {
this.prev = -2;
this.elements[3].attr({ fill: 'none' });
this.fillColor('none');
}
}
/**
Expand Down Expand Up @@ -222,6 +234,21 @@ export class RGBLED extends CircuitElement {
body
};
}
/**
* Removes glow
*/
removeGlow() {
if (this.glow) {
this.glow.remove();
this.glow = null;
}
}
/**
* Handles connection error
*/
handleConnectionError() {
this.removeGlow();
}
/**
* Called on start simulation
*/
Expand All @@ -231,10 +258,7 @@ export class RGBLED extends CircuitElement {
* Remove Glow and clear the filling
*/
closeSimulation(): void {
if (this.glow) {
this.glow.remove();
this.glow = null;
}
this.removeGlow();
this.elements[1].attr({
fill: 'none'
});
Expand Down

0 comments on commit 046e32a

Please sign in to comment.