Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete character / text? #492

Closed
epikao opened this issue Oct 28, 2018 · 43 comments
Closed

delete character / text? #492

epikao opened this issue Oct 28, 2018 · 43 comments

Comments

@epikao
Copy link

epikao commented Oct 28, 2018

Hello

I can set a text, for example a number:
lv_label_set_text(txt, "45");

but how can I delete this text, number now?

thanks

@kisvegabor
Copy link
Member

Hi,

Just set the test again with an empty string lv_label_set_text(txt, "");

@epikao
Copy link
Author

epikao commented Oct 29, 2018

hm, but that doesn't delete the previous set text, see:

void button1()
{
num++;

        lv_label_set_text(txt,"  ");
        lv_obj_set_pos(txt, 50,50);
        sprintf(buf, "#ff0000 %d", num);
        lv_label_set_text(txt, buf);
        lv_obj_set_pos(txt, 50,50);
}

@epikao
Copy link
Author

epikao commented Oct 29, 2018

oh, I think, I need to create second text object... but with " " it doesn't delete the previous set characters

@kisvegabor
Copy link
Member

I don't understand. What do you expect to happen exactly? Please, write it down step by step.

@epikao
Copy link
Author

epikao commented Oct 30, 2018

I want increment a number beginning at "1".. and show it on the display.
To show the next number "2" I need to delete "1" before, otherwise 1 will be overwritten from 2.
So if I do before:

    lv_label_set_text(txt2,"  ");
    lv_obj_set_pos(txt2, 50,50);
    num++;

    sprintf(buf, "#ff0000 %d", num);
    lv_label_set_text(txt, buf);
    lv_obj_set_pos(txt, 50,50);

it doesn't delete anything... why that?

@kisvegabor
Copy link
Member

lv_label_set_text() should change the text. So

lv_label_set_text(txt, "1");
lv_label_set_text(txt, "2");

should result "2".

This simple example is working there?

@turoksama
Copy link
Collaborator

turoksama commented Nov 1, 2018

@kisvegabor
I think the problem is that num++; isn't called periodically, because void button1() is initialized once.

@epikao You should set action function of that button, with num++; in it. So, when you press the button, it will be increased, and you'll see 2,3,4,,,etc.

@epikao
Copy link
Author

epikao commented Nov 2, 2018

please see attached picture, which should show/explain better my problem:

count numbers

@turoksama
Copy link
Collaborator

turoksama commented Nov 2, 2018

you've called function button() many times.

@epikao
Copy link
Author

epikao commented Nov 2, 2018

press button first time i want show 1, press button second time I want show 2 etc. so to show 2 properly I need to delete the 1 from before.... but how delete the 1?

@embeddedt
Copy link
Member

oh, I think, I need to create second text object

If you simply create a new label every time, you will see overlapping text like this. Are you using the same label object?

@epikao
Copy link
Author

epikao commented Nov 2, 2018

I simply want count up a number... :-/ ... but before I count 1 to 2 and show to the display I need to delete the 1 otherwise 2 is written over 1 etc.

I created a second text object for lv_label_set_text(txt2," ");.
but with that object I cannot delete or wipe away the number written before.

@embeddedt
Copy link
Member

@epikao You do not need to create a new text object. Simply call lv_label_set_text on the old one.

@epikao
Copy link
Author

epikao commented Nov 2, 2018

I'm not sure if someone understand what I'm looking for?, see below my whole button code. I want simply count up a number by pressing a button....
so press first time button => 1 is show
press second time button => 2 is show, but behind, and that is my problem I still have the 1 ... and don't know how to delete this 1
press third time button => 3 is show, but behind I have 1 and 2... etc :-(

void intbutton1()
{  
   if ( (millis() - lastDebounceTime) > debouncedelay) {

        //background();
        Serial.print("buff1:");
        Serial.print(button1);
        Serial.print("\n");

        /*Create anew style*/
        static lv_style_t style_txt;
        lv_style_copy(&style_txt, &lv_style_plain);
        style_txt.text.letter_space = 2;
        style_txt.text.line_space = 1;
        style_txt.text.color = LV_COLOR_HEX(0x606060);
        lv_obj_t * txt = lv_label_create(lv_scr_act(), NULL);
        lv_obj_set_style(txt, &style_txt);
        lv_label_set_recolor(txt, 1);
        //lv_label_set_text(txt, "#ff0000 "SYMBOL_LEFT);

        num ++; //new Value

        lv_label_set_text(txt,"");
        sprintf(buf, "#ff0000 %d", num);
        lv_label_set_text(txt, buf);
        lv_obj_set_pos(txt, 50,50);
      
      lastDebounceTime = millis(); //set the current time 
    }
}

@embeddedt
Copy link
Member

@epikao

lv_obj_t * txt = lv_label_create(lv_scr_act(), NULL);

Should not be called multiple times in the loop.

@epikao
Copy link
Author

epikao commented Nov 2, 2018

lv_obj_t * txt = lv_label_create(lv_scr_act(), NULL);

I already tried to move these parts outside, for example in the setup() function or global - but so far I know it makes problem with the arduino compiler... but I will try it asap again.

@kisvegabor
Copy link
Member

I already tried to move these parts outside, for example in the setup() function or global - but so far I know it makes problem with the arduino compiler...

@epikao
Please update lvgl from the master branch. There were updates to solve hard faults for some compiler.

If the issue still persists you should:

  1. Declare lv_obj_t * txt as global variable
  2. In intbutton1: if(txt == NULL) txt = lv_label_create(lv_scr_act(), NULL);. It will create a label only if ti not exists yet

It will create the label only once. Anyway, if you create multiple labels on top of each other, you will get multiple get multiple labels on top of each other. So don't create a new label every time.

@epikao
Copy link
Author

epikao commented Nov 4, 2018

if I put code below code in the setup function, I still have the same problem (cannot delete previous set text with " " or something else):

*Create anew style*/
        static lv_style_t style_txt;
        lv_style_copy(&style_txt, &lv_style_plain);
        style_txt.text.letter_space = 2;
        style_txt.text.line_space = 1;
        style_txt.text.color = LV_COLOR_HEX(0x606060);
        lv_obj_t * txt = lv_label_create(lv_scr_act(), NULL);
        lv_obj_set_style(txt, &style_txt);
        lv_label_set_recolor(txt, 1);

@kisvegabor
Copy link
Member

Ok, let's try this in your setup:

lv_obj_t * test_txt = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(test_txt, "1");
lv_label_set_text(test_txt, "2");

And do nothing with labels in the loop.
Does it result "2"?

@epikao
Copy link
Author

epikao commented Nov 19, 2018

yes 2

@epikao
Copy link
Author

epikao commented Nov 19, 2018

so how I delete now this 2 and write a 3 at the same position?

@embeddedt
Copy link
Member

@epikao I don't think you understand how labels work. You can simply call lv_label_set_text again and it changes the value. Do not call lv_label_create more than once for the same label.

@epikao
Copy link
Author

epikao commented Nov 20, 2018

Do not call lv_label_create more than once for the same label.

unfortunately that does not work with arduino.. I get always an error if I don't call "lv_label_create" see error below.
And if I do "lv_obj_t * test_txt = lv_label_create(lv_scr_act(), NULL);" global the program will be compiled but after load nothing happens (black display). I think arduino does not understand if do this function global.

And If I call for example in the setup follow:
lv_obj_t * test_txt = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(test_txt, "1");
lv_label_set_text(test_txt, "2");
than in the button function:
lv_obj_t * test_txt = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(test_txt, "3");

the functions does not delete the previous text... so it's simply overwritten and looks like my pictures above :-(

See the error without the create function in button function:

lvgl_test:306: error: 'test_txt' was not declared in this scope
     lv_label_set_text(test_txt, "3");

                       ^

'test_txt' was not declared in this scope
```

@kisvegabor
Copy link
Member

It should work:

Above setup:

lv_obj_t * my_label;
int num = 0;

In setup

my_label = lv_label_create(lv_scr_act(), NULL);

In loop:

char buf[32];
sprintf(buf, "num: %d\n", num);
num++;
lv_label_set_text(my_label, buf);

@epikao
Copy link
Author

epikao commented Nov 21, 2018

Above setup:

lv_obj_t * my_label;
int num = 0;

"lv_obj_t * my_label;" above setup makes the display not work, it stay's black, not start anything.

@embeddedt
Copy link
Member

@epikao If adding a single global variable above setup breaks the program, this looks like an indication that something else is wrong with your program.

@epikao
Copy link
Author

epikao commented Nov 21, 2018

I found that is not the global variable the problem, is more the function "lv_label_set..." (which I use in my button function):

        num ++; //new Value
        sprintf(buf, "#ff0000 %d", num);
        //lv_label_set_text(my_label, buf);

as soon I activate "lv_label..." I can only call the button function once and than the whole program crashs, freeze...

@embeddedt
Copy link
Member

@epikao Would you mind showing the whole file? It would be easier than trying to debug from several code snippets.

@epikao
Copy link
Author

epikao commented Nov 21, 2018

see more or less the whole code:

#include <lvgl.h>
#include <SPI.h>

....

//Button settings
const int button1 = 0;

volatile unsigned long lastDebounceTime = 0, debouncedelay = 300;

SPISettings settingsA(30000000, MSBFIRST, SPI_MODE0);
IntervalTimer tickTimer;

int num = 0;
char buf[32];
lv_color_t c_test[1000];
uint16_t i;
lv_obj_t * my_label;

void my_disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t *color_array)
{
...
}

void hal_init(void)
{
    ...
	tickTimer.begin(tick,1000); //
}
...

void setup() {
  #ifdef DEBUG
  Serial.begin(9600);
  #endif
  
....

  pinMode(button1, INPUT_PULLUP);

  attachInterrupt(digitalPinToInterrupt(button1), intbutton1, FALLING);

  SPI.begin();
  SPI.beginTransaction(settingsA);
  initST7789V();
  delay(10);
  
  lv_init(); 
  hal_init();

  delay(10);
 my_label = lv_label_create(lv_scr_act(), NULL);
  //LV_IMG_DECLARE(pic1);
  LV_IMG_DECLARE(pic2);
  //LV_IMG_DECLARE(pic3);

  lv_obj_t * img_src = lv_img_create(lv_scr_act(), NULL); /*Crate an image object*/
  lv_img_set_src(img_src, &pic2);  /*Set the created file as image (a red fl  ower)*/
  lv_obj_set_pos(img_src, 0, 0);      /*Set the positions*/
  lv_obj_set_drag(img_src, true);

//lv_obj_t * test_txt = lv_label_create(lv_scr_act(), NULL);
//lv_label_set_text(test_txt, "1");
//lv_label_set_text(test_txt, "2");

}
void intbutton1()
{  
    //lv_obj_t * test_txt = lv_label_create(lv_scr_act(), NULL);
    //lv_label_set_text(test_txt, "3");
   if ( (millis() - lastDebounceTime) > debouncedelay) {

        //background();
        Serial.print("buff1:");
        Serial.print(button1);
        Serial.print("\n");

        num ++; //new Value
        sprintf(buf, "#ff0000 %d", num);
        //lv_label_set_text(my_label, buf);
        //lv_obj_set_pos(my_label, 50,50);
      
      lastDebounceTime = millis(); //set the current time 
    }//close if(time buffer)
}

void tick()
{
  Serial.print("tick");
  Serial.print("\n");
  lv_tick_inc(1); 
}

void loop() {
  // put your main code here, to run repeatedly:

  lv_task_handler();
  /*If 'lv_tick_inc(5)' is not called in a Timer then call it here*/
  delay(5);             /*Wait a little*/
}

@embeddedt
Copy link
Member

You can't create a label before you call lv_init!

@epikao
Copy link
Author

epikao commented Nov 21, 2018

it's the same after hal / lv_init:

  lv_init();
  
  hal_init();
  delay(10);
   my_label = lv_label_create(lv_scr_act(), NULL);

I think there are still some problems with Arduino, especially the tick function together with other function... don't know?? I use branch 5.2

@embeddedt
Copy link
Member

@epikao Is the tick function actually being called?

@epikao
Copy link
Author

epikao commented Nov 21, 2018

yes (but only if lv_label is uncommented)

@embeddedt
Copy link
Member

@epikao Can you show lv_conf.h? I think something has changed/broken since you first opened this issue.

@epikao
Copy link
Author

epikao commented Nov 21, 2018

lv_conf.txt

@turoksama
Copy link
Collaborator

It should work:

Above setup:

lv_obj_t * my_label;
int num = 0;

In setup

my_label = lv_label_create(lv_scr_act(), NULL);

In loop:

char buf[32];
sprintf(buf, "num: %d\n", num);
num++;
lv_label_set_text(my_label, buf);

I think you should carefully read and check what kisvegabor said above.
It should be helpful.

@epikao
Copy link
Author

epikao commented Nov 22, 2018

I think you should carefully read and check what kisvegabor said above.
It should be helpful.

you can see my code above, it's exactly according.
my_label = lv_label_create(lv_scr_act(), NULL); I have put now after hal/lv init.
char buf[32]; I have global.. but should not be the problem??

Also I have put the code "loop" in my button function... but I think that should not be a problem?!

@kisvegabor
Copy link
Member

You have this:

my_label = lv_label_create(lv_scr_act(), NULL);
lv_init();

lv_init should be called first!

@epikao
Copy link
Author

epikao commented Nov 26, 2018

lv_init should be called first!

as mentioned, I already did that... but that still not works :-( .. (I have modify my code above, so maybe somebody can check again, if there is still something wrong??)

Anyway does somebody already could do / test that with arduino / teensy?

@embeddedt
Copy link
Member

@epikao I would try creating a new project. In October it sounded like LittlevGL was running normally, but somehow something appears to have been broken between then and now.

@FutureOfAI
Copy link

What means of label? you can't change label casually. I advise you use lv_ta_create() function instead of lv_label_create() function... and the number will update without delete ex-number.

@embeddedt
Copy link
Member

@xiaoloveyao Actually a label can be changed by calling lv_label_set_text again.

@kisvegabor
Copy link
Member

kisvegabor commented Jan 5, 2019

I suppose the issue has been solved finally so I close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants