Get slider value (FT800-FT813 lib)

FTDI/Bridgetek EVE2 & EVE3 & EVE4 SPI TFT Series by Matrix Orbital

Moderator: Mods

Post Reply
dood
LCD Geek
Posts: 20
Joined: Fri Oct 30, 2020 5:10 pm

Get slider value (FT800-FT813 lib)

Post by dood »

Hi',

I'm working on a laptimer project based on Arduino and EVE3 TFT screen.

Rudolph's lib looks perfect to me (FT800-FT813)
I've always setup some little things but I'm scratching my head on how to get values from widgets like toggle buttons or sliders after the user change it on the screen ?
Could I read the value somewhere ?

Rudolph
LCD Guru
Posts: 67
Joined: Wed Feb 28, 2018 11:09 am

Re: Get slider value (FT800-FT813 lib)

Post by Rudolph »

To obtain the values of sliders you use CMD_TRACK when you detect a touch event.
And while you hold down and move your finger the changed value is received by reading REG_Tracker.

There are a few tricky bits involved.
One thing is that REG_TRACKER delivers a 32 bit value.
You need to scale that to yours slider value.
And then the slider value is zero on top and max on bottom.

Here are a few snippets from one of my latest projects:

in TFT_display():
EVE_cmd_dl_burst(TAG(40));
EVE_cmd_slider_burst(675, 100, 20, 260, 0, 8000-PST_Cmd_n_SpeedMechCmd, 8000);

in TFT_touch():
uint8_t tag = 0;
static uint8_t track = 0;
...
tag = EVE_memRead8(REG_TOUCH_TAG);
uint32_t touchtest = EVE_memRead32(REG_TOUCH_RAW_XY);

switch(tag)
{
case 0:
if(touchtest == 0xffffffff) /* display is not touched anymore */
{
if(track != 0 )
{
EVE_cmd_track(0, 0, 0, 0, 0); // stop tracking
track = 0;
}
}
break;
...
case 30:
if(track == 0) /* whatever this does, do nothing when tracking is in progress */
{
....
}
break;
case 40:
if(track == 0)
{
EVE_cmd_track(660,90,40,280,40); /* start tracking */
track = 10;
}
else
{
uint32_t tracker_val = EVE_memRead32(REG_TRACKER);
if((tracker_val & 0xff) == 40)
{
tracker_val = tracker_val / 536870; /* scale to 8000 max */
PST_Cmd_n_SpeedMechCmd = 8000 - tracker_val;
}
}
break;
...

So, when a touch even is registered with tag 40, CMD_TRACK is used to start tracking finger movement.
And when the tracking is in progress the value for the slider gets updated.
When the finger is moving out of the box left in contact with the display, the lockout thru the "track" variable prevents
accidental touch events from elements near the slider.
And when the finger is removed from the display this touch state-machine is unlocked for new touch events again.

The math looks a little counter-intuitive but that "PST_Cmd_n_SpeedMechCmd" is not only used for displaying the slider value.
The value is also displayed as number and send out by CAN to control annother unit, so I need the actual number, not the inverted value.


Oh, annother tipp, I am using an invisible rectangle under the slider to improve the touch performance.

in initStaticBackground():
EVE_color_rgb(WHITE);
...
// EVE_color_rgb(YELLOW);
EVE_cmd_dl(LINE_WIDTH(1*16));
EVE_cmd_dl(DL_BEGIN | EVE_RECTS);
EVE_cmd_dl(TAG(40));
EVE_cmd_dl(VERTEX2F(660,80));
EVE_cmd_dl(VERTEX2F(710,380));
EVE_cmd_dl(TAG(0));
EVE_cmd_dl(DL_END);

So, usually I use a white background and only switch these rectangles on during development.

dood
LCD Geek
Posts: 20
Joined: Fri Oct 30, 2020 5:10 pm

Re: Get slider value (FT800-FT813 lib)

Post by dood »

As usual, a very detailed answer :)
Thanks for all these explanations.

I try on my side and everything is working smoothly.
Invisible rectangles are smart even if I'll probably create big sliders (motorcycle use, with gloves). Anyway good to know.

About this :

Code: Select all

uint32_t tracker_val = EVE_memRead32(REG_TRACKER);
REG_TRACKER is a 32 bits int but the value is only on 16 higher bits isn't it ? (and tag can be read on the lower 16 bits).

I have to use the "PST_Cmd_n_SpeedMechCmd" var to get the slider position updated on screen, that's right ?
I give a try without, that's working (value is updated) but the slider doesn't move anymore on the screen.

Did you have or post somewhere small examples of toggle buttons and checkbox ?

Rudolph
LCD Guru
Posts: 67
Joined: Wed Feb 28, 2018 11:09 am

Re: Get slider value (FT800-FT813 lib)

Post by Rudolph »

dood wrote:
Sun Mar 14, 2021 7:37 am
REG_TRACKER is a 32 bits int but the value is only on 16 higher bits isn't it ? (and tag can be read on the lower 16 bits).
You are right and I even check for the tag.
Sometimes it is a good idea to review code like this, even when it is working alright. :-)
Looks like I need to check the math on that if that really is the fastest way to scale that value down. :-)
I have to use the "PST_Cmd_n_SpeedMechCmd" var to get the slider position updated on screen, that's right ?
I give a try without, that's working (value is updated) but the slider doesn't move anymore on the screen.
Exactly, that is just one global variable.
Did you have or post somewhere small examples of toggle buttons and checkbox ?
Nope, but toggle is just like this:
EVE_cmd_toggle_burst(100, LAYOUT_Y1+50, 80, 27, 0, (somevar == true) ? 65535 : 0, "on" "\xff" "off");

case 0:
toggle_lock = 0;
break;

case 100:
if(toggle_lock == 0)
{
toggle_lock = 42;
if(somevar == true)
{
somevar = false;
}
else
{
somevar = true;
}
}
break;

As there is no checkbox widget you could either change an image based on a variable.
Or with a plainer interface that is using rectangles for buttons the color of that rectangle can be changed based on state.

In one of my interfaces I have a "save" button that is just a rectangle with the text "save" on it.
When the parameters are changed it turns orange. When the parameters do match the stored parameters by either using the save
button or changing the settings back it turns green.
Then I have a "radio-button" with "ID 0", "ID 1", "ID 2"... which allows to edit a serial number.
Also just plain rectangles and the active one is displayed in a brighter shade of blue.

dood
LCD Geek
Posts: 20
Joined: Fri Oct 30, 2020 5:10 pm

Re: Get slider value (FT800-FT813 lib)

Post by dood »

Toggle is perfectly working (easy compared to sliders :)).
Checkbox will be replaced by toggle buttons, that's fine !

I'm quickly coding all my screens with every options I need.
Source code will be available on Github as soon as I get a working copy, that would provide some basic examples for people.

(I don't take time to work on the bargraph viewtopic.php?f=45&t=6903&p=27266#p27266 but that's on the roadmap too)

Post Reply