Skip to content

Commit a0dcf2f

Browse files
committed
feat: add verbose logging flag and display scaling overrides
replace --log with -v/--verbose and document usage add --develop override plus circular display handling logs auto-scale fonts, expose temp_max_scale, and refine bar rendering
1 parent ff51283 commit a0dcf2f

9 files changed

Lines changed: 143 additions & 40 deletions

File tree

.SRCINFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pkgbase = coolerdash
22
pkgdesc = Extends CoolerControl with a polished LCD dashboard
3-
pkgver = 1.91
3+
pkgver = 1.92
44
pkgrel = 1
55
url = https://github.com/damachine/coolerdash
66
install = coolerdash.install

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ gnupg/
3636
*.tmp
3737
*.log
3838
*.bak
39+
*.env
3940

4041
# Editor files
4142
*.code-workspace

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ make help # Show all options
146146
# Run manually (with minimal status logging)
147147
coolerdash
148148

149-
# Run with detailed debug logging
150-
coolerdash --log
149+
# Run with detailed verbose logging
150+
coolerdash --verbose
151+
# or short form:
152+
coolerdash -v
151153
```
152154

153155
#### Debugging Steps
@@ -160,11 +162,13 @@ curl http://localhost:11987/devices
160162
# 2. Test CoolerDash manually (with clean output)
161163
coolerdash
162164

163-
# 3. Test CoolerDash with detailed debug logging
164-
coolerdash --log
165+
# 3. Test CoolerDash with detailed verbose logging
166+
coolerdash --verbose
167+
# or short form:
168+
coolerdash -v
165169

166170
# 4. Debug build for detailed information (if needed)
167-
make debug && coolerdash --log
171+
make debug && coolerdash --verbose
168172

169173
# 5. Check service logs (STATUS messages always visible)
170174
journalctl -xeu coolerdash.service -f

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.91
1+
1.92

src/config.c

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,15 +476,16 @@ static int get_temperature_config(Config *config, const char *name, const char *
476476
static const TemperatureConfigEntry entries[] = {
477477
{"temp_threshold_1", offsetof(Config, temp_threshold_1)},
478478
{"temp_threshold_2", offsetof(Config, temp_threshold_2)},
479-
{"temp_threshold_3", offsetof(Config, temp_threshold_3)}};
479+
{"temp_threshold_3", offsetof(Config, temp_threshold_3)},
480+
{"temp_max_scale", offsetof(Config, temp_max_scale)}};
480481

481482
for (size_t i = 0; i < sizeof(entries) / sizeof(entries[0]); i++)
482483
{
483484
if (strcmp(name, entries[i].key) == 0)
484485
{
485486
void *field_ptr = (void *)((char *)config + entries[i].offset);
486487
float *dest = (float *)field_ptr;
487-
*dest = safe_atof(value, 50.0f + i * 15.0f); // 50, 65, 80
488+
*dest = safe_atof(value, 50.0f + i * 15.0f); // 50, 65, 80, 115
488489
return 1;
489490
}
490491
}
@@ -686,22 +687,48 @@ static void set_display_positioning_defaults(Config *config)
686687

687688
/**
688689
* @brief Set font default values.
689-
* @details Helper function to set default font configuration values.
690+
* @details Helper function to set default font configuration values with dynamic scaling based on display resolution.
690691
*/
691692
static void set_font_defaults(Config *config)
692693
{
693694
if (config->font_face[0] == '\0')
694695
SAFE_STRCPY(config->font_face, "Roboto Black");
696+
697+
// Dynamic font size scaling based on display resolution
698+
// Base: 240×240 with font_size_temp=100.0 and font_size_labels=30.0
695699
if (config->font_size_temp == 0.0f)
696-
config->font_size_temp = 100.0f;
700+
{
701+
const double base_resolution = 240.0;
702+
const double base_font_size_temp = 100.0;
703+
704+
// Calculate scaling factor from average of width and height
705+
const double scale_factor = ((double)config->display_width + (double)config->display_height) / (2.0 * base_resolution);
706+
707+
config->font_size_temp = (float)(base_font_size_temp * scale_factor);
708+
709+
log_message(LOG_INFO, "Font size (temp) auto-scaled: %.1f (display: %dx%d, scale: %.2f)",
710+
config->font_size_temp, config->display_width, config->display_height, scale_factor);
711+
}
712+
697713
if (config->font_size_labels == 0.0f)
698-
config->font_size_labels = 30.0f;
714+
{
715+
const double base_resolution = 240.0;
716+
const double base_font_size_labels = 30.0;
717+
718+
// Calculate scaling factor from average of width and height
719+
const double scale_factor = ((double)config->display_width + (double)config->display_height) / (2.0 * base_resolution);
720+
721+
config->font_size_labels = (float)(base_font_size_labels * scale_factor);
722+
723+
log_message(LOG_INFO, "Font size (labels) auto-scaled: %.1f (display: %dx%d, scale: %.2f)",
724+
config->font_size_labels, config->display_width, config->display_height, scale_factor);
725+
}
699726

700727
set_display_positioning_defaults(config);
701728
}
702729

703730
/**
704-
* @brief Set temperature threshold default values.
731+
* @brief Set temperature defaults
705732
* @details Helper function to set default temperature threshold values.
706733
*/
707734
static void set_temperature_defaults(Config *config)
@@ -712,6 +739,8 @@ static void set_temperature_defaults(Config *config)
712739
config->temp_threshold_2 = 65.0f;
713740
if (config->temp_threshold_3 == 0.0f)
714741
config->temp_threshold_3 = 75.0f;
742+
if (config->temp_max_scale == 0.0f)
743+
config->temp_max_scale = 115.0f;
715744
}
716745

717746
/**

src/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ typedef struct Config
7676
uint32_t display_refresh_interval_nsec;
7777
uint8_t lcd_brightness;
7878
uint8_t lcd_orientation;
79+
// Developer/testing override: force display to be treated as circular (1) or not (0)
80+
int force_display_circular;
7981

8082
// Layout configuration - all positioning is now calculated dynamically from display dimensions
8183
uint16_t layout_bar_width; // Legacy - not used in dynamic scaling
@@ -104,6 +106,7 @@ typedef struct Config
104106
float temp_threshold_1;
105107
float temp_threshold_2;
106108
float temp_threshold_3;
109+
float temp_max_scale; // Maximum temperature for bar scaling (default: 115°C)
107110
Color temp_threshold_1_bar;
108111
Color temp_threshold_2_bar;
109112
Color temp_threshold_3_bar;

src/coolercontrol.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,8 @@ static int validate_device_dimensions(void)
787787
*/
788788
static int update_dimension(uint16_t *config_dim, int device_dim, const char *dim_name)
789789
{
790+
const uint16_t original_value = *config_dim;
791+
790792
if (*config_dim == 0)
791793
{
792794
*config_dim = (uint16_t)device_dim;
@@ -795,8 +797,18 @@ static int update_dimension(uint16_t *config_dim, int device_dim, const char *di
795797
return 1;
796798
}
797799

798-
log_message(LOG_INFO, "Display %s from config.ini: %d (overrides device value %d)",
799-
dim_name, *config_dim, device_dim);
800+
// Only log if the values differ (to avoid misleading logs when using defaults)
801+
if (original_value != (uint16_t)device_dim)
802+
{
803+
log_message(LOG_INFO, "Display %s from config.ini: %d (device reports %d)",
804+
dim_name, *config_dim, device_dim);
805+
}
806+
else
807+
{
808+
// Values match - using device value (config was commented, default matches device)
809+
log_message(LOG_INFO, "Display %s: %d (device and default match)",
810+
dim_name, *config_dim);
811+
}
800812
return 0;
801813
}
802814

src/display.c

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,16 @@ static inline void set_cairo_color(cairo_t *cr, const Color *color)
6565

6666
/**
6767
* @brief Calculate temperature fill width with bounds checking
68+
* @param temp_value Current temperature value
69+
* @param max_width Maximum width of the bar in pixels
70+
* @param max_temp Maximum temperature from configuration (highest threshold)
6871
*/
69-
static inline int calculate_temp_fill_width(float temp_value, int max_width)
72+
static inline int calculate_temp_fill_width(float temp_value, int max_width, float max_temp)
7073
{
7174
if (temp_value <= 0.0f)
7275
return 0;
7376

74-
const float ratio = fminf(temp_value / 105.0f, 1.0f);
77+
const float ratio = fminf(temp_value / max_temp, 1.0f);
7578
return (int)(ratio * max_width);
7679
}
7780

@@ -106,15 +109,30 @@ static void calculate_scaling_params(const struct Config *config, ScalingParams
106109
int is_circular_by_device = is_circular_display_device(device_name,
107110
config->display_width,
108111
config->display_height);
109-
params->is_circular = is_circular_by_device;
110-
params->inscribe_factor = params->is_circular ? M_SQRT1_2 : 1.0;
112+
113+
// Allow developer override from config (set via CLI --develop)
114+
if (config->force_display_circular)
115+
{
116+
params->is_circular = 1;
117+
params->inscribe_factor = M_SQRT1_2;
118+
log_message(LOG_INFO, "Developer override active: forcing circular display detection (device: %s)", device_name ? device_name : "unknown");
119+
}
120+
else
121+
{
122+
params->is_circular = is_circular_by_device;
123+
params->inscribe_factor = params->is_circular ? M_SQRT1_2 : 1.0;
124+
}
111125

112126
// Calculate safe area width
113127
const double safe_area_width = config->display_width * params->inscribe_factor;
114128
params->safe_bar_width = (int)(safe_area_width * CONTENT_SCALE_FACTOR);
115129
params->safe_content_margin = (config->display_width - params->safe_bar_width) / 2.0;
116130

117131
params->corner_radius = 8.0 * scale_avg;
132+
133+
// Log detailed scaling calculations (verbose only)
134+
log_message(LOG_INFO, "Scaling: safe_area=%.0fpx, bar_width=%dpx, margin=%.1fpx",
135+
safe_area_width, params->safe_bar_width, params->safe_content_margin);
118136
}
119137

120138
/**
@@ -128,6 +146,16 @@ static Color get_temperature_bar_color(const struct Config *config, float val);
128146
static void draw_rounded_rectangle_path(cairo_t *cr, int x, int y, int width, int height, double radius);
129147
static cairo_t *create_cairo_context(const struct Config *config, cairo_surface_t **surface);
130148
static void render_display_content(cairo_t *cr, const struct Config *config, const monitor_sensor_data_t *data, const ScalingParams *params);
149+
// Helper to draw degree symbol at calculated position with proper font scaling
150+
static void draw_degree_symbol(cairo_t *cr, double x, double y, const struct Config *config)
151+
{
152+
if (!cr || !config)
153+
return;
154+
cairo_set_font_size(cr, config->font_size_temp / 1.66);
155+
cairo_move_to(cr, x, y);
156+
cairo_show_text(cr, "°");
157+
cairo_set_font_size(cr, config->font_size_temp);
158+
}
131159

132160
/**
133161
* @brief Draw rounded rectangle path for temperature bars
@@ -194,13 +222,24 @@ static void draw_temperature_displays(cairo_t *cr, const monitor_sensor_data_t *
194222
cairo_font_extents_t font_ext;
195223
cairo_font_extents(cr, &font_ext);
196224

197-
// Calculate maximum width for 2-digit numbers to keep position stable
198-
cairo_text_extents_t max_num_ext;
199-
cairo_text_extents(cr, "88", &max_num_ext); // Widest 2-digit number
225+
// Use actual text extents for positioning to handle 3-digit temperatures correctly
226+
// For values ≥100, use actual width; for <100, use fixed width of "88" for stability
227+
double cpu_width = (data->temp_cpu >= 100.0f) ? cpu_num_ext.width : cpu_num_ext.width;
228+
double gpu_width = (data->temp_gpu >= 100.0f) ? gpu_num_ext.width : gpu_num_ext.width;
229+
230+
// Calculate reference width (widest 2-digit number) for sub-100 alignment
231+
cairo_text_extents_t ref_width_ext;
232+
cairo_text_extents(cr, "88", &ref_width_ext);
233+
234+
// Use reference width for values <100 to keep position stable
235+
if (data->temp_cpu < 100.0f)
236+
cpu_width = ref_width_ext.width;
237+
if (data->temp_gpu < 100.0f)
238+
gpu_width = ref_width_ext.width;
200239

201-
// Left-align numbers at center position (fixed X to prevent jumping)
202-
double cpu_temp_x = bar_x + (effective_bar_width - max_num_ext.width) / 2.0;
203-
double gpu_temp_x = bar_x + (effective_bar_width - max_num_ext.width) / 2.0;
240+
// Center-align based on actual or reference width
241+
double cpu_temp_x = bar_x + (effective_bar_width - cpu_width) / 2.0;
242+
double gpu_temp_x = bar_x + (effective_bar_width - gpu_width) / 2.0;
204243

205244
// For small displays (≤240×240), shift temperatures 12px to the right
206245
if (config->display_width <= 240 && config->display_height <= 240)
@@ -241,29 +280,26 @@ static void draw_temperature_displays(cairo_t *cr, const monitor_sensor_data_t *
241280
// Draw degree symbols at fixed offset
242281
cairo_set_font_size(cr, config->font_size_temp / 1.66);
243282

244-
// Position degree symbols 18px to the right of temperature numbers
245-
double degree_symbol_x = cpu_temp_x + max_num_ext.width + 16;
283+
// Position degree symbols 16px to the right of temperature numbers (using actual widths)
284+
double degree_cpu_x = cpu_temp_x + cpu_width + 16;
285+
double degree_gpu_x = gpu_temp_x + gpu_width + 16;
246286
double degree_cpu_y = cpu_temp_y - cpu_num_ext.height * 0.40;
247287
double degree_gpu_y = gpu_temp_y - gpu_num_ext.height * 0.40;
248288

249289
// Apply user-defined degree offsets if set
250290
if (config->display_degree_offset_x != -9999)
251291
{
252-
degree_symbol_x += config->display_degree_offset_x;
292+
degree_cpu_x += config->display_degree_offset_x;
293+
degree_gpu_x += config->display_degree_offset_x;
253294
}
254295
if (config->display_degree_offset_y != -9999)
255296
{
256297
degree_cpu_y += config->display_degree_offset_y;
257298
degree_gpu_y += config->display_degree_offset_y;
258299
}
259300

260-
cairo_move_to(cr, degree_symbol_x, degree_cpu_y);
261-
cairo_show_text(cr, "°");
262-
263-
cairo_move_to(cr, degree_symbol_x, degree_gpu_y);
264-
cairo_show_text(cr, "°");
265-
266-
cairo_set_font_size(cr, config->font_size_temp);
301+
draw_degree_symbol(cr, degree_cpu_x, degree_cpu_y, config);
302+
draw_degree_symbol(cr, degree_gpu_x, degree_gpu_y, config);
267303
}
268304

269305
/**
@@ -274,7 +310,9 @@ static void draw_single_temperature_bar(cairo_t *cr, const struct Config *config
274310
if (!cr || !config || !params)
275311
return;
276312

277-
const int fill_width = calculate_temp_fill_width(temp_value, bar_width);
313+
// Use configured maximum temperature for bar scaling (default: 115°C)
314+
const float max_temp = config->temp_max_scale;
315+
const int fill_width = calculate_temp_fill_width(temp_value, bar_width, max_temp);
278316

279317
// Background
280318
set_cairo_color(cr, &config->layout_bar_color_background);

src/main.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ static volatile sig_atomic_t running = 1; // flag whether daemon is running
6565
* @details Controls whether detailed INFO logs are shown (enabled with --log parameter).
6666
*/
6767
int verbose_logging = 0; // Only ERROR and WARNING by default (exported)
68+
// Developer/testing flag: when set (via --develop), force displays to be treated as circular
69+
int force_display_circular = 0;
6870

6971
/**
7072
* @brief Global pointer to configuration.
@@ -453,12 +455,14 @@ static void show_help(const char *program_name, const Config *config)
453455
printf("USAGE:\n");
454456
printf(" %s [OPTIONS] [CONFIG_PATH]\n\n", program_name);
455457
printf("OPTIONS:\n");
456-
printf(" -h, --help Show this help message and exit\n");
457-
printf(" --log Enable detailed INFO logging for debugging\n\n");
458+
printf(" -h, --help Show this help message and exit\n");
459+
printf(" -v, --verbose Enable verbose logging (shows detailed INFO messages)\n\n");
460+
printf(" --develop Developer: force display to be treated as circular for testing\n\n");
458461
printf("EXAMPLES:\n");
459462
printf(" sudo systemctl start coolerdash # Start as system service (recommended)\n");
460463
printf(" %s # Manual start with default config\n", program_name);
461-
printf(" %s --log # Start with detailed logging enabled\n", program_name);
464+
printf(" %s --verbose # Start with detailed logging enabled\n", program_name);
465+
printf(" %s -v # Short form: enable verbose logging\n", program_name);
462466
printf(" %s /custom/config.ini # Start with custom configuration\n\n", program_name);
463467
printf("FILES:\n");
464468
printf(" /usr/bin/coolerdash # Main program executable\n");
@@ -747,10 +751,15 @@ static const char *parse_arguments(int argc, char **argv)
747751
show_help(argv[0], NULL);
748752
exit(EXIT_SUCCESS);
749753
}
750-
else if (strcmp(argv[i], "--log") == 0)
754+
else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0)
751755
{
752756
verbose_logging = 1;
753757
}
758+
else if (strcmp(argv[i], "--develop") == 0)
759+
{
760+
force_display_circular = 1;
761+
verbose_logging = 1; // Developer mode implies verbose logging
762+
}
754763
else if (argv[i][0] != '-')
755764
{
756765
config_path = argv[i];
@@ -782,6 +791,13 @@ static int initialize_config_and_instance(const char *config_path, Config *confi
782791
return -1;
783792
}
784793

794+
/* Apply CLI overrides (developer/testing) */
795+
if (force_display_circular)
796+
{
797+
config->force_display_circular = 1;
798+
log_message(LOG_INFO, "Developer override: forcing circular display detection (via --develop)");
799+
}
800+
785801
int is_service_start = is_started_by_systemd();
786802
log_message(LOG_INFO, "Running mode: %s", is_service_start ? "systemd service" : "manual");
787803

0 commit comments

Comments
 (0)