From e7bebd4121855613c354a3fb46cb75fc17a430f3 Mon Sep 17 00:00:00 2001 From: deepampriyadarshi Date: Tue, 2 Aug 2022 22:04:19 +0530 Subject: [PATCH 01/33] Auto Grading Component --- .../app/code-editor/code-editor.component.ts | 5 +-- .../src/app/graph/graph.component.ts | 8 ++-- .../app/graphlist/graphlist.component.html | 6 ++- .../src/app/graphlist/graphlist.component.ts | 34 +++++++++++++---- .../src/app/lti-form/lti-form.component.css | 4 ++ .../src/app/lti-form/lti-form.component.html | 34 ++++++++++++----- .../src/app/lti-form/lti-form.component.ts | 38 ++++++++++++------- .../app/simulator/simulator.component.html | 3 +- .../src/app/simulator/simulator.component.ts | 19 +++++----- esim-cloud-backend/ltiAPI/models.py | 2 + .../ltiAPI/process_submission.py | 26 +++++++++++++ esim-cloud-backend/ltiAPI/serializers.py | 6 +-- esim-cloud-backend/ltiAPI/views.py | 27 ++++++------- esim-cloud-backend/saveAPI/admin.py | 1 + esim-cloud-backend/simulationAPI/urls.py | 2 +- esim-cloud-backend/simulationAPI/views.py | 2 +- 16 files changed, 146 insertions(+), 71 deletions(-) diff --git a/ArduinoFrontend/src/app/code-editor/code-editor.component.ts b/ArduinoFrontend/src/app/code-editor/code-editor.component.ts index 45113973e..e76ad25d1 100644 --- a/ArduinoFrontend/src/app/code-editor/code-editor.component.ts +++ b/ArduinoFrontend/src/app/code-editor/code-editor.component.ts @@ -126,11 +126,8 @@ export class CodeEditorComponent { this.selectedIndex = 0; } // select the code of respective arduino - if (this.arduinos.length > 0 && this.codeView) { + if (this.arduinos.length > 0) { this.code = this.arduinos[this.selectedIndex].code; - } else { - this.code = ''; - this.codeChanged(); } // show loading animation if code editor is nor initialized if (this.names.length !== 0 && !this.init) { diff --git a/ArduinoFrontend/src/app/graph/graph.component.ts b/ArduinoFrontend/src/app/graph/graph.component.ts index 7f2b4b80c..811c2ab80 100644 --- a/ArduinoFrontend/src/app/graph/graph.component.ts +++ b/ArduinoFrontend/src/app/graph/graph.component.ts @@ -1,7 +1,8 @@ -import { Component, Directive, Input, OnInit, AfterViewInit } from '@angular/core'; +import { Component, Directive, Input, OnInit, AfterViewInit, Output } from '@angular/core'; import { Chart } from 'chart.js'; import { GraphDataService } from '../graph-data.service'; import { Workspace } from '../Libs/Workspace'; +import { EventEmitter } from '@angular/core'; @Component({ selector: 'app-graph', @@ -56,8 +57,8 @@ export class GraphComponent implements OnInit, AfterViewInit { this.xlabels.push(new Date(res.time).getTime() - new Date(this.previousTime).getTime()); } this.previousTime = new Date(res.time); - console.log(this.pinLabel, this.data); - console.log(this.pinLabel, this.xlabels); + // console.log(this.pinLabel, this.data); + // console.log(this.pinLabel, this.xlabels); this.pinGraph.update(); } }); @@ -67,7 +68,6 @@ export class GraphComponent implements OnInit, AfterViewInit { this.data.splice(0, this.data.length); this.xlabels.splice(0, this.xlabels.length); this.pinGraph.update(); - // console.log(this.nodes); } configChart() { diff --git a/ArduinoFrontend/src/app/graphlist/graphlist.component.html b/ArduinoFrontend/src/app/graphlist/graphlist.component.html index 013ffa2c9..5ccc67e30 100644 --- a/ArduinoFrontend/src/app/graphlist/graphlist.component.html +++ b/ArduinoFrontend/src/app/graphlist/graphlist.component.html @@ -9,9 +9,13 @@

Waveforms

Start the simulation to visualize
+
+ Number of Data Points: {{dataPoints}} +
- +
\ No newline at end of file diff --git a/ArduinoFrontend/src/app/graphlist/graphlist.component.ts b/ArduinoFrontend/src/app/graphlist/graphlist.component.ts index d02713754..e778aa0f3 100644 --- a/ArduinoFrontend/src/app/graphlist/graphlist.component.ts +++ b/ArduinoFrontend/src/app/graphlist/graphlist.component.ts @@ -7,6 +7,7 @@ import { GraphComponent } from '../graph/graph.component'; import { Login } from '../Libs/Login'; import { Workspace } from '../Libs/Workspace'; import { SimulatorComponent } from '../simulator/simulator.component'; +import { GraphDataService } from '../graph-data.service'; @Component({ selector: 'app-graphlist', @@ -21,7 +22,10 @@ export class GraphlistComponent implements OnInit { @Output() simDataSave: EventEmitter = new EventEmitter(); @ViewChildren('pinGraph') graphList!: QueryList; nodes: object[] = []; + arduinoList: object[] = []; simulationStatus = false; + dataPoints = 0; + hexData: number[] = []; constructor( private router: Router, @@ -39,12 +43,17 @@ export class GraphlistComponent implements OnInit { } }); }); + window['scope'].ArduinoUno.forEach(arduino => { + this.arduinoList.push({arduinoId: arduino.id, arduinoName: arduino.name}); + }); // }); } ngOnInit() { Workspace.simulationStarted.subscribe(res => { this.simulationStatus = res; + this.dataPoints = 0; + this.hexData = []; }); Workspace.simulationStopped.subscribe(res => { this.simulationStatus = res; @@ -83,6 +92,12 @@ export class GraphlistComponent implements OnInit { } } }); + GraphDataService.voltageChange.subscribe(res => { + if (this.arduinoList[0]['arduinoId'] === res.arduino.id) { + this.hexData.push(res.value); + this.dataPoints++; + } + }); } pushPoint(arduino, pointId) { @@ -95,22 +110,25 @@ export class GraphlistComponent implements OnInit { } SaveData() { - console.log('Clicked'); - const data = {}; + const pins = []; + const newData = {}; this.graphList.forEach(pinGraph => { - data[pinGraph.pinLabel] = { - values: pinGraph.data, - delay: pinGraph.xlabels, - length: pinGraph.data.length, + pins.push(pinGraph.pinLabel); + }); + this.arduinoList.forEach(ard => { + newData[ard['arduinoId']] = { + pinConnected: pins, + hexVals: this.hexData, + length: this.dataPoints }; }); const token = Login.getToken(); if (!this.lti) { - this.api.storeSimulationData(this.id, token, data).subscribe(res => AlertService.showAlert('Record Saved Successfully') + this.api.storeSimulationData(this.id, token, newData).subscribe(res => AlertService.showAlert('Record Saved Successfully') , err => AlertService.showAlert(err)); } else { this.aroute.queryParams.subscribe(v => { - this.api.storeLTISimulationData(this.id, v.lti_id, token, data).subscribe(res => { + this.api.storeLTISimulationData(this.id, v.lti_id, token, newData).subscribe(res => { AlertService.showAlert('Record Saved Successfully'); this.simDataSave.emit(true); } diff --git a/ArduinoFrontend/src/app/lti-form/lti-form.component.css b/ArduinoFrontend/src/app/lti-form/lti-form.component.css index 00ec88642..31fede487 100644 --- a/ArduinoFrontend/src/app/lti-form/lti-form.component.css +++ b/ArduinoFrontend/src/app/lti-form/lti-form.component.css @@ -6,6 +6,10 @@ mat-form-field { width: 100%; } +.code-weight { + padding-top: 25pt; +} + .form-buttons { padding: 10px; } diff --git a/ArduinoFrontend/src/app/lti-form/lti-form.component.html b/ArduinoFrontend/src/app/lti-form/lti-form.component.html index fde7075f5..b35e02c2a 100644 --- a/ArduinoFrontend/src/app/lti-form/lti-form.component.html +++ b/ArduinoFrontend/src/app/lti-form/lti-form.component.html @@ -33,13 +33,13 @@
  • Branch: {{ studentCircuit.branch }}
  • Version: {{ studentCircuit.version }}
  • -
  • + -
  • + + -->
This field is mandatory - Value should be 0 or 1 + Value should be between 0 and 100 -
- - Accept Submissions - +
+
+ + Accept Submissions + +
+
+ + Show Code + +
+ + +
diff --git a/ArduinoFrontend/src/app/lti-form/lti-form.component.ts b/ArduinoFrontend/src/app/lti-form/lti-form.component.ts index 70da8967b..b83d9fd6f 100644 --- a/ArduinoFrontend/src/app/lti-form/lti-form.component.ts +++ b/ArduinoFrontend/src/app/lti-form/lti-form.component.ts @@ -36,6 +36,8 @@ export interface LTIDetails { id: string; sim_params: string[]; view_code: boolean; + con_weightage: number; + code_weightage: number; } /** @@ -125,19 +127,25 @@ export class LTIFormComponent implements OnInit { scored: false, id: '', sim_params: [], - view_code: false + view_code: false, + con_weightage: 60, + code_weightage: 40 }; + /** * Defines LTI Form Controls and Validators */ form: FormGroup = new FormGroup({ consumer_key: new FormControl('', [Validators.required, Validators.minLength(2)]), secret_key: new FormControl('', [Validators.required, Validators.minLength(2)]), - score: new FormControl(0, [Validators.required, Validators.min(0), Validators.max(1)]), + score: new FormControl(0, [Validators.required, Validators.min(0), Validators.max(100)]), + con_weightage: new FormControl(60, [Validators.required, Validators.min(0), Validators.max(100)]), + code_weightage: new FormControl(40), test_case: new FormControl(''), initial_schematic: new FormControl(0, Validators.required), model_schematic: new FormControl(0, Validators.required), scored: new FormControl(true), + viewCode: new FormControl(false) }); /** @@ -208,6 +216,7 @@ export class LTIFormComponent implements OnInit { this.details.configExists = false; this.getAllVersions(); this.getTestCases(); + this.form.get('con_weightage').setValue(this.details.con_weightage); } }); } @@ -226,8 +235,10 @@ export class LTIFormComponent implements OnInit { model_schematic: parseInt(res['model_schematic'], 10), test_case: res['test_case'], scored: res['scored'], + con_weightage: res['con_weightage'], + code_weightage: 100 - res['con_weightage'], + viewCode: res['view_code'] }); - this.viewCodeCheckBox = res['view_code']; } gettestCaseSelectChange(value) { @@ -268,16 +279,10 @@ export class LTIFormComponent implements OnInit { this.getStudentSimulation(event.value); } - /** - * Called on view code checkbox is checked or unchecked - */ - toggleViewCode(event) { - if (event.checked) { - this.details.view_code = true; - } else { - this.details.view_code = false; - } + conCodeWeight(event) { + this.details.code_weightage = 100 - this.form.value.con_weightage; + this.form.get('code_weightage').setValue(100 - this.form.value.con_weightage); } /** @@ -292,9 +297,11 @@ export class LTIFormComponent implements OnInit { ...this.details, ...this.form.value, scored: this.form.value.scored ? true : false, + view_code: this.form.value.viewCode ? true : false, model_schematic: this.modelCircuit.id, test_case: this.form.value.test_case ? this.form.value.test_case : null, score: this.form.value.score, + con_weightage: this.form.value.con_weightage, configExists: false, }; const token = Login.getToken(); @@ -356,7 +363,9 @@ export class LTIFormComponent implements OnInit { sim_params: [], scored: false, id: '', - view_code: false + view_code: false, + con_weightage: 60, + code_weightage: 40, }; this.studentCircuit = undefined; this.circuits = []; @@ -396,7 +405,8 @@ export class LTIFormComponent implements OnInit { test_case: this.details.test_case, score: this.form.value.score, sim_params: [], - view_code: this.details.view_code + view_code: this.form.value.viewCode ? true : false, + con_weightage: this.details.con_weightage }; if (!this.details.scored) { this.details.score = null; diff --git a/ArduinoFrontend/src/app/simulator/simulator.component.html b/ArduinoFrontend/src/app/simulator/simulator.component.html index cfdba7753..82ad117f6 100644 --- a/ArduinoFrontend/src/app/simulator/simulator.component.html +++ b/ArduinoFrontend/src/app/simulator/simulator.component.html @@ -250,8 +250,7 @@
- +
diff --git a/ArduinoFrontend/src/app/simulator/simulator.component.ts b/ArduinoFrontend/src/app/simulator/simulator.component.ts index bcffa7830..ba135b7cb 100644 --- a/ArduinoFrontend/src/app/simulator/simulator.component.ts +++ b/ArduinoFrontend/src/app/simulator/simulator.component.ts @@ -123,10 +123,6 @@ export class SimulatorComponent implements OnInit, OnDestroy { * Hide/Show submit button */ submitButtonVisibility = false; - /** - * Whether the LTI user is allowed to see the code - */ - codeVisibility = true; /** * LTI ID of LTI App (if simulator is opened on LMS) */ @@ -260,7 +256,6 @@ export class SimulatorComponent implements OnInit, OnDestroy { this.LoadOnlineProject(v.id, v.offline); this.submitButtonVisibility = false; } - console.log(this.projectId); }); @@ -348,7 +343,6 @@ export class SimulatorComponent implements OnInit, OnDestroy { getSimRecSelectChange(value) { this.simSelected = value; - console.log(this.simSelected); } /** @@ -364,14 +358,22 @@ export class SimulatorComponent implements OnInit, OnDestroy { showCode(ltiID) { const token = Login.getToken(); this.api.viewArduinoCode(ltiID, token).subscribe((v) => { - console.log(v['view']); - this.codeVisibility = v['view']; + if (!v['view']) { + for (const key in window['ArduinoUno_name']) { + if (window['ArduinoUno_name'][key]) { + window['ArduinoUno_name'][key].code = ''; + } + } + } }); } /** Function called when Start Simulation button is triggered */ StartSimulation() { this.disabled = true; + if (!this.graphToggle) { + this.graphToggle = !this.graphToggle; + } // Clears Output in Console Workspace.ClearConsole(); // prints the output in console @@ -722,7 +724,6 @@ export class SimulatorComponent implements OnInit, OnDestroy { * @param data any */ LoadProject(data: any) { - // console.log(data); this.projectTitle = data.project.name; this.description = data.project.description; this.title.setTitle(this.projectTitle + ' | Arduino On Cloud'); diff --git a/esim-cloud-backend/ltiAPI/models.py b/esim-cloud-backend/ltiAPI/models.py index babf726c1..ee85b1aa0 100644 --- a/esim-cloud-backend/ltiAPI/models.py +++ b/esim-cloud-backend/ltiAPI/models.py @@ -1,3 +1,4 @@ +from pyexpat import model from django.db import models from saveAPI.models import ArduinoModelSimulationData, StateSave from django.contrib.postgres.fields import ArrayField @@ -37,6 +38,7 @@ class ArduinLTIConsumer(models.Model): model_schematic = models.ForeignKey(to=StateSave, on_delete=models.CASCADE, related_name="arduino_model_schematic") score = models.FloatField(null=True, blank=True) + con_weightage = models.FloatField(null=False, default=60) initial_schematic = models.ForeignKey( to=StateSave, on_delete=models.SET_NULL, diff --git a/esim-cloud-backend/ltiAPI/process_submission.py b/esim-cloud-backend/ltiAPI/process_submission.py index 130f8ec11..89aeb6bf3 100644 --- a/esim-cloud-backend/ltiAPI/process_submission.py +++ b/esim-cloud-backend/ltiAPI/process_submission.py @@ -1,3 +1,7 @@ +import json +from wsgiref.util import request_uri + + def parseJSON(json): list = json['data'] results = {} @@ -74,3 +78,25 @@ def process_submission(expected_simulation, given_simulation, sim_params): len(comparison_result['missing']) score += len(comparison_result['same'])/total return score, comparison_result + + +def arduino_eval(original_data, student_data, con_weight, max_score): + original_data = original_data.replace("\'", "\"") + student_data = student_data.replace("\'", "\"") + original_data = json.loads(original_data) + student_data = json.loads(student_data) + key = list(original_data.keys())[0] + org_hexvals = list(original_data[key]['hexVals']) + st_hexvals = list(student_data[key]['hexVals']) + org_pins = list(original_data[key]['pinConnected']) + st_pins = list(student_data[key]['pinConnected']) + common_pins = list(set(org_pins).intersection(st_pins)) + con_weightage = (((len(common_pins)/len(org_pins)) * con_weight)/100) \ + * (max_score/100) + count = 0 + for i in range(int(len(org_hexvals))): + if st_hexvals[i] == org_hexvals[i]: + count += 1 + code_weightage = (((count/len(org_hexvals)) * (100-con_weight))/100) \ + * (max_score/100) + return round(con_weightage+code_weightage, 2) diff --git a/esim-cloud-backend/ltiAPI/serializers.py b/esim-cloud-backend/ltiAPI/serializers.py index 0d3589718..75c520b32 100644 --- a/esim-cloud-backend/ltiAPI/serializers.py +++ b/esim-cloud-backend/ltiAPI/serializers.py @@ -31,7 +31,7 @@ class Meta: model = ArduinLTIConsumer fields = ['consumer_key', 'secret_key', 'model_schematic', 'score', 'initial_schematic', 'test_case', 'scored', - 'id', 'view_code'] + 'id', 'view_code', 'con_weightage'] def create(self, validated_data): consumer = ArduinLTIConsumer.objects.create(**validated_data) @@ -58,7 +58,7 @@ class Meta: model = ArduinLTIConsumer fields = ['consumer_key', 'secret_key', 'model_schematic', 'score', 'initial_schematic', 'test_case', 'scored', - 'id', 'view_code'] + 'id', 'view_code', 'con_weightage'] def create(self, validated_data): pass @@ -94,6 +94,7 @@ class ArduinoConsumerResponseSerializer(serializers.Serializer): model_schematic = serializers.IntegerField() test_case = serializers.IntegerField(required=False, allow_null=True) scored = serializers.BooleanField() + con_weightage = serializers.FloatField(required=True, allow_null=False) class SessionSerializer(serializers.ModelSerializer): @@ -177,4 +178,3 @@ class Meta: fields = ["schematic", "student", "project", "score", "lms_success", "ltisession", "student_simulation"] - diff --git a/esim-cloud-backend/ltiAPI/views.py b/esim-cloud-backend/ltiAPI/views.py index 30b2df21e..77d64cabc 100644 --- a/esim-cloud-backend/ltiAPI/views.py +++ b/esim-cloud-backend/ltiAPI/views.py @@ -25,7 +25,7 @@ from django.shortcuts import render from pylti.common import LTIException, verify_request_common, post_message, \ generate_request_xml, LTIPostMessageException -from .process_submission import process_submission +from .process_submission import arduino_eval, process_submission def denied(r): @@ -94,7 +94,8 @@ def get(self, request, save_id): "test_case": consumer.test_case.id if consumer.test_case else None, "scored": consumer.scored, "id": consumer.id, - "view_code": consumer.view_code + "view_code": consumer.view_code, + "con_weightage": consumer.con_weightage # "sim_params": consumer.sim_params } return Response(response_data, @@ -218,7 +219,8 @@ def post(self, request): "test_case": serialized.data['test_case'], "scored": serialized.data['scored'], "id": serialized.data['id'], - "view_code": serialized.data['view_code'] + "view_code": serialized.data['view_code'], + "con_weightage": serialized.data['con_weightage'] } print("Recieved POST for LTI APP:", response_data) response_serializer = ArduinoConsumerResponseSerializer( @@ -329,7 +331,8 @@ def post(self, request): "test_case": serialized.data['test_case'], "scored": serialized.data['scored'], "id": consumer.id, - "view_code": serialized.data['view_code'] + "view_code": serialized.data['view_code'], + "con_weightage": serialized.data['con_weightage'] } return Response(response_data, status=status.HTTP_200_OK) else: @@ -627,7 +630,6 @@ def post(self, request): :return: True if post successful and score valid :exception: LTIPostMessageException if call failed """ - print(request.data) try: lti_session = ArduinoLTISession.objects.get( id=request.data["ltisession"]["id"]) @@ -648,11 +650,10 @@ def post(self, request): schematic.is_submission = True schematic.save() if(sim): - score = consumer.score - comparison_result = None + score = arduino_eval(consumer.test_case.result, sim.result, + consumer.con_weightage, consumer.score) else: - score = consumer.score - comparison_result = None + score = 0 submission_data = { "project": consumer, "student": schematic.owner, @@ -684,18 +685,14 @@ def post(self, request): response_data = { "message": msg, "score": score, - "given": sim.result if sim else None, - "comparison_result": comparison_result, - # "sim_params": consumer.sim_params, + "given": sim.result if sim else None } else: response_data = { "message": msg, "score": score, "expected": consumer.test_case.result, - "given": sim.result if sim else None, - "comparison_result": comparison_result, - # "sim_params": consumer.sim_params, + "given": sim.result if sim else None } return Response(data=response_data, status=status.HTTP_200_OK) diff --git a/esim-cloud-backend/saveAPI/admin.py b/esim-cloud-backend/saveAPI/admin.py index e1b0a1f40..7c644f65b 100644 --- a/esim-cloud-backend/saveAPI/admin.py +++ b/esim-cloud-backend/saveAPI/admin.py @@ -16,6 +16,7 @@ class ArduinoSimulation(admin.ModelAdmin): list_display = ('save_id', "result") list_filter = ('save_id', "result",) + @admin.register(Gallery) class GalleryCircuits(admin.ModelAdmin): list_display = ('name', 'image_tag', 'description', 'shared', 'is_arduino') diff --git a/esim-cloud-backend/simulationAPI/urls.py b/esim-cloud-backend/simulationAPI/urls.py index b0400c339..15612def7 100644 --- a/esim-cloud-backend/simulationAPI/urls.py +++ b/esim-cloud-backend/simulationAPI/urls.py @@ -17,7 +17,7 @@ path('history////', simulationAPI_views.SimulationResults.as_view(), name='schematic sim history'), - + path('history/lti////', simulationAPI_views.SimulationResultsForLTI.as_view(), name='schematic sim history for lti'), diff --git a/esim-cloud-backend/simulationAPI/views.py b/esim-cloud-backend/simulationAPI/views.py index 23705e5eb..9c4f7a67a 100644 --- a/esim-cloud-backend/simulationAPI/views.py +++ b/esim-cloud-backend/simulationAPI/views.py @@ -159,6 +159,7 @@ def get(self, request, save_id, sim, version, branch): serialized = simulationSerializer(sims, many=True) return Response(serialized.data, status=status.HTTP_200_OK) + class SimulationResultsForLTI(APIView): permission_classes = (IsAuthenticated, ) @@ -175,7 +176,6 @@ def get(self, request, save_id, sim, version, branch): return Response(serialized.data, status=status.HTTP_200_OK) - class SimulationResultsFromSimulator(APIView): permission_classes = (IsAuthenticated, ) From 7666431b1e5427bffbba3a9339f17bd0e1b3ddba Mon Sep 17 00:00:00 2001 From: deepampriyadarshi Date: Wed, 3 Aug 2022 17:33:04 +0530 Subject: [PATCH 02/33] Fixing Config URL error. --- ArduinoFrontend/src/app/lti-form/lti-form.component.ts | 1 + esim-cloud-backend/ltiAPI/serializers.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/ArduinoFrontend/src/app/lti-form/lti-form.component.ts b/ArduinoFrontend/src/app/lti-form/lti-form.component.ts index b83d9fd6f..33017d174 100644 --- a/ArduinoFrontend/src/app/lti-form/lti-form.component.ts +++ b/ArduinoFrontend/src/app/lti-form/lti-form.component.ts @@ -217,6 +217,7 @@ export class LTIFormComponent implements OnInit { this.getAllVersions(); this.getTestCases(); this.form.get('con_weightage').setValue(this.details.con_weightage); + this.form.get('code_weightage').setValue(this.details.code_weightage); } }); } diff --git a/esim-cloud-backend/ltiAPI/serializers.py b/esim-cloud-backend/ltiAPI/serializers.py index 75c520b32..898bb1942 100644 --- a/esim-cloud-backend/ltiAPI/serializers.py +++ b/esim-cloud-backend/ltiAPI/serializers.py @@ -82,6 +82,7 @@ class consumerResponseSerializer(serializers.Serializer): model_schematic = serializers.IntegerField() test_case = serializers.IntegerField(required=False, allow_null=True) scored = serializers.BooleanField() + class ArduinoConsumerResponseSerializer(serializers.Serializer): @@ -95,6 +96,7 @@ class ArduinoConsumerResponseSerializer(serializers.Serializer): test_case = serializers.IntegerField(required=False, allow_null=True) scored = serializers.BooleanField() con_weightage = serializers.FloatField(required=True, allow_null=False) + view_code = serializers.BooleanField(allow_null=False) class SessionSerializer(serializers.ModelSerializer): From 48425b6833bb11dcc84d31ff9fb538245d660fd8 Mon Sep 17 00:00:00 2001 From: deepampriyadarshi Date: Sun, 21 Aug 2022 18:07:57 +0530 Subject: [PATCH 03/33] UI Changes and Evaluation bug fix --- ArduinoFrontend/src/app/api.service.ts | 6 ++--- .../src/app/graphlist/graphlist.component.ts | 21 +++++++++------- .../src/app/lti-form/lti-form.component.html | 8 +++---- .../src/app/lti-form/lti-form.component.ts | 2 +- .../app/simulator/simulator.component.html | 1 + .../src/app/simulator/simulator.component.ts | 24 +++++++------------ .../ltiAPI/process_submission.py | 10 +++++--- esim-cloud-backend/ltiAPI/serializers.py | 1 - esim-cloud-backend/ltiAPI/views.py | 15 ++++++++---- 9 files changed, 47 insertions(+), 41 deletions(-) diff --git a/ArduinoFrontend/src/app/api.service.ts b/ArduinoFrontend/src/app/api.service.ts index 9713e1b3e..c557bf761 100644 --- a/ArduinoFrontend/src/app/api.service.ts +++ b/ArduinoFrontend/src/app/api.service.ts @@ -481,9 +481,7 @@ export class ApiService { }); } - getLTISimulationData(id, ltiId, token: string): Observable { - return this.http.get(`${this.url}api/lti/save/arduinodata/${id}/${ltiId}`, { - headers: this.httpHeaders(token), - }); + getLTISimulationData(id, ltiId): Observable { + return this.http.get(`${this.url}api/lti/save/arduinodata/${id}/${ltiId}`); } } diff --git a/ArduinoFrontend/src/app/graphlist/graphlist.component.ts b/ArduinoFrontend/src/app/graphlist/graphlist.component.ts index e778aa0f3..3ce1a4892 100644 --- a/ArduinoFrontend/src/app/graphlist/graphlist.component.ts +++ b/ArduinoFrontend/src/app/graphlist/graphlist.component.ts @@ -54,6 +54,7 @@ export class GraphlistComponent implements OnInit { this.simulationStatus = res; this.dataPoints = 0; this.hexData = []; + this.hexData.push(0); }); Workspace.simulationStopped.subscribe(res => { this.simulationStatus = res; @@ -93,7 +94,7 @@ export class GraphlistComponent implements OnInit { } }); GraphDataService.voltageChange.subscribe(res => { - if (this.arduinoList[0]['arduinoId'] === res.arduino.id) { + if (this.arduinoList[0]['arduinoId'] === res.arduino.id && this.hexData[this.hexData.length - 1] !== res.value) { this.hexData.push(res.value); this.dataPoints++; } @@ -127,15 +128,17 @@ export class GraphlistComponent implements OnInit { this.api.storeSimulationData(this.id, token, newData).subscribe(res => AlertService.showAlert('Record Saved Successfully') , err => AlertService.showAlert(err)); } else { + let ltiID; this.aroute.queryParams.subscribe(v => { - this.api.storeLTISimulationData(this.id, v.lti_id, token, newData).subscribe(res => { - AlertService.showAlert('Record Saved Successfully'); - this.simDataSave.emit(true); - } - , err => { - AlertService.showAlert(err); - this.simDataSave.emit(false); - }); + ltiID = v.lti_id; + }); + this.api.storeLTISimulationData(this.id, ltiID, token, newData).subscribe(res => { + AlertService.showAlert('Record Saved Successfully'); + this.simDataSave.emit(true); + } + , err => { + AlertService.showAlert(err); + this.simDataSave.emit(false); }); } } diff --git a/ArduinoFrontend/src/app/lti-form/lti-form.component.html b/ArduinoFrontend/src/app/lti-form/lti-form.component.html index b35e02c2a..c3d311e74 100644 --- a/ArduinoFrontend/src/app/lti-form/lti-form.component.html +++ b/ArduinoFrontend/src/app/lti-form/lti-form.component.html @@ -108,7 +108,7 @@
- + This field is mandatory Value should be between 0 and 100 @@ -116,10 +116,10 @@
- + This field is mandatory - Value should be between 0 and 100 + Value should be between 0 and 1
@@ -134,7 +134,7 @@
- +
diff --git a/ArduinoFrontend/src/app/lti-form/lti-form.component.ts b/ArduinoFrontend/src/app/lti-form/lti-form.component.ts index 33017d174..c54416329 100644 --- a/ArduinoFrontend/src/app/lti-form/lti-form.component.ts +++ b/ArduinoFrontend/src/app/lti-form/lti-form.component.ts @@ -138,7 +138,7 @@ export class LTIFormComponent implements OnInit { form: FormGroup = new FormGroup({ consumer_key: new FormControl('', [Validators.required, Validators.minLength(2)]), secret_key: new FormControl('', [Validators.required, Validators.minLength(2)]), - score: new FormControl(0, [Validators.required, Validators.min(0), Validators.max(100)]), + score: new FormControl(0, [Validators.required, Validators.min(0), Validators.max(1)]), con_weightage: new FormControl(60, [Validators.required, Validators.min(0), Validators.max(100)]), code_weightage: new FormControl(40), test_case: new FormControl(''), diff --git a/ArduinoFrontend/src/app/simulator/simulator.component.html b/ArduinoFrontend/src/app/simulator/simulator.component.html index 82ad117f6..8471ac4ea 100644 --- a/ArduinoFrontend/src/app/simulator/simulator.component.html +++ b/ArduinoFrontend/src/app/simulator/simulator.component.html @@ -229,6 +229,7 @@ + @@ -122,12 +122,12 @@
Value should be between 0 and 1
-
+
Accept Submissions
-
+
Show Code From 1992153a02e315fe6e165565fd27a6d19aec23ac Mon Sep 17 00:00:00 2001 From: deepampriyadarshi Date: Tue, 13 Sep 2022 02:06:33 +0530 Subject: [PATCH 06/33] Fixing lint errors --- ArduinoFrontend/src/app/graphlist/graphlist.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ArduinoFrontend/src/app/graphlist/graphlist.component.ts b/ArduinoFrontend/src/app/graphlist/graphlist.component.ts index 33b847bd9..e41828fd3 100644 --- a/ArduinoFrontend/src/app/graphlist/graphlist.component.ts +++ b/ArduinoFrontend/src/app/graphlist/graphlist.component.ts @@ -96,7 +96,7 @@ export class GraphlistComponent implements OnInit { } }); GraphDataService.voltageChange.subscribe(res => { - if (res.value === 0){ + if (res.value === 0) { this.initData = true; } if (this.arduinoList[0]['arduinoId'] === res.arduino.id && this.hexData[this.hexData.length - 1] !== res.value) { From 3b8617e50119e3b5bce71691f5930df626ea2231 Mon Sep 17 00:00:00 2001 From: SofiaChen2000 Date: Fri, 17 Feb 2023 11:44:33 +0530 Subject: [PATCH 07/33] Fix push button with LED not working issue --- .../src/app/Libs/inputs/Buttons.ts | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts b/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts index 4f5251a91..9afb37cd2 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts @@ -46,10 +46,10 @@ export class PushButton extends CircuitElement { } }); this.pinNamedMap['Terminal 2a'].addValueListener((v) => { - this.pinNamedMap['Terminal 2b'].setValue(v, null); + this.pinNamedMap['Terminal 2b'].setValue(v, null); }); this.pinNamedMap['Terminal 2b'].addValueListener((v) => { - this.pinNamedMap['Terminal 2a'].setValue(v, null); + this.pinNamedMap['Terminal 2a'].setValue(v, null); }); } /** @@ -72,13 +72,21 @@ export class PushButton extends CircuitElement { * Initialize Variable,callback and animation caller when start simulation is pressed */ initSimulation(): void { - - // Determine Arduino connected ends for all terminals of push button - this.terminalParent['terminal1a'] = BreadBoard.getRecArduinov2(this.pinNamedMap['Terminal 1a'], 'Terminal 1a'); - this.terminalParent['terminal1b'] = BreadBoard.getRecArduinov2(this.pinNamedMap['Terminal 1b'], 'Terminal 1b'); - this.terminalParent['terminal2a'] = BreadBoard.getRecArduinov2(this.pinNamedMap['Terminal 2a'], 'Terminal 2a'); - this.terminalParent['terminal2b'] = BreadBoard.getRecArduinov2(this.pinNamedMap['Terminal 2b'], 'Terminal 2b'); - + //Determine Arduino Connected ends for all terminals of push button + for (let i in this.pinNamedMap) { + if(this.pinNamedMap[i].connectedTo !== null){ + if(this.pinNamedMap[i].connectedTo.start.parent.keyName === 'ArduinoUno' || this.pinNamedMap[i].connectedTo.end.parent.keyName === 'ArduinoUno') { + this.terminalParent[i] = BreadBoard.getRecArduinov2(this.pinNamedMap[i], i); + } + else { + this.terminalParent[i] = BreadBoard.getRecArduinoBreadv2(this.pinNamedMap[i], i); + } + } + } + + const Dports = new RegExp('^D([2-9]|[1][0-3])$'); + const Aports = new RegExp('^A([0-5])$'); + // console.log(this.pinNamedMap['']) this.elements.unmousedown(); let iniValue = -1; @@ -86,10 +94,22 @@ export class PushButton extends CircuitElement { // create mousedown for the button this.elements[9].mousedown(() => { let val = -1; + let pullUp = false; + for (let i in this.terminalParent) { + // set value only if any pin have inputPullUpEnabled + if(this.terminalParent[i] !== undefined){ + pullUp = pullUp || this.terminalParent[i].pullUpEnabled; + } + } - // set value only if any pin have inputPullUpEnabled - const pullUp = this.terminalParent['terminal1a'].pullUpEnabled || this.terminalParent['terminal1b'].pullUpEnabled - || this.terminalParent['terminal2a'].pullUpEnabled || this.terminalParent['terminal2b'].pullUpEnabled; + for (let i in this.terminalParent){ + if(this.terminalParent[i] !== undefined){ + // set initial value to the pin which connects the digital pin on Arduino + if(Dports.test(this.terminalParent[i].label) || Aports.test(this.terminalParent[i].label)){ + iniValue = this.pinNamedMap[i].value; + } + } + } if (this.pinNamedMap['Terminal 1a'].value > 0) { val = this.pinNamedMap['Terminal 1a'].value; @@ -99,7 +119,6 @@ export class PushButton extends CircuitElement { val = 0; } by = 0; - iniValue = this.pinNamedMap['Terminal 2a'].value; // set value to other pins this.pinNamedMap['Terminal 2a'].setValue(val, null); this.pinNamedMap['Terminal 2b'].setValue(val, null); @@ -111,7 +130,6 @@ export class PushButton extends CircuitElement { val = 0; } by = 0; - iniValue = this.pinNamedMap['Terminal 2a'].value; // set value to other pins this.pinNamedMap['Terminal 2a'].setValue(val, null); this.pinNamedMap['Terminal 2b'].setValue(val, null); @@ -123,7 +141,6 @@ export class PushButton extends CircuitElement { val = 0; } by = 1; - iniValue = this.pinNamedMap['Terminal 1a'].value; // set value to other pins this.pinNamedMap['Terminal 1a'].setValue(val, null); this.pinNamedMap['Terminal 1b'].setValue(val, null); @@ -135,7 +152,6 @@ export class PushButton extends CircuitElement { val = 0; } by = 1; - iniValue = this.pinNamedMap['Terminal 1a'].value; // set value to other pins this.pinNamedMap['Terminal 1a'].setValue(val, null); this.pinNamedMap['Terminal 1b'].setValue(val, null); @@ -168,6 +184,7 @@ export class PushButton extends CircuitElement { this.elements.unmouseup(); this.elements.unmouseout(); this.setClickListener(null); + this.setDragListeners(); } } From 7af7781172e6a01268f6ba5ffa5e419af1cee2fd Mon Sep 17 00:00:00 2001 From: SofiaChen2000 Date: Fri, 17 Feb 2023 12:32:10 +0530 Subject: [PATCH 08/33] Linting Buttons.ts --- .../src/app/Libs/inputs/Buttons.ts | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts b/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts index 9afb37cd2..f4fcb1cb5 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts @@ -72,13 +72,13 @@ export class PushButton extends CircuitElement { * Initialize Variable,callback and animation caller when start simulation is pressed */ initSimulation(): void { - //Determine Arduino Connected ends for all terminals of push button - for (let i in this.pinNamedMap) { - if(this.pinNamedMap[i].connectedTo !== null){ - if(this.pinNamedMap[i].connectedTo.start.parent.keyName === 'ArduinoUno' || this.pinNamedMap[i].connectedTo.end.parent.keyName === 'ArduinoUno') { + // Determine Arduino Connected ends for all terminals of push button + for (const i in this.pinNamedMap) { + if (this.pinNamedMap[i].connectedTo !== null) { + if (this.pinNamedMap[i].connectedTo.start.parent.keyName === 'ArduinoUno' + || this.pinNamedMap[i].connectedTo.end.parent.keyName === 'ArduinoUno') { this.terminalParent[i] = BreadBoard.getRecArduinov2(this.pinNamedMap[i], i); - } - else { + } else { this.terminalParent[i] = BreadBoard.getRecArduinoBreadv2(this.pinNamedMap[i], i); } } @@ -95,17 +95,17 @@ export class PushButton extends CircuitElement { this.elements[9].mousedown(() => { let val = -1; let pullUp = false; - for (let i in this.terminalParent) { + for (const i in this.terminalParent) { // set value only if any pin have inputPullUpEnabled - if(this.terminalParent[i] !== undefined){ + if (this.terminalParent[i] !== undefined) { pullUp = pullUp || this.terminalParent[i].pullUpEnabled; } } - for (let i in this.terminalParent){ - if(this.terminalParent[i] !== undefined){ + for (const i in this.terminalParent) { + if (this.terminalParent[i] !== undefined) { // set initial value to the pin which connects the digital pin on Arduino - if(Dports.test(this.terminalParent[i].label) || Aports.test(this.terminalParent[i].label)){ + if (Dports.test(this.terminalParent[i].label) || Aports.test(this.terminalParent[i].label)) { iniValue = this.pinNamedMap[i].value; } } From 38055cf23ebed0346b26be3ed2ebce1c9fd27a12 Mon Sep 17 00:00:00 2001 From: SofiaChen2000 Date: Fri, 17 Feb 2023 12:35:12 +0530 Subject: [PATCH 09/33] Linting Buttons.ts --- ArduinoFrontend/src/app/Libs/inputs/Buttons.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts b/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts index f4fcb1cb5..b0f59ddcf 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts @@ -46,10 +46,10 @@ export class PushButton extends CircuitElement { } }); this.pinNamedMap['Terminal 2a'].addValueListener((v) => { - this.pinNamedMap['Terminal 2b'].setValue(v, null); + this.pinNamedMap['Terminal 2b'].setValue(v, null); }); this.pinNamedMap['Terminal 2b'].addValueListener((v) => { - this.pinNamedMap['Terminal 2a'].setValue(v, null); + this.pinNamedMap['Terminal 2a'].setValue(v, null); }); } /** From 2de66b46bd99bdbc72507e95996dbcdc263f6aed Mon Sep 17 00:00:00 2001 From: SofiaChen2000 Date: Fri, 17 Feb 2023 12:44:56 +0530 Subject: [PATCH 10/33] Linting Buttons.ts --- ArduinoFrontend/src/app/Libs/inputs/Buttons.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts b/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts index b0f59ddcf..8cf82f58d 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts @@ -75,7 +75,7 @@ export class PushButton extends CircuitElement { // Determine Arduino Connected ends for all terminals of push button for (const i in this.pinNamedMap) { if (this.pinNamedMap[i].connectedTo !== null) { - if (this.pinNamedMap[i].connectedTo.start.parent.keyName === 'ArduinoUno' + if (this.pinNamedMap[i].connectedTo.start.parent.keyName === 'ArduinoUno' || this.pinNamedMap[i].connectedTo.end.parent.keyName === 'ArduinoUno') { this.terminalParent[i] = BreadBoard.getRecArduinov2(this.pinNamedMap[i], i); } else { @@ -83,10 +83,8 @@ export class PushButton extends CircuitElement { } } } - const Dports = new RegExp('^D([2-9]|[1][0-3])$'); - const Aports = new RegExp('^A([0-5])$'); - + const Aports = new RegExp('^A([0-5])$'); // console.log(this.pinNamedMap['']) this.elements.unmousedown(); let iniValue = -1; From ac49e7f9dec4abe97cfcc074b43c596db5e7e563 Mon Sep 17 00:00:00 2001 From: Saimadhav Date: Tue, 7 Mar 2023 16:42:15 +0530 Subject: [PATCH 11/33] Fixed Breadboard drag issue --- ArduinoFrontend/src/app/Libs/General.ts | 156 +++++++++++++++--- ArduinoFrontend/src/app/Libs/Point.ts | 87 ++-------- ArduinoFrontend/src/assets/jsons/Buzzer.json | 3 +- .../src/assets/jsons/CoinCell.json | 3 +- ArduinoFrontend/src/assets/jsons/L293D.json | 3 +- ArduinoFrontend/src/assets/jsons/MQ2.json | 3 +- ArduinoFrontend/src/assets/jsons/Motor.json | 3 +- .../src/assets/jsons/PIRSensor.json | 3 +- .../src/assets/jsons/PhotoResistor.json | 3 +- .../src/assets/jsons/Potentiometer.json | 3 +- .../src/assets/jsons/PushButton.json | 3 +- ArduinoFrontend/src/assets/jsons/RGBLED.json | 3 +- ArduinoFrontend/src/assets/jsons/Relay.json | 3 +- .../src/assets/jsons/Resistor.json | 7 +- .../src/assets/jsons/SlideSwitch.json | 3 +- ArduinoFrontend/src/assets/jsons/TMP36.json | 3 +- .../src/assets/jsons/Thermistor.json | 3 +- .../src/assets/jsons/UltrasonicSensor.json | 3 +- 18 files changed, 184 insertions(+), 111 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/General.ts b/ArduinoFrontend/src/app/Libs/General.ts index 2d1be11ed..aaa4c0cc3 100644 --- a/ArduinoFrontend/src/app/Libs/General.ts +++ b/ArduinoFrontend/src/app/Libs/General.ts @@ -288,11 +288,6 @@ export class BreadBoard extends CircuitElement { */ static visitedNodesv2 = new Set(); - /** - * Stores group of points which are interconnected - */ - static groupings: any = []; - /** * Nodes that are connected */ @@ -585,10 +580,8 @@ export class BreadBoard extends CircuitElement { /** init is called when the component is complety drawn to the canvas */ init() { this.sortedNodes = _.sortBy(this.nodes, ['x', 'y']); - if (BreadBoard.groupings.length === 0) { - BreadBoard.groupings = this.data.groupings; - } + // initialise sameX and sameY node sets for (const node of this.nodes) { // create the set for x this.sameXNodes[node.x] = this.sameXNodes[node.x] || []; @@ -603,7 +596,17 @@ export class BreadBoard extends CircuitElement { for (const node of this.nodes) { node.connectCallback = (item) => { this.joined.push(item); + }; + node.disconnectCallback = (item) => { + let index = this.joined.indexOf(item); + + if (index > -1) { + this.joined.splice(index, 1); + } + + }; + } this.elements.toBack(); @@ -615,6 +618,10 @@ export class BreadBoard extends CircuitElement { let fdy = 0; let tmpar = []; let tmpar2 = []; + let ConnEleList = []; + let NodeList = []; + let tmpx2 = []; + let tmpy2 = []; // Create Custom Drag event this.elements.drag((dx, dy) => { this.elements.transform(`t${this.tx + dx},${this.ty + dy}`); @@ -625,6 +632,11 @@ export class BreadBoard extends CircuitElement { for (let i = 0; i < this.joined.length; ++i) { this.joined[i].move(tmpar[i][0] + dx, tmpar[i][1] + dy); } + for (let i = 0; i < ConnEleList.length; ++i) { + ConnEleList[i].dragAlong(NodeList[i],dx,dy) + tmpx2[i] = ConnEleList[i].tx + dx; + tmpy2[i] = ConnEleList[i].ty + dy; + } }, () => { fdx = 0; fdy = 0; @@ -637,10 +649,54 @@ export class BreadBoard extends CircuitElement { node.remainHidden(); } for (const node of this.joined) { + let ElementFlag = false; tmpar.push( [node.x, node.y] ); node.remainShow(); + if(node.connectedTo != null) + { + let ConnElement1 = node.connectedTo.start.parent; + let ConnElement2 = node.connectedTo.end.parent; + console.log(ConnElement1.keyName) + console.log(ConnElement2.keyName) + if(ConnElement1.keyName != "BreadBoard") + { + for(const ele of ConnEleList) + { + if( ele === ConnElement1) + { + ElementFlag = true; + break; + } + } + if(!ElementFlag && "isBreadBoardPlaceable" in ConnElement1.info.properties && ConnElement1.info.properties.isBreadBoardPlaceable == 1) + { + ConnEleList.push(ConnElement1); + tmpx2.push(0); + tmpy2.push(0); + NodeList.push(ConnElement1.getNodesCoord()); + } + } + else + { + for(const ele of ConnEleList) + { + if( ele === ConnElement1) + { + ElementFlag = true; + break; + } + } + if(!ElementFlag && "isBreadBoardPlaceable" in ConnElement2.info.properties && ConnElement2.info.properties.isBreadBoardPlaceable == 1) + { + ConnEleList.push(ConnElement2); + tmpx2.push(0); + tmpy2.push(0); + NodeList.push(ConnElement2.getNodesCoord()); + } + } + } } }, () => { @@ -651,9 +707,18 @@ export class BreadBoard extends CircuitElement { this.nodes[i].remainShow(); } tmpar2 = []; + this.tx = tmpx; this.ty = tmpy; // reBuild SameNodeObject after drag stop + for(let i = 0; i < ConnEleList.length; i++){ + ConnEleList[i].dragAlongStop(tmpx2[i],tmpy2[i]); + } + ConnEleList = []; + NodeList = []; + tmpx2 = []; + tmpy2 = []; + tmpar = []; this.reBuildSameNodes(); }); } @@ -670,7 +735,10 @@ export class BreadBoard extends CircuitElement { let tmpy = 0; let ffdx = 0; let ffdy = 0; - + let ConnEleList = []; + let NodeList = []; + let tmpx2 = []; + let tmpy2 = []; ffdx = 0; ffdy = 0; tmpar = []; @@ -686,6 +754,50 @@ export class BreadBoard extends CircuitElement { [node.x, node.y] ); node.remainShow(); + let ConnElement1 = node.connectedTo.start.parent; + let ConnElement2 = node.connectedTo.end.parent; + console.log(ConnElement1.keyName) + console.log(ConnElement2.keyName) + let ElementFlag = false; + if(ConnElement1.keyName != "BreadBoard") + { + + for(const ele of ConnEleList) + { + if( ele === ConnElement1) + { + ElementFlag = true; + break; + } + } + if(!ElementFlag && ConnElement1.info.properties.isBreadBoardPlaceable == 1) + { + ConnEleList.push(ConnElement1); + tmpx2.push(0); + tmpy2.push(0); + NodeList.push(ConnElement1.getNodesCoord()); + } + } + else + { + for(const ele of ConnEleList) + { + if( ele === ConnElement1) + { + ElementFlag = true; + break; + } + } + if(!ElementFlag && ConnElement2.info.properties.isBreadBoardPlaceable == 1) + { + ConnEleList.push(ConnElement2); + tmpx2.push(0); + tmpy2.push(0); + NodeList.push(ConnElement2.getNodesCoord()); + } + } + + } this.elements.transform(`t${this.tx + fdx},${this.ty + fdy}`); @@ -697,16 +809,30 @@ export class BreadBoard extends CircuitElement { this.joined[i].move(tmpar[i][0] + fdx, tmpar[i][1] + fdy); } + for (let i = 0; i < ConnEleList.length; ++i) { + ConnEleList[i].dragAlong(NodeList[i],fdx,fdy) + tmpx2[i] = ConnEleList[i].tx + fdx; + tmpy2[i] = ConnEleList[i].ty + fdy; + } for (let i = 0; i < this.nodes.length; ++i) { this.nodes[i].move(tmpar2[i][0] + ffdx, tmpar2[i][1] + ffdy); this.nodes[i].remainShow(); } + this.tx = tmpx; this.ty = tmpy; - + for(let i = 0; i < ConnEleList.length; i++){ + ConnEleList[i].dragAlongStop(tmpx2[i],tmpy2[i]); + } + ConnEleList = []; + NodeList = []; + tmpx2 = []; + tmpy2 = []; + tmpar = []; + this.reBuildSameNodes(); } - + /** * Function provides component details * @param keyName Unique Class name @@ -854,12 +980,4 @@ export class BreadBoard extends CircuitElement { BreadBoard.visitedNodesv2.clear(); } - /** - * Returns groupings - */ - getGroupings() { - const groups = _.cloneDeep(BreadBoard.groupings); - return groups; - } - } diff --git a/ArduinoFrontend/src/app/Libs/Point.ts b/ArduinoFrontend/src/app/Libs/Point.ts index 8ac06b7f8..d7c7b185a 100644 --- a/ArduinoFrontend/src/app/Libs/Point.ts +++ b/ArduinoFrontend/src/app/Libs/Point.ts @@ -2,8 +2,6 @@ import { Wire } from './Wire'; import { CircuitElement } from './CircuitElement'; import { isNull } from 'util'; import { BoundingBox } from './Geometry'; -import _ from 'lodash'; - /** * Declare window so that custom created function don't throw error @@ -62,6 +60,10 @@ export class Point { * Callback called when we connect wire. */ connectCallback: any = null; + /* + Callback called on disconnecting a wire. + */ + disconnectCallback: any = null; /** * The Value of the node */ @@ -121,46 +123,10 @@ export class Point { // Check if showBubbleBool is enabled if (Point.showBubbleBool) { // Check if callback is present if it is then call it - if (this.hoverCallback) { this.hoverCallback(this.x, this.y); } window.showBubble(this.label, evt.clientX, evt.clientY); - if (this.parent.keyName === 'BreadBoard') { - - let ref: any = {}; - - for (const obj of window.scope['BreadBoard']) { - if (obj.id === this.parent.id) { - ref = obj; - } - } - if (this.label === '+' || this.label === '-') { - for (const point of ref.sameYNodes[this.y]) { - if (this.id === point.id) { - this.highlight(); - } else { - point.outline(); - } - } - - } else { - const groups = ref.getGroupings(); - const index = groups.findIndex(prefix => prefix.includes(this.label.charAt(0))); - - for (const point of ref.sameXNodes[this.x]) { - if (point.label !== '+' && point.label !== '-') { - if (groups[index].includes(point.label.charAt(0))) { - if (this.id === point.id) { - this.highlight(); - } else { - point.outline(); - } - } - } - } - } - } } else { // TODO: Do not show node highligtht this.remainHidden(); @@ -171,34 +137,6 @@ export class Point { this.hoverCloseCallback(this.x, this.y); } window.hideBubble(); - - if (this.parent.keyName === 'BreadBoard') { - let ref: any = {}; - for (const obj of window.scope['BreadBoard']) { - if (obj.id === this.parent.id) { - ref = obj; - } - } - if (this.label === '+' || this.label === '-') { - for (const point of ref.sameYNodes[this.y]) { - if (this.id === point.id) { - this.undoHighlight(); - } else { - point.undoOutline(); - } - } - } else { - for (const point of ref.sameXNodes[this.x]) { - if (point.label !== '+' && point.label !== '-') { - if (this.id === point.id) { - this.undoHighlight(); - } else { - point.undoOutline(); - } - } - } - } - } // Show node highligtht this.remainShow(); }); @@ -273,6 +211,7 @@ export class Point { * Unsolders wire to the point */ unsolderWire() { + console.log("Removing2") const wire = this.connectedTo; if (wire) { this.setValue(-1, this); @@ -281,6 +220,10 @@ export class Point { this.soldered = false; const newClass = this.body.node.getAttribute('class').replace(' solder-highlight', ''); this.body.node.setAttribute('class', newClass); + + if (this.disconnectCallback) { + this.disconnectCallback(this); + } } connectWire(wire, pushToUndo = true) { @@ -340,16 +283,6 @@ export class Point { this.body.node.setAttribute('class', newClass); } - outline() { - const newClass = `${this.body.node.getAttribute('class')} outline`; - this.body.node.setAttribute('class', newClass); - } - - undoOutline() { - const newClass = this.body.node.getAttribute('class').replace(' outline', ''); - this.body.node.setAttribute('class', newClass); - } - /** * Change the Position of Node with relative to current position * @param dx change in x axis @@ -411,6 +344,7 @@ export class Point { * Disconnects the point to wire */ disconnect() { + console.log("Removing1") this.connectedTo = null; if (this.isSoldered()) { this.unsolderWire(); @@ -421,6 +355,7 @@ export class Point { * Remove Node from canvas */ remove() { + this.body.remove(); if (this.connectedTo) { this.connectedTo.remove(); diff --git a/ArduinoFrontend/src/assets/jsons/Buzzer.json b/ArduinoFrontend/src/assets/jsons/Buzzer.json index 6317371ee..3426ae373 100644 --- a/ArduinoFrontend/src/assets/jsons/Buzzer.json +++ b/ArduinoFrontend/src/assets/jsons/Buzzer.json @@ -57,7 +57,8 @@ "Minimum Voltage": "4V", "Maximum Voltage": "8V", "Maximum Current": "0.03A", - "Frequency": "2300Hz" + "Frequency": "2300Hz", + "isBreadBoardPlaceable" : 1 } } } diff --git a/ArduinoFrontend/src/assets/jsons/CoinCell.json b/ArduinoFrontend/src/assets/jsons/CoinCell.json index 1bd160acd..5c4a7c531 100644 --- a/ArduinoFrontend/src/assets/jsons/CoinCell.json +++ b/ArduinoFrontend/src/assets/jsons/CoinCell.json @@ -32,7 +32,8 @@ "description": "Coin cell batteries like CR2032 are generally used for small portable electronics devices such as wrist watches, pocket calculators, automobile key less entry transmitter and hearing aids. Typically they are of compact size, 5-25mm in diameter and 1-6mm in height. The name defines the size of the battery like for CR2032, the first two digits stands for diameter and second for height or thickness in tenths of mm.", "properties": { "Voltage - Rated": "3V", - "Capacity": "240mAh @ 190µA" + "Capacity": "240mAh @ 190µA", + "isBreadBoardPlaceable" : 1 } } } \ No newline at end of file diff --git a/ArduinoFrontend/src/assets/jsons/L293D.json b/ArduinoFrontend/src/assets/jsons/L293D.json index 03d61d29c..ea06e8b4e 100644 --- a/ArduinoFrontend/src/assets/jsons/L293D.json +++ b/ArduinoFrontend/src/assets/jsons/L293D.json @@ -116,7 +116,8 @@ "Operation temp. range": "0-70°C", "Max Power at t=90°C ": "4W", "Dimensions": "19.8 x 9.14 ", - "Weight": "20g" + "Weight": "20g", + "isBreadBoardPlaceable" : 1 } } } \ No newline at end of file diff --git a/ArduinoFrontend/src/assets/jsons/MQ2.json b/ArduinoFrontend/src/assets/jsons/MQ2.json index 98a083adb..567133096 100644 --- a/ArduinoFrontend/src/assets/jsons/MQ2.json +++ b/ArduinoFrontend/src/assets/jsons/MQ2.json @@ -55,7 +55,8 @@ "Preheat duration": "20 seconds", "Measuring angle covered": "<15°", "power consumption ": "65mA", - "Operating Temperature": "-20° to +80° Celsius" + "Operating Temperature": "-20° to +80° Celsius", + "isBreadBoardPlaceable" : 1 } } } diff --git a/ArduinoFrontend/src/assets/jsons/Motor.json b/ArduinoFrontend/src/assets/jsons/Motor.json index 63e877141..664278f8a 100644 --- a/ArduinoFrontend/src/assets/jsons/Motor.json +++ b/ArduinoFrontend/src/assets/jsons/Motor.json @@ -46,7 +46,8 @@ "Loaded current": "250mA (approx)", "Rated Load": "10g*cm", "Motor Size": "27.5mm x 20mm x 15mm", - "Weight": "17 grams" + "Weight": "17 grams", + "isBreadBoardPlaceable" : 1 } } } diff --git a/ArduinoFrontend/src/assets/jsons/PIRSensor.json b/ArduinoFrontend/src/assets/jsons/PIRSensor.json index 516c39f4e..06886ffd6 100644 --- a/ArduinoFrontend/src/assets/jsons/PIRSensor.json +++ b/ArduinoFrontend/src/assets/jsons/PIRSensor.json @@ -106,7 +106,8 @@ "Covers Distance": "120° and 7 meters", "Measuring angle covered": "<15°", "power consumption ": "65mA", - "Operating Temperature": "-20° to +80° Celsius" + "Operating Temperature": "-20° to +80° Celsius", + "isBreadBoardPlaceable" : 1 } } } diff --git a/ArduinoFrontend/src/assets/jsons/PhotoResistor.json b/ArduinoFrontend/src/assets/jsons/PhotoResistor.json index 80e164c00..ead9db83c 100644 --- a/ArduinoFrontend/src/assets/jsons/PhotoResistor.json +++ b/ArduinoFrontend/src/assets/jsons/PhotoResistor.json @@ -42,7 +42,8 @@ "Max. resistance @ 10lux": "4.5kΩ(@ 10lux)", "Typ. resistance @ 100lux": "0.7kΩ(@ 100lux)", "Dark resistance after 1 sec ": "0.03MΩ", - "Dark resistance after 5 sec": "0.25MΩ" + "Dark resistance after 5 sec": "0.25MΩ", + "isBreadBoardPlaceable" : 1 } } } \ No newline at end of file diff --git a/ArduinoFrontend/src/assets/jsons/Potentiometer.json b/ArduinoFrontend/src/assets/jsons/Potentiometer.json index 0b715aa6e..c82773d80 100644 --- a/ArduinoFrontend/src/assets/jsons/Potentiometer.json +++ b/ArduinoFrontend/src/assets/jsons/Potentiometer.json @@ -80,7 +80,8 @@ "Peak wavelength": "600nm", "Power Rating": "0.3W", "Maximum Input Voltage": "200Vdc", - "Rotational Life": " 2000K cycles" + "Rotational Life": " 2000K cycles", + "isBreadBoardPlaceable" : 1 } } } \ No newline at end of file diff --git a/ArduinoFrontend/src/assets/jsons/PushButton.json b/ArduinoFrontend/src/assets/jsons/PushButton.json index cb677b236..03f7b0c44 100644 --- a/ArduinoFrontend/src/assets/jsons/PushButton.json +++ b/ArduinoFrontend/src/assets/jsons/PushButton.json @@ -129,7 +129,8 @@ "Operating Force": "2.55±0.69 N", "Contact Resistance": "MAX 100 mOhm", "Operating Temperature Range": " -20 to +70 ℃", - "Storage Temperature Range": "-20 to +70 ℃" + "Storage Temperature Range": "-20 to +70 ℃", + "isBreadBoardPlaceable" : 1 } } } \ No newline at end of file diff --git a/ArduinoFrontend/src/assets/jsons/RGBLED.json b/ArduinoFrontend/src/assets/jsons/RGBLED.json index eb756d5cb..1f06a07ec 100644 --- a/ArduinoFrontend/src/assets/jsons/RGBLED.json +++ b/ArduinoFrontend/src/assets/jsons/RGBLED.json @@ -49,7 +49,8 @@ "Size": "5mm LED RGB - Common Cathode", "Lens Type": "Diffused", "Emitting Color": "Red, Green and Blue", - "Voltage Rated": "3V-5V" + "Voltage Rated": "3V-5V", + "isBreadBoardPlaceable" : 1 } } } diff --git a/ArduinoFrontend/src/assets/jsons/Relay.json b/ArduinoFrontend/src/assets/jsons/Relay.json index f098b66aa..ad220de28 100644 --- a/ArduinoFrontend/src/assets/jsons/Relay.json +++ b/ArduinoFrontend/src/assets/jsons/Relay.json @@ -54,7 +54,8 @@ "channel": "4", "Rated through-current": "10A (NO) 5A (NC)", "Control signal": "TTL level", - "Max. switching current": "10A" + "Max. switching current": "10A", + "isBreadBoardPlaceable" : 1 } } } \ No newline at end of file diff --git a/ArduinoFrontend/src/assets/jsons/Resistor.json b/ArduinoFrontend/src/assets/jsons/Resistor.json index 369720633..f3ac4fcdb 100644 --- a/ArduinoFrontend/src/assets/jsons/Resistor.json +++ b/ArduinoFrontend/src/assets/jsons/Resistor.json @@ -97,6 +97,11 @@ 1000, 1000000, 1000000000 - ] + ], + "info" : { + "properties" : { + "isBreadBoardPlaceable" : 1 + } + } } } diff --git a/ArduinoFrontend/src/assets/jsons/SlideSwitch.json b/ArduinoFrontend/src/assets/jsons/SlideSwitch.json index 34c272f78..9e883df93 100644 --- a/ArduinoFrontend/src/assets/jsons/SlideSwitch.json +++ b/ArduinoFrontend/src/assets/jsons/SlideSwitch.json @@ -53,7 +53,8 @@ "Mechanical life": " minimum 5000 operations", "Contacts": "phosphor bronze, silver-plated", "Terminals": "brass silver-plated", - "Contact timing": "non-shorting" + "Contact timing": "non-shorting", + "isBreadBoardPlaceable" : 1 } } } \ No newline at end of file diff --git a/ArduinoFrontend/src/assets/jsons/TMP36.json b/ArduinoFrontend/src/assets/jsons/TMP36.json index 848536634..2f96017a1 100644 --- a/ArduinoFrontend/src/assets/jsons/TMP36.json +++ b/ArduinoFrontend/src/assets/jsons/TMP36.json @@ -45,7 +45,8 @@ "Output voltage ": "750mV/25°C", "Accuracy": "±2°C ", "Supply Current": "less than 50uA", - "Shutdown current": "0.5 µA max" + "Shutdown current": "0.5 µA max", + "isBreadBoardPlaceable" : 1 } } } diff --git a/ArduinoFrontend/src/assets/jsons/Thermistor.json b/ArduinoFrontend/src/assets/jsons/Thermistor.json index c121689ef..f4792e371 100644 --- a/ArduinoFrontend/src/assets/jsons/Thermistor.json +++ b/ArduinoFrontend/src/assets/jsons/Thermistor.json @@ -33,7 +33,8 @@ "properties": { "Minimum Temprature": "0 degree C", "Maximum Temprature": "1000 degree C", - "Voltage Range": "0V-6V" + "Voltage Range": "0V-6V", + "isBreadBoardPlaceable" : 1 }, "innerHTMLContent": "

Formula:

Beta: ß = ln(R1/R2)/((1/T1)-(1/T2))
Internal Resistance: Rt = 10000 * eß*( (1/T1)-(1/T2) )
Voltage Out: Vout = (Rs / (Rs + Rt)) * Vin

References

Thermistors - NTC & PTC: Video
Voltage out formula: Document

Resistance vs Temprature chart

" } diff --git a/ArduinoFrontend/src/assets/jsons/UltrasonicSensor.json b/ArduinoFrontend/src/assets/jsons/UltrasonicSensor.json index 7aeb3f52a..13f1f3b03 100644 --- a/ArduinoFrontend/src/assets/jsons/UltrasonicSensor.json +++ b/ArduinoFrontend/src/assets/jsons/UltrasonicSensor.json @@ -47,7 +47,8 @@ "Accuracy": "3mm", "Measuring angle covered": "<15°", "Operating Current": "<15mA", - "Operating Frequency": "40Hz" + "Operating Frequency": "40Hz", + "isBreadBoardPlaceable" : 1 } } } \ No newline at end of file From 59900e79c6b171d4cbb7c5cf733c2b3efad3c15f Mon Sep 17 00:00:00 2001 From: Saimadhav Date: Tue, 7 Mar 2023 17:17:28 +0530 Subject: [PATCH 12/33] Missed Changes --- .../src/app/Libs/CircuitElement.ts | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/ArduinoFrontend/src/app/Libs/CircuitElement.ts b/ArduinoFrontend/src/app/Libs/CircuitElement.ts index 606a01fdb..8d639d4a9 100644 --- a/ArduinoFrontend/src/app/Libs/CircuitElement.ts +++ b/ArduinoFrontend/src/app/Libs/CircuitElement.ts @@ -282,11 +282,13 @@ export abstract class CircuitElement { */ setDragListeners() { // let tmpx = 0; + console.log("I'm inside drag listener") // let tmpy = 0; let fdx = 0; let fdy = 0; let tmpar = []; this.elements.drag((dx, dy) => { + this.elements.transform(`t${this.tx + dx},${this.ty + dy}`); // tmpx = this.tx + dx; // tmpy = this.ty + dy; @@ -450,6 +452,56 @@ export abstract class CircuitElement { * Return the Name of the component.Can be inheriter to return custom name. */ getName() { return this.title; } + /** + * Function to move/transform an element + * @param fdx relative x position to move + * @param fdy relative y position to move + */ + getNodesCoord() : number[] { + let tmpar = []; + for(let i = 0; i < this.nodes.length; i++) + { + tmpar.push( + [this.nodes[i].x, this.nodes[i].y] + ); + } + return tmpar; + } + + dragAlong(tmpar: any, fdx: number, fdy: number): any { + + this.elements.transform(`t${this.tx + fdx},${this.ty + fdy}`); + + for (const node of this.nodes) { + tmpar.push( + [node.x, node.y] + ); + } + for (let i = 0; i < this.nodes.length; ++i) { + this.nodes[i].move(tmpar[i][0] + fdx, tmpar[i][1] + fdy); + } + /* + this.elements.transform(`t${this.tx + dx},${this.ty + dy}`); + tmpx2[i] = this.tx + dx; + tmpy2[i] = this.ty + dy; + //16 nodes per LCD panel + for (let j = 16 * i; j < ConnElementsArr[i].nodes.length + (16 * i); ++j) { + ConnElementsArr[i].nodes[j].move(NodeList[j][0] + dx, NodeList[j][1] + dy); + } + console.log("Before Simulating - I") + console.log("X : " , ConnElementsArr[i].data.startX , "Y : " ,ConnElementsArr[i].data.startY) + //ConnElementsArr[i].data.startX = PanelCoord[0][0] + dx; + //ConnElementsArr[i].data.startY = PanelCoord[0][1] + dy; + console.log("Before Simulating - II")*/ + + } + dragAlongStop(x : number,y : number) : void { + //UndoUtils.pushChangeToUndoAndReset({ keyName: this.keyName, element: this.save(), event: 'drag', dragJson: { dx: (x - this.tx) , dy: (y - this.ty) } }); + this.tx = x; + this.ty = y; + + } + /** * Function to move/transform an element From bd14b227a1cf544204d9cbe4e13831745abf2f09 Mon Sep 17 00:00:00 2001 From: Saimadhav Date: Tue, 7 Mar 2023 17:42:25 +0530 Subject: [PATCH 13/33] More missing changes --- ArduinoFrontend/src/app/Libs/UndoUtils.ts | 10 +++++++++- ArduinoFrontend/src/app/Libs/outputs/Display.ts | 4 +++- ArduinoFrontend/src/assets/jsons/Arduino.json | 3 ++- ArduinoFrontend/src/assets/jsons/Breadboard.json | 7 ++++--- ArduinoFrontend/src/assets/jsons/LCD16X2.json | 3 ++- ArduinoFrontend/src/assets/jsons/LED.json | 3 ++- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/UndoUtils.ts b/ArduinoFrontend/src/app/Libs/UndoUtils.ts index 82d75d84b..88a9d55b3 100644 --- a/ArduinoFrontend/src/app/Libs/UndoUtils.ts +++ b/ArduinoFrontend/src/app/Libs/UndoUtils.ts @@ -35,6 +35,7 @@ export abstract class UndoUtils { * Call this function to Undo */ static workspaceUndo() { + console.log("Workspace undo") if (this.undo.length > 0) { const cng = this.undo.pop(); this.loadChange(cng, 'undo'); @@ -127,10 +128,12 @@ export abstract class UndoUtils { * @param operation undo/redo */ static async loadChange(ele, operation) { + console.log("LoadChange") // All elements in window.scope with similar const grup = window.scope[ele.keyName]; // Check if dragJson is present, & jump to next operation if both dx & dy are 0 + //Which case is this?? if (ele.dragJson) { if (ele.dragJson.dx === 0 && ele.dragJson.dy === 0) { if (operation === 'undo') { @@ -280,16 +283,21 @@ export abstract class UndoUtils { const existing = this.getExistingWindowElement(grup, ele); if (operation === 'undo') { if (ele.keyName === 'BreadBoard') { + console.log("BreadBoard specific drag") existing.transformBoardPosition(-ele.dragJson.dx, -ele.dragJson.dy); } else { existing.transformPosition(-ele.dragJson.dx, -ele.dragJson.dy); } } else { - existing.transformPosition(ele.dragJson.dx, ele.dragJson.dy); + if (ele.keyName !== 'BreadBoard') { + existing.transformPosition(ele.dragJson.dx, ele.dragJson.dy); Workspace.onDragEvent(existing); Workspace.onDragStopEvent(existing); } + else { + existing.transformBoardPosition(ele.dragJson.dx, ele.dragJson.dy); + } } for (const ec in window.scope['wires']) { if (window.scope['wires'].hasOwnProperty(ec)) { diff --git a/ArduinoFrontend/src/app/Libs/outputs/Display.ts b/ArduinoFrontend/src/app/Libs/outputs/Display.ts index 5ac3308ba..011653849 100644 --- a/ArduinoFrontend/src/app/Libs/outputs/Display.ts +++ b/ArduinoFrontend/src/app/Libs/outputs/Display.ts @@ -613,7 +613,7 @@ export class LCD16X2 extends CircuitElement { const posX = this.data.startX; const posY = this.data.startY; - + // Getting the number of pixel/panel rows, columns from the active data display state const gridRows = this.dataDisplayState.getPixelRows(); const gridColumns = this.dataDisplayState.getPixelColumns(); @@ -696,6 +696,8 @@ export class LCD16X2 extends CircuitElement { const isConnectedRowInFirstBlock = connectedRow <= 101; // checking for all the nodes with the same x-coordinate + console.log(breadboard.sameXNodes) + console.log(connectedPin.x) for (const neighbor of breadboard.sameXNodes[connectedPin.x]) { const neighborRow = neighbor.label.charCodeAt(0); const isSameBlock = neighborRow <= 101 === isConnectedRowInFirstBlock; diff --git a/ArduinoFrontend/src/assets/jsons/Arduino.json b/ArduinoFrontend/src/assets/jsons/Arduino.json index 8ce57d018..61d1a182f 100644 --- a/ArduinoFrontend/src/assets/jsons/Arduino.json +++ b/ArduinoFrontend/src/assets/jsons/Arduino.json @@ -191,7 +191,8 @@ "SRAM": "2KB(ATmega328)", "Clock Speed": "16MHz", "EEPROM": "1 KB (ATmega328)", - "LED": "Inbuilt" + "LED": "Inbuilt", + "isBreadBoardPlaceable" : 0 } } } diff --git a/ArduinoFrontend/src/assets/jsons/Breadboard.json b/ArduinoFrontend/src/assets/jsons/Breadboard.json index 20a551524..06013061f 100644 --- a/ArduinoFrontend/src/assets/jsons/Breadboard.json +++ b/ArduinoFrontend/src/assets/jsons/Breadboard.json @@ -2015,8 +2015,9 @@ } ], "simulation": {}, - "info": {}, - "data" : { - "groupings" : [["a","b","c","d","e"],["f","g","h","i","j"]] + "info": { + "properties" : { + "isBreadBoardPlaceable" : 0 + } } } diff --git a/ArduinoFrontend/src/assets/jsons/LCD16X2.json b/ArduinoFrontend/src/assets/jsons/LCD16X2.json index e6d4d0b19..a912cda61 100644 --- a/ArduinoFrontend/src/assets/jsons/LCD16X2.json +++ b/ArduinoFrontend/src/assets/jsons/LCD16X2.json @@ -117,7 +117,8 @@ "Operating Voltage": "4.7V to 5.3V", "Current consumption": "1mA (without backlight)", "Work Mode": " 8-bit and 4-bit mode", - "Voltage Rated": "3V-5V" + "Voltage Rated": "3V-5V", + "isBreadBoardPlaceable" : 1 } } } \ No newline at end of file diff --git a/ArduinoFrontend/src/assets/jsons/LED.json b/ArduinoFrontend/src/assets/jsons/LED.json index bca62ba94..a0d3a0e7f 100644 --- a/ArduinoFrontend/src/assets/jsons/LED.json +++ b/ArduinoFrontend/src/assets/jsons/LED.json @@ -70,7 +70,8 @@ "description": "A light-emitting diode (LED) is a semiconductor light source that emits light when current flows through it.", "properties": { "Light Color": "White, Yellow, Red, Green & Blue", - "Voltage ": "DC 3V - 5V" + "Voltage ": "DC 3V - 5V", + "isBreadBoardPlaceable" : 1 } } } \ No newline at end of file From 1137ee3753ae6afc1d086644c57eaf9f4ab9be31 Mon Sep 17 00:00:00 2001 From: Saimadhav Date: Wed, 8 Mar 2023 20:10:09 +0530 Subject: [PATCH 14/33] Resistor drag along board fix --- ArduinoFrontend/src/assets/jsons/Resistor.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ArduinoFrontend/src/assets/jsons/Resistor.json b/ArduinoFrontend/src/assets/jsons/Resistor.json index f3ac4fcdb..77fd0cc15 100644 --- a/ArduinoFrontend/src/assets/jsons/Resistor.json +++ b/ArduinoFrontend/src/assets/jsons/Resistor.json @@ -97,11 +97,11 @@ 1000, 1000000, 1000000000 - ], - "info" : { + ] + }, + "info" : { "properties" : { "isBreadBoardPlaceable" : 1 } - } } } From 1e781b2c2224b66c465c7077eda81c2c490934db Mon Sep 17 00:00:00 2001 From: Saimadhav Date: Wed, 8 Mar 2023 20:41:58 +0530 Subject: [PATCH 15/33] Servo / SevenSegment identified breadboard placeable --- ArduinoFrontend/src/assets/jsons/ServoMotor.json | 3 ++- ArduinoFrontend/src/assets/jsons/SevenSegment.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ArduinoFrontend/src/assets/jsons/ServoMotor.json b/ArduinoFrontend/src/assets/jsons/ServoMotor.json index 90102cce5..90f013a13 100644 --- a/ArduinoFrontend/src/assets/jsons/ServoMotor.json +++ b/ArduinoFrontend/src/assets/jsons/ServoMotor.json @@ -49,7 +49,8 @@ "Torque ": "1.80/4.8V(Kg-cm)", "Size ": "23.1mm x 12.2mm x 29mm", "Pulse Width": "500-2400 µs", - "Rotation Angle": "180 degree" + "Rotation Angle": "180 degree", + "isBreadBoardPlaceable" : 1 } } } diff --git a/ArduinoFrontend/src/assets/jsons/SevenSegment.json b/ArduinoFrontend/src/assets/jsons/SevenSegment.json index 02a415b5d..ba14c2e52 100644 --- a/ArduinoFrontend/src/assets/jsons/SevenSegment.json +++ b/ArduinoFrontend/src/assets/jsons/SevenSegment.json @@ -377,7 +377,8 @@ "sizes": "9.14mm,14.20mm,20.40mm,38.10mm,57.0mm and 100mm (Commonly used/available size is 14.20mm)", "Current consumption": "30mA / segment", "Peak current ": "70mA", - "Voltage Rated": "3V-5V" + "Voltage Rated": "3V-5V", + "isBreadBoardPlaceable" : 1 } } } \ No newline at end of file From 720f8728e3e17360b8c7dc4ec22c8bd88ff72f11 Mon Sep 17 00:00:00 2001 From: Saimadhav Date: Thu, 9 Mar 2023 17:12:14 +0530 Subject: [PATCH 16/33] Code Linting --- .../src/app/Libs/CircuitElement.ts | 35 +--- ArduinoFrontend/src/app/Libs/General.ts | 158 ++++++++---------- 2 files changed, 75 insertions(+), 118 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/CircuitElement.ts b/ArduinoFrontend/src/app/Libs/CircuitElement.ts index 8d639d4a9..d7989946b 100644 --- a/ArduinoFrontend/src/app/Libs/CircuitElement.ts +++ b/ArduinoFrontend/src/app/Libs/CircuitElement.ts @@ -281,9 +281,7 @@ export abstract class CircuitElement { * Add Drag listener to the components */ setDragListeners() { - // let tmpx = 0; - console.log("I'm inside drag listener") - // let tmpy = 0; + let fdx = 0; let fdy = 0; let tmpar = []; @@ -457,21 +455,18 @@ export abstract class CircuitElement { * @param fdx relative x position to move * @param fdy relative y position to move */ - getNodesCoord() : number[] { - let tmpar = []; - for(let i = 0; i < this.nodes.length; i++) - { + getNodesCoord(): number[] { + const tmpar = []; + for (const node of this.nodes) { tmpar.push( - [this.nodes[i].x, this.nodes[i].y] + [node.x, node.y] ); } return tmpar; } - dragAlong(tmpar: any, fdx: number, fdy: number): any { - + dragAlong(tmpar: any, fdx: number, fdy: number): any { this.elements.transform(`t${this.tx + fdx},${this.ty + fdy}`); - for (const node of this.nodes) { tmpar.push( [node.x, node.y] @@ -480,26 +475,10 @@ export abstract class CircuitElement { for (let i = 0; i < this.nodes.length; ++i) { this.nodes[i].move(tmpar[i][0] + fdx, tmpar[i][1] + fdy); } - /* - this.elements.transform(`t${this.tx + dx},${this.ty + dy}`); - tmpx2[i] = this.tx + dx; - tmpy2[i] = this.ty + dy; - //16 nodes per LCD panel - for (let j = 16 * i; j < ConnElementsArr[i].nodes.length + (16 * i); ++j) { - ConnElementsArr[i].nodes[j].move(NodeList[j][0] + dx, NodeList[j][1] + dy); - } - console.log("Before Simulating - I") - console.log("X : " , ConnElementsArr[i].data.startX , "Y : " ,ConnElementsArr[i].data.startY) - //ConnElementsArr[i].data.startX = PanelCoord[0][0] + dx; - //ConnElementsArr[i].data.startY = PanelCoord[0][1] + dy; - console.log("Before Simulating - II")*/ - } - dragAlongStop(x : number,y : number) : void { - //UndoUtils.pushChangeToUndoAndReset({ keyName: this.keyName, element: this.save(), event: 'drag', dragJson: { dx: (x - this.tx) , dy: (y - this.ty) } }); + dragAlongStop(x: number, y: number): void { this.tx = x; this.ty = y; - } diff --git a/ArduinoFrontend/src/app/Libs/General.ts b/ArduinoFrontend/src/app/Libs/General.ts index aaa4c0cc3..dfb21c16a 100644 --- a/ArduinoFrontend/src/app/Libs/General.ts +++ b/ArduinoFrontend/src/app/Libs/General.ts @@ -596,20 +596,15 @@ export class BreadBoard extends CircuitElement { for (const node of this.nodes) { node.connectCallback = (item) => { this.joined.push(item); - }; node.disconnectCallback = (item) => { - let index = this.joined.indexOf(item); - + const index = this.joined.indexOf(item); if (index > -1) { this.joined.splice(index, 1); } - }; - } this.elements.toBack(); - // Remove the drag event this.elements.undrag(); let tmpx = 0; @@ -633,7 +628,7 @@ export class BreadBoard extends CircuitElement { this.joined[i].move(tmpar[i][0] + dx, tmpar[i][1] + dy); } for (let i = 0; i < ConnEleList.length; ++i) { - ConnEleList[i].dragAlong(NodeList[i],dx,dy) + ConnEleList[i].dragAlong(NodeList[i], dx, dy); tmpx2[i] = ConnEleList[i].tx + dx; tmpy2[i] = ConnEleList[i].ty + dy; } @@ -654,49 +649,40 @@ export class BreadBoard extends CircuitElement { [node.x, node.y] ); node.remainShow(); - if(node.connectedTo != null) - { - let ConnElement1 = node.connectedTo.start.parent; - let ConnElement2 = node.connectedTo.end.parent; - console.log(ConnElement1.keyName) - console.log(ConnElement2.keyName) - if(ConnElement1.keyName != "BreadBoard") - { - for(const ele of ConnEleList) - { - if( ele === ConnElement1) - { - ElementFlag = true; - break; + if (node.connectedTo != null) { + const ConnElement1 = node.connectedTo.start.parent; + const ConnElement2 = node.connectedTo.end.parent; + console.log(ConnElement1.keyName); + console.log(ConnElement2.keyName); + if (ConnElement1.keyName !== 'BreadBoard') { + for (const ele of ConnEleList) { + if (ele === ConnElement1) { + ElementFlag = true; + break; + } } - } - if(!ElementFlag && "isBreadBoardPlaceable" in ConnElement1.info.properties && ConnElement1.info.properties.isBreadBoardPlaceable == 1) - { - ConnEleList.push(ConnElement1); - tmpx2.push(0); - tmpy2.push(0); - NodeList.push(ConnElement1.getNodesCoord()); - } - } - else - { - for(const ele of ConnEleList) - { - if( ele === ConnElement1) - { - ElementFlag = true; - break; + if (!ElementFlag && 'isBreadBoardPlaceable' in ConnElement1.info.properties && ConnElement1.info.properties.isBreadBoardPlaceable === 1) { + ConnEleList.push(ConnElement1); + tmpx2.push(0); + tmpy2.push(0); + NodeList.push(ConnElement1.getNodesCoord()); } } - if(!ElementFlag && "isBreadBoardPlaceable" in ConnElement2.info.properties && ConnElement2.info.properties.isBreadBoardPlaceable == 1) - { - ConnEleList.push(ConnElement2); - tmpx2.push(0); - tmpy2.push(0); - NodeList.push(ConnElement2.getNodesCoord()); + else { + for (const ele of ConnEleList) { + if (ele === ConnElement1) { + ElementFlag = true; + break; + } + } + if (!ElementFlag && "isBreadBoardPlaceable" in ConnElement2.info.properties && ConnElement2.info.properties.isBreadBoardPlaceable == 1) { + ConnEleList.push(ConnElement2); + tmpx2.push(0); + tmpy2.push(0); + NodeList.push(ConnElement2.getNodesCoord()); + } } } - } } }, () => { @@ -707,12 +693,12 @@ export class BreadBoard extends CircuitElement { this.nodes[i].remainShow(); } tmpar2 = []; - + this.tx = tmpx; this.ty = tmpy; // reBuild SameNodeObject after drag stop - for(let i = 0; i < ConnEleList.length; i++){ - ConnEleList[i].dragAlongStop(tmpx2[i],tmpy2[i]); + for (let i = 0; i < ConnEleList.length; i++) { + ConnEleList[i].dragAlongStop(tmpx2[i], tmpy2[i]); } ConnEleList = []; NodeList = []; @@ -755,49 +741,41 @@ export class BreadBoard extends CircuitElement { ); node.remainShow(); let ConnElement1 = node.connectedTo.start.parent; - let ConnElement2 = node.connectedTo.end.parent; - console.log(ConnElement1.keyName) - console.log(ConnElement2.keyName) - let ElementFlag = false; - if(ConnElement1.keyName != "BreadBoard") - { - - for(const ele of ConnEleList) - { - if( ele === ConnElement1) - { - ElementFlag = true; - break; - } - } - if(!ElementFlag && ConnElement1.info.properties.isBreadBoardPlaceable == 1) - { - ConnEleList.push(ConnElement1); - tmpx2.push(0); - tmpy2.push(0); - NodeList.push(ConnElement1.getNodesCoord()); + let ConnElement2 = node.connectedTo.end.parent; + console.log(ConnElement1.keyName) + console.log(ConnElement2.keyName) + let ElementFlag = false; + if (ConnElement1.keyName != "BreadBoard") { + + for (const ele of ConnEleList) { + if (ele === ConnElement1) { + ElementFlag = true; + break; } } - else - { - for(const ele of ConnEleList) - { - if( ele === ConnElement1) - { - ElementFlag = true; - break; - } - } - if(!ElementFlag && ConnElement2.info.properties.isBreadBoardPlaceable == 1) - { - ConnEleList.push(ConnElement2); - tmpx2.push(0); - tmpy2.push(0); - NodeList.push(ConnElement2.getNodesCoord()); + if (!ElementFlag && ConnElement1.info.properties.isBreadBoardPlaceable == 1) { + ConnEleList.push(ConnElement1); + tmpx2.push(0); + tmpy2.push(0); + NodeList.push(ConnElement1.getNodesCoord()); + } + } + else { + for (const ele of ConnEleList) { + if (ele === ConnElement1) { + ElementFlag = true; + break; } } + if (!ElementFlag && ConnElement2.info.properties.isBreadBoardPlaceable == 1) { + ConnEleList.push(ConnElement2); + tmpx2.push(0); + tmpy2.push(0); + NodeList.push(ConnElement2.getNodesCoord()); + } + } + - } this.elements.transform(`t${this.tx + fdx},${this.ty + fdy}`); @@ -810,7 +788,7 @@ export class BreadBoard extends CircuitElement { } for (let i = 0; i < ConnEleList.length; ++i) { - ConnEleList[i].dragAlong(NodeList[i],fdx,fdy) + ConnEleList[i].dragAlong(NodeList[i], fdx, fdy) tmpx2[i] = ConnEleList[i].tx + fdx; tmpy2[i] = ConnEleList[i].ty + fdy; } @@ -822,8 +800,8 @@ export class BreadBoard extends CircuitElement { this.tx = tmpx; this.ty = tmpy; - for(let i = 0; i < ConnEleList.length; i++){ - ConnEleList[i].dragAlongStop(tmpx2[i],tmpy2[i]); + for (let i = 0; i < ConnEleList.length; i++) { + ConnEleList[i].dragAlongStop(tmpx2[i], tmpy2[i]); } ConnEleList = []; NodeList = []; @@ -832,7 +810,7 @@ export class BreadBoard extends CircuitElement { tmpar = []; this.reBuildSameNodes(); } - + /** * Function provides component details * @param keyName Unique Class name From 2dec5ce9bf15cc5553645df445f80ffa7478f834 Mon Sep 17 00:00:00 2001 From: Saimadhav Date: Fri, 10 Mar 2023 21:15:24 +0530 Subject: [PATCH 17/33] Code Linting 2 --- .../src/app/Libs/CircuitElement.ts | 5 ++-- ArduinoFrontend/src/app/Libs/General.ts | 30 ++++++++++--------- ArduinoFrontend/src/app/Libs/Point.ts | 3 -- ArduinoFrontend/src/app/Libs/UndoUtils.ts | 10 ++----- .../src/app/Libs/outputs/Display.ts | 7 +---- 5 files changed, 21 insertions(+), 34 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/CircuitElement.ts b/ArduinoFrontend/src/app/Libs/CircuitElement.ts index d7989946b..16a6d788c 100644 --- a/ArduinoFrontend/src/app/Libs/CircuitElement.ts +++ b/ArduinoFrontend/src/app/Libs/CircuitElement.ts @@ -463,9 +463,8 @@ export abstract class CircuitElement { ); } return tmpar; - } - - dragAlong(tmpar: any, fdx: number, fdy: number): any { + } + dragAlong(tmpar: any, fdx: number, fdy: number): any { this.elements.transform(`t${this.tx + fdx},${this.ty + fdy}`); for (const node of this.nodes) { tmpar.push( diff --git a/ArduinoFrontend/src/app/Libs/General.ts b/ArduinoFrontend/src/app/Libs/General.ts index dfb21c16a..277bb9f05 100644 --- a/ArduinoFrontend/src/app/Libs/General.ts +++ b/ArduinoFrontend/src/app/Libs/General.ts @@ -661,21 +661,24 @@ export class BreadBoard extends CircuitElement { break; } } - if (!ElementFlag && 'isBreadBoardPlaceable' in ConnElement1.info.properties && ConnElement1.info.properties.isBreadBoardPlaceable === 1) { + const PlaceableCheck = 'isBreadBoardPlaceable' in ConnElement1.info.properties; + const isBreadBoardPlaceable = ConnElement1.info.properties.isBreadBoardPlaceable; + if ( !ElementFlag && PlaceableCheck && isBreadBoardPlaceable === 1 ) { ConnEleList.push(ConnElement1); tmpx2.push(0); tmpy2.push(0); NodeList.push(ConnElement1.getNodesCoord()); } - } - else { + } else { for (const ele of ConnEleList) { if (ele === ConnElement1) { ElementFlag = true; break; } } - if (!ElementFlag && "isBreadBoardPlaceable" in ConnElement2.info.properties && ConnElement2.info.properties.isBreadBoardPlaceable == 1) { + const PlaceableCheck = 'isBreadBoardPlaceable' in ConnElement2.info.properties; + const isBreadBoardPlaceable = ConnElement2.info.properties.isBreadBoardPlaceable; + if (!ElementFlag && PlaceableCheck && isBreadBoardPlaceable === 1) { ConnEleList.push(ConnElement2); tmpx2.push(0); tmpy2.push(0); @@ -740,12 +743,12 @@ export class BreadBoard extends CircuitElement { [node.x, node.y] ); node.remainShow(); - let ConnElement1 = node.connectedTo.start.parent; - let ConnElement2 = node.connectedTo.end.parent; - console.log(ConnElement1.keyName) - console.log(ConnElement2.keyName) + const ConnElement1 = node.connectedTo.start.parent; + const ConnElement2 = node.connectedTo.end.parent; + console.log(ConnElement1.keyName); + console.log(ConnElement2.keyName); let ElementFlag = false; - if (ConnElement1.keyName != "BreadBoard") { + if (ConnElement1.keyName !== 'BreadBoard') { for (const ele of ConnEleList) { if (ele === ConnElement1) { @@ -753,21 +756,20 @@ export class BreadBoard extends CircuitElement { break; } } - if (!ElementFlag && ConnElement1.info.properties.isBreadBoardPlaceable == 1) { + if (!ElementFlag && ConnElement1.info.properties.isBreadBoardPlaceable === 1) { ConnEleList.push(ConnElement1); tmpx2.push(0); tmpy2.push(0); NodeList.push(ConnElement1.getNodesCoord()); } - } - else { + } else { for (const ele of ConnEleList) { if (ele === ConnElement1) { ElementFlag = true; break; } } - if (!ElementFlag && ConnElement2.info.properties.isBreadBoardPlaceable == 1) { + if (!ElementFlag && ConnElement2.info.properties.isBreadBoardPlaceable === 1) { ConnEleList.push(ConnElement2); tmpx2.push(0); tmpy2.push(0); @@ -788,7 +790,7 @@ export class BreadBoard extends CircuitElement { } for (let i = 0; i < ConnEleList.length; ++i) { - ConnEleList[i].dragAlong(NodeList[i], fdx, fdy) + ConnEleList[i].dragAlong(NodeList[i], fdx, fdy); tmpx2[i] = ConnEleList[i].tx + fdx; tmpy2[i] = ConnEleList[i].ty + fdy; } diff --git a/ArduinoFrontend/src/app/Libs/Point.ts b/ArduinoFrontend/src/app/Libs/Point.ts index d7c7b185a..268ca0fcb 100644 --- a/ArduinoFrontend/src/app/Libs/Point.ts +++ b/ArduinoFrontend/src/app/Libs/Point.ts @@ -211,7 +211,6 @@ export class Point { * Unsolders wire to the point */ unsolderWire() { - console.log("Removing2") const wire = this.connectedTo; if (wire) { this.setValue(-1, this); @@ -344,7 +343,6 @@ export class Point { * Disconnects the point to wire */ disconnect() { - console.log("Removing1") this.connectedTo = null; if (this.isSoldered()) { this.unsolderWire(); @@ -355,7 +353,6 @@ export class Point { * Remove Node from canvas */ remove() { - this.body.remove(); if (this.connectedTo) { this.connectedTo.remove(); diff --git a/ArduinoFrontend/src/app/Libs/UndoUtils.ts b/ArduinoFrontend/src/app/Libs/UndoUtils.ts index 88a9d55b3..26273733b 100644 --- a/ArduinoFrontend/src/app/Libs/UndoUtils.ts +++ b/ArduinoFrontend/src/app/Libs/UndoUtils.ts @@ -35,7 +35,6 @@ export abstract class UndoUtils { * Call this function to Undo */ static workspaceUndo() { - console.log("Workspace undo") if (this.undo.length > 0) { const cng = this.undo.pop(); this.loadChange(cng, 'undo'); @@ -128,12 +127,10 @@ export abstract class UndoUtils { * @param operation undo/redo */ static async loadChange(ele, operation) { - console.log("LoadChange") // All elements in window.scope with similar const grup = window.scope[ele.keyName]; // Check if dragJson is present, & jump to next operation if both dx & dy are 0 - //Which case is this?? if (ele.dragJson) { if (ele.dragJson.dx === 0 && ele.dragJson.dy === 0) { if (operation === 'undo') { @@ -283,19 +280,16 @@ export abstract class UndoUtils { const existing = this.getExistingWindowElement(grup, ele); if (operation === 'undo') { if (ele.keyName === 'BreadBoard') { - console.log("BreadBoard specific drag") existing.transformBoardPosition(-ele.dragJson.dx, -ele.dragJson.dy); } else { existing.transformPosition(-ele.dragJson.dx, -ele.dragJson.dy); } - } else { - + } else { if (ele.keyName !== 'BreadBoard') { existing.transformPosition(ele.dragJson.dx, ele.dragJson.dy); Workspace.onDragEvent(existing); Workspace.onDragStopEvent(existing); - } - else { + } else { existing.transformBoardPosition(ele.dragJson.dx, ele.dragJson.dy); } } diff --git a/ArduinoFrontend/src/app/Libs/outputs/Display.ts b/ArduinoFrontend/src/app/Libs/outputs/Display.ts index 011653849..e8fcecd75 100644 --- a/ArduinoFrontend/src/app/Libs/outputs/Display.ts +++ b/ArduinoFrontend/src/app/Libs/outputs/Display.ts @@ -610,10 +610,8 @@ export class LCD16X2 extends CircuitElement { */ generateCharacterPanels() { this.destroyCharacterPanels(); - const posX = this.data.startX; - const posY = this.data.startY; - + const posY = this.data.startY; // Getting the number of pixel/panel rows, columns from the active data display state const gridRows = this.dataDisplayState.getPixelRows(); const gridColumns = this.dataDisplayState.getPixelColumns(); @@ -696,12 +694,9 @@ export class LCD16X2 extends CircuitElement { const isConnectedRowInFirstBlock = connectedRow <= 101; // checking for all the nodes with the same x-coordinate - console.log(breadboard.sameXNodes) - console.log(connectedPin.x) for (const neighbor of breadboard.sameXNodes[connectedPin.x]) { const neighborRow = neighbor.label.charCodeAt(0); const isSameBlock = neighborRow <= 101 === isConnectedRowInFirstBlock; - if (neighbor.y !== connectedPin.y && isSameBlock) { if (neighbor.connectedTo) { let arduinoPin = null; From a08b62ac8177574830872f6b37868f6b951932e5 Mon Sep 17 00:00:00 2001 From: Tyron Date: Sat, 11 Mar 2023 16:34:55 +0530 Subject: [PATCH 18/33] Adding functions to get Resistance in circuit --- ArduinoFrontend/src/app/Libs/General.ts | 14 ++ ArduinoFrontend/src/app/Libs/outputs/Led.ts | 172 +++++++++++++++++++- 2 files changed, 185 insertions(+), 1 deletion(-) diff --git a/ArduinoFrontend/src/app/Libs/General.ts b/ArduinoFrontend/src/app/Libs/General.ts index 2d1be11ed..167d242cd 100644 --- a/ArduinoFrontend/src/app/Libs/General.ts +++ b/ArduinoFrontend/src/app/Libs/General.ts @@ -272,6 +272,20 @@ export class Resistor extends CircuitElement { */ closeSimulation(): void { } + + /** + * Get resistance value of resistor + */ + getResistance() { + return this.value; + } + /** + * Get ID of the resistor + * TODO: Add this function inside CircuitElements.ts instead + */ + getID() { + return this.id; + } } /** diff --git a/ArduinoFrontend/src/app/Libs/outputs/Led.ts b/ArduinoFrontend/src/app/Libs/outputs/Led.ts index 3d36e7744..bb9368208 100644 --- a/ArduinoFrontend/src/app/Libs/outputs/Led.ts +++ b/ArduinoFrontend/src/app/Libs/outputs/Led.ts @@ -22,6 +22,10 @@ export class LED extends CircuitElement { * Name of Color of LED */ static colorNames: string[] = []; + /** + * Internal resistance of LED in ohms + */ + static internalResistance = 13; /** * Selectedindex wrt to color */ @@ -54,6 +58,15 @@ export class LED extends CircuitElement { * Flag to check if logic function's recursion should be skipped */ skipCheck = false; + /** + * Variable to store resistance of entire circuit + * Internal resistance of LED by default set to 13 + */ + resistance: number = LED.internalResistance; + /** + * Stores visited resistors + */ + visitedResistors = new Set(); /** * LED constructor @@ -107,7 +120,7 @@ export class LED extends CircuitElement { if (this.prev === val) { this.skipCheck = true; } - + const current = val / this.resistance; if (!this.allNodesConnected) { const arduinoEnd: any = this.getRecArduinov2(this.pinNamedMap['POSITIVE'], 'POSITIVE'); const negativeEnd = this.getRecArduinov2(this.pinNamedMap['NEGATIVE'], 'NEGATIVE'); @@ -225,6 +238,10 @@ export class LED extends CircuitElement { this.pinNamedMap[node.label] = node; } + // Getting resistance values from resistors in the circuit + this.getRecResistance(this.pinNamedMap['POSITIVE'], 'POSITIVE'); + this.getRecResistance(this.pinNamedMap['NEGATIVE'], 'NEGATIVE'); + // Determine if Positive terminal of LED is attached to Arduino const arduinoEnd: any = this.getRecArduinov2(this.pinNamedMap['POSITIVE'], 'POSITIVE'); // Determine if Negative terminal of LED is attached to Arduino @@ -272,6 +289,8 @@ export class LED extends CircuitElement { // reset PWM boolean & voltage = 0 this.pwmAttached = false; this.voltage = 0; + this.resistance = LED.internalResistance; + this.visitedResistors.clear(); } /** @@ -414,6 +433,157 @@ export class LED extends CircuitElement { } } + /** + * Return the node which is connected to arduino by recursively finding connected node + * @param node The Node which need to be checked + */ + getRecResistance(node: Point, startedOn: string) { + try { + if (node.connectedTo.start.parent.keyName === "Resistor") { + const resistorID = (node.connectedTo.start.parent as Resistor).getID(); + if (!this.visitedResistors.has(resistorID)) { + this.resistance = this.resistance + (node.connectedTo.start.parent as Resistor).getResistance(); + this.visitedResistors.add(resistorID); + } + } else if (node.connectedTo.end.parent.keyName === "Resistor") { + const resistorID = (node.connectedTo.end.parent as Resistor).getID(); + if (!this.visitedResistors.has(resistorID)) { + this.resistance = this.resistance + (node.connectedTo.end.parent as Resistor).getResistance(); + this.visitedResistors.add(resistorID); + } + } + 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 + return this.getRecResistanceBread(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.getRecResistanceBread(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.getRecResistance(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.getRecResistance(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.getRecResistance(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.getRecResistance(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 + */ + private getRecResistanceBread(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.getRecResistance(bb.joined[e], startedOn); + } + } else if (ascii >= 102 && ascii <= 106) { + if (bb.joined[e].isConnected() && (currAscii >= 102 && currAscii <= 106)) { + return this.getRecResistance(bb.joined[e], startedOn); + } + } else { + if (bb.joined[e].isConnected() && (bb.joined[e].label === node.connectedTo.end.label)) { + return this.getRecResistance(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.getRecResistance(bb.joined[e], startedOn); + } + } else if (ascii >= 102 && ascii <= 106) { + if (bb.joined[e].isConnected() && (currAscii >= 102 && currAscii <= 106)) { + return this.getRecResistance(bb.joined[e], startedOn); + } + } else { + if (bb.joined[e].isConnected() && (bb.joined[e].label === node.connectedTo.end.label)) { + return this.getRecResistance(bb.joined[e], startedOn); + } + } + } + } + } + } + } + } From 73a3f7dced97f4ebd7460fd0054ac43d2ff68709 Mon Sep 17 00:00:00 2001 From: Tyron Date: Sat, 11 Mar 2023 17:48:20 +0530 Subject: [PATCH 19/33] LED glow logic changed from voltage to current --- ArduinoFrontend/src/app/Libs/outputs/Led.ts | 37 +++++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/outputs/Led.ts b/ArduinoFrontend/src/app/Libs/outputs/Led.ts index bb9368208..c537e175a 100644 --- a/ArduinoFrontend/src/app/Libs/outputs/Led.ts +++ b/ArduinoFrontend/src/app/Libs/outputs/Led.ts @@ -120,7 +120,9 @@ export class LED extends CircuitElement { if (this.prev === val) { this.skipCheck = true; } - const current = val / this.resistance; + let current = val / this.resistance; + const pin0Current = (this.nodes[0].value / this.resistance); + if (!this.allNodesConnected) { const arduinoEnd: any = this.getRecArduinov2(this.pinNamedMap['POSITIVE'], 'POSITIVE'); const negativeEnd = this.getRecArduinov2(this.pinNamedMap['NEGATIVE'], 'NEGATIVE'); @@ -135,17 +137,17 @@ 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) { - if (val >= 5 || this.nodes[0].value === 5) { + if (current > 0.03 || pin0Current > 0.03) { + window.showToast("LED has burst"); + this.handleConnectionError(); + } else if (current >= 0.02 || pin0Current >= 0.02) { 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 if ((current > 0.012 && current < 0.02) || (pin0Current > 0.012)) { + this.glowWithAlpha(current); } else { this.fillColor('none'); } + if (val >= 0 && !this.skipCheck) { this.prev = val; this.nodes[1].setValue(val, null); @@ -155,7 +157,8 @@ export class LED extends CircuitElement { } } else if (this.pwmAttached && this.allNodesConnected) { // TODO: Run if PWM is attached - this.glowWithAlpha(this.voltage); + current = this.voltage / this.resistance; + this.glowWithAlpha(current); } } else { @@ -167,11 +170,23 @@ export class LED extends CircuitElement { /** * create color and add alpha to color */ - glowWithAlpha(value: number) { + glowWithAlpha(current: number) { + + const minCurrent = 0.012; + const maxCurrent = 0.02; + const minOpacity = 2; + const maxOpacity = 9; + + if (current < minCurrent) { + return; + } const color = `r(0.5, 0.5)${LED.glowColors[this.selectedIndex]}`; const split = color.split('-'); let genColor = 'none'; - const alpha = (value / 5) * 9; + + // Scalaing current values to range between 2-9 + const alpha = (((current - minCurrent) / (maxCurrent - minCurrent)) * (maxOpacity - minOpacity)) + minOpacity + genColor = `${split[0].substr(0, split[0].length - 2)}${alpha})-${split[1]}`; this.elements[3].attr({ fill: genColor }); } From 6b2ffae46b26822e0c075b17332991e6697d6e42 Mon Sep 17 00:00:00 2001 From: Tyron Date: Sat, 11 Mar 2023 18:02:35 +0530 Subject: [PATCH 20/33] Linting --- ArduinoFrontend/src/app/Libs/outputs/Led.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/outputs/Led.ts b/ArduinoFrontend/src/app/Libs/outputs/Led.ts index c537e175a..ce8c4d612 100644 --- a/ArduinoFrontend/src/app/Libs/outputs/Led.ts +++ b/ArduinoFrontend/src/app/Libs/outputs/Led.ts @@ -138,7 +138,7 @@ export class LED extends CircuitElement { if (this.nodes[0].connectedTo && this.nodes[1].connectedTo) { if (!this.pwmAttached && this.allNodesConnected) { if (current > 0.03 || pin0Current > 0.03) { - window.showToast("LED has burst"); + window.showToast('LED has burst'); this.handleConnectionError(); } else if (current >= 0.02 || pin0Current >= 0.02) { this.anim(); @@ -185,7 +185,7 @@ export class LED extends CircuitElement { let genColor = 'none'; // Scalaing current values to range between 2-9 - const alpha = (((current - minCurrent) / (maxCurrent - minCurrent)) * (maxOpacity - minOpacity)) + minOpacity + const alpha = (((current - minCurrent) / (maxCurrent - minCurrent)) * (maxOpacity - minOpacity)) + minOpacity; genColor = `${split[0].substr(0, split[0].length - 2)}${alpha})-${split[1]}`; this.elements[3].attr({ fill: genColor }); @@ -454,13 +454,13 @@ export class LED extends CircuitElement { */ getRecResistance(node: Point, startedOn: string) { try { - if (node.connectedTo.start.parent.keyName === "Resistor") { + if (node.connectedTo.start.parent.keyName === 'Resistor') { const resistorID = (node.connectedTo.start.parent as Resistor).getID(); if (!this.visitedResistors.has(resistorID)) { this.resistance = this.resistance + (node.connectedTo.start.parent as Resistor).getResistance(); this.visitedResistors.add(resistorID); } - } else if (node.connectedTo.end.parent.keyName === "Resistor") { + } else if (node.connectedTo.end.parent.keyName === 'Resistor') { const resistorID = (node.connectedTo.end.parent as Resistor).getID(); if (!this.visitedResistors.has(resistorID)) { this.resistance = this.resistance + (node.connectedTo.end.parent as Resistor).getResistance(); @@ -535,7 +535,7 @@ export class LED extends CircuitElement { /** * Recursive Function to handle BreadBoard * @param node Node which is to be checked for BreadBoard - */ + */ private getRecResistanceBread(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) { From a9bd0704d8c84a7b698fcd9ca7aa9e15e89380ef Mon Sep 17 00:00:00 2001 From: Saimadhav Date: Sat, 11 Mar 2023 21:48:19 +0530 Subject: [PATCH 21/33] Code Linting 3 --- ArduinoFrontend/src/app/Libs/UndoUtils.ts | 2 +- ArduinoFrontend/src/app/Libs/outputs/Display.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/UndoUtils.ts b/ArduinoFrontend/src/app/Libs/UndoUtils.ts index 26273733b..550af18fe 100644 --- a/ArduinoFrontend/src/app/Libs/UndoUtils.ts +++ b/ArduinoFrontend/src/app/Libs/UndoUtils.ts @@ -284,7 +284,7 @@ export abstract class UndoUtils { } else { existing.transformPosition(-ele.dragJson.dx, -ele.dragJson.dy); } - } else { + } else { if (ele.keyName !== 'BreadBoard') { existing.transformPosition(ele.dragJson.dx, ele.dragJson.dy); Workspace.onDragEvent(existing); diff --git a/ArduinoFrontend/src/app/Libs/outputs/Display.ts b/ArduinoFrontend/src/app/Libs/outputs/Display.ts index e8fcecd75..c4f2c4c89 100644 --- a/ArduinoFrontend/src/app/Libs/outputs/Display.ts +++ b/ArduinoFrontend/src/app/Libs/outputs/Display.ts @@ -611,7 +611,7 @@ export class LCD16X2 extends CircuitElement { generateCharacterPanels() { this.destroyCharacterPanels(); const posX = this.data.startX; - const posY = this.data.startY; + const posY = this.data.startY; // Getting the number of pixel/panel rows, columns from the active data display state const gridRows = this.dataDisplayState.getPixelRows(); const gridColumns = this.dataDisplayState.getPixelColumns(); From e7c59b5ae4866ea8bcba480520ad6c6feb9aa6e8 Mon Sep 17 00:00:00 2001 From: SofiaChen2000 Date: Mon, 13 Mar 2023 17:39:30 +0530 Subject: [PATCH 22/33] Fix push button for up and down counter --- ArduinoFrontend/src/app/Libs/General.ts | 9 ++++- .../src/app/Libs/inputs/Buttons.ts | 39 ++++++++++++++----- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/General.ts b/ArduinoFrontend/src/app/Libs/General.ts index 2d1be11ed..0c6116045 100644 --- a/ArduinoFrontend/src/app/Libs/General.ts +++ b/ArduinoFrontend/src/app/Libs/General.ts @@ -820,7 +820,14 @@ export class BreadBoard extends CircuitElement { && (labelCalledBy.charCodeAt(0) !== labelParent.charCodeAt(0) || labelCalledBy === labelParent)) { return; } - if (node.label === '+' || node.label === '-') { + if (node.label === '-') { + for (const neigh of ytemp[node.y]) { + if (neigh.x !== node.x && value <= 0) { + neigh.setValue(value, neigh); + } + } + } + else if (node.label === '+') { for (const neigh of ytemp[node.y]) { if (neigh.x !== node.x) { neigh.setValue(value, neigh); diff --git a/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts b/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts index 8cf82f58d..573925566 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/Buttons.ts @@ -1,10 +1,13 @@ import { CircuitElement } from '../CircuitElement'; import { BreadBoard } from '../General'; +import { Point } from '../Point'; /** * Declare Raphael so that build don't throws error */ declare var Raphael; + +declare var window; /** * Pushbutton Class */ @@ -17,7 +20,15 @@ export class PushButton extends CircuitElement { * Object of terminals and their respective arduino pin */ terminalParent = {}; - + parentList = new Set(); + /** + * Set of Visited Nodes + */ + visitedNodesv2 = new Set(); + // /** + // * Set of Visited Nodes + // */ + // visitedNodesv2 = new Set(); /** * pushbutton constructor * @param canvas Raphael Canvas (Paper) @@ -41,7 +52,7 @@ export class PushButton extends CircuitElement { }); this.pinNamedMap['Terminal 1b'].addValueListener((v) => { if (v !== this.pinNamedMap['Terminal 1a'].value) { - console.log(v); + // console.log(v); this.pinNamedMap['Terminal 1a'].setValue(v, this.pinNamedMap['Terminal 1a']); } }); @@ -76,7 +87,7 @@ export class PushButton extends CircuitElement { for (const i in this.pinNamedMap) { if (this.pinNamedMap[i].connectedTo !== null) { if (this.pinNamedMap[i].connectedTo.start.parent.keyName === 'ArduinoUno' - || this.pinNamedMap[i].connectedTo.end.parent.keyName === 'ArduinoUno') { + || this.pinNamedMap[i].connectedTo.end.parent.keyName === 'ArduinoUno') { this.terminalParent[i] = BreadBoard.getRecArduinov2(this.pinNamedMap[i], i); } else { this.terminalParent[i] = BreadBoard.getRecArduinoBreadv2(this.pinNamedMap[i], i); @@ -87,7 +98,8 @@ export class PushButton extends CircuitElement { const Aports = new RegExp('^A([0-5])$'); // console.log(this.pinNamedMap['']) this.elements.unmousedown(); - let iniValue = -1; + let iniValue = 0; + let iniPin = ''; let by = -1; // create mousedown for the button this.elements[9].mousedown(() => { @@ -103,8 +115,10 @@ export class PushButton extends CircuitElement { for (const i in this.terminalParent) { if (this.terminalParent[i] !== undefined) { // set initial value to the pin which connects the digital pin on Arduino - if (Dports.test(this.terminalParent[i].label) || Aports.test(this.terminalParent[i].label)) { + if ((Dports.test(this.terminalParent[i].label) || Aports.test(this.terminalParent[i].label)) + && this.pinNamedMap[i].value <= 0) { iniValue = this.pinNamedMap[i].value; + iniPin = i; } } } @@ -113,6 +127,7 @@ export class PushButton extends CircuitElement { val = this.pinNamedMap['Terminal 1a'].value; // TODO: run for 1a if (pullUp) { + iniValue = val; // TODO: If pullUp enabled set val to zero val = 0; } @@ -124,6 +139,7 @@ export class PushButton extends CircuitElement { val = this.pinNamedMap['Terminal 1b'].value; // TODO: run for 1b if (pullUp) { + iniValue = val; // TODO: If pullUp enabled set val to zero val = 0; } @@ -135,6 +151,7 @@ export class PushButton extends CircuitElement { val = this.pinNamedMap['Terminal 2a'].value; // TODO: run for 2a if (pullUp) { + iniValue = val; // TODO: If pullUp enabled set val to zero val = 0; } @@ -146,6 +163,7 @@ export class PushButton extends CircuitElement { val = this.pinNamedMap['Terminal 2b'].value; // TODO: run for 2b if (pullUp) { + iniValue = val; // TODO: If pullUp enabled set val to zero val = 0; } @@ -154,12 +172,15 @@ export class PushButton extends CircuitElement { this.pinNamedMap['Terminal 1a'].setValue(val, null); this.pinNamedMap['Terminal 1b'].setValue(val, null); } - - // console.log(val); }); // Set mouseup listener for the button - this.elements[9].mouseup(() => this.MouseUp(by, iniValue)); - this.elements[9].mouseout(() => this.MouseUp(by, iniValue)); + this.elements[9].mouseup(() => { + this.MouseUp(by, iniValue); + + if (iniPin !== undefined && iniPin !== null) { + this.terminalParent[iniPin].setValue(-1, null); + } + }); } /** * Mouse Up Callback From 287d3018cfef870fe0afed04ebb469cc478fbf9e Mon Sep 17 00:00:00 2001 From: SofiaChen2000 Date: Mon, 13 Mar 2023 17:45:49 +0530 Subject: [PATCH 23/33] Linting General.ts --- ArduinoFrontend/src/app/Libs/General.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/General.ts b/ArduinoFrontend/src/app/Libs/General.ts index 0c6116045..aac2fa529 100644 --- a/ArduinoFrontend/src/app/Libs/General.ts +++ b/ArduinoFrontend/src/app/Libs/General.ts @@ -826,8 +826,7 @@ export class BreadBoard extends CircuitElement { neigh.setValue(value, neigh); } } - } - else if (node.label === '+') { + } else if (node.label === '+') { for (const neigh of ytemp[node.y]) { if (neigh.x !== node.x) { neigh.setValue(value, neigh); From 758a62c34af356299db759e4753561e71e2fc710 Mon Sep 17 00:00:00 2001 From: Tyron Date: Tue, 14 Mar 2023 01:50:36 +0530 Subject: [PATCH 24/33] Function addition to work with Potentiometer --- ArduinoFrontend/src/app/Libs/outputs/Led.ts | 24 +++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/outputs/Led.ts b/ArduinoFrontend/src/app/Libs/outputs/Led.ts index ce8c4d612..1232f2ec0 100644 --- a/ArduinoFrontend/src/app/Libs/outputs/Led.ts +++ b/ArduinoFrontend/src/app/Libs/outputs/Led.ts @@ -67,7 +67,10 @@ export class LED extends CircuitElement { * Stores visited resistors */ visitedResistors = new Set(); - + /** + * Stores variable resistance from Potentiometer + */ + variableResistance: number = 0; /** * LED constructor * @param canvas Raphael Canvas (Paper) @@ -120,8 +123,8 @@ export class LED extends CircuitElement { if (this.prev === val) { this.skipCheck = true; } - let current = val / this.resistance; - const pin0Current = (this.nodes[0].value / this.resistance); + let current = val / (this.resistance + this.variableResistance); + const pin0Current = (this.nodes[0].value / (this.resistance + this.variableResistance)); if (!this.allNodesConnected) { const arduinoEnd: any = this.getRecArduinov2(this.pinNamedMap['POSITIVE'], 'POSITIVE'); @@ -305,7 +308,20 @@ export class LED extends CircuitElement { this.pwmAttached = false; this.voltage = 0; this.resistance = LED.internalResistance; - this.visitedResistors.clear(); + this.visitedResistors.clear(); + this.variableResistance = 0; + } + /** + * Returns ID + */ + getID() { + return this.id; + } + /** + * Sets variable resitance + */ + setVariableResistance(resistance: number) { + this.variableResistance = resistance; } /** From 442aef32c8ff464e9f79d67eceb69ce3d56c47e8 Mon Sep 17 00:00:00 2001 From: Tyron Date: Tue, 14 Mar 2023 02:03:21 +0530 Subject: [PATCH 25/33] Changed Potentiometer Logic --- .../src/app/Libs/inputs/Potentiometer.ts | 279 +++++++++++++++++- 1 file changed, 263 insertions(+), 16 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts b/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts index 63ec55066..84f0fee7a 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts @@ -1,6 +1,7 @@ import { CircuitElement } from '../CircuitElement'; import { BreadBoard } from '../General'; import { Vector } from './Collision'; +import { Point } from '../Point'; /** * Declare window so that custom created function don't throw error @@ -31,7 +32,14 @@ export class Potentiometer extends CircuitElement { * Arduino Pin connected to 2 of potentiometer */ arduinoEndTwo: any; - + /** + * Set to keep track of visited nodes + */ + visitedNodesv2 = new Set(); + /** + * Check the connection type + */ + isRheostat: boolean = null; /** * Potentiometer constructor * @param canvas Raphael Canvas (Paper) @@ -110,6 +118,73 @@ export class Potentiometer extends CircuitElement { this.nodes[1].setValue(intp, this.nodes[1]); } + /** + * Rotates the dial and sets the analog value for Rheostat connection + * @param center Center of the Potentiometer + * @param clientX Mouse X + * @param clientY Mouse Y + */ + rotateDialRheostat(center: Vector, clientX: number, clientY: number) { + const point = this.svgPoint(clientX, clientY); + const difX = point.x - center.x; + const difY = point.y - center.y; + const resistanceValue = Potentiometer.variantsValue[this.selectedIndex]; + + let ang = Math.atan2(difY, difX); + if (ang < 0) { + ang += 2 * Math.PI; + } + // if(line){ + // line.remove(); + // line = null; + // } + // const ex = center.x + 100*Math.cos(ang); + // const ey = center.y + 100*Math.sin(ang); + // line = this.canvas.path(`M${center.x},${center.y}L${ex},${ey}`) + ang *= (180 / Math.PI); + ang = (ang + 225) % 360; + if (ang > 268) { + ang = 268; + } + let to; + let outputVoltage = 0; + let calResistance = -1; + const minVoltage = 0; + const minLEDResistance = 100; + const maxLEDResitance = 466; + if (this.arduinoEndZero) { + to = Math.max( + this.nodes[0].value, + this.nodes[1].value + ); + // intp = (ang / 268) * to; + calResistance = ((ang / 268) * resistanceValue); + if (calResistance < minLEDResistance || calResistance > maxLEDResitance) { + outputVoltage = 0; + } + else { + outputVoltage = to - (((calResistance - minLEDResistance) / (maxLEDResitance - minLEDResistance)) * (to - minVoltage)) + minVoltage; + } + } else if (this.arduinoEndTwo) { + to = Math.max( + this.nodes[1].value, + this.nodes[2].value + ); + calResistance = resistanceValue - ((ang / 268) * resistanceValue); + if (calResistance < minLEDResistance || calResistance > maxLEDResitance) { + outputVoltage = 0; + } + else { + outputVoltage = to - (((calResistance - minLEDResistance) / (maxLEDResitance - minLEDResistance)) * (to - minVoltage)) + minVoltage; + } + } + if (to < 0) { + window['showToast']('Potentiometer Not Connected'); + return; + } + this.elements[1].transform(`r${ang}`); + this.nodes[1].setValue(outputVoltage, this.nodes[1]); + } /** * Function provides component details * @param keyName Unique Class name @@ -146,11 +221,11 @@ export class Potentiometer extends CircuitElement { * Called on start simulation. Add Event listener. */ initSimulation(): void { - if ( - !(this.nodes[0].connectedTo && - this.nodes[1].connectedTo && - this.nodes[2].connectedTo)) { - // console.log("ss") + + if (!this.areNodesConnectedProperly()) { + console.log("Nodes not connected properly"); + window.toast("Potentiometer not connected properly."); + return; } const attr = this.elements[1].attr(); const center = { @@ -164,17 +239,29 @@ export class Potentiometer extends CircuitElement { }); this.elements.undrag(); this.elements.unmousedown(); - this.elements.drag((_, __, mX, mY) => { - this.rotateDial(center, mX, mY); - }, (mX, mY) => { - this.rotateDial(center, mX, mY); - }, - (ev: MouseEvent) => { - this.rotateDial(center, ev.clientX, ev.clientY); - }); + + if (!this.isRheostat) { + this.elements.drag((_, __, mX, mY) => { + this.rotateDial(center, mX, mY); + }, (mX, mY) => { + this.rotateDial(center, mX, mY); + }, + (ev: MouseEvent) => { + this.rotateDial(center, ev.clientX, ev.clientY); + }); + } else { + this.elements.drag((_, __, mX, mY) => { + this.rotateDialRheostat(center, mX, mY); + }, (mX, mY) => { + this.rotateDialRheostat(center, mX, mY); + }, + (ev: MouseEvent) => { + this.rotateDialRheostat(center, ev.clientX, ev.clientY); + }); + } // Get Arduino Connected ends for terminal 1 & terminal 2 - this.arduinoEndZero = BreadBoard.getRecArduinov2(this.nodes[0], 'Terminal 1'); - this.arduinoEndTwo = BreadBoard.getRecArduinov2(this.nodes[2], 'Terminal 2'); + this.arduinoEndZero = this.getRecArduinov2(this.nodes[0], 'Terminal 1'); + this.arduinoEndTwo = this.getRecArduinov2(this.nodes[2], 'Terminal 2'); if (this.arduinoEndZero) { // TODO : If arduino is connected to Terminal 1 of potentiometer // set WIPER value 0 @@ -218,5 +305,165 @@ export class Potentiometer extends CircuitElement { this.elements.unmousedown(); this.setClickListener(null); this.setDragListeners(); + this.isRheostat = null; + } + /** + * Checks if nodes of Potentiometer are connected either as + * 1. Rheostat: Wiper + Left Pin (or) Wiper + Right Pin + * 2. Voltage divider: All pins + */ + areNodesConnectedProperly() { + if (this.nodes[0].isConnected() && this.nodes[1].isConnected() && this.nodes[2].isConnected()) { + this.isRheostat = false; + return true; + } + else if (this.nodes[0].isConnected() && this.nodes[1].isConnected()) { + this.isRheostat = true; + return true; + } + else if (this.nodes[1].isConnected() && this.nodes[2].isConnected()) { + this.isRheostat = true; + return true; + } + return false; + } + /** + * Return the node which is connected to arduino by recursively finding connected node + * @param node The Node which need to be checked + */ + getRecArduinov2(node: Point, startedOn: string) { + 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 + 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 + */ + private 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); + } + } + } + } + } + } } } From e57ba8bde6ceaedb91a999e84bb38cbfe11693fc Mon Sep 17 00:00:00 2001 From: Tyron Date: Tue, 14 Mar 2023 02:10:42 +0530 Subject: [PATCH 26/33] Logic change to compliment LED --- .../src/app/Libs/inputs/Potentiometer.ts | 195 ++++++++++++++++-- 1 file changed, 181 insertions(+), 14 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts b/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts index 84f0fee7a..7e4bb022d 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts @@ -2,6 +2,7 @@ import { CircuitElement } from '../CircuitElement'; import { BreadBoard } from '../General'; import { Vector } from './Collision'; import { Point } from '../Point'; +import { LED } from '../outputs/Led'; /** * Declare window so that custom created function don't throw error @@ -40,6 +41,14 @@ export class Potentiometer extends CircuitElement { * Check the connection type */ isRheostat: boolean = null; + /** + * Stores visited LEDs' ids + */ + visitedLEDs = new Set(); + /** + * Stores connected LEDs + */ + connectedLEDs: LED[] = []; /** * Potentiometer constructor * @param canvas Raphael Canvas (Paper) @@ -147,7 +156,6 @@ export class Potentiometer extends CircuitElement { ang = 268; } let to; - let outputVoltage = 0; let calResistance = -1; const minVoltage = 0; const minLEDResistance = 100; @@ -159,31 +167,21 @@ export class Potentiometer extends CircuitElement { ); // intp = (ang / 268) * to; calResistance = ((ang / 268) * resistanceValue); - if (calResistance < minLEDResistance || calResistance > maxLEDResitance) { - outputVoltage = 0; - } - else { - outputVoltage = to - (((calResistance - minLEDResistance) / (maxLEDResitance - minLEDResistance)) * (to - minVoltage)) + minVoltage; - } + this.sendResistance(calResistance); } else if (this.arduinoEndTwo) { to = Math.max( this.nodes[1].value, this.nodes[2].value ); calResistance = resistanceValue - ((ang / 268) * resistanceValue); - if (calResistance < minLEDResistance || calResistance > maxLEDResitance) { - outputVoltage = 0; - } - else { - outputVoltage = to - (((calResistance - minLEDResistance) / (maxLEDResitance - minLEDResistance)) * (to - minVoltage)) + minVoltage; - } + this.sendResistance(calResistance); } if (to < 0) { window['showToast']('Potentiometer Not Connected'); return; } this.elements[1].transform(`r${ang}`); - this.nodes[1].setValue(outputVoltage, this.nodes[1]); + this.nodes[1].setValue(to, this.nodes[1]); } /** * Function provides component details @@ -259,6 +257,12 @@ export class Potentiometer extends CircuitElement { this.rotateDialRheostat(center, ev.clientX, ev.clientY); }); } + + // Find out the LEDs in the circuit + this.getRecLED(this.nodes[0], 'Terminal 1'); + this.getRecLED(this.nodes[1], 'WIPER'); + this.getRecLED(this.nodes[2], 'Ternimal 2'); + // Get Arduino Connected ends for terminal 1 & terminal 2 this.arduinoEndZero = this.getRecArduinov2(this.nodes[0], 'Terminal 1'); this.arduinoEndTwo = this.getRecArduinov2(this.nodes[2], 'Terminal 2'); @@ -306,6 +310,8 @@ export class Potentiometer extends CircuitElement { this.setClickListener(null); this.setDragListeners(); this.isRheostat = null; + this.visitedLEDs.clear(); + this.connectedLEDs = []; } /** * Checks if nodes of Potentiometer are connected either as @@ -327,6 +333,17 @@ export class Potentiometer extends CircuitElement { } return false; } + /** + * Function to transfer resistance to connected LEDs + * ToDo: Function is hardcoded + * ToDo: Make it work for other components + */ + sendResistance(resistance : number) { + for (const led of this.connectedLEDs) { + console.log(led); + led.setVariableResistance(resistance); + } + } /** * Return the node which is connected to arduino by recursively finding connected node * @param node The Node which need to be checked @@ -466,4 +483,154 @@ export class Potentiometer extends CircuitElement { } } } + /** + * Return the node which is connected to arduino by recursively finding LEDs inside the circuit + * @param node The Node which need to be checked + */ + getRecLED(node: Point, startedOn: string) { + try { + if (node.connectedTo.start.parent.keyName === 'LED') { + const led = (node.connectedTo.start.parent as LED); + if (!this.visitedLEDs.has(led.getID())) { + this.connectedLEDs.push(led); + this.visitedLEDs.add(led.getID()); + } + } else if (node.connectedTo.end.parent.keyName === 'LED') { + const led = (node.connectedTo.end.parent as LED); + if (!this.visitedLEDs.has(led.getID())) { + this.connectedLEDs.push(led); + this.visitedLEDs.add(led.getID()); + } + } + 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 + return this.getRecLEDBread(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.getRecLEDBread(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.getRecLED(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.getRecLED(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.getRecLED(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.getRecLED(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 + */ + private getRecLEDBread(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.getRecLED(bb.joined[e], startedOn); + } + } else if (ascii >= 102 && ascii <= 106) { + if (bb.joined[e].isConnected() && (currAscii >= 102 && currAscii <= 106)) { + return this.getRecLED(bb.joined[e], startedOn); + } + } else { + if (bb.joined[e].isConnected() && (bb.joined[e].label === node.connectedTo.end.label)) { + return this.getRecLED(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.getRecLED(bb.joined[e], startedOn); + } + } else if (ascii >= 102 && ascii <= 106) { + if (bb.joined[e].isConnected() && (currAscii >= 102 && currAscii <= 106)) { + return this.getRecLED(bb.joined[e], startedOn); + } + } else { + if (bb.joined[e].isConnected() && (bb.joined[e].label === node.connectedTo.end.label)) { + return this.getRecLED(bb.joined[e], startedOn); + } + } + } + } + } + } + } } From 419b351cecb03f242d3e2a25bc3799f5adedfa4c Mon Sep 17 00:00:00 2001 From: Tyron Date: Tue, 14 Mar 2023 02:32:10 +0530 Subject: [PATCH 27/33] Minor checks --- .../src/app/Libs/inputs/Potentiometer.ts | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts b/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts index 7e4bb022d..41d0f6897 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts @@ -222,7 +222,7 @@ export class Potentiometer extends CircuitElement { if (!this.areNodesConnectedProperly()) { console.log("Nodes not connected properly"); - window.toast("Potentiometer not connected properly."); + window.showToast("Potentiometer not connected properly."); return; } const attr = this.elements[1].attr(); @@ -320,10 +320,20 @@ export class Potentiometer extends CircuitElement { */ areNodesConnectedProperly() { if (this.nodes[0].isConnected() && this.nodes[1].isConnected() && this.nodes[2].isConnected()) { - this.isRheostat = false; - return true; + const leftNode = this.getRecArduinov2(this.nodes[0], 'Terminal 1'); + const rightNode = this.getRecArduinov2(this.nodes[2], 'Terminal 2'); + if (leftNode && rightNode) { + if (leftNode.label === 'GND' && rightNode.value > 0) { + this.isRheostat = false; + return true; + } else if (rightNode.label === 'GND' && leftNode.value > 0) { + this.isRheostat = false; + return true; + } + } } - else if (this.nodes[0].isConnected() && this.nodes[1].isConnected()) { + + if (this.nodes[0].isConnected() && this.nodes[1].isConnected()) { this.isRheostat = true; return true; } @@ -338,10 +348,9 @@ export class Potentiometer extends CircuitElement { * ToDo: Function is hardcoded * ToDo: Make it work for other components */ - sendResistance(resistance : number) { - for (const led of this.connectedLEDs) { - console.log(led); - led.setVariableResistance(resistance); + sendResistance(resistance: number) { + for (const led of this.connectedLEDs) { + led.setVariableResistance(resistance); } } /** From e9eb678146f0e35813584183cba8065f33250254 Mon Sep 17 00:00:00 2001 From: Tyron Date: Tue, 14 Mar 2023 11:25:03 +0530 Subject: [PATCH 28/33] Linting --- .../src/app/Libs/inputs/Potentiometer.ts | 15 +++++++-------- ArduinoFrontend/src/app/Libs/outputs/Led.ts | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts b/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts index 41d0f6897..0c2cdf2ee 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts @@ -46,7 +46,7 @@ export class Potentiometer extends CircuitElement { */ visitedLEDs = new Set(); /** - * Stores connected LEDs + * Stores connected LEDs */ connectedLEDs: LED[] = []; /** @@ -221,8 +221,7 @@ export class Potentiometer extends CircuitElement { initSimulation(): void { if (!this.areNodesConnectedProperly()) { - console.log("Nodes not connected properly"); - window.showToast("Potentiometer not connected properly."); + window.showToast('Potentiometer not connected properly.'); return; } const attr = this.elements[1].attr(); @@ -336,8 +335,7 @@ export class Potentiometer extends CircuitElement { if (this.nodes[0].isConnected() && this.nodes[1].isConnected()) { this.isRheostat = true; return true; - } - else if (this.nodes[1].isConnected() && this.nodes[2].isConnected()) { + } else if (this.nodes[1].isConnected() && this.nodes[2].isConnected()) { this.isRheostat = true; return true; } @@ -492,10 +490,11 @@ export class Potentiometer extends CircuitElement { } } } + /** - * Return the node which is connected to arduino by recursively finding LEDs inside the circuit - * @param node The Node which need to be checked - */ + * Return the node which is connected to arduino by recursively finding LEDs inside the circuit + * @param node The Node which need to be checked + */ getRecLED(node: Point, startedOn: string) { try { if (node.connectedTo.start.parent.keyName === 'LED') { diff --git a/ArduinoFrontend/src/app/Libs/outputs/Led.ts b/ArduinoFrontend/src/app/Libs/outputs/Led.ts index 1232f2ec0..b3b0d9b61 100644 --- a/ArduinoFrontend/src/app/Libs/outputs/Led.ts +++ b/ArduinoFrontend/src/app/Libs/outputs/Led.ts @@ -70,7 +70,7 @@ export class LED extends CircuitElement { /** * Stores variable resistance from Potentiometer */ - variableResistance: number = 0; + variableResistance = 0; /** * LED constructor * @param canvas Raphael Canvas (Paper) @@ -308,7 +308,7 @@ export class LED extends CircuitElement { this.pwmAttached = false; this.voltage = 0; this.resistance = LED.internalResistance; - this.visitedResistors.clear(); + this.visitedResistors.clear(); this.variableResistance = 0; } /** From 8ef51b9a7223b3cb293ea870f8e03c7716b77a74 Mon Sep 17 00:00:00 2001 From: Tyron Date: Tue, 14 Mar 2023 21:55:12 +0530 Subject: [PATCH 29/33] changing logic on fetching BreadBoard reference --- ArduinoFrontend/src/app/Libs/Point.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/Point.ts b/ArduinoFrontend/src/app/Libs/Point.ts index 8ac06b7f8..b6c980fff 100644 --- a/ArduinoFrontend/src/app/Libs/Point.ts +++ b/ArduinoFrontend/src/app/Libs/Point.ts @@ -3,6 +3,7 @@ import { CircuitElement } from './CircuitElement'; import { isNull } from 'util'; import { BoundingBox } from './Geometry'; import _ from 'lodash'; +import { BreadBoard } from './General'; /** @@ -128,13 +129,8 @@ export class Point { window.showBubble(this.label, evt.clientX, evt.clientY); if (this.parent.keyName === 'BreadBoard') { - let ref: any = {}; + const ref = this.parent as BreadBoard; - for (const obj of window.scope['BreadBoard']) { - if (obj.id === this.parent.id) { - ref = obj; - } - } if (this.label === '+' || this.label === '-') { for (const point of ref.sameYNodes[this.y]) { if (this.id === point.id) { @@ -173,12 +169,9 @@ export class Point { window.hideBubble(); if (this.parent.keyName === 'BreadBoard') { - let ref: any = {}; - for (const obj of window.scope['BreadBoard']) { - if (obj.id === this.parent.id) { - ref = obj; - } - } + + const ref = this.parent as BreadBoard; + if (this.label === '+' || this.label === '-') { for (const point of ref.sameYNodes[this.y]) { if (this.id === point.id) { From b6b509c00af94d6f939ebf1cab4b766f390f1c39 Mon Sep 17 00:00:00 2001 From: Tyron Date: Tue, 14 Mar 2023 22:22:42 +0530 Subject: [PATCH 30/33] Pin highlight bugfixes --- ArduinoFrontend/src/app/Libs/General.ts | 9 ++++++++- ArduinoFrontend/src/app/Libs/Point.ts | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ArduinoFrontend/src/app/Libs/General.ts b/ArduinoFrontend/src/app/Libs/General.ts index c428f7373..8c1f90165 100644 --- a/ArduinoFrontend/src/app/Libs/General.ts +++ b/ArduinoFrontend/src/app/Libs/General.ts @@ -677,7 +677,7 @@ export class BreadBoard extends CircuitElement { } const PlaceableCheck = 'isBreadBoardPlaceable' in ConnElement1.info.properties; const isBreadBoardPlaceable = ConnElement1.info.properties.isBreadBoardPlaceable; - if ( !ElementFlag && PlaceableCheck && isBreadBoardPlaceable === 1 ) { + if (!ElementFlag && PlaceableCheck && isBreadBoardPlaceable === 1) { ConnEleList.push(ConnElement1); tmpx2.push(0); tmpy2.push(0); @@ -979,5 +979,12 @@ export class BreadBoard extends CircuitElement { closeSimulation(): void { BreadBoard.visitedNodesv2.clear(); } + /** + * Returns groupings + */ + getGroupings() { + const groups = _.cloneDeep(BreadBoard.groupings); + return groups; + } } diff --git a/ArduinoFrontend/src/app/Libs/Point.ts b/ArduinoFrontend/src/app/Libs/Point.ts index 8190ab71b..757e3f2d8 100644 --- a/ArduinoFrontend/src/app/Libs/Point.ts +++ b/ArduinoFrontend/src/app/Libs/Point.ts @@ -339,6 +339,15 @@ export class Point { const newClass = this.body.node.getAttribute('class').replace(' highlight', ''); this.body.node.setAttribute('class', newClass); } + outline() { + const newClass = `${this.body.node.getAttribute('class')} outline`; + this.body.node.setAttribute('class', newClass); + } + + undoOutline() { + const newClass = this.body.node.getAttribute('class').replace(' outline', ''); + this.body.node.setAttribute('class', newClass); + } /** * Change the Position of Node with relative to current position From d9037bdd008133503f2c6a67c7bc69c10ac54d04 Mon Sep 17 00:00:00 2001 From: Tyron Date: Tue, 14 Mar 2023 22:57:37 +0530 Subject: [PATCH 31/33] BreadBoard pin highlight additions --- ArduinoFrontend/src/app/Libs/General.ts | 8 ++++++++ ArduinoFrontend/src/assets/jsons/Breadboard.json | 3 +++ 2 files changed, 11 insertions(+) diff --git a/ArduinoFrontend/src/app/Libs/General.ts b/ArduinoFrontend/src/app/Libs/General.ts index 8c1f90165..45401348c 100644 --- a/ArduinoFrontend/src/app/Libs/General.ts +++ b/ArduinoFrontend/src/app/Libs/General.ts @@ -331,6 +331,10 @@ export class BreadBoard extends CircuitElement { * Map of y and nodes with y-coordinates as y */ public sameYNodes: { [key: string]: Point[] } = {}; + /** + * Stores group of points which are interconnected + */ + static groupings: any = []; /** * Breadboard constructor @@ -595,6 +599,10 @@ export class BreadBoard extends CircuitElement { init() { this.sortedNodes = _.sortBy(this.nodes, ['x', 'y']); + if (BreadBoard.groupings.length === 0) { + BreadBoard.groupings = this.data.groupings; + } + // initialise sameX and sameY node sets for (const node of this.nodes) { // create the set for x diff --git a/ArduinoFrontend/src/assets/jsons/Breadboard.json b/ArduinoFrontend/src/assets/jsons/Breadboard.json index 06013061f..cb67981d5 100644 --- a/ArduinoFrontend/src/assets/jsons/Breadboard.json +++ b/ArduinoFrontend/src/assets/jsons/Breadboard.json @@ -2015,6 +2015,9 @@ } ], "simulation": {}, + "data" : { + "groupings" : [["a","b","c","d","e"],["f","g","h","i","j"]] + }, "info": { "properties" : { "isBreadBoardPlaceable" : 0 From 202eb067428691f5e59d91c1d6b3d33fcadbd0c4 Mon Sep 17 00:00:00 2001 From: Tyron Date: Tue, 14 Mar 2023 23:03:38 +0530 Subject: [PATCH 32/33] Linting --- ArduinoFrontend/src/app/Libs/General.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/General.ts b/ArduinoFrontend/src/app/Libs/General.ts index 45401348c..4b37d025c 100644 --- a/ArduinoFrontend/src/app/Libs/General.ts +++ b/ArduinoFrontend/src/app/Libs/General.ts @@ -302,6 +302,11 @@ export class BreadBoard extends CircuitElement { */ static visitedNodesv2 = new Set(); + /** + * Stores group of points which are interconnected + */ + static groupings: any = []; + /** * Nodes that are connected */ @@ -331,10 +336,7 @@ export class BreadBoard extends CircuitElement { * Map of y and nodes with y-coordinates as y */ public sameYNodes: { [key: string]: Point[] } = {}; - /** - * Stores group of points which are interconnected - */ - static groupings: any = []; + /** * Breadboard constructor @@ -599,8 +601,8 @@ export class BreadBoard extends CircuitElement { init() { this.sortedNodes = _.sortBy(this.nodes, ['x', 'y']); - if (BreadBoard.groupings.length === 0) { - BreadBoard.groupings = this.data.groupings; + if (BreadBoard.groupings.length === 0) { + BreadBoard.groupings = this.data.groupings; } // initialise sameX and sameY node sets From 2502d8c5d08da64ee39e3f3820c51ca34d43734e Mon Sep 17 00:00:00 2001 From: Tyron Date: Tue, 14 Mar 2023 23:06:16 +0530 Subject: [PATCH 33/33] Linting --- ArduinoFrontend/src/app/Libs/General.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ArduinoFrontend/src/app/Libs/General.ts b/ArduinoFrontend/src/app/Libs/General.ts index 4b37d025c..1c31b714e 100644 --- a/ArduinoFrontend/src/app/Libs/General.ts +++ b/ArduinoFrontend/src/app/Libs/General.ts @@ -303,7 +303,7 @@ export class BreadBoard extends CircuitElement { static visitedNodesv2 = new Set(); /** - * Stores group of points which are interconnected + * Stores group of points which are interconnected */ static groupings: any = [];