refactor: update component wiring and properties in Arduino examples
parent
405b6d8a6d
commit
7acce0b610
|
|
@ -148,22 +148,40 @@ void loop() {
|
||||||
"board": "arduino:avr:uno",
|
"board": "arduino:avr:uno",
|
||||||
"components": [
|
"components": [
|
||||||
{
|
{
|
||||||
"type": "wokwi-pushbutton",
|
"type": "led",
|
||||||
"id": "button-1",
|
"id": "led-builtin",
|
||||||
"x": 400,
|
"x": 956.2066448009604,
|
||||||
"y": -100,
|
"y": -15.285273464964305,
|
||||||
"rotation": 0,
|
|
||||||
"props": {}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "wokwi-led",
|
|
||||||
"id": "led-1",
|
|
||||||
"x": 400,
|
|
||||||
"y": -250,
|
|
||||||
"rotation": 0,
|
"rotation": 0,
|
||||||
"props": {
|
"props": {
|
||||||
"color": "green",
|
"color": "red",
|
||||||
"pin": 13
|
"pin": 13,
|
||||||
|
"state": false,
|
||||||
|
"value": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "resistor",
|
||||||
|
"id": "resistor-1776299815587-z0q0jzny8",
|
||||||
|
"x": 808.6031046903261,
|
||||||
|
"y": 44.96592399354325,
|
||||||
|
"rotation": 0,
|
||||||
|
"props": {
|
||||||
|
"value": false,
|
||||||
|
"state": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "pushbutton",
|
||||||
|
"id": "pushbutton-1776299852057-07xh6qh7g",
|
||||||
|
"x": 829.2414304859469,
|
||||||
|
"y": 230.19576790585754,
|
||||||
|
"rotation": 0,
|
||||||
|
"props": {
|
||||||
|
"color": "red",
|
||||||
|
"pressed": false,
|
||||||
|
"label": "",
|
||||||
|
"xray": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
@ -179,20 +197,54 @@ PRESSED
|
||||||
{
|
{
|
||||||
"wires": [
|
"wires": [
|
||||||
{
|
{
|
||||||
"start": { "componentId": "arduino-uno", "pinName": "2" },
|
"start": {
|
||||||
"end": { "componentId": "button-1", "pinName": "1.l" }
|
"componentId": "resistor-1776299815587-z0q0jzny8",
|
||||||
|
"pinName": "2"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"componentId": "led-builtin",
|
||||||
|
"pinName": "A"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"start": { "componentId": "button-1", "pinName": "2.l" },
|
"start": {
|
||||||
"end": { "componentId": "arduino-uno", "pinName": "GND" }
|
"componentId": "arduino-uno",
|
||||||
|
"pinName": "GND.1"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"componentId": "led-builtin",
|
||||||
|
"pinName": "C"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"start": { "componentId": "arduino-uno", "pinName": "13" },
|
"start": {
|
||||||
"end": { "componentId": "led-1", "pinName": "A" }
|
"componentId": "resistor-1776299815587-z0q0jzny8",
|
||||||
|
"pinName": "1"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"componentId": "arduino-uno",
|
||||||
|
"pinName": "13"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"start": { "componentId": "led-1", "pinName": "C" },
|
"start": {
|
||||||
"end": { "componentId": "arduino-uno", "pinName": "GND" }
|
"componentId": "pushbutton-1776299852057-07xh6qh7g",
|
||||||
|
"pinName": "1.l"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"componentId": "arduino-uno",
|
||||||
|
"pinName": "2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"start": {
|
||||||
|
"componentId": "arduino-uno",
|
||||||
|
"pinName": "GND.3"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"componentId": "pushbutton-1776299852057-07xh6qh7g",
|
||||||
|
"pinName": "2.l"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,40 +147,81 @@ void loop() {
|
||||||
"board": "arduino:avr:uno",
|
"board": "arduino:avr:uno",
|
||||||
"components": [
|
"components": [
|
||||||
{
|
{
|
||||||
"type": "wokwi-led",
|
"type": "led",
|
||||||
"id": "led-red",
|
"id": "led-red",
|
||||||
"x": 370,
|
"x": 409.6091884525257,
|
||||||
"y": -300,
|
"y": 65.40692157090741,
|
||||||
"rotation": 0,
|
"rotation": 0,
|
||||||
"props": {
|
"props": {
|
||||||
"color": "red",
|
"color": "red",
|
||||||
"pin": 13
|
"pin": 13,
|
||||||
|
"state": true,
|
||||||
|
"value": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "wokwi-led",
|
"type": "led",
|
||||||
"id": "led-yellow",
|
"id": "led-yellow",
|
||||||
"x": 370,
|
"x": 466.09101803924966,
|
||||||
"y": -200,
|
"y": 66.43228050989252,
|
||||||
"rotation": 0,
|
"rotation": 0,
|
||||||
"props": {
|
"props": {
|
||||||
"color": "yellow",
|
"color": "yellow",
|
||||||
"pin": 12
|
"pin": 12,
|
||||||
|
"state": false,
|
||||||
|
"value": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "wokwi-led",
|
"type": "led",
|
||||||
"id": "led-green",
|
"id": "led-green",
|
||||||
"x": 370,
|
"x": 522.0366933470766,
|
||||||
"y": -100,
|
"y": 63.613964067867315,
|
||||||
"rotation": 0,
|
"rotation": 0,
|
||||||
"props": {
|
"props": {
|
||||||
"color": "green",
|
"color": "green",
|
||||||
"pin": 11
|
"pin": 11,
|
||||||
|
"state": false,
|
||||||
|
"value": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "resistor",
|
||||||
|
"id": "resistor-1776300566703-7pi4wei9j",
|
||||||
|
"x": 275.08055011716567,
|
||||||
|
"y": 133.79325981817132,
|
||||||
|
"rotation": 0,
|
||||||
|
"props": {
|
||||||
|
"value": true,
|
||||||
|
"state": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "resistor",
|
||||||
|
"id": "resistor-1776300590088-k4l87u1rf",
|
||||||
|
"x": 273.3198126609919,
|
||||||
|
"y": 178.95644554504224,
|
||||||
|
"rotation": 0,
|
||||||
|
"props": {
|
||||||
|
"value": false,
|
||||||
|
"state": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "resistor",
|
||||||
|
"id": "resistor-1776300593575-rklkixiwy",
|
||||||
|
"x": 270.5981563595655,
|
||||||
|
"y": 220.2759558909028,
|
||||||
|
"rotation": 0,
|
||||||
|
"props": {
|
||||||
|
"value": false,
|
||||||
|
"state": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"wires": []
|
"wires": [
|
||||||
|
|
||||||
|
]
|
||||||
}
|
}
|
||||||
---END_VELXIO_CIRCUIT---
|
---END_VELXIO_CIRCUIT---
|
||||||
|
|
||||||
|
|
@ -195,28 +236,94 @@ YELLOW
|
||||||
{
|
{
|
||||||
"wires": [
|
"wires": [
|
||||||
{
|
{
|
||||||
"start": { "componentId": "arduino-uno", "pinName": "13" },
|
"start": {
|
||||||
"end": { "componentId": "led-red", "pinName": "A" }
|
"componentId": "resistor-1776300566703-7pi4wei9j",
|
||||||
|
"pinName": "2"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"componentId": "led-red",
|
||||||
|
"pinName": "A"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"start": { "componentId": "led-red", "pinName": "C" },
|
"start": {
|
||||||
"end": { "componentId": "arduino-uno", "pinName": "GND" }
|
"componentId": "resistor-1776300590088-k4l87u1rf",
|
||||||
|
"pinName": "2"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"componentId": "led-yellow",
|
||||||
|
"pinName": "A"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"start": { "componentId": "arduino-uno", "pinName": "12" },
|
"start": {
|
||||||
"end": { "componentId": "led-yellow", "pinName": "A" }
|
"componentId": "resistor-1776300593575-rklkixiwy",
|
||||||
|
"pinName": "2"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"componentId": "led-green",
|
||||||
|
"pinName": "A"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"start": { "componentId": "led-yellow", "pinName": "C" },
|
"start": {
|
||||||
"end": { "componentId": "arduino-uno", "pinName": "GND" }
|
"componentId": "arduino-uno",
|
||||||
|
"pinName": "GND.3"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"componentId": "led-red",
|
||||||
|
"pinName": "C"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"start": { "componentId": "arduino-uno", "pinName": "11" },
|
"start": {
|
||||||
"end": { "componentId": "led-green", "pinName": "A" }
|
"componentId": "arduino-uno",
|
||||||
|
"pinName": "GND.3"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"componentId": "led-yellow",
|
||||||
|
"pinName": "C"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"start": { "componentId": "led-green", "pinName": "C" },
|
"start": {
|
||||||
"end": { "componentId": "arduino-uno", "pinName": "GND" }
|
"componentId": "arduino-uno",
|
||||||
|
"pinName": "GND.3"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"componentId": "led-green",
|
||||||
|
"pinName": "C"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"start": {
|
||||||
|
"componentId": "resistor-1776300566703-7pi4wei9j",
|
||||||
|
"pinName": "1"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"componentId": "arduino-uno",
|
||||||
|
"pinName": "13"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"start": {
|
||||||
|
"componentId": "resistor-1776300590088-k4l87u1rf",
|
||||||
|
"pinName": "1"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"componentId": "arduino-uno",
|
||||||
|
"pinName": "12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"start": {
|
||||||
|
"componentId": "resistor-1776300593575-rklkixiwy",
|
||||||
|
"pinName": "1"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"componentId": "arduino-uno",
|
||||||
|
"pinName": "11"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<nav class="navbar">
|
<nav class="navbar" onclick={() => auth.recordActivity()}>
|
||||||
<div class="container navbar-inner">
|
<div class="container navbar-inner">
|
||||||
{#if $lessonContext}
|
{#if $lessonContext}
|
||||||
<!-- Lesson mode -->
|
<!-- Lesson mode -->
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,38 @@ import { writable, get } from 'svelte/store';
|
||||||
import { validateToken, login as apiLogin, logout as apiLogout } from '$services/api';
|
import { validateToken, login as apiLogin, logout as apiLogout } from '$services/api';
|
||||||
|
|
||||||
const STORAGE_KEY = 'student_token';
|
const STORAGE_KEY = 'student_token';
|
||||||
|
const LAST_ACTIVE_KEY = 'student_last_active';
|
||||||
|
const MAX_INACTIVITY = 24 * 60 * 60 * 1000; // 1 day in ms
|
||||||
|
|
||||||
export const authToken = writable('');
|
export const authToken = writable('');
|
||||||
export const authStudentName = writable('');
|
export const authStudentName = writable('');
|
||||||
export const authLoggedIn = writable(false);
|
export const authLoggedIn = writable(false);
|
||||||
export const authIsTeacher = writable(false);
|
export const authIsTeacher = writable(false);
|
||||||
|
|
||||||
|
function clearAllCookies() {
|
||||||
|
if (typeof document === 'undefined') return;
|
||||||
|
const cookies = document.cookie.split(';');
|
||||||
|
for (let i = 0; i < cookies.length; i++) {
|
||||||
|
const cookie = cookies[i];
|
||||||
|
const eqPos = cookie.indexOf('=');
|
||||||
|
const name = eqPos > -1 ? cookie.substr(0, eqPos).trim() : cookie.trim();
|
||||||
|
document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearAuthData() {
|
||||||
|
clearAllCookies();
|
||||||
|
localStorage.removeItem(STORAGE_KEY);
|
||||||
|
localStorage.removeItem(LAST_ACTIVE_KEY);
|
||||||
|
sessionStorage.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateLastActive() {
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
localStorage.setItem(LAST_ACTIVE_KEY, Date.now().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const auth = {
|
export const auth = {
|
||||||
/** Current token value (non-reactive). */
|
/** Current token value (non-reactive). */
|
||||||
get token() { return get(authToken); },
|
get token() { return get(authToken); },
|
||||||
|
|
@ -25,9 +51,21 @@ export const auth = {
|
||||||
/** Restore session from localStorage on app mount. */
|
/** Restore session from localStorage on app mount. */
|
||||||
async init() {
|
async init() {
|
||||||
if (typeof window === 'undefined') return;
|
if (typeof window === 'undefined') return;
|
||||||
|
|
||||||
const saved = localStorage.getItem(STORAGE_KEY);
|
const saved = localStorage.getItem(STORAGE_KEY);
|
||||||
|
const lastActive = localStorage.getItem(LAST_ACTIVE_KEY);
|
||||||
|
|
||||||
if (!saved) return;
|
if (!saved) return;
|
||||||
|
|
||||||
|
// Check for 1 day inactivity
|
||||||
|
if (lastActive) {
|
||||||
|
const inactiveTime = Date.now() - parseInt(lastActive, 10);
|
||||||
|
if (inactiveTime > MAX_INACTIVITY) {
|
||||||
|
clearAuthData();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await validateToken(saved);
|
const res = await validateToken(saved);
|
||||||
if (res.success && res.student_name) {
|
if (res.success && res.student_name) {
|
||||||
|
|
@ -35,17 +73,18 @@ export const auth = {
|
||||||
authStudentName.set(res.student_name);
|
authStudentName.set(res.student_name);
|
||||||
authLoggedIn.set(true);
|
authLoggedIn.set(true);
|
||||||
authIsTeacher.set(res.is_teacher ?? false);
|
authIsTeacher.set(res.is_teacher ?? false);
|
||||||
|
updateLastActive();
|
||||||
} else {
|
} else {
|
||||||
localStorage.removeItem(STORAGE_KEY);
|
clearAuthData();
|
||||||
sessionStorage.clear();
|
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
localStorage.removeItem(STORAGE_KEY);
|
clearAuthData();
|
||||||
sessionStorage.clear();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async login(inputToken: string) {
|
async login(inputToken: string) {
|
||||||
|
clearAuthData();
|
||||||
|
|
||||||
const res = await apiLogin(inputToken);
|
const res = await apiLogin(inputToken);
|
||||||
if (res.success && res.student_name) {
|
if (res.success && res.student_name) {
|
||||||
authToken.set(inputToken);
|
authToken.set(inputToken);
|
||||||
|
|
@ -53,18 +92,29 @@ export const auth = {
|
||||||
authLoggedIn.set(true);
|
authLoggedIn.set(true);
|
||||||
authIsTeacher.set(res.is_teacher ?? false);
|
authIsTeacher.set(res.is_teacher ?? false);
|
||||||
localStorage.setItem(STORAGE_KEY, inputToken);
|
localStorage.setItem(STORAGE_KEY, inputToken);
|
||||||
sessionStorage.clear();
|
updateLastActive();
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
async logout() {
|
async logout() {
|
||||||
|
try {
|
||||||
await apiLogout();
|
await apiLogout();
|
||||||
|
} catch {
|
||||||
|
// ignore logout failure, proceed to clear local state
|
||||||
|
}
|
||||||
authToken.set('');
|
authToken.set('');
|
||||||
authStudentName.set('');
|
authStudentName.set('');
|
||||||
authLoggedIn.set(false);
|
authLoggedIn.set(false);
|
||||||
authIsTeacher.set(false);
|
authIsTeacher.set(false);
|
||||||
localStorage.removeItem(STORAGE_KEY);
|
clearAuthData();
|
||||||
sessionStorage.clear();
|
location.reload();
|
||||||
|
},
|
||||||
|
|
||||||
|
/** Update activity timestamp. Call this on user interactions. */
|
||||||
|
recordActivity() {
|
||||||
|
if (get(authLoggedIn)) {
|
||||||
|
updateLastActive();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
2
velxio
2
velxio
|
|
@ -1 +1 @@
|
||||||
Subproject commit 87be2526bab379258593086587dd64bf02965436
|
Subproject commit 9402b6c40f338b4c65ea275e42fb94341cd354db
|
||||||
Loading…
Reference in New Issue