Update mouse

This commit is contained in:
Serge NOEL
2026-02-23 13:13:32 +01:00
parent aab249e7eb
commit 49b731c26c
4 changed files with 120 additions and 32 deletions

View File

@@ -4,50 +4,53 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mouse Speedometer</title>
<style>
body { background: #f4f4f4; font-family: Arial, sans-serif; }
.container { max-width: 400px; margin: 40px auto; background: #fff; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); padding: 32px; }
#speedometer { display: block; margin: 0 auto; }
</style>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="container">
<h2>Mouse Speedometer</h2>
<div id="toolBar">
<!-- ON/OFF (Gray OFF/ Orange ON) -->
<i class="fa-solid fa-power-off"></i>
<!-- display DCCID or '-' if Analogique or Marklin -->
<i class="fa-solid fa-train"></i><span id="DCCID">34</span>
<!-- display mode (Analogique or Marklin or DCC) -->
<i class="fa-solid fa-wave-square"></i><span id="Mode">Analogique</span>
<!-- display direction (Forward or Reverse) -->
<i class="fa-solid fa-forward"></i>
<!-- Program CV -->
<i class="fa-solid fa-cogs"></i>
<!-- Accessories switch to accessories page -->
<i class="fa-solid fa-traffic-light"></i>
</div>
<div id="SelectLoco">
<!-- display a view of scale model -->
<img src="img/locos/loco.png" alt="Loco" width="300" height="50" onClick="SelectLoco();" style="cursor:pointer; margin-right:20px;">
</div>
<div id="speedometer">
<!-- Inline SVG for speedometer -->
<svg width="300" height="200" viewBox="0 0 300 200" xmlns="http://www.w3.org/2000/svg">
<image href="Speed.png" x="0" y="0" width="300" height="200"/>
<image href="img/Speed.png" x="0" y="0" width="300" height="200"/>
<line id="needle" x1="150" y1="120" x2="150" y2="70" stroke="#e74c3c" stroke-width="6" stroke-linecap="round" />
</svg>
</div>
<div style="text-align:center; margin-top:20px;">
<button onclick="setSpeed(0)">0</button>
<button onclick="setSpeed(100)">100</button>
<button onclick="setSpeed(200)">200</button>
<!-- slider-->
<input type="range" id="speedSlider" min="0" max="128" value="0" oninput="updateSpeedometer(this.value);" style="width:80%;">
</div>
<div id="Functions">
<!-- Display F0 to F7 -->
<div class="function" id="F0">F0</div>
<div class="function" id="F1">F1</div>
<div class="function" id="F2">F2</div>
<div class="function" id="F3">F3</div>
<div class="function" id="F4">F4</div>
<div class="function" id="F5">F5</div>
<div class="function" id="F6">F6</div>
<div class="function" id="F7">F7</div>
</div>
</div>
<script>
/**
* Speed is expected to be in the range 0-200. This function maps it to an angle for the needle.
* at 100Kmh, needle is vertical, it's length is 50px, and it rotates from -120deg (0 speed) to +120deg (max speed).
* At speed=100, x2=150, y2=70
*/
function setSpeed(speed)
{
// Clamp speed
speed = Math.max(0, Math.min(200, speed));
// Map speed to angle: 0 = -120deg, 100 = 0deg, 200 = +120deg
var angle = -120 + (speed / 200) * 240;
var rad = angle * Math.PI / 180;
var r = 50; // needle length
var cx = 150, cy = 120;
var x2 = cx + r * Math.sin(rad); // Use sin for x, cos for y to match SVG coordinate system
var y2 = cy - r * Math.cos(rad);
document.getElementById('needle').setAttribute('x2', x2);
document.getElementById('needle').setAttribute('y2', y2);
}
// Example: set speed to 0 initially
setSpeed(20);
</script>
<script type="text/javascript" src="js/mouse.js"></script>
</body>
</html>