rot finished

This commit is contained in:
2026-01-09 11:56:40 +01:00
parent 1ee0afa088
commit ac99f291a7
30 changed files with 5581 additions and 293 deletions

92
web/src/lib/api.js Normal file
View File

@@ -0,0 +1,92 @@
const API_BASE = '/api';
async function request(endpoint, options = {}) {
try {
const response = await fetch(`${API_BASE}${endpoint}`, {
...options,
headers: {
'Content-Type': 'application/json',
...options.headers,
},
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('API request failed:', error);
throw error;
}
}
export const api = {
// Status
getStatus: () => request('/status'),
getConfig: () => request('/config'),
// WebSwitch
webswitch: {
relayOn: (relay) => request(`/webswitch/relay/on?relay=${relay}`, { method: 'POST' }),
relayOff: (relay) => request(`/webswitch/relay/off?relay=${relay}`, { method: 'POST' }),
allOn: () => request('/webswitch/all/on', { method: 'POST' }),
allOff: () => request('/webswitch/all/off', { method: 'POST' }),
},
// Rotator
rotator: {
move: (rotator, azimuth) => request('/rotator/move', {
method: 'POST',
body: JSON.stringify({ rotator, azimuth }),
}),
cw: (rotator) => request(`/rotator/cw?rotator=${rotator}`, { method: 'POST' }),
ccw: (rotator) => request(`/rotator/ccw?rotator=${rotator}`, { method: 'POST' }),
stop: () => request('/rotator/stop', { method: 'POST' }),
},
// Tuner
tuner: {
setOperate: (value) => request('/tuner/operate', {
method: 'POST',
body: JSON.stringify({ value }),
}),
setBypass: (value) => request('/tuner/bypass', {
method: 'POST',
body: JSON.stringify({ value }),
}),
autoTune: () => request('/tuner/autotune', { method: 'POST' }),
},
// Antenna Genius
antenna: {
selectAntenna: (port, antenna) => request('/antenna/select', {
method: 'POST',
body: JSON.stringify({ port, antenna }),
}),
reboot: () => request('/antenna/reboot', { method: 'POST' }),
},
// Power Genius
power: {
setFanMode: (mode) => request('/power/fanmode', {
method: 'POST',
body: JSON.stringify({ mode }),
}),
setOperate: (value) => request('/power/operate', {
method: 'POST',
body: JSON.stringify({ value }),
}),
},
// Rotator Genius
rotator: {
setHeading: (heading) => request('/rotator/heading', {
method: 'POST',
body: JSON.stringify({ heading }),
}),
rotateCW: () => request('/rotator/cw', { method: 'POST' }),
rotateCCW: () => request('/rotator/ccw', { method: 'POST' }),
stop: () => request('/rotator/stop', { method: 'POST' }),
},
};