added brightness and touch settings commands

This commit is contained in:
my 2026-09-16 23:04:57 +02:00
parent a1777c1d5f
commit d6d2c432f5
4 changed files with 71 additions and 35 deletions

View file

@ -375,6 +375,23 @@ static void bt_dump_start() {
toggle_bt_mode(); // done, leave BT mode, restore the previous screen
}
bool apply_setting(String key, String value) {
if (key.startsWith("color_")) {
return settings_set_color(key.c_str(), value.c_str());
}
if (key.startsWith("tones_")) {
return settings_set_tones(key.c_str(), value.c_str());
}
if (key == "touch_threshold") {
return settings_set("touch_threshold", value.c_str());
}
if (key == "brightness") {
return settings_set("brightness", value.c_str());
}
return false;
}
/* ----- Commandes ----- */
void handleCommand(const char* in) {
if (!strncmp(in, "/nick ", 6)) {
@ -396,23 +413,20 @@ void handleCommand(const char* in) {
toggle_bt_mode();
} else if (!strncmp(in, "/set ", 5)) {
char args[MAX_MSG_LEN];
strncpy(args, in + 5, sizeof(args) - 1); args[sizeof(args) - 1] = '\0';
char* sp = strchr(args, ' ');
if (!sp) {
ui_push_message("", "Usage: /set color_bg ff0000", false, true);
String args = String(in + 5);
args.trim();
int spaceIdx = args.indexOf(' ');
if (spaceIdx == -1) {
ui_push_message("", "Usage: /set <key> <value>", false, true);
} else {
*sp = '\0';
size_t klen = strlen(args);
bool is_tones = klen > 6 && strncmp(args, "tones_", 6) == 0;
bool ok = is_tones ? settings_set_tones(args, sp + 1)
: settings_set_color(args, sp + 1);
if (ok)
String key = args.substring(0, spaceIdx);
String value = args.substring(spaceIdx + 1);
if ( apply_setting (key, value)) {
ui_push_message("", "Saved. Restart to apply.", false, true);
else if (is_tones)
ui_push_message("", "Unknown tones key.", false, true);
else
ui_push_message("", "Unknown color or bad hex value.", false, true);
} else {
ui_push_message("", "Unknown key or invalid value.", false, true);
}
}
} else if (!strncmp(in, "/me ", 4)) {
@ -453,6 +467,8 @@ void handleCommand(const char* in) {
}
}
/* ----- Envoi d'un message Chat (hors callback) ----- */
void broadcastChatMessage(const char* from, const char* body) {
MeshMessage msg;
@ -661,6 +677,7 @@ static void go_to_sleep() {
delay(200); // let the packet fly
// Hold the backlight OFF pin through deep sleep so the screen stays dark.
pinMode(PIN_TFT_BL, OUTPUT);
digitalWrite(PIN_TFT_BL, LOW);
gpio_hold_en((gpio_num_t)PIN_TFT_BL);

View file

@ -57,23 +57,20 @@ static bool apply_kv(const char* key, const char* val) {
}
static void dump_settings() {
Serial.println("[settings]");
Serial.printf ("[settings] nick=%s brightness=%d\n",
g_settings.nick, g_settings.brightness);
Serial.printf ("[settings] tones_msg=%s tones_sys=%s\n",
g_settings.tones_msg.c_str(), g_settings.tones_sys.c_str());
Serial.printf ("[settings] nick=%s\n", g_settings.nick);
Serial.printf ("[settings] brightness=%d\n", g_settings.brightness);
Serial.printf ("[settings] touch_threshold=%u\n", g_settings.touch_threshold);
Serial.printf ("[settings] color_bg=%02x%02x%02x color_header_bg=%02x%02x%02x\n",
g_settings.color_bg.red, g_settings.color_bg.green, g_settings.color_bg.blue,
g_settings.color_header_bg.red, g_settings.color_header_bg.green, g_settings.color_header_bg.blue);
Serial.printf ("[settings] color_msg=%02x%02x%02x color_nick_other=%02x%02x%02x color_nick_own=%02x%02x%02x\n",
g_settings.color_msg.red, g_settings.color_msg.green, g_settings.color_msg.blue,
g_settings.color_nick_other.red, g_settings.color_nick_other.green, g_settings.color_nick_other.blue,
g_settings.color_nick_own.red, g_settings.color_nick_own.green, g_settings.color_nick_own.blue);
Serial.printf ("[settings] color_system=%02x%02x%02x color_input_prompt=%02x%02x%02x\n",
g_settings.color_system.red, g_settings.color_system.green, g_settings.color_system.blue,
g_settings.color_input_prompt.red, g_settings.color_input_prompt.green, g_settings.color_input_prompt.blue);
Serial.println("[settings]");
Serial.printf ("[settings] --- TONES: ---\n");
Serial.printf ("[settings] tones_msg=%s\n", g_settings.tones_msg.c_str());
Serial.printf ("[settings] tones_sys=%s\n", g_settings.tones_sys.c_str());
Serial.printf ("[settings] --- COLORS: ---\n");
Serial.printf ("[settings] color_bg=%02x%02x%02x\n", g_settings.color_header_bg.red, g_settings.color_header_bg.green, g_settings.color_header_bg.blue);
Serial.printf ("[settings] color_header_bg=%02x%02x%02x\n", g_settings.color_header_bg.red, g_settings.color_header_bg.green, g_settings.color_header_bg.blue);
Serial.printf ("[settings] color_msg=%02x%02x%02x\n", g_settings.color_msg.red, g_settings.color_msg.green, g_settings.color_msg.blue);
Serial.printf ("[settings] color_nick_other=%02x%02x%02x\n", g_settings.color_nick_other.red, g_settings.color_nick_other.green, g_settings.color_nick_other.blue);
Serial.printf ("[settings] color_nick_own=%02x%02x%02x\n", g_settings.color_nick_own.red, g_settings.color_nick_own.green, g_settings.color_nick_own.blue);
Serial.printf("[settings] color_system=%02x%02x%02x\n", g_settings.color_system.red, g_settings.color_system.green, g_settings.color_system.blue );
Serial.printf("[settings] color_input_prompt=%02x%02x%02x\n", g_settings.color_input_prompt.red, g_settings.color_input_prompt.green, g_settings.color_input_prompt.blue);
}
// Public
@ -176,7 +173,6 @@ bool settings_set_color(const char* key, const char* hex) {
return true;
}
bool settings_set_tones(const char* key, const char* tones) {
if (strlen(key) <= 6 || strncmp(key, "tones_", 6) != 0) {
return false;
@ -185,3 +181,17 @@ bool settings_set_tones(const char* key, const char* tones) {
rewrite_config_line(key, tones);
return true;
}
// for brightness and touch_threshold
bool settings_set(const char* key, const char* value) {
if (!apply_kv(key, value)) return false; // unknown key or bad value
rewrite_config_line(key, value);
return true;
}
// bool settings_set_touch_threshold(const char* number) {
// const char *key = "touch_threshold";
// if (!apply_kv(key, number)) return false; // unknown key or bad hex
// rewrite_config_line(key, number);
// return true;
// }

View file

@ -26,3 +26,4 @@ void settings_load();
void settings_set_nick(const char* nick);
bool settings_set_color(const char* key, const char* hex);
bool settings_set_tones(const char* key, const char* tones);
bool settings_set(const char* key, const char *number);

View file

@ -83,6 +83,8 @@ static lv_obj_t* input_label = nullptr;
struct MsgRow { lv_obj_t *row, *nick, *text; };
static MsgRow msg_rows[UI_VISIBLE_LINES];
uint8_t pBrightness = -1;
static void refresh_msgs() {
int empty = UI_VISIBLE_LINES - msg_count;
for (int i = 0; i < UI_VISIBLE_LINES; i++) {
@ -182,6 +184,8 @@ void ui_chat_init() {
lv_obj_set_pos(msg_area, 0, UI_MSG_AREA_Y);
strip_style(msg_area);
lv_obj_set_flex_flow(msg_area, LV_FLEX_FLOW_COLUMN);
lv_obj_set_style_pad_row(msg_area, 0, 0); // no gap between message rows
lv_obj_set_flex_flow(msg_area, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(msg_area, LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);
@ -284,7 +288,11 @@ void ui_clear_messages() {
refresh_msgs();
}
void ui_tick() {
void ui_tick()
{
lv_timer_handler();
if(pBrightness != g_settings.brightness){
pBrightness = g_settings.brightness;
tft.setBrightness(g_settings.brightness);
}
}