cancel
Showing results for 
Search instead for 
Did you mean: 

Touchgfx, set text problem.

ABURM
Senior

Hi Guys.

I want to set textarea. I created the new texts.

touchgfx.png

 

 

 

 

 

 

 

 

 

And program is here;
Model.cpp

void Model::tick()
{
    static uint32_t counter = 0;
    const uint32_t updateInterval = 5;
    touchgfx::TypedTextId Bat4TextId;
    counter++;
    if (counter >= updateInterval)
    {
        switch (BAT4_CAN_Rx.fields.BAT4_State)
        {
            case CHARGE_MODE: Bat4TextId = T_CHARGE; break;
            case RELAXING_MODE: Bat4TextId = T_RELAXING; break;
            case DISCHARGE_MODE: Bat4TextId = T_DISCHARGE; break;
            case READY: Bat4TextId = T_READY; break;
            case COMPLETE: Bat4TextId = T_COMPLETE; break;
            default: Bat4TextId = T_UNKNOWN; break;
        }
		counter = 0;
    }
	if (modelListener)
	{
		modelListener->updateStatusData(Bat4TextId);
	}
}

ModelListener.hpp

class ModelListener
{
public:
    ModelListener() : model(0) {}
    
    virtual ~ModelListener() {}

    void bind(Model* m)
    {
        model = m;
    }

    virtual void updateStatusData(touchgfx::TypedTextId bat4TextId){}
protected:
    Model* model;
};

screenPresenter.cpp

void screenPresenter::updateStatusData(touchgfx::TypedTextId bat4TextId)
{
	view.updateStatusText4(bat4TextId);
}

screenPresenter.hpp

class screenPresenter : public touchgfx::Presenter, public ModelListener
{
public:
    screenPresenter(screenView& v);

    /**
     * The activate function is called automatically when this screen is "switched in"
     * (ie. made active). Initialization logic can be placed here.
     */
    virtual void activate();

    /**
     * The deactivate function is called automatically when this screen is "switched out"
     * (ie. made inactive). Teardown functionality can be placed here.
     */
    virtual void deactivate();

    virtual ~screenPresenter() {}

    virtual void updateStatusData(touchgfx::TypedTextId bat4TextId) override;
private:
    screenPresenter();

    screenView& view;
};

screenView.hpp

class screenView : public screenViewBase
{
public:
    screenView();
    virtual ~screenView() {}
    virtual void setupScreen();
    virtual void tearDownScreen();

    virtual void updateStatusText4(touchgfx::TypedTextId bat4TextId);
protected:
};

screenView.cpp

void screenView::updateStatusText4(touchgfx::TypedTextId bat4TextId)
{
	Unicode::snprintf(BT4_Status_Value_TextBuffer, BT4_STATUS_VALUE_TEXT_SIZE, "%s", touchgfx::TypedText(bat4TextId).getText());
	BT4_Status_Value_Text.invalidate();
}

BT4_Status_Value_Text buffer is 25 byte. When I compile the program it doesn't give any errors. But when I load, program is doesn't work.TFT screen and other hardwares (canbus, status led etc.) is not working. If I assign any text id directly to "bat4TextId" the program runs and I see the text I assigned on the screen.

void screenView::updateStatusText4(touchgfx::TypedTextId bat4TextId)
{
	bat4TextId = T_CHARGE;
	Unicode::snprintf(BT4_Status_Value_TextBuffer, BT4_STATUS_VALUE_TEXT_SIZE, "%s", touchgfx::TypedText(bat4TextId).getText());
	BT4_Status_Value_Text.invalidate();
}

All text ids are defined in TextKeysAndLanguages.hpp.

text_id.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I think I can't link the Bat4TextId with the bat4TextId in presenter. What's the problem?

1 ACCEPTED SOLUTION

Accepted Solutions
ABURM
Senior

Hi guys.

I struggled with this problem a lot over the weekend and finally found the cause. Actually, the problem is pretty simple. The problem is caused by "Bat4TextId" being defined inside void Model::tick(). I moved the definitions into the Model.hpp file. I added other TypedTextId (Bat1TextId, Bat2TextId etc.) and it works fine now. The problem is solved.

Thanks for your help.

Best regards.

#ifndef MODEL_HPP
#define MODEL_HPP

#include <touchgfx/TypedText.hpp>

class ModelListener;

class Model
{
public:
    Model();

    void bind(ModelListener* listener)
    {
        modelListener = listener;
    }

    void tick();
protected:
    ModelListener* modelListener;
    touchgfx::TypedTextId Bat1TextId;
    touchgfx::TypedTextId Bat2TextId;
    touchgfx::TypedTextId Bat3TextId;
    touchgfx::TypedTextId Bat4TextId;
    touchgfx::TypedTextId Fan1TextId;
    touchgfx::TypedTextId Fan2TextId;
    touchgfx::TypedTextId Fan3TextId;
};

#endif // MODEL_HPP

 

View solution in original post

9 REPLIES 9
Jakicaa
Associate II

Hello,

I tried to recreate the problem, but it seems that it works in my display.

 

When not working for you, do you mean just the text not showing or does everything crash?

 

Did you enable wildcard buffer and set the proper size in touchgfx?

 

Why is your member function updateStatusText4 in screenview virtual, are you overriding something?

In screenview mine is not virtual.

 

Also are you planning to use multiple languages in the future, if not you can pass std::string from model to view and it will probably work.

 

 

GaetanGodart
ST Employee

Hello @ABURM ,

 

Are you able to change the text by running the code in the screenView files?
So perhaps not using the model files but only using snprintf and invalidate that can get triggered from a button press or simply in the initialize function.

Does it happen for every text? I see some characters that are not standard roman characters, maybe they could be causing the issue?

You say that when you flash, the display doesn´t show anything but have you been able to make it work previously?

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)

Hi @Jakicaa .

When it doesn't work everything crashes. Yes, enabled wildcard buffer (25 bytes) and setted the proper size. I defined the updateStatusText4 procedure in the screenview as "void". It still did not work. In the future I will add Russian, Portuguese, German and a few more languages.

Hi @GaetanGodart.

I edit the data read from the canbus in the model file and display it on the screen. As you said, I can do it using snprintf. However, sticking to the MVP structure, I want to process all the screen data in the model file. If I do the assignment using a switch-case inside the model file, that is, if I assign a value to the 'Bat4TextId' variable within model::tick, the system crashes (screen refresh, LEDs, buttons, everything crashes). However, if I assign a value to the 'bat4TextId' variable within screenView (inside updateStatusText4) (regardless of whether it's GEVŞEME, ŞARJ, or DEŞARJ), the assigned text appears on the screen, and the system continues to operate normally. 

As I mentioned in my first message, the problem is probably related to the failure to link the definitions of 'Bat4TextId' and 'bat4TextId'.

I think your touchgfx code is correct.

Are you using touchGFX 4.25.0?

You said if you assign it directly it works ok? Does directly mean in screenView?

Did you include atleast these two things in all files (model, presenter, view)"

#include <texts/TextKeysAndLanguages.hpp>

#include <TouchGFXGeneratedHAL.hpp>

"?

Can you debug it and pause to see where the program is stoping/crashing?

Hi @Jakicaa 

I am using touchgfx 4.24.0.


You said if you assign it directly it works ok? Does directly mean in screenView?


 What I meant to say is that when I make a direct assignment to "bat4TextId" in the screenView::updateStatusText4 procedure in screenView.cpp, the program works. Like bat4TextId = T_CHARGE or bat4TextId = T_DISCHARGE.


Did you include atleast these two things in all files (model, presenter, view)"

#include <texts/TextKeysAndLanguages.hpp>

#include <TouchGFXGeneratedHAL.hpp>


Yes, i included these two things in all files. This is important.


Can you debug it and pause to see where the program is stoping/crashing?


I tried debugging, but I couldn't see where the program was stuck/stop.

Hello,

what if you remove the switch statement and make some kind of toggle that changes the text id in model to see if it works, also what if you directly put the variable into updateStatusText4? (so every 100 ticks text id changes with no relation to CAN variable, set directly); to see if that works with no CAN variable.

 

Are you certain it crashes exactly on the line where you set the Bat4TextId to a value? Can you set a breakpoint in model::tick member function and step over to see where it crashes?

 

 

JTP1
Lead

Hello Aburm

With quick review, it seems you are sending uninitialized value multiple times and when counter reaches 5, then you send the correct textID.

At  model.cpp tick handler, test to move this:

modelListener->updateStatusData(Bat4TextId);

Inside of if statement  to be executed only when counter-variable reaches limit value.

 

Br JTP

ABURM
Senior

Hi guys.

I struggled with this problem a lot over the weekend and finally found the cause. Actually, the problem is pretty simple. The problem is caused by "Bat4TextId" being defined inside void Model::tick(). I moved the definitions into the Model.hpp file. I added other TypedTextId (Bat1TextId, Bat2TextId etc.) and it works fine now. The problem is solved.

Thanks for your help.

Best regards.

#ifndef MODEL_HPP
#define MODEL_HPP

#include <touchgfx/TypedText.hpp>

class ModelListener;

class Model
{
public:
    Model();

    void bind(ModelListener* listener)
    {
        modelListener = listener;
    }

    void tick();
protected:
    ModelListener* modelListener;
    touchgfx::TypedTextId Bat1TextId;
    touchgfx::TypedTextId Bat2TextId;
    touchgfx::TypedTextId Bat3TextId;
    touchgfx::TypedTextId Bat4TextId;
    touchgfx::TypedTextId Fan1TextId;
    touchgfx::TypedTextId Fan2TextId;
    touchgfx::TypedTextId Fan3TextId;
};

#endif // MODEL_HPP