Add preset polish and broadcast metadata (fw 0.8.0).
Ship station reorder, DAB playing ids in presets, RDS PS/RT and DAB DLS in tuner status, Si4684 data-service read, host tests, and UI now-playing lines. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -50,7 +50,7 @@ namespace net {
|
||||
|
||||
namespace {
|
||||
constexpr char kTag[] = "SetupWebServer";
|
||||
constexpr char kFirmwareVersion[] = "0.7.0";
|
||||
constexpr char kFirmwareVersion[] = "0.8.0";
|
||||
constexpr unsigned kRebootDelaySec = 3;
|
||||
|
||||
extern const uint8_t www_index_html_gz_start[] asm(
|
||||
@@ -796,6 +796,38 @@ esp_err_t stationsRemovePostHandler(httpd_req_t* req)
|
||||
return httpd_resp_send(req, "{\"status\":\"removed\"}", 20);
|
||||
}
|
||||
|
||||
esp_err_t stationsReorderPostHandler(httpd_req_t* req)
|
||||
{
|
||||
auto* ctx = routeContextFrom(req);
|
||||
if (ctx == nullptr || ctx->stations == nullptr) {
|
||||
httpd_resp_set_status(req, "503 Service Unavailable");
|
||||
return httpd_resp_send(req, nullptr, 0);
|
||||
}
|
||||
std::array<char, 128> body{};
|
||||
if (!readRequestBody(req, body)) {
|
||||
httpd_resp_set_status(req, "400 Bad Request");
|
||||
return httpd_resp_send(req, nullptr, 0);
|
||||
}
|
||||
auto parsed = core::parseStationReorderJson(body.data());
|
||||
if (!parsed) {
|
||||
const std::string json =
|
||||
core::serializeStationListErrorJson(parseErrorToken(parsed.error()));
|
||||
httpd_resp_set_status(req, "400 Bad Request");
|
||||
httpd_resp_set_type(req, "application/json");
|
||||
return httpd_resp_send(req, json.c_str(), json.size());
|
||||
}
|
||||
if (auto moved = ctx->stations->reorder(parsed->fromIndex, parsed->toIndex);
|
||||
!moved) {
|
||||
const std::string json = core::serializeStationListErrorJson(
|
||||
core::stationListErrorToken(moved.error()));
|
||||
httpd_resp_set_status(req, "409 Conflict");
|
||||
httpd_resp_set_type(req, "application/json");
|
||||
return httpd_resp_send(req, json.c_str(), json.size());
|
||||
}
|
||||
httpd_resp_set_type(req, "application/json");
|
||||
return httpd_resp_send(req, "{\"status\":\"reordered\"}", 22);
|
||||
}
|
||||
|
||||
esp_err_t stationsTunePostHandler(httpd_req_t* req)
|
||||
{
|
||||
auto* ctx = routeContextFrom(req);
|
||||
@@ -1101,6 +1133,14 @@ std::expected<void, NetError> SetupWebServer::start(
|
||||
};
|
||||
httpd_register_uri_handler(server_, &stationsRemoveUri);
|
||||
|
||||
const httpd_uri_t stationsReorderUri = {
|
||||
.uri = "/api/stations/reorder",
|
||||
.method = HTTP_POST,
|
||||
.handler = stationsReorderPostHandler,
|
||||
.user_ctx = routeCtx,
|
||||
};
|
||||
httpd_register_uri_handler(server_, &stationsReorderUri);
|
||||
|
||||
const httpd_uri_t stationsTuneUri = {
|
||||
.uri = "/api/stations/tune",
|
||||
.method = HTTP_POST,
|
||||
|
||||
@@ -261,11 +261,14 @@
|
||||
if (s.dab) {
|
||||
lines.push("DAB index: " + (s.dab.freq_index != null ? s.dab.freq_index : "—"));
|
||||
if (s.dab.fic_quality != null) lines.push("FIC: " + s.dab.fic_quality);
|
||||
if (s.dab.dynamic_label) lines.push("Now: " + s.dab.dynamic_label);
|
||||
}
|
||||
if (s.fm) {
|
||||
if (s.fm.frequency_khz != null) lines.push("FM: " + s.fm.frequency_khz + " kHz");
|
||||
if (s.fm.rssi_dbuv != null) lines.push("RSSI: " + s.fm.rssi_dbuv + " dBµV");
|
||||
if (s.fm.stereo != null) lines.push("Stereo: " + s.fm.stereo);
|
||||
if (s.fm.station_name) lines.push("Station: " + s.fm.station_name);
|
||||
if (s.fm.radiotext) lines.push("Text: " + s.fm.radiotext);
|
||||
}
|
||||
return lines.join("\n");
|
||||
}
|
||||
@@ -623,6 +626,7 @@
|
||||
var label = s.name + " (" + s.band + ")";
|
||||
if (s.fm_frequency_khz) label += " " + s.fm_frequency_khz + " kHz";
|
||||
if (s.dab_freq_index != null) label += " idx " + s.dab_freq_index;
|
||||
if (s.dab_service_id != null) label += " svc " + s.dab_service_id;
|
||||
li.textContent = label;
|
||||
var tuneBtn = document.createElement("button");
|
||||
tuneBtn.textContent = "Tune";
|
||||
@@ -643,12 +647,60 @@
|
||||
body: JSON.stringify({ index: idx })
|
||||
}).then(function () { loadPresets(); });
|
||||
});
|
||||
var upBtn = document.createElement("button");
|
||||
upBtn.textContent = "Up";
|
||||
upBtn.className = "secondary";
|
||||
upBtn.disabled = idx === 0;
|
||||
upBtn.addEventListener("click", function () {
|
||||
fetch("/api/stations/reorder", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ from: idx, to: idx - 1 })
|
||||
}).then(function () { loadPresets(); });
|
||||
});
|
||||
var downBtn = document.createElement("button");
|
||||
downBtn.textContent = "Dn";
|
||||
downBtn.className = "secondary";
|
||||
downBtn.disabled = idx >= (data.stations.length - 1);
|
||||
downBtn.addEventListener("click", function () {
|
||||
fetch("/api/stations/reorder", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ from: idx, to: idx + 1 })
|
||||
}).then(function () { loadPresets(); });
|
||||
});
|
||||
li.appendChild(tuneBtn);
|
||||
li.appendChild(upBtn);
|
||||
li.appendChild(downBtn);
|
||||
li.appendChild(delBtn);
|
||||
list.appendChild(li);
|
||||
});
|
||||
}
|
||||
|
||||
function buildPresetBody(name, band, status) {
|
||||
var body = { name: name, band: band };
|
||||
if (band === "fm") {
|
||||
var khz = status && status.fm && status.fm.frequency_khz != null
|
||||
? status.fm.frequency_khz
|
||||
: parseInt(document.getElementById("fm-khz").value, 10);
|
||||
body.fm_frequency_khz = khz;
|
||||
} else {
|
||||
var idx = status && status.dab && status.dab.freq_index != null
|
||||
? status.dab.freq_index
|
||||
: parseInt(document.getElementById("dab-index").value, 10);
|
||||
body.dab_freq_index = idx;
|
||||
if (status && status.dab && status.dab.playing_service_id != null) {
|
||||
body.dab_service_id = status.dab.playing_service_id;
|
||||
}
|
||||
if (status && status.dab && status.dab.playing_component_id != null) {
|
||||
body.dab_component_id = status.dab.playing_component_id;
|
||||
}
|
||||
}
|
||||
var slotVal = document.getElementById("preset-slot").value;
|
||||
if (slotVal) body.preset_slot = parseInt(slotVal, 10);
|
||||
return body;
|
||||
}
|
||||
|
||||
function loadPresets() {
|
||||
return fetch("/api/stations")
|
||||
.then(function (r) { return r.json(); })
|
||||
@@ -664,20 +716,18 @@
|
||||
return;
|
||||
}
|
||||
var band = document.getElementById("band").value;
|
||||
var body = { name: name, band: band };
|
||||
if (band === "fm") {
|
||||
body.fm_frequency_khz = parseInt(document.getElementById("fm-khz").value, 10);
|
||||
} else {
|
||||
body.dab_freq_index = parseInt(document.getElementById("dab-index").value, 10);
|
||||
}
|
||||
var slotVal = document.getElementById("preset-slot").value;
|
||||
if (slotVal) body.preset_slot = parseInt(slotVal, 10);
|
||||
fetch("/api/stations", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body)
|
||||
})
|
||||
.then(function (r) { return r.json().then(function (d) { return { ok: r.ok, d: d }; }); })
|
||||
fetch("/api/tuner/status")
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (status) {
|
||||
var body = buildPresetBody(name, band, status);
|
||||
return fetch("/api/stations", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body)
|
||||
}).then(function (r) {
|
||||
return r.json().then(function (d) { return { ok: r.ok, d: d }; });
|
||||
});
|
||||
})
|
||||
.then(function (res) {
|
||||
if (res.ok && res.d.status === "saved") {
|
||||
showMsg(msg, "Preset saved.", true);
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user