Skip to content

Commit

Permalink
Merge pull request #11 from Rugz007/develop
Browse files Browse the repository at this point in the history
Rebasing workflow-versioning
  • Loading branch information
Rugz007 authored Jul 22, 2021
2 parents f4699d8 + 1361616 commit c6b31f0
Show file tree
Hide file tree
Showing 16 changed files with 1,259 additions and 88 deletions.
153 changes: 152 additions & 1 deletion ArduinoFrontend/src/app/Libs/General.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ export class BreadBoard extends CircuitElement {
*/
static PROXIMITY_DISTANCE = 20;

/**
* Set to keep track of visited nodes
*/
static visitedNodesv2 = new Set();

/**
* Nodes that are connected
*/
Expand Down Expand Up @@ -325,6 +330,147 @@ export class BreadBoard extends CircuitElement {
this.subscribeToDragStop({ id: this.id, fn: this.onOtherComponentDragStop.bind(this) });
}

/**
* Returns node connected to arduino
* @param node node to start search on
* @param startedOn label of node search started on
* @returns Arduino connected Node
*/
static getRecArduinov2(node: Point, startedOn: string) {
try {
if (node.connectedTo.start.parent.keyName === 'ArduinoUno') {
// TODO: Return if arduino is connected to start node
return node.connectedTo.start;
} else if (node.connectedTo.end.parent.keyName === 'ArduinoUno') {
// TODO: Return if arduino is connected to end node
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
return this.getRecArduinoBreadv2(node, startedOn);
} else if (node.connectedTo.end.parent.keyName === 'BreadBoard' && !this.visitedNodesv2.has(node.connectedTo.end.gid)) {
// TODO: Call recursive BreadBoard handler function if node is connected to Breadboard && visited nodes doesn't have node's gid
return this.getRecArduinoBreadv2(node, startedOn);
} else if (node.connectedTo.end.parent.keyName === 'Battery9v' && window.scope.ArduinoUno.length === 0) {
// TODO: Return false if node's end is connected to 9V Battery
return false;
} else if (node.connectedTo.end.parent.keyName === 'CoinCell' && window.scope.ArduinoUno.length === 0) {
// TODO: Return false if node's end is connected to Coin Cell
return false;
} else if (node.connectedTo.end.parent.keyName === 'RelayModule') {
// TODO: Handle RelayModule
if (startedOn === 'POSITIVE') {
// If search was started on Positive node then return connected node of VCC in Relay
return this.getRecArduinov2(node.connectedTo.end.parent.nodes[3], startedOn);
} else if (startedOn === 'NEGATIVE') {
// If search was started on Negative node then return connected node of GND in Relay
return this.getRecArduinov2(node.connectedTo.end.parent.nodes[5], startedOn);
}
} else {
// TODO: If nothing matches
// IF/ELSE: Determine if start is to be used OR end for further recursion
if (node.connectedTo.end.gid !== node.gid) {
// Loops through all nodes in parent
for (const e in node.connectedTo.end.parent.nodes) {
// IF: gid is different && gid not in visited node
if (node.connectedTo.end.parent.nodes[e].gid !== node.connectedTo.end.gid
&& !this.visitedNodesv2.has(node.connectedTo.end.parent.nodes[e].gid) && node.connectedTo.end.parent.nodes[e].isConnected()) {
// add gid in visited nodes
this.visitedNodesv2.add(node.connectedTo.end.parent.nodes[e].gid);
// call back Arduino Recursive Fn
return this.getRecArduinov2(node.connectedTo.end.parent.nodes[e], startedOn);
}
}
} else if (node.connectedTo.start.gid !== node.gid) {
// Loops through all nodes in parent
for (const e in node.connectedTo.start.parent.nodes) {
// IF: gid is different && gid not in visited node
if (node.connectedTo.start.parent.nodes[e].gid !== node.connectedTo.start.gid
&& !this.visitedNodesv2.has(node.connectedTo.start.parent.nodes[e].gid)
&& node.connectedTo.start.parent.nodes[e].isConnected()) {
// add gid in visited nodes
this.visitedNodesv2.add(node.connectedTo.start.parent.nodes[e].gid);
// call back Arduino Recursive Fn
return this.getRecArduinov2(node.connectedTo.start.parent.nodes[e], startedOn);
}
}
}

}
} catch (e) {
console.warn(e);
return false;
}

}

/**
* Recursive Function to handle BreadBoard
* @param node Node which is to be checked for BreadBoard
*/
static getRecArduinoBreadv2(node: Point, startedOn: string) {
// IF/ELSE: Determine if start is to be used OR end for further recursion
if (node.connectedTo.end.gid !== node.gid) {
const bb = (node.connectedTo.end.parent as BreadBoard);
// loop through joined nodes of breadboard
for (const e in bb.joined) {
if (bb.joined[e].gid !== node.connectedTo.end.gid) {
// Run only if substring matches
if (bb.joined[e].label.substring(1, bb.joined[e].label.length)
=== node.connectedTo.end.label.substring(1, node.connectedTo.end.label.length)) {
const ascii = node.connectedTo.end.label.charCodeAt(0);
const currAscii = bb.joined[e].label.charCodeAt(0);
// add gid to VisitedNode
this.visitedNodesv2.add(bb.joined[e].gid);
// IF/ELSE: determine which part of breadboard is connected
if (ascii >= 97 && ascii <= 101) {
if (bb.joined[e].isConnected() && (currAscii >= 97 && currAscii <= 101)) {
return this.getRecArduinov2(bb.joined[e], startedOn);
}
} else if (ascii >= 102 && ascii <= 106) {
if (bb.joined[e].isConnected() && (currAscii >= 102 && currAscii <= 106)) {
return this.getRecArduinov2(bb.joined[e], startedOn);
}
} else {
if (bb.joined[e].isConnected() && (bb.joined[e].label === node.connectedTo.end.label)) {
return this.getRecArduinov2(bb.joined[e], startedOn);
}
}
}
}
}
} else if (node.connectedTo.start.gid !== node.gid) {
const bb = (node.connectedTo.start.parent as BreadBoard);
// loop through joined nodes of breadboard
for (const e in bb.joined) {
if (bb.joined[e].gid !== node.connectedTo.start.gid) {
// Run only if substring matches
if (bb.joined[e].label.substring(1, bb.joined[e].label.length)
=== node.connectedTo.start.label.substring(1, node.connectedTo.start.label.length)) {
const ascii = node.connectedTo.start.label.charCodeAt(0);
const currAscii = bb.joined[e].label.charCodeAt(0);
// add gid to VisitedNode
this.visitedNodesv2.add(bb.joined[e].gid);
// IF/ELSE: determine which part of breadboard is connected
if (ascii >= 97 && ascii <= 101) {
if (bb.joined[e].isConnected() && (currAscii >= 97 && currAscii <= 101)) {
return this.getRecArduinov2(bb.joined[e], startedOn);
}
} else if (ascii >= 102 && ascii <= 106) {
if (bb.joined[e].isConnected() && (currAscii >= 102 && currAscii <= 106)) {
return this.getRecArduinov2(bb.joined[e], startedOn);
}
} else {
if (bb.joined[e].isConnected() && (bb.joined[e].label === node.connectedTo.end.label)) {
return this.getRecArduinov2(bb.joined[e], startedOn);
}
}
}
}
}
}

}

/**
* Subscribes to drag listener of the workspace
* @param fn listener functino
Expand Down Expand Up @@ -661,7 +807,10 @@ export class BreadBoard extends CircuitElement {
for (const node of this.nodes) {
// Add a Node value change listener
node.addValueListener((value, calledBy, parent) => {
if (calledBy.y === parent.y) {
const labelCalledBy = calledBy.label;
const labelParent = parent.label;
if (calledBy.y === parent.y
&& (labelCalledBy.charCodeAt(0) !== labelParent.charCodeAt(0) || labelCalledBy === labelParent)) {
return;
}
if (node.label === '+' || node.label === '-') {
Expand Down Expand Up @@ -695,5 +844,7 @@ export class BreadBoard extends CircuitElement {
* Called on Stop Simulation is pressed
*/
closeSimulation(): void {
BreadBoard.visitedNodesv2.clear();
}

}
5 changes: 5 additions & 0 deletions ArduinoFrontend/src/app/Libs/Point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export class Point {
* The Node ID
*/
id: number;
/**
* Boolean for inputPullUp
*/
pullUpEnabled = false;

/**
* Constructor for Circuit Node
* @param canvas Raphael Canvas / paper
Expand Down
8 changes: 7 additions & 1 deletion ArduinoFrontend/src/app/Libs/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Potentiometer } from './inputs/Potentiometer';
import { Relay } from './inputs/Relay';
import { MQ2 } from './inputs/GasSensor';
import { Resistor, BreadBoard } from './General';
import { L293D } from './drivers/L293D';

/**
* Utils class
Expand Down Expand Up @@ -41,7 +42,7 @@ export class Utils {
['LCD16X2']
],
drivers: [
['L298N']
['L298N', 'L293D']
],
misc: [
['Label', 'RelayModule']
Expand Down Expand Up @@ -167,6 +168,11 @@ export class Utils {
name: 'Buzzer',
image: './assets/images/components/Buzzer.png',
className: Buzzer
},
L293D: {
name: 'L293D',
image: './assets/images/components/L293D.png',
className: L293D
}
};
}
Loading

0 comments on commit c6b31f0

Please sign in to comment.