refactor: update component wiring and properties in Arduino examples

master
a2nr 2026-04-16 08:00:54 +07:00
parent 405b6d8a6d
commit 7acce0b610
5 changed files with 267 additions and 58 deletions

View File

@ -148,22 +148,40 @@ void loop() {
"board": "arduino:avr:uno",
"components": [
{
"type": "wokwi-pushbutton",
"id": "button-1",
"x": 400,
"y": -100,
"rotation": 0,
"props": {}
},
{
"type": "wokwi-led",
"id": "led-1",
"x": 400,
"y": -250,
"type": "led",
"id": "led-builtin",
"x": 956.2066448009604,
"y": -15.285273464964305,
"rotation": 0,
"props": {
"color": "green",
"pin": 13
"color": "red",
"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": [
{
"start": { "componentId": "arduino-uno", "pinName": "2" },
"end": { "componentId": "button-1", "pinName": "1.l" }
"start": {
"componentId": "resistor-1776299815587-z0q0jzny8",
"pinName": "2"
},
"end": {
"componentId": "led-builtin",
"pinName": "A"
}
},
{
"start": { "componentId": "button-1", "pinName": "2.l" },
"end": { "componentId": "arduino-uno", "pinName": "GND" }
"start": {
"componentId": "arduino-uno",
"pinName": "GND.1"
},
"end": {
"componentId": "led-builtin",
"pinName": "C"
}
},
{
"start": { "componentId": "arduino-uno", "pinName": "13" },
"end": { "componentId": "led-1", "pinName": "A" }
"start": {
"componentId": "resistor-1776299815587-z0q0jzny8",
"pinName": "1"
},
"end": {
"componentId": "arduino-uno",
"pinName": "13"
}
},
{
"start": { "componentId": "led-1", "pinName": "C" },
"end": { "componentId": "arduino-uno", "pinName": "GND" }
"start": {
"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"
}
}
]
}

View File

@ -147,40 +147,81 @@ void loop() {
"board": "arduino:avr:uno",
"components": [
{
"type": "wokwi-led",
"type": "led",
"id": "led-red",
"x": 370,
"y": -300,
"x": 409.6091884525257,
"y": 65.40692157090741,
"rotation": 0,
"props": {
"color": "red",
"pin": 13
"pin": 13,
"state": true,
"value": true
}
},
{
"type": "wokwi-led",
"type": "led",
"id": "led-yellow",
"x": 370,
"y": -200,
"x": 466.09101803924966,
"y": 66.43228050989252,
"rotation": 0,
"props": {
"color": "yellow",
"pin": 12
"pin": 12,
"state": false,
"value": false
}
},
{
"type": "wokwi-led",
"type": "led",
"id": "led-green",
"x": 370,
"y": -100,
"x": 522.0366933470766,
"y": 63.613964067867315,
"rotation": 0,
"props": {
"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---
@ -194,29 +235,95 @@ YELLOW
---EXPECTED_WIRING---
{
"wires": [
{
"start": { "componentId": "arduino-uno", "pinName": "13" },
"end": { "componentId": "led-red", "pinName": "A" }
{
"start": {
"componentId": "resistor-1776300566703-7pi4wei9j",
"pinName": "2"
},
"end": {
"componentId": "led-red",
"pinName": "A"
}
},
{
"start": { "componentId": "led-red", "pinName": "C" },
"end": { "componentId": "arduino-uno", "pinName": "GND" }
"start": {
"componentId": "resistor-1776300590088-k4l87u1rf",
"pinName": "2"
},
"end": {
"componentId": "led-yellow",
"pinName": "A"
}
},
{
"start": { "componentId": "arduino-uno", "pinName": "12" },
"end": { "componentId": "led-yellow", "pinName": "A" }
"start": {
"componentId": "resistor-1776300593575-rklkixiwy",
"pinName": "2"
},
"end": {
"componentId": "led-green",
"pinName": "A"
}
},
{
"start": { "componentId": "led-yellow", "pinName": "C" },
"end": { "componentId": "arduino-uno", "pinName": "GND" }
"start": {
"componentId": "arduino-uno",
"pinName": "GND.3"
},
"end": {
"componentId": "led-red",
"pinName": "C"
}
},
{
"start": { "componentId": "arduino-uno", "pinName": "11" },
"end": { "componentId": "led-green", "pinName": "A" }
"start": {
"componentId": "arduino-uno",
"pinName": "GND.3"
},
"end": {
"componentId": "led-yellow",
"pinName": "C"
}
},
{
"start": { "componentId": "led-green", "pinName": "C" },
"end": { "componentId": "arduino-uno", "pinName": "GND" }
"start": {
"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"
}
}
]
}

View File

@ -31,7 +31,7 @@
}
</script>
<nav class="navbar">
<nav class="navbar" onclick={() => auth.recordActivity()}>
<div class="container navbar-inner">
{#if $lessonContext}
<!-- Lesson mode -->

View File

@ -11,12 +11,38 @@ import { writable, get } from 'svelte/store';
import { validateToken, login as apiLogin, logout as apiLogout } from '$services/api';
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 authStudentName = writable('');
export const authLoggedIn = 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 = {
/** Current token value (non-reactive). */
get token() { return get(authToken); },
@ -25,9 +51,21 @@ export const auth = {
/** Restore session from localStorage on app mount. */
async init() {
if (typeof window === 'undefined') return;
const saved = localStorage.getItem(STORAGE_KEY);
const lastActive = localStorage.getItem(LAST_ACTIVE_KEY);
if (!saved) return;
// Check for 1 day inactivity
if (lastActive) {
const inactiveTime = Date.now() - parseInt(lastActive, 10);
if (inactiveTime > MAX_INACTIVITY) {
clearAuthData();
return;
}
}
try {
const res = await validateToken(saved);
if (res.success && res.student_name) {
@ -35,17 +73,18 @@ export const auth = {
authStudentName.set(res.student_name);
authLoggedIn.set(true);
authIsTeacher.set(res.is_teacher ?? false);
updateLastActive();
} else {
localStorage.removeItem(STORAGE_KEY);
sessionStorage.clear();
clearAuthData();
}
} catch {
localStorage.removeItem(STORAGE_KEY);
sessionStorage.clear();
clearAuthData();
}
},
async login(inputToken: string) {
clearAuthData();
const res = await apiLogin(inputToken);
if (res.success && res.student_name) {
authToken.set(inputToken);
@ -53,18 +92,29 @@ export const auth = {
authLoggedIn.set(true);
authIsTeacher.set(res.is_teacher ?? false);
localStorage.setItem(STORAGE_KEY, inputToken);
sessionStorage.clear();
updateLastActive();
}
return res;
},
async logout() {
await apiLogout();
try {
await apiLogout();
} catch {
// ignore logout failure, proceed to clear local state
}
authToken.set('');
authStudentName.set('');
authLoggedIn.set(false);
authIsTeacher.set(false);
localStorage.removeItem(STORAGE_KEY);
sessionStorage.clear();
clearAuthData();
location.reload();
},
/** Update activity timestamp. Call this on user interactions. */
recordActivity() {
if (get(authLoggedIn)) {
updateLastActive();
}
}
};

2
velxio

@ -1 +1 @@
Subproject commit 87be2526bab379258593086587dd64bf02965436
Subproject commit 9402b6c40f338b4c65ea275e42fb94341cd354db