cancel
Showing results for 
Search instead for 
Did you mean: 

update a TouchGFX textArea from a .c file

FJB2069
Senior

I am trying to update a textArea object from a .c file.

I have been able to open the screen by creating a wrapper, the wrapper also handles the data to update.  

The screen is called ResultsView.cpp and the textArea is called textAreaTap

 

to open the screen i created a wrapper: showResultsScreen()

// ResultsScreenWrapper.cpp
#include "ResultsScreenWrapper.h"
#include <gui/common/FrontendApplication.hpp>
#include <gui/results_screen/ResultsView.hpp>
#include <touchgfx/Application.hpp>


#include <gui/results_screen/ResultsPresenter.hpp>


extern "C" void showResultsScreen()
{
    static_cast<FrontendApplication*>(touchgfx::Application::getInstance())->gotoResultsScreenNoTransition();
}
extern "C" void update_results_screen(const char* resultText)
{
    auto* app = static_cast<FrontendApplication*>(touchgfx::Application::getInstance());
    ResultsPresenter* presenter = static_cast<ResultsPresenter*>(app->getCurrentPresenter());

    if (presenter)
    {
        presenter->updateResults(resultText);
    }
}

and in:

// ResultsScreenWrapper.h
#ifndef RESULTS_SCREEN_WRAPPER_H
#define RESULTS_SCREEN_WRAPPER_H

#ifdef __cplusplus
extern "C" {
#endif

void showResultsScreen();
//void update_results_screen(const char* resultText, int rpm, bool success);
void update_results_screen(const char* resultText);


#ifdef __cplusplus
}
#endif

#endif // RESULTS_SCREEN_WRAPPER_H

 I modified FrontendApp to include gotoResultsScreenNoTransition

#include <gui/common/FrontendApplication.hpp>

FrontendApplication::FrontendApplication(Model& m, FrontendHeap& heap)
    : FrontendApplicationBase(m, heap)
{
}

void FrontendApplication::gotoResultsScreenNoTransition()
{
    FrontendApplicationBase::gotoResultsScreenNoTransition();
}

touchgfx::Presenter* FrontendApplication::getCurrentPresenter()
{
    return currentPresenter;  // 👈 This is protected in base class, now exposed
}

  Then in my .c file I call:

showResultsScreen();

 

and the screen opens and it is initialized correctly with the textAreaTap = "4" as setupScreen is called from:

#include <gui/results_screen/ResultsView.hpp>
#include <touchgfx/Unicode.hpp>

#include "string.h"
#include "stdio.h"

ResultsView::ResultsView()
{

}

void ResultsView::setupScreen()
{
    ResultsViewBase::setupScreen();
    // Explicitly rebind the wildcard
    Unicode::strncpy(textAreaTapUpCountBuffer, "4", TEXTAREATAPUPCOUNT_SIZE);
    textAreaTapUpCount.setWildcard(textAreaTapUpCountBuffer);
     textAreaTapUpCount.invalidate();

}

void ResultsView::tearDownScreen()
{
    ResultsViewBase::tearDownScreen();
}

void ResultsView::applyRunResults(const char* resultText)
{



Unicode::strncpy(textAreaTapUpCountBuffer, "3", TEXTAREATAPUPCOUNT_SIZE);
// textAreaTapUpCount.setWildcard(textAreaTapUpCountBuffer);


printf("Buffer address: %p\n", (void*)textAreaTapUpCountBuffer);
printf("Wildcard address: %p\n", (void*)textAreaTapUpCount.getWildcard());
printf("tapUpCountBuffer: %s\n", textAreaTapUpCountBuffer);

textAreaTapUpCount.setWildcard(textAreaTapUpCountBuffer);
textAreaTapUpCount.invalidate();



}

 So at this point I know the buffers are setup correctly.

I have a presenter: updateResults to pass data to applyRunResults()

#include <gui/results_screen/ResultsView.hpp>
#include <gui/results_screen/ResultsPresenter.hpp>

ResultsPresenter::ResultsPresenter(ResultsView& v)
    : view(v)
{

}

void ResultsPresenter::activate()
{

}

void ResultsPresenter::deactivate()
{

}

void ResultsPresenter::updateResults(const char* resultText)
{
    view.applyRunResults(resultText);
}

 

Issue is when I try to call update_results_screen();  from same .c file (also set up in wrapper above) it will not change textAreaTap to a "3"  

I am getting the correct data through resultText, but I just tried to a "3" value to test.

 

I have verified the correct data is in the buffer and that the addresses are correct.  I do not know if the screen will just not validate or if it is trying to update the wrong instance of the screen?    Maybe I am going about this the wrong way?

 

Update:  I created a button on the screen,  The button does nothing, but when I press it the screen updates and updates the textAreaTap with a "3".   So, obviously the screen is not updating without the press?

 

1 ACCEPTED SOLUTION

Accepted Solutions
FJB2069
Senior

I determined the gui was not updating the screen, because creating and pressing a button causes the screen to update. 

apparently, it was trying to update out of sync with the handleTickEvent because it is getting called from a C file.

So to sync it up:  flag a pending update in the handelTickEvent

bool pendingUpdate = false;

void ResultsView::applyRunResults(const char* resultText)
{

Unicode::strncpy(textAreaTapUpCountBuffer, "3", TEXTAREATAPUPCOUNT_SIZE);


textAreaTapUpCount.setWildcard(textAreaTapUpCountBuffer);
textAreaTapUpCount.invalidate();

pendingUpdate = true;  // Delay redraw until tick
}


void ResultsView::handleTickEvent()
{
    if (pendingUpdate)
    {
    	textAreaTapUpCount.invalidate();  // Now this works!
        pendingUpdate = false;
    }
}

 

 

 

View solution in original post

1 REPLY 1
FJB2069
Senior

I determined the gui was not updating the screen, because creating and pressing a button causes the screen to update. 

apparently, it was trying to update out of sync with the handleTickEvent because it is getting called from a C file.

So to sync it up:  flag a pending update in the handelTickEvent

bool pendingUpdate = false;

void ResultsView::applyRunResults(const char* resultText)
{

Unicode::strncpy(textAreaTapUpCountBuffer, "3", TEXTAREATAPUPCOUNT_SIZE);


textAreaTapUpCount.setWildcard(textAreaTapUpCountBuffer);
textAreaTapUpCount.invalidate();

pendingUpdate = true;  // Delay redraw until tick
}


void ResultsView::handleTickEvent()
{
    if (pendingUpdate)
    {
    	textAreaTapUpCount.invalidate();  // Now this works!
        pendingUpdate = false;
    }
}