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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions ArduinoFrontend/src/app/Libs/Workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,12 @@ export class Workspace {
window['scope'][classString].push(obj);
// Push dump to Undo stack & Reset
UndoUtils.pushChangeToUndoAndReset({ keyName: obj.keyName, event: 'add', element: obj.save() });
// **Trigger Reinit Only for Arduino Uno**
if (classString === 'ArduinoUno') {
setTimeout(() => {
window['reinitCodeEditor'] = true; // Set global reinit flag
}, 0);
}
}
/** Function updates the position of wires */
static updateWires() {
Expand Down Expand Up @@ -798,14 +804,6 @@ export class Workspace {
// Save Dump of current Workspace
// Check if component is selected
if (window['Selected']) {
// is selected component is an arduini uno then show confirm message
if (window['Selected'] instanceof ArduinoUno) {
const ans = confirm('The Respective code will also be lost!');
if (!ans) {
return;
}
}

// get the component id
const uid = window.Selected.id;
const key = window.Selected.keyName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<div [style.width.px]=width [style.minHeight]="height+'vh'" style="margin-top: 0px;">

<div class=" text text-center" style="display:flex;height: 100vh; background-color: whitesmoke; font-size: 1.4em;"
*ngIf="names.length == 0">
<p style="margin:auto auto;">No Programmable Component in this Circuit</p>
</div>

<div *ngIf="names.length>0">
<div>
<div class="inline-block"
style="display: flex; background-color:whitesmoke; justify-content: space-between;margin:auto;">
<span style="flex:1 1 auto;"></span>
Expand Down
40 changes: 28 additions & 12 deletions ArduinoFrontend/src/app/code-editor/code-editor.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, Input } from '@angular/core';
import { Component, OnInit, Input, DoCheck } from '@angular/core';
import { ArduinoUno } from '../Libs/outputs/Arduino';
import { Download } from '../Libs/Download';

Expand All @@ -16,7 +16,7 @@ declare var window;
templateUrl: './code-editor.component.html',
styleUrls: ['./code-editor.component.css']
})
export class CodeEditorComponent {
export class CodeEditorComponent implements DoCheck {
// TODO: Fetch records and Suggestion from api

/**
Expand Down Expand Up @@ -122,6 +122,8 @@ export class CodeEditorComponent {
window['isCodeEditorOpened'] = value;

if (value) {
const DEFAULT_CODE = 'void setup(){\n\t\n}\n\nvoid loop(){\n\t\n}';
const previousCode = this.code || '';
// Clear names and instances
this.names = [];
this.arduinos = [];
Expand All @@ -132,31 +134,41 @@ export class CodeEditorComponent {
this.arduinos.push(window['ArduinoUno_name'][key]);
}
}
// reset selected index
if (this.selectedIndex >= this.arduinos.length) {
this.selectedIndex = 0;
}
// select the code of respective arduino
// If an Uno is present, ensure it gets the existing code
if (this.arduinos.length > 0) {
this.code = this.arduinos[this.selectedIndex].code;
// Assign the code to all newly added Uno boards
this.arduinos.forEach((arduino, index) => {
if (arduino.code === DEFAULT_CODE && previousCode !== '') {
arduino.code = previousCode;
}
});
this.code = this.arduinos[this.selectedIndex].code || '';
}
// show loading animation if code editor is nor initialized

// Show loading animation if the code editor is not initialized
if (this.names.length !== 0 && !this.init) {
window['showLoading']();
}
}
}
ngDoCheck() {
if (window['reinitCodeEditor']) {
// console.log('Reinitializing the code editor');
window['reinitCodeEditor'] = false; // Reset flag
this.reinit = true;
}
}
/**
* Increase the size of the font in the editor
*/
IncreaseFont(fontSize: number) {
IncreaseFont(): void {
this.size = this.size + 1;
this.editorOptions = {...this.editorOptions, fontSize: this.size};
}
/**
* Decrease the size of the font in the editor
*/
DecreaseFont(fontSize: number) {
DecreaseFont(): void {
this.size = this.size - 1;
this.editorOptions = {...this.editorOptions, fontSize: this.size};
}
Expand Down Expand Up @@ -1216,7 +1228,11 @@ export class CodeEditorComponent {
* On code Change update the code in arduino
*/
codeChanged() {
this.arduinos[this.selectedIndex].code = this.code;
if (this.arduinos && this.selectedIndex >= 0 && this.selectedIndex < this.arduinos.length) {
this.arduinos[this.selectedIndex].code = this.code;
} else {
window['savedCode'] = this.code;
}
}
/**
* Select the code for respective arduino. Event handler for Choosing arduino
Expand Down