Initialisation depot
This commit is contained in:
commit
56d8cd96c8
28 files changed
+3154
No files matched your search
+182
@@ -0,0 +1,182 @@
|
||||
let currentMode = 'analog';
|
||||
let currentDirection = 1;
|
||||
let dccFunctions = 0;
|
||||
|
||||
// Initialize
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadStatus();
|
||||
setupEventListeners();
|
||||
generateFunctionButtons();
|
||||
setInterval(loadStatus, 2000);
|
||||
});
|
||||
|
||||
function setupEventListeners() {
|
||||
document.getElementById('speedSlider').addEventListener('input', function(e) {
|
||||
updateSpeed(e.target.value);
|
||||
});
|
||||
|
||||
document.querySelectorAll('input[name="mode"]').forEach(radio => {
|
||||
radio.addEventListener('change', function(e) {
|
||||
setMode(e.target.value);
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById('wifiMode').addEventListener('change', function(e) {
|
||||
toggleWiFiSettings(e.target.value);
|
||||
});
|
||||
}
|
||||
|
||||
function generateFunctionButtons() {
|
||||
const container = document.getElementById('functionButtons');
|
||||
for (let i = 0; i <= 12; i++) {
|
||||
const btn = document.createElement('button');
|
||||
btn.className = 'btn btn-outline-secondary function-btn';
|
||||
btn.id = 'f' + i;
|
||||
btn.textContent = 'F' + i;
|
||||
btn.onclick = () => toggleFunction(i);
|
||||
container.appendChild(btn);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadStatus() {
|
||||
try {
|
||||
const response = await fetch('/api/status');
|
||||
const data = await response.json();
|
||||
|
||||
document.getElementById('statusIndicator').className = 'status-indicator status-connected';
|
||||
document.getElementById('statusText').textContent = 'Connected';
|
||||
document.getElementById('ipAddress').textContent = data.ip || '-';
|
||||
|
||||
currentMode = data.mode;
|
||||
currentDirection = data.direction;
|
||||
document.getElementById(data.mode === 'dcc' ? 'modeDCC' : 'modeAnalog').checked = true;
|
||||
document.getElementById('speedSlider').value = data.speed;
|
||||
document.getElementById('speedValue').textContent = data.speed + '%';
|
||||
document.getElementById('dccAddress').value = data.dccAddress;
|
||||
|
||||
updateUIForMode(data.mode);
|
||||
updateDirectionIndicator();
|
||||
} catch (error) {
|
||||
document.getElementById('statusIndicator').className = 'status-indicator status-disconnected';
|
||||
document.getElementById('statusText').textContent = 'Disconnected';
|
||||
}
|
||||
}
|
||||
|
||||
function updateUIForMode(mode) {
|
||||
currentMode = mode;
|
||||
document.getElementById('dccSection').style.display = mode === 'dcc' ? 'block' : 'none';
|
||||
document.getElementById('functionsSection').style.display = mode === 'dcc' ? 'block' : 'none';
|
||||
}
|
||||
|
||||
async function setMode(mode) {
|
||||
try {
|
||||
await fetch('/api/mode', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({mode: mode})
|
||||
});
|
||||
updateUIForMode(mode);
|
||||
} catch (error) {
|
||||
console.error('Error setting mode:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function updateSpeed(speed) {
|
||||
document.getElementById('speedValue').textContent = speed + '%';
|
||||
try {
|
||||
await fetch('/api/speed', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({
|
||||
speed: parseInt(speed),
|
||||
direction: currentDirection
|
||||
})
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error setting speed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function emergencyStop() {
|
||||
document.getElementById('speedSlider').value = 0;
|
||||
updateSpeed(0);
|
||||
}
|
||||
|
||||
async function reverseDirection() {
|
||||
currentDirection = currentDirection === 1 ? 0 : 1;
|
||||
updateDirectionIndicator();
|
||||
const speed = document.getElementById('speedSlider').value;
|
||||
updateSpeed(speed);
|
||||
}
|
||||
|
||||
function updateDirectionIndicator() {
|
||||
document.getElementById('directionIndicator').textContent = currentDirection === 1 ? '→' : '←';
|
||||
}
|
||||
|
||||
async function setDCCAddress() {
|
||||
const address = document.getElementById('dccAddress').value;
|
||||
try {
|
||||
await fetch('/api/dcc/address', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({address: parseInt(address)})
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error setting DCC address:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleFunction(fn) {
|
||||
const btn = document.getElementById('f' + fn);
|
||||
const isActive = btn.classList.contains('btn-secondary');
|
||||
|
||||
if (isActive) {
|
||||
btn.classList.remove('btn-secondary');
|
||||
btn.classList.add('btn-outline-secondary');
|
||||
} else {
|
||||
btn.classList.remove('btn-outline-secondary');
|
||||
btn.classList.add('btn-secondary');
|
||||
}
|
||||
|
||||
try {
|
||||
await fetch('/api/dcc/function', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({
|
||||
function: fn,
|
||||
state: !isActive
|
||||
})
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error setting function:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleWiFiSettings(mode) {
|
||||
document.getElementById('apSettings').style.display = mode === 'ap' ? 'block' : 'none';
|
||||
document.getElementById('clientSettings').style.display = mode === 'client' ? 'block' : 'none';
|
||||
}
|
||||
|
||||
async function saveWiFiSettings() {
|
||||
const mode = document.getElementById('wifiMode').value;
|
||||
const config = {
|
||||
isAPMode: mode === 'ap',
|
||||
apSSID: document.getElementById('apSSID').value,
|
||||
apPassword: document.getElementById('apPassword').value,
|
||||
ssid: document.getElementById('wifiSSID').value,
|
||||
password: document.getElementById('wifiPassword').value
|
||||
};
|
||||
|
||||
if (confirm('Save WiFi settings and restart?')) {
|
||||
try {
|
||||
await fetch('/api/wifi', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify(config)
|
||||
});
|
||||
alert('Settings saved. Device will restart...');
|
||||
} catch (error) {
|
||||
console.error('Error saving WiFi settings:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
/*!
|
||||
* Bootstrap v5.3.0 (https://getbootstrap.com/)
|
||||
* Copyright 2011-2023 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
*/
|
||||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).bootstrap=e()}(this,(function(){"use strict";const t=new Map,e={set(e,i,n){t.has(e)||t.set(e,new Map);const s=t.get(e);s.has(i)||0===s.size?s.set(i,n):console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(s.keys())[0]}.`)},get:(e,i)=>t.has(e)&&t.get(e).get(i)||null,remove(e,i){if(!t.has(e))return;const n=t.get(e);n.delete(i),0===n.size&&t.delete(e)}},i="transitionend",n=t=>(t&&window.CSS&&window.CSS.escape&&(t=t.replace(/#([^\s"#']+)/g,((t,e)=>`#${CSS.escape(e)}`))),t),s=t=>{t.dispatchEvent(new Event(i))},o=t=>!(!t||"object"!=typeof t)&&(void 0!==t.jquery&&(t=t[0]),void 0!==t.nodeType),r=t=>o(t)?t.jquery?t[0]:t:"string"==typeof t&&t.length>0?document.querySelector(n(t)):null,a=t=>{if(!o(t)||0===t.getClientRects().length)return!1;const e="visible"===getComputedStyle(t).getPropertyValue("visibility"),i=t.closest("details:not([open])");if(!i)return e;if(i!==t){const e=t.closest("summary");if(e&&e.parentNode!==i)return!1;if(null===e)return!1}return e},l=t=>!t||t.nodeType!==Node.ELEMENT_NODE||!!t.classList.contains("disabled")||(void 0!==t.disabled?t.disabled:t.hasAttribute("disabled")&&"false"!==t.getAttribute("disabled")),c=t=>{if(!document.documentElement.attachShadow)return null;if("function"==typeof t.getRootNode){const e=t.getRootNode();return e instanceof ShadowRoot?e:null}return t instanceof ShadowRoot?t:t.parentNode?c(t.parentNode):null},h=()=>{},d=t=>{t.offsetHeight},u=()=>window.jQuery&&!document.body.hasAttribute("data-bs-no-jquery")?window.jQuery:null,f=[],p=()=>"rtl"===document.documentElement.dir,m=t=>{var e;e=()=>{const e=u();if(e){const i=t.NAME,n=e.fn[i];e.fn[i]=t.jQueryInterface,e.fn[i].Constructor=t,e.fn[i].noConflict=()=>(e.fn[i]=n,t.jQueryInterface)}},"loading"===document.readyState?(f.length||document.addEventListener("DOMContentLoaded",(()=>{for(const t of f)t()})),f.push(e)):e()},g=(t,e=[],i=t)=>"function"==typeof t?t(...e):i,_=(t,e,n=!0)=>{if(!n)return void g(t);const o=(t=>{if(!t)return 0;let{transitionDuration:e,transitionDelay:i}=window.getComputedStyle(t);const n=Number.parseFloat(e),s=Number.parseFloat(i);return n||s?(e=e.split(",")[0],i=i.split(",")[0],1e3*(Number.parseFloat(e)+Number.parseFloat(i))):0})(e)+5;let r=!1;const a=({target:n})=>{n===e&&(r=!0,e.removeEventListener(i,a),g(t))};e.addEventListener(i,a),setTimeout((()=>{r||s(e)}),o)},b=(t,e,i,n)=>{const s=t.length;let o=t.indexOf(e);return-1===o?!i&&n?t[s-1]:t[0]:(o+=i?1:-1,n&&(o=(o+s)%s),t[Math.max(0,Math.min(o,s-1))])},v=/[^.]*(?=\..*)\.|.*/,y=/\..*/,w=/::\d+$/,A={};let E=1;const T={mouseenter:"mouseover",mouseleave:"mouseout"},C=new Set(["click","dblclick","mouseup","mousedown","contextmenu","mousewheel","DOMMouseScroll","mouseover","mouseout","mousemove","selectstart","selectend","keydown","keypress","keyup","orientationchange","touchstart","touchmove","touchend","touchcancel","pointerdown","pointermove","pointerup","pointerleave","pointercancel","gesturestart","gesturechange","gestureend","focus","blur","change","reset","select","submit","focusin","focusout","load","unload","beforeunload","resize","move","DOMContentLoaded","readystatechange","error","abort","scroll"]);function O(t,e){return e&&`${e}::${E++}`||t.uidEvent||E++}function x(t){const e=O(t);return t.uidEvent=e,A[e]=A[e]||{},A[e]}function k(t,e,i=null){return Object.values(t).find((t=>t.callable===e&&t.delegationSelector===i))}function L(t,e,i){const n="string"==typeof e,s=n?i:e||i;let o=N(t);return C.has(o)||(o=t),[n,s,o]}function S(t,e,i,n,s){if("string"!=typeof e||!t)return;let[o,r,a]=L(e,i,n);if(e in T){const t=t=>function(e){if(!e.relatedTarget||e.relatedTarget!==e.delegateTarget&&!e.delegateTarget.contains(e.relatedTarget))return t.call(this,e)};r=t(r)}const l=x(t),c=l[a]||(l[a]={}),h=k(c,r,o?i:null);if(h)return void(h.oneOff=h.oneOff&&s);const d=O(r,e.replace(v,"")),u=o?function(t,e,i){return function n(s){const o=t.querySelectorAll(e);for(let{target:r}=s;r&&r!==this;r=r.parentNode)for(const a of o)if(a===r)return M(s,{delegateTarget:r}),n.oneOff&&P.off(t,s.type,e,i),i.apply(r,[s])}}(t,i,r):function(t,e){return function i(n){return M(n,{delegateTarget:t}),i.oneOff&&P.off(t,n.type,e),e.apply(t,[n])}}(t,r);u.delegationSelector=o?i:null,u.callable=r,u.oneOff=s,u.uidEvent=d,c[d]=u,t.addEventListener(a,u,o)}function D(t,e,i,n,s){const o=k(e[i],n,s);o&&(t.removeEventListener(i,o,Boolean(s)),delete e[i][o.uidEvent])}function I(t,e,i,n){const s=e[i]||{};for(const[o,r]of Object.entries(s))o.includes(n)&&D(t,e,i,r.callable,r.delegationSelector)}function N(t){return t=t.replace(y,""),T[t]||t}const P={on(t,e,i,n){S(t,e,i,n,!1)},one(t,e,i,n){S(t,e,i,n,!0)},off(t,e,i,n){if("string"!=typeof e||!t)return;const[s,o,r]=L(e,i,n),a=r!==e,l=x(t),c=l[r]||{},h=e.startsWith(".");if(void 0===o){if(h)for(const i of Object.keys(l))I(t,l,i,e.slLine truncated
|
||||
//# sourceMappingURL=bootstrap.bundle.min.js.map
|
||||
Reference in new issue
Block a user