cancel
Showing results for 
Search instead for 
Did you mean: 

TouchGFX Graph widget inside custom container

Michael N
Associate II

Hi ,

I'm using 4.10 library version , I've downloaded the Graph widget from https://github.com/touchgfx/touchgfx-open-repository/tree/master/widgets/Graph .

Updated Graph::Setup function as recommended in repository .

I've created custom container named baseContainer which contains some common, to whole application ,values .So I'm also wanted to add Graph representation from ADC readings (ADC readings works , because I've added another field to container which displays the ADC readings once per second)

I've placed the Graph widget source code to "\gui\src\common" and headers to "gui\include\gui\common" ,I'v added instance of Graph to my container and initialized as follows :

void baseContainer::initialize()
{
    baseContainerBase::initialize();
    graph.setXY(46,201);
    graph.setup(220,250,Color::getColorFrom24BitRGB(111, 156, 233));
    graph.setRange(0, 220, 0, 250);
    graph.setLineWidth(5);
    graph_insert_index = 0;
    graph_insert_period  = graph.getRangeRight() / 22 ;   //  debugging
    add(graph);
}

The aim is to display the graph in bottom left corner on 800x480 screen .

The background color of the screen is RGB(16, 20, 40) ;

The update of the graph is as follows :

void baseContainer::periodicRefresh(CONT_DATA_STRUCT adc_data)
{
    
    Unicode::snprintf(txtCurrPressBuffer, TXTCURRPRESS_SIZE, "%d", adc_data.internal_pressure);
   // Unicode::snprintf(txtCurrPressBuffer, TXTCURRPRESS_SIZE, "%d", 0);
    txtCurrPress.invalidate(); 
    
    boxBatProg.setValue(adc_data.bettery_percentage);
    boxBatProg.invalidate();
    if((graph_insert_index % graph_insert_period) == 0)
    {
      graph.addValue(graph_insert_index,adc_data.bettery_percentage);
    }
    graph_insert_index = ((graph_insert_index + 1) % graph.getRangeRight());
    graph.invalidate();
}

the other values : boxBatProg and txtCurrentPressure updated good . The debugger showed that periodicRefresh function is reached .

The problem is that graph is not showed at all :no dots ,no lines ,nothing . Just background.

The Graph::NUMBER_OF_POINTS is set to 25 . Also , my IAR compiler , complained about line 325 of AbstractGraph.cpp file (void AbstractGraph::invalidateLineFromIndex(int index)) ,that numPointsUsed variable is undefined ,so I've fixed it to numPoints .

Best Regards ,

12 REPLIES 12
Harwinder Singh
Associate II

Hello Martin,

waiting for your reply.

Martin KJELDSEN
Chief III

Hi @Community member​,

I'll get around to your issue asap.

/Martin

Harwinder Singh
Associate II

Hello Martin,

I have done some testing

if i declare canvas buffer inside view base class then graph works fine even in any (second third) screen.like below

GraphscreenViewBase.hpp
 
private:
 
    /*
     * Canvas Buffer Size
     */
    static const uint16_t CANVAS_BUFFER_SIZE = 12000;
    uint8_t canvasBuffer[CANVAS_BUFFER_SIZE];
GraphscreenViewBase.cpp
 
                                                                                      
Graph_ScreenViewBase::Graph_ScreenViewBase()                                          
{                                                                                     
                                                                                      
    touchgfx::CanvasWidgetRenderer::setupBuffer(canvasBuffer, CANVAS_BUFFER_SIZE);    
                                                                                      

But if we declare in GraphsreenView class then it is not working. i don't know why?

Why its working only in view base class?

if we declare canvas buffer in main.cpp then it will work only in startup screen.

Thanks