Changing brightness at runtime?

@hzeller, I’m trying to port some code that changes the panel brightness at runtime (this is because in dark environments, I take brightness down, so as not to blind people, and other times I take it down to save on batteries).

All I’ve found right now is how to set brightness at creation time in &mopts->brightness

Is there a way to change it at runtime?
I do see an led_matrix_set_brightness in led-matrix-c.c but haven’t quite managed to use it yet.

Tips appreciated :slight_smile:

I am changing brightness at runtime successfully

m_matrix->SetBrightness(static_cast<uint8_t>(brightness));

Thanks. I did find the brightness code against the matrix object, but I was using a canvas, that’s the only thing I have defined.

rgb_matrix::Canvas *canvas = rgb_matrix::CreateMatrixFromOptions(defaults, ropt);

Looking at led-matrix.h, RGBMatrix inherits from Canvas, and SetBrightness is a method of RGBMatrix, not Canvas.

I changed my library to use an RGBMatrix instead of Canvas, and now I can use SetBrightness, thanks.

Given that Canvas is a much less capable object, I’m a bit confused as to why some rpirgbpanel examples like ledcat, use Canvas. Feels to me like it would be simpler if all everything used RGBPanel

Tangential question, what does “static_cast<uint8_t>” achieve when you’re passing a simple uint8_t by value?