2024-11-06 02:53 AM
Hello everyone!
I'm working on an application using TouchGFX, and I've implemented a slider to control the display brightness. Here's the relevant code:
brightness_slider.setXY(864, 262);
brightness_slider.setBitmaps(touchgfx::Bitmap(BITMAP_ALTERNATE_THEME_IMAGES_WIDGETS_SLIDER_HORIZONTAL_THIN_TRACK_SMALL_ID), touchgfx::Bitmap(BITMAP_ALTERNATE_THEME_IMAGES_WIDGETS_SLIDER_HORIZONTAL_THIN_FILLER_SMALL_ID), touchgfx::Bitmap(BITMAP_ALTERNATE_THEME_IMAGES_WIDGETS_SLIDER_HORIZONTAL_THIN_ROUND_LIGHT_ID));
brightness_slider.setupHorizontalSlider(12, 9, 0, 0, 200);
brightness_slider.setValueRange(100, 998);
brightness_slider.setValue(TIM15->CCR1);
brightness_slider.setNewValueCallback(sliderValueChangedCallback);
add(brightness_slider);
In this setup, setValue is initialized with TIM15->CCR1 to align the slider position with the current brightness level. The code works as expected; however, there’s an issue: this code is located in myScreenViewBase.cpp, a file generated by TouchGFX. Every time I regenerate the code, this file resets, causing my custom code to be erased.
Is there a way to prevent this from happening? Ideally, I’d like to synchronize the slider’s position with the actual brightness level without having to reapply these changes every time TouchGFX regenerates the code.
Any suggestions or best practices to avoid this problem would be greatly appreciated!
Thanks in advance!