Skip to main content
OBorz.1
Associate II
December 17, 2020
Solved

Send variable from screen1View.cpp to Model.cpp

  • December 17, 2020
  • 22 replies
  • 4041 views

Hello,

I would like to send the value of a parameter from screen1View.cpp to Model.cpp.

Is there any way to do this?

I work with TouchGFX 4.14 and STM32429-Eval

Thanks!

This topic has been closed for replies.
Best answer by MM..1

When you are newbie, star twith simple think and irq use later. Working solution is config I2C in main and too in main create function to pool read state on joystick, no based on interrupt .

// recomm 400kHz I2C
#define I2CREADTIMEOUT 4
uint8_t joystik_GET_state(void)
{
uint8_t joystik_state[] = {0xFF}; 
 HAL_I2C_Mem_Read(&hi2c1, 0x84, 0x0B, I2C_MEMADD_SIZE_8BIT, joystik_state, 1, I2CREADTIMEOUT);
return joystik_state[0];
}

in model tick

if (joystik_GET_state() &MASKBIT ) 
 
 {
 
 static_cast<FrontendApplication*>(Application::getInstance())->handleKeyEvent(88); // keycode from gui interaction
 
 }

22 replies

December 17, 2020

What do you mean by parameter? Do you mean a variable? If so define that in main.h for example as extern, then define it completely in main, and then include the header file.

OBorz.1
OBorz.1Author
Associate II
December 17, 2020

Thanks for the quick replies.

Yes, I mean a variable.

Is it also possible to send the variable directly from screen1View to main.c?

I have already implemented the reverse way. From main.c to Model.cpp using xQueueSendFromISR

MM..1
Super User
December 17, 2020

All peaple read and use complicated example on TouchGFX. Sending is hard multithread processing, in simple project you can use memory shared variables.

UNDERSTAND uintx_t var;

When is properly used can be changed or read on any place. Nothing sending is required.

But in handletick you need if for compare and detect changing this var .

if(lastvavr!=var) do change on screen.

OBorz.1
OBorz.1Author
Associate II
December 18, 2020

I'm sorry I don't understand this way.

Do you have an example?

MM..1
Super User
December 18, 2020

Unzip and read model.cpp screenview.cpp or open .touchgfx file , but is 4.15 . Then run simulator.

OBorz.1
OBorz.1Author
Associate II
December 20, 2020

it works. Thank you very much!

Alexandre RENOUX
Visitor II
December 21, 2020

Hello OBorz.1,

When your question is answered, please close this topic by choosing Select as Best.

/Alexandre

MM..1
Super User
December 20, 2020

Queues is good for situation, when you dont have reference value is displayed or not, or when exist big amount to display and make if for every is complicated.

Then you wait for queue event and then change display once per event. switch case or if is here same , but executed only on event received.

OBorz.1
OBorz.1Author
Associate II
December 21, 2020

Hello,

I have no data to send.

With the queue I want to set a sign that something moves in the display.

Correct: I press the joystick button of the STM32429I-EVAL1 down and a bar in the display should move down.

MM..1
Super User
December 21, 2020

For this too dont need queue, simply in model tick check gpio , but all checks need be non blocking

OBorz.1
OBorz.1Author
Associate II
December 22, 2020

Hello Alexandre,

thank you very much for the answer.

Where can I find the G0 application template?

Do you know if it works with a button connected to the processor via I²C?

MM..1
Super User
December 22, 2020

As i write all checking in gui thread need be minimal blocking type , then you cant while wait to transfer i2c ...

For this type is better use other thread and set shared memory variable when key is received

i2C ...

keyCode = xx; (OR USE QUEUE)

Then in model tick or buttoncontroller class do if(keyCode ...

OBorz.1
OBorz.1Author
Associate II
December 22, 2020

I tried to include the hardware button as described in the TouchGFX document: "External events as trigger" (https://support.touchgfx.com/docs/4.14/development/board-bring-up/example-gpio).

It fails already at the definition of the PIN! The GPIO pin cannot be declared as "input" in "GPIO_MODE". Currently it is set to "GPIO_MODE_IT_RISING_FALLING".

I think this is the reason why my program terminates after a few clicks on the button.

Is there an example somewhere?

MM..1
Super User
December 22, 2020
OBorz.1
OBorz.1Author
Associate II
December 22, 2020

I already did that with the keyboard a few months ago and it worked.

I have tried this now.

First:

Initialize interrput of the joystick on the board in main.c.

__________________________________________________________________________________________________________________

 uint8_t i2c_buffer[3];

 //uint8_t joystik_state = 0xFF;

 memset(i2c_buffer,0x00,sizeof(i2c_buffer));

 volatile HAL_StatusTypeDef result = HAL_OK;

 /* In System Control soft reset */

 i2c_buffer[0] = 0x10;

 result = HAL_I2C_Mem_Write(&hi2c1, 0x84, 0x03, I2C_MEMADD_SIZE_8BIT, i2c_buffer, 1, 1000);

 /* Read the Chip-ID and version number */

 result = HAL_I2C_Mem_Read(&hi2c1, 0x84, 0x00, I2C_MEMADD_SIZE_8BIT, i2c_buffer,3, 1000);

 /* Set joystick PINs of Input*/

 result = HAL_I2C_Mem_Read(&hi2c1, 0x84, 0x15, I2C_MEMADD_SIZE_8BIT, i2c_buffer, 1, 1000);

 i2c_buffer[0] = i2c_buffer[0] & 0x13;

 result = HAL_I2C_Mem_Write(&hi2c1, 0x84, 0x15, I2C_MEMADD_SIZE_8BIT, i2c_buffer, 1, 1000);

 /* In system Control register activate interrupt */

 i2c_buffer[0] = 0x04;

 result = HAL_I2C_Mem_Write(&hi2c1, 0x84, 0x03, I2C_MEMADD_SIZE_8BIT, i2c_buffer, 1, 1000);

 /* activate interrupt Joystick PINs */

 i2c_buffer[0] = 0x7C;

 result = HAL_I2C_Mem_Write(&hi2c1, 0x84, 0x09, I2C_MEMADD_SIZE_8BIT, i2c_buffer, 1, 1000);

 /* delete interrupt in state register*/

 i2c_buffer[0] = 0x00;

 result = HAL_I2C_Mem_Read(&hi2c1, 0x84, 0x0B, I2C_MEMADD_SIZE_8BIT, i2c_buffer, 1, 1000);

 _________________________________________________________________________________________________________________

Second:

Implemented the following code in Model.cpp

__________________________________________________________________________________________________________________

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

{

 // Prevent unused argument(s) compilation warning

 UNUSED(GPIO_Pin);

 uint8_t joystik_NEW_state = 0xFF;

      I2C_HandleTypeDef hi2c1;

 //aks Value from PIN

 if(GPIO_PIN_8)

 {

       uint8_t joystik_state = 0xFF;

       HAL_StatusTypeDef result = HAL_OK;

       result = HAL_I2C_Mem_Read(&hi2c1, 0x84, 0x0B, I2C_MEMADD_SIZE_8BIT, &joystik_state, 1, 1000);

       

       uint8_t dummy = 0x00;

       result = HAL_I2C_Mem_Read(&hi2c1, 0x84, 0x0B, I2C_MEMADD_SIZE_8BIT, &dummy, 1, 1000);

 }

}

 __________________________________________________________________________________________________________________

I have set a breakpoint at the beginning of the function. When I press the joystick button once, the program also stops at this point. If I press it a second time, the breakpoint is not reached anymore.

I have run the code to query the interrupts also in the main.c and there it runs through often, but sometime after 10....20...30 times pressing the program hangs in the task.c.

MM..1
Super User
December 22, 2020

Hmm your coding style is out of range...

You cant cretae new  I2C_HandleTypeDef hi2c1; in irq and without init.

C calback placed in C++ file isnt good idea too.

USW.