Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions native/waze-on-cluster/patch/patchd.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,21 @@
* {"cmd":"hud","on":0|1}
* {"cmd":"hud-size","hud_width_pct":0|20..100} (over 85 saved as 85)
* {"cmd":"hud-pos","hud_x":-800..800,"hud_y":-800..800}
* {"cmd":"hud-brightness","hud_brightness_pct":10..100}
* {"cmd":"hud-keep-shown","on":0|1}
* the map on the cluster on or off, on the HUD on
* or off, the HUD's size
* (0: the default box), where it is moved from
* the centre (HUD pixels) and whether it stays
* shown over BMW's pop-ups, saved for the render's
* next start as "cluster", "hud", "hud_width_pct",
* "hud_offset_x", "hud_offset_y" and
* "hud_keep_shown" in MAP_STATE
* "hud_offset_x", "hud_offset_y",
* "hud_brightness_pct" and "hud_keep_shown" in MAP_STATE
* (the app changes the running render itself).
* Changes are written together MAP_SAVE_MS
* after the last one; the reply (cluster-reply,
* hud-reply, hud-size-reply, hud-pos-reply,
* hud-keep-shown-reply)
* hud-brightness-reply, hud-keep-shown-reply)
* follows the write and carries ok, the values
* saved and reason.
* {"cmd":"profile","id":"<id>"|null}
Expand Down Expand Up @@ -245,7 +246,7 @@ var LOCAL_CONF = process.env.WOC_LOCAL_CONF || '/var/opt/waze-on-cluster/waze-on
* configuration. Not in LOCAL_CONF, which waze-on-cluster 0.8 refuses to
* start with any of MAP_KEYS in. */
var MAP_STATE = path.join(STATE_DIR, 'map.state.conf');
var MAP_KEYS = ['cluster', 'hud', 'hud_width_pct', 'hud_offset_x', 'hud_offset_y', 'hud_keep_shown'];
var MAP_KEYS = ['cluster', 'hud', 'hud_width_pct', 'hud_offset_x', 'hud_offset_y', 'hud_brightness_pct', 'hud_keep_shown'];
/* The opt-in settings: the render reads this file (its features_file) over
* its configuration. Not in LOCAL_CONF, which every release up to 0.10.7
* refuses to start with any of FEATURE_KEYS in; no release before 0.10.9
Expand Down Expand Up @@ -284,6 +285,7 @@ function rewriteConf(file, set, drop) {
function mapValueOk(k, v) {
var n = Number(v);
return /^-?\d+$/.test(v) && (k === 'hud_width_pct' ? n === 0 || (n >= 20 && n <= 100)
: k === 'hud_brightness_pct' ? n >= 10 && n <= 100
: /^hud_offset_/.test(k) ? n >= -800 && n <= 800 : n === 0 || n === 1);
}

Expand Down Expand Up @@ -417,7 +419,9 @@ function saveLater(settings, withProfiles) {
var PROFILES_FILE = path.join(STATE_DIR, 'profiles.json');
var PROFILE_ID = /^[A-Za-z0-9][A-Za-z0-9._:@+={}-]{0,127}$/;
var MAX_OWN = 16;
var MAP_DEFAULTS = { cluster: 1, hud: 0, hud_width_pct: 0, hud_offset_x: 0, hud_offset_y: 0, hud_keep_shown: 0 };
var MAP_DEFAULTS = { cluster: 1, hud: 0, hud_width_pct: 0, hud_offset_x: 0, hud_offset_y: 0, hud_brightness_pct: 50, hud_keep_shown: 0 };
/* Keys a profiles file from before them may lack: their default then. */
var MAP_KEYS_LATER = ['hud_brightness_pct', 'hud_keep_shown'];
var profiles = null; /* PROFILES_FILE as read at the start, and changed since */
var currentProfile; /* the profile the app last told (null: none; undefined: not told since the start) */
var restored = false; /* MAP_STATE written from PROFILES_FILE at the start, not yet told to the app */
Expand All @@ -432,13 +436,13 @@ function profilesKept(p) { return profilesInUse(p) || !!p.shared; }
/* The settings in effect as PROFILES_FILE keeps them. */
function profileEntry(p) { return p.active ? p.own[p.active] : p.shared; }
/* Settings as PROFILES_FILE holds them, or null when any key is missing or
* out of range; hud_keep_shown missing (a set saved before it) is its default. */
* out of range; a key of MAP_KEYS_LATER missing (a set saved before it) is its default. */
function profileSettings(o) {
if (!o || typeof o !== 'object') return null;
var s = {};
for (var i = 0; i < MAP_KEYS.length; i++) {
var k = MAP_KEYS[i];
var v = typeof o[k] === 'number' ? String(o[k]) : k === 'hud_keep_shown' && !(k in o) ? String(MAP_DEFAULTS[k]) : null;
var v = typeof o[k] === 'number' ? String(o[k]) : !(k in o) && MAP_KEYS_LATER.indexOf(k) >= 0 ? String(MAP_DEFAULTS[k]) : null;
if (v === null || !mapValueOk(k, v)) return null;
s[k] = Number(v);
}
Expand Down Expand Up @@ -1829,6 +1833,15 @@ function handle(line, sock) {
saveMapSettings(sock, 'hud-pos-reply', { hud_offset_x: msg.hud_x, hud_offset_y: msg.hud_y }, 'the HUD map position');
return;
}
if (msg.cmd === 'hud-brightness') {
var b = msg.hud_brightness_pct;
if (!(typeof b === 'number' && b >= 10 && b <= 100 && b === Math.floor(b))) {
reply(sock, { ev: 'hud-brightness-reply', ok: false, reason: 'HUD map brightness must be 10-100 %' });
return;
}
saveMapSettings(sock, 'hud-brightness-reply', { hud_brightness_pct: b }, 'the HUD map brightness');
return;
}
if (msg.cmd === 'hud-keep-shown') {
if (msg.on !== 0 && msg.on !== 1) { reply(sock, { ev: 'hud-keep-shown-reply', ok: false, reason: 'on must be 0 or 1' }); return; }
saveMapSettings(sock, 'hud-keep-shown-reply', { hud_keep_shown: msg.on }, 'the HUD map over pop-ups');
Expand Down
3 changes: 2 additions & 1 deletion native/waze-on-cluster/src/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
* {"cmd":"hud","on":"0"|"1"} the map on the HUD off or on
* {"cmd":"hud","hud_width_pct":"0"|"20".."100"} the HUD map's size
* {"cmd":"hud","hud_x":"-800".."800","hud_y":...} where it is, from the centre
* {"cmd":"hud","hud_brightness_pct":"10".."100"} how bright the map is (it alone)
* {"cmd":"hud","hud_keep_shown":"0"|"1"} kept shown over BMW's pop-ups, or not
* {"cmd":"guide","hide":0|1} BMW's turn box hidden or not (guide_setting.h)
* tool -> owner {"ev":"status",...,"hide_bmw_guidance":0|1,"guide_disabled":0|1,
* "cluster":0|1,"hud":0|1,"hud_state":"off"|"disabled"|"idle"|"starting"|"showing"|...,
* "hud_width_pct":...,"hud_x":...,"hud_y":...,"hud_keep_shown":0|1}
* "hud_width_pct":...,"hud_brightness_pct":...,"hud_x":...,"hud_y":...,"hud_keep_shown":0|1}
* {"ev":"log","line":...}
*
* One connection is the owner; a second one is told "busy" and closed. */
Expand Down
17 changes: 16 additions & 1 deletion native/waze-on-cluster/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ std::string status_line(const FeedStatus &s)
",\"cluster\":" + (s.cluster ? "1" : "0") +
",\"hud\":" + (s.hud ? "1" : "0") + ",\"hud_state\":" + json_escape(s.hud_state) +
",\"hud_width_pct\":" + std::to_string(s.hud_width_pct) +
",\"hud_brightness_pct\":" + std::to_string(s.hud_brightness_pct) +
",\"hud_x\":" + std::to_string(s.hud_offset_x) + ",\"hud_y\":" + std::to_string(s.hud_offset_y) +
",\"hud_keep_shown\":" + (s.hud_keep_shown ? "1" : "0") +
/* only while hosted: otherwise the line is as it always was */
Expand All @@ -98,14 +99,15 @@ class Server : public Control::Handler {
auto hide = msg.find("hide");
auto pct = msg.find("hud_width_pct");
auto hx = msg.find("hud_x"), hy = msg.find("hud_y"), on = msg.find("on");
auto bright = msg.find("hud_brightness_pct");
auto keep = msg.find("hud_keep_shown");
if (cmd == "guide" && hide != msg.end() && guide_->set(hide->second)) {
log_info("guide: BMW's turn box %s while the map shows", guide_->hide() ? "hidden" : "shown");
feeds_->set_guide_hold(guide_->hide());
} else if (cmd == "cluster" && on != msg.end() && (on->second == "0" || on->second == "1")) {
feeds_->set_cluster(on->second == "1");
} else if (cmd == "hud" && (on != msg.end() || pct != msg.end() || hx != msg.end() || hy != msg.end() ||
keep != msg.end())) {
bright != msg.end() || keep != msg.end())) {
if (on != msg.end()) {
if (on->second == "0" || on->second == "1")
feeds_->set_hud(on->second == "1");
Expand All @@ -132,6 +134,16 @@ class Server : public Control::Handler {
log_warn("hud: offset %ld,%ld out of range (-800..800)", x, y);
}
}
/* how bright the map is (its layer's opacity; BMW's HUD content keeps its own brightness) */
if (bright != msg.end()) {
const long v = std::strtol(bright->second.c_str(), nullptr, 10);
if (v >= 10 && v <= 100) {
log_info("hud: map at %ld%% brightness", v);
feeds_->set_hud_brightness((unsigned)v);
} else {
log_warn("hud: brightness %s out of range (10-100)", bright->second.c_str());
}
}
/* and whether it stays shown over BMW's pop-ups */
if (keep != msg.end()) {
if (keep->second == "0" || keep->second == "1")
Expand Down Expand Up @@ -205,6 +217,7 @@ int serve(Config cfg)
{"cluster", 0, 1}, {"hud", 0, 1}, {"hud_fps", 1, 30},
{"hud_width_pct", 0, 100}, {"hud_offset_x", -800, 800}, {"hud_offset_y", -800, 800},
{"hud_scale_down", 0, 1}, {"hud_round_corners", 0, 1}, {"hud_black_background", 0, 1},
{"hud_brightness_pct", 10, 100},
{"hud_keep_shown", 0, 1},
{"freeze_ms", 0, 600000}, {"freeze_min_fps", 1, 60}, {"alt_screen_port", 0, 65535},
{"idle_ms", 1000, 600000}, {"blank_ms", 1000, 600000},
Expand Down Expand Up @@ -248,6 +261,7 @@ int serve(Config cfg)
}
fc.hud_offset_x = (int)cfg.num("hud_offset_x");
fc.hud_offset_y = (int)cfg.num("hud_offset_y");
fc.hud_brightness_pct = (unsigned)cfg.num("hud_brightness_pct");
fc.hud_keep_shown = cfg.num("hud_keep_shown") != 0;
fc.scale_down = cfg.num("hud_scale_down") != 0;
fc.hud_round_corners = cfg.num("hud_round_corners") != 0;
Expand Down Expand Up @@ -497,6 +511,7 @@ void define_keys(Config *cfg)
cfg->define("hud_width_pct", "0");
cfg->define("hud_offset_x", "0");
cfg->define("hud_offset_y", "0");
cfg->define("hud_brightness_pct", "50");
cfg->define("hud_keep_shown", "0");
cfg->define("hud_scale_down", "1");
cfg->define("hud_round_corners", "1");
Expand Down
14 changes: 14 additions & 0 deletions native/waze-on-cluster/src/map_feed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ void MapFeed::make_layer()
lo_.w = q.w;
lo_.h = q.h;
lo_.visible = live_ && !frozen_ && picture_ == Picture::Shown;
lo_.opacity = cfg_.target == "hud" ? (float)cfg_.hud_brightness_pct / 100.0f : 1.0f;
layer_ = client_.video(lo_, vo);
if (hosted())
target_size(client_.targets, host_.into, &tw, &th);
Expand Down Expand Up @@ -289,6 +290,18 @@ void MapFeed::set_hud_offset(int dx, int dy)
log_info("render: HUD map moved to %u,%u (offset %+d,%+d)", q.x, q.y, placed_x_, placed_y_);
}

void MapFeed::set_hud_brightness(unsigned pct)
{
if (pct == cfg_.hud_brightness_pct)
return;
cfg_.hud_brightness_pct = pct;
if (cfg_.target != "hud" || !layer_)
return;
lo_.opacity = (float)pct / 100.0f;
client_.set(layer_, lo_);
log_info("render: HUD map at %u%% brightness", pct);
}

void MapFeed::set_hud_keep_shown(bool keep)
{
cfg_.hud_keep_shown = keep;
Expand Down Expand Up @@ -564,6 +577,7 @@ FeedStatus MapFeed::status(const std::string &decode, const std::string &stream)
s.target = drawn_target();
s.hosted = hosted();
s.hud_width_pct = cfg_.hud_width_pct;
s.hud_brightness_pct = cfg_.hud_brightness_pct;
s.hud_offset_x = placed_x_;
s.hud_keep_shown = cfg_.hud_keep_shown;
s.hud_offset_y = placed_y_;
Expand Down
6 changes: 6 additions & 0 deletions native/waze-on-cluster/src/map_feed.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ struct FeedConfig {
/* On the HUD: the map moved from its centred place, in the HUD scene's
* pixels (+x right, +y down), held inside the HUD's scene. */
int hud_offset_x = 0, hud_offset_y = 0;
/* On the HUD: the map's brightness, % (10-100), its layer's opacity over the
* HUD's black, so the map dims and BMW's own HUD content does not. */
unsigned hud_brightness_pct = 100;
/* On the HUD: kept shown over the stock HMI's pop-ups (the layer's
* yield 0); else it gives way to them (cluster-render's hud_yield_slots). */
bool hud_keep_shown = false;
Expand Down Expand Up @@ -132,6 +135,7 @@ struct FeedStatus {
std::string hud_state = "off"; /* off, disabled, or the HUD feed's state */
unsigned hud_width_pct = 0; /* the HUD map's size setting (0: the default) */
int hud_offset_x = 0, hud_offset_y = 0; /* and where it is moved to from the centre */
unsigned hud_brightness_pct = 100; /* and how bright, % */
bool hud_keep_shown = false; /* the HUD map kept shown over the stock HMI's pop-ups */
};

Expand Down Expand Up @@ -180,6 +184,8 @@ class MapFeed {
/* The HUD map kept shown over the stock HMI's pop-ups or not
* (FeedConfig::hud_keep_shown), at once. */
void set_hud_keep_shown(bool keep);
/* The HUD map's brightness (FeedConfig::hud_brightness_pct), at once. */
void set_hud_brightness(unsigned pct);
/* A layer to take frames: made, and not reported disabled by
* cluster-render. */
bool takes_frames() const { return layer_ && !disabled(); }
Expand Down
8 changes: 8 additions & 0 deletions native/waze-on-cluster/src/map_feeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ void MapFeeds::set_hud_offset(int dx, int dy)
hud_->set_hud_offset(dx, dy);
}

void MapFeeds::set_hud_brightness(unsigned pct)
{
base_.hud_brightness_pct = pct;
if (hud_)
hud_->set_hud_brightness(pct);
}

void MapFeeds::set_hud_keep_shown(bool keep)
{
base_.hud_keep_shown = keep;
Expand Down Expand Up @@ -206,6 +213,7 @@ FeedStatus MapFeeds::status(const std::string &decode, const std::string &stream
}
}
s.hud_width_pct = base_.hud_width_pct;
s.hud_brightness_pct = base_.hud_brightness_pct;
s.hud_keep_shown = base_.hud_keep_shown;
s.hud_offset_x = hud_ ? hud_->hud_offset_x() : base_.hud_offset_x;
s.hud_offset_y = hud_ ? hud_->hud_offset_y() : base_.hud_offset_y;
Expand Down
1 change: 1 addition & 0 deletions native/waze-on-cluster/src/map_feeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class MapFeeds {
/* The HUD map kept shown over the stock HMI's pop-ups or not, kept for a
* HUD feed made later. */
void set_hud_keep_shown(bool keep);
void set_hud_brightness(unsigned pct);
int hud_offset_x() const { return base_.hud_offset_x; }
int hud_offset_y() const { return base_.hud_offset_y; }
/* The cluster map layer's guide_hold. */
Expand Down
6 changes: 4 additions & 2 deletions native/waze-on-cluster/src/map_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace woc {

const char *const kMapStateKeys[6] = {"cluster", "hud", "hud_width_pct",
"hud_offset_x", "hud_offset_y", "hud_keep_shown"};
const char *const kMapStateKeys[7] = {"cluster", "hud", "hud_width_pct", "hud_offset_x", "hud_offset_y",
"hud_brightness_pct", "hud_keep_shown"};

namespace {

Expand All @@ -32,6 +32,8 @@ bool valid(const std::string &key, const std::string &value)
const long v = std::strtol(value.c_str(), &end, 10);
if (value.empty() || *end)
return false;
if (key == "hud_brightness_pct")
return v >= 10 && v <= 100;
if (key == "hud_width_pct")
return v == 0 || (v >= 20 && v <= 100);
if (key == "hud_offset_x" || key == "hud_offset_y")
Expand Down
9 changes: 5 additions & 4 deletions native/waze-on-cluster/src/map_state.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 Robert Nisipeanu
/* Where the map shows and the HUD map's size, place and whether it stays
* shown over BMW's pop-ups, as the app chose them: cluster, hud,
* hud_width_pct, hud_offset_x, hud_offset_y and hud_keep_shown, which
/* Where the map shows and the HUD map's size, place, brightness and whether
* it stays shown over BMW's pop-ups, as the app chose them: cluster, hud,
* hud_width_pct, hud_offset_x, hud_offset_y, hud_brightness_pct and
* hud_keep_shown, which
* patchd saves in map_state_file (key = value lines). Each valid value
* replaces the configuration's; one out of range, another key or a line
* that does not read is left out with a warning, as is a file that cannot
Expand All @@ -17,7 +18,7 @@
namespace woc {

/* The keys map_state_file holds. */
extern const char *const kMapStateKeys[6];
extern const char *const kMapStateKeys[7];

void load_map_state(cld::Config *cfg, const std::string &path);

Expand Down
19 changes: 14 additions & 5 deletions native/waze-on-cluster/test/map_state_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static cld::Config conf()
c.define("hud_width_pct", "60");
c.define("hud_offset_x", "0");
c.define("hud_offset_y", "0");
c.define("hud_brightness_pct", "100");
c.define("hud_keep_shown", "0");
return c;
}
Expand All @@ -53,30 +54,38 @@ int main()
unlink(path.c_str());
cld::Config c = conf();
load_map_state(&c, path);
ok("no state file: the configuration's", settings(c) == "1 0 60 0 0 0");
ok("no state file: the configuration's", settings(c) == "1 0 60 0 0 100 0");
std::ofstream(path) << "hud = 1\ncluster = 0\nhud_width_pct = 85\nhud_offset_x = -40\nhud_offset_y = 800\n"
"hud_keep_shown = 1\n";
c = conf();
load_map_state(&c, path);
ok("the state file's, over the configuration's", settings(c) == "0 1 85 -40 800 1");
ok("the state file's, over the configuration's", settings(c) == "0 1 85 -40 800 100 1");
std::ofstream(path) << "cluster = 2\nhud = 1\nhud_width_pct = 10\n\nhud_offset_x = 900\nhud_offset_y = -20\n"
"hud_fps = 30\ntarget = panel\ngarbage\nhud = yes\nhud_keep_shown = 2\n";
c = conf();
c.define("hud_fps", "10");
c.define("target", "map");
load_map_state(&c, path);
ok("out of range, another key or a line that does not read: left out, the rest taken",
settings(c) == "1 1 60 0 -20 0" && c.str("hud_fps") == "10" && c.str("target") == "map");
settings(c) == "1 1 60 0 -20 100 0" && c.str("hud_fps") == "10" && c.str("target") == "map");
std::ofstream(path) << "hud_width_pct = 0\nhud_offset_x = 1x\nhud_offset_y = \ncluster =1\n";
c = conf();
load_map_state(&c, path);
ok("Standard (0) taken; a number with more after it, or none, left out", settings(c) == "1 0 0 0 0 0");
ok("Standard (0) taken; a number with more after it, or none, left out", settings(c) == "1 0 0 0 0 100 0");
std::ofstream(path) << "hud_brightness_pct = 40\n";
c = conf();
load_map_state(&c, path);
ok("the HUD map's brightness", settings(c) == "1 0 60 0 0 40 0");
std::ofstream(path) << "hud_brightness_pct = 5\nhud_brightness_pct = 101\n";
c = conf();
load_map_state(&c, path);
ok("a brightness under 10 % or over 100 %: left out", settings(c) == "1 0 60 0 0 100 0");
std::ofstream(path) << "hud = 1\n";
chmod(path.c_str(), 0);
if (access(path.c_str(), R_OK) != 0) { /* root reads it anyway */
c = conf();
load_map_state(&c, path);
ok("a state file that cannot be read: the configuration's", settings(c) == "1 0 60 0 0 0");
ok("a state file that cannot be read: the configuration's", settings(c) == "1 0 60 0 0 100 0");
}
unlink(path.c_str());
std::ifstream shipped("waze-on-cluster.conf");
Expand Down
Loading