Passing Variable values between Arduino ino and lv_demo_printer.c

Description

I have adapted the lv_demo_printer() example and it is called from and Arduino.ino file. In this I have created a task that runs every 10 seconds and should update the gui based on incoming sensor readings.

The problem is that when I update a variable value in the main arduino loop, when the task is ran by lv_task_gandler() it only reverences varables which are in the lv_demo_printer.c file and does not take te updated value from the Arduino.ino file.

What MCU/Processor/Board and compiler are you using?

ESP32 ILI9488

What LVGL version are you using?

7.8

What do you want to achieve?

access values updated from arduino loop into lv_demo_printer.c to change GUI items.

so if you look at the code below and you called the lv_printer_example from lv_examples, how would you use the globalCounter value to determine GUI changes. This probably c 101 but I am stick so please help!

What have you tried so far?

using extern in the lv_demo_printer.c file but when I call the variable values the updated value is not used.

I have created a task within lv_demo_printer, which runs, but when It tries to take the value set in the loop it does not pick up the value.

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

#include <lvgl.h>
#include <TFT_eSPI.h>
#include <lv_examples.h>
// #include <lv_demo_printer.c>
// #include <lv_examples.h>
#include <Ticker.h>






static int globalCounter = 0; // I WANT TO USE THIS VALUE GLOBALY






static String LoRaData;

#define screenWidth 480
#define screenHeight 320
#define LVGL_TICK_PERIOD 20

TFT_eSPI tft = TFT_eSPI(); /* TFT instance */
static lv_disp_buf_t disp_buf;
static lv_color_t buf[LV_HOR_RES_MAX * 10];
Ticker   lvgl_tick;             /* timer for lvgl */






#if LV_USE_LOG != 0
/* Serial debugging */
void my_print(lv_log_level_t level, const char * file, uint32_t line, const char * fn_name, const char * dsc)
{

  Serial.printf("%[email protected]%d->%s\r\n", file, line, dsc);
  Serial.flush();
}
#endif

/* Display flushing */
void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
  uint32_t w = (area->x2 - area->x1 + 1);
  uint32_t h = (area->y2 - area->y1 + 1);

  tft.startWrite();
  tft.setAddrWindow(area->x1, area->y1, w, h);
  tft.pushColors(&color_p->full, w * h, true);
  tft.endWrite();

  lv_disp_flush_ready(disp);
}

/*Read the touchpad*/
bool my_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{
  uint16_t touchX, touchY;

  bool touched = tft.getTouch(&touchX, &touchY, 600);

  if (!touched)
  {
    data->state = LV_INDEV_STATE_REL;
    return false;
  }
  else
  {
    data->state = LV_INDEV_STATE_PR;
  }

  if (touchX > screenWidth || touchY > screenHeight)
  {
    Serial.println("Y or y outside of expected parameters..");
    Serial.print("y:");
    Serial.print(touchX);
    Serial.print(" x:");
    Serial.print(touchY);
  }
  else
  {
    /*Set the coordinates*/
    if (3 == tft.getRotation()) {
      //Shift coordinates
      data->point.x = 480 - touchX;
      data->point.y = 320 - touchY;
    } else if (1 == tft.getRotation()) {
      data->point.x = touchX;
      data->point.y = touchY;
    }

    Serial.print("Data x");
    Serial.println(touchX);

    Serial.print("Data y");
    Serial.println(touchY);
  }

  return false; /*Return `false` because we are not buffering and no more data to read*/




}

void lv_tick_handler() {
  lv_tick_inc(LVGL_TICK_PERIOD);
}


void setup()
{

  lv_init();

#if LV_USE_LOG != 0
  lv_log_register_print_cb(my_print); /* register print function for debugging */
#endif

  tft.begin(); /* TFT init */
  tft.setRotation(1); /* Landscape orientation */

  // uint16_t calData[5] = { 305, 3542, 245, 3529, 3  };
  uint16_t calData[5] = { 270, 3639, 250, 3556, 7  };
  tft.setTouch(calData);

  lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10);

  /*Initialize the display*/
  lv_disp_drv_t disp_drv;
  lv_disp_drv_init(&disp_drv);
  disp_drv.hor_res = 480;
  disp_drv.ver_res = 320;
  disp_drv.flush_cb = my_disp_flush;
  disp_drv.buffer = &disp_buf;
  lv_disp_drv_register(&disp_drv);

  /*Initialize the (dummy) input device driver*/
  lv_indev_drv_t indev_drv;
  lv_indev_drv_init(&indev_drv);
  indev_drv.type = LV_INDEV_TYPE_POINTER;
  indev_drv.read_cb = my_touchpad_read;
  lv_indev_drv_register(&indev_drv);


  lvgl_tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);



lv_demo_printer();



}





void loop()
{



      lv_task_handler(); /* let the GUI do its work */
      delay(5);

      }

      globalCounter++;



}

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

I managed to find a fix using this post: https://stackoverflow.com/questions/19395178/share-global-variable-between-c-file.