2025-06-19 1:19 AM
Hi Guys.
I want to set textarea. I created the new texts.
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.
I think I can't link the Bat4TextId with the bat4TextId in presenter. What's the problem?