aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.gitignore1
-rw-r--r--demo/src/index.html1
-rw-r--r--demo/src/index.ts21
-rw-r--r--demo/src/utils/editor-history.util.ts17
4 files changed, 39 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 92cd86e..3a05d54 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
node_modules
dist
*.log
+.idea
diff --git a/demo/src/index.html b/demo/src/index.html
index 99b1c84..9b69306 100644
--- a/demo/src/index.html
+++ b/demo/src/index.html
@@ -17,6 +17,7 @@
<div class="toolbar">
<button id="run-button">Run</button>
<button id="stop-button" disabled>Stop</button>
+ <button id="revert-button">Back to leds example</button>
<div class="spacer"></div>
<div id="status-label"></div>
</div>
diff --git a/demo/src/index.ts b/demo/src/index.ts
index c886bba..4246547 100644
--- a/demo/src/index.ts
+++ b/demo/src/index.ts
@@ -5,6 +5,7 @@ import { formatTime } from './format-time';
import './index.css';
import { CPUPerformance } from './cpu-performance';
import { LEDElement } from '@wokwi/elements';
+import { EditorHistoryUtil } from './utils/editor-history.util';
let editor: any; // eslint-disable-line @typescript-eslint/no-explicit-any
const BLINK_CODE = `
@@ -32,7 +33,7 @@ window.require.config({
});
window.require(['vs/editor/editor.main'], () => {
editor = monaco.editor.create(document.querySelector('.code-editor'), {
- value: BLINK_CODE,
+ value: EditorHistoryUtil.getValue() || BLINK_CODE,
language: 'cpp',
minimap: { enabled: false }
});
@@ -50,6 +51,8 @@ const runButton = document.querySelector('#run-button');
runButton.addEventListener('click', compileAndRun);
const stopButton = document.querySelector('#stop-button');
stopButton.addEventListener('click', stopCode);
+const revertButton = document.querySelector('#revert-button');
+revertButton.addEventListener('click', setBlinkSnippet);
const statusLabel = document.querySelector('#status-label');
const compilerOutputText = document.querySelector('#compiler-output-text');
const serialOutputText = document.querySelector('#serial-output-text');
@@ -80,7 +83,11 @@ async function compileAndRun() {
led12.value = false;
led13.value = false;
+ storeUserSnippet();
+
runButton.setAttribute('disabled', '1');
+ revertButton.setAttribute('disabled', '1');
+
serialOutputText.textContent = '';
try {
statusLabel.textContent = 'Compiling...';
@@ -97,15 +104,27 @@ async function compileAndRun() {
runButton.removeAttribute('disabled');
alert('Failed: ' + err);
} finally {
+ revertButton.removeAttribute('disabled');
statusLabel.textContent = '';
}
}
+function storeUserSnippet() {
+ EditorHistoryUtil.clearSnippet();
+ EditorHistoryUtil.storeSnippet(editor.getValue());
+}
+
function stopCode() {
stopButton.setAttribute('disabled', '1');
runButton.removeAttribute('disabled');
+ revertButton.removeAttribute('disabled');
if (runner) {
runner.stop();
runner = null;
}
}
+
+function setBlinkSnippet() {
+ editor.setValue(BLINK_CODE);
+ EditorHistoryUtil.storeSnippet(editor.getValue());
+}
diff --git a/demo/src/utils/editor-history.util.ts b/demo/src/utils/editor-history.util.ts
new file mode 100644
index 0000000..33d1916
--- /dev/null
+++ b/demo/src/utils/editor-history.util.ts
@@ -0,0 +1,17 @@
+const AVRJS8_EDITOR_HISTORY = 'AVRJS8_EDITOR_HISTORY';
+
+export class EditorHistoryUtil {
+ static storeSnippet(codeSnippet: string) {
+ if (window.localStorage) {
+ window.localStorage.setItem(AVRJS8_EDITOR_HISTORY, codeSnippet);
+ } else throw new Error('no localStorage support');
+ }
+
+ static clearSnippet() {
+ localStorage.removeItem(AVRJS8_EDITOR_HISTORY);
+ }
+
+ static getValue() {
+ return localStorage.getItem(AVRJS8_EDITOR_HISTORY);
+ }
+}
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.