cancel
Showing results for 
Search instead for 
Did you mean: 

Initialisation of a slider with a a choosen value. touchGFX

massimoperdigo
Associate III

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!

1 ACCEPTED SOLUTION

Accepted Solutions
GaetanGodart
ST Employee

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,

Gaetan Godart
Software engineer at ST (TouchGFX)

View solution in original post

3 REPLIES 3
GaetanGodart
ST Employee

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,

Gaetan Godart
Software engineer at ST (TouchGFX)
massimoperdigo
Associate III

Great!!!

Hello @massimoperdigo ,

 

I am glad it helped you!

Don't hesitate if you have other questions. :smiling_face_with_smiling_eyes:

 

Regards

Gaetan Godart
Software engineer at ST (TouchGFX)