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!
Solved! Go to Solution.
2024-11-07 07:06 AM
Hello @massimoperdigo ,
Indeed, the files ending by "Base" are generated by TouchGFX Generator and will be regenerated every time you click on the "Generate code" or "Run simulator" button.
It is written at the top of the screen to not modify the file.
Instead, you should modify the file called myScreeView.cpp. This is the one intendent to carry your custom code.
Since you want the slider to start at a specific value, you can use the same method to initialize it's value and since you want it to be initialize as soon as we get to the relevant screen, you should place your code in the setupScreen function.
So it should look like this :
void myScreenView::setupScreen()
{
myScreenViewBase::setupScreen();
brightness_slider.setValue(TIM15->CCR1);
}
I hope this helps! :smiling_face_with_smiling_eyes:
If this comment answered your question, I invite you to select it as "best answer".
Regards,
2024-11-07 07:06 AM
Hello @massimoperdigo ,
Indeed, the files ending by "Base" are generated by TouchGFX Generator and will be regenerated every time you click on the "Generate code" or "Run simulator" button.
It is written at the top of the screen to not modify the file.
Instead, you should modify the file called myScreeView.cpp. This is the one intendent to carry your custom code.
Since you want the slider to start at a specific value, you can use the same method to initialize it's value and since you want it to be initialize as soon as we get to the relevant screen, you should place your code in the setupScreen function.
So it should look like this :
void myScreenView::setupScreen()
{
myScreenViewBase::setupScreen();
brightness_slider.setValue(TIM15->CCR1);
}
I hope this helps! :smiling_face_with_smiling_eyes:
If this comment answered your question, I invite you to select it as "best answer".
Regards,
2024-11-07 07:30 AM
Great!!!
2024-11-08 01:04 AM
Hello @massimoperdigo ,
I am glad it helped you!
Don't hesitate if you have other questions. :smiling_face_with_smiling_eyes:
Regards