PtTrend help

Hello, I’m starting to learn how to do an application with PhAB. I want to learn how to use PtTrend widget. I’d tried to do a window with a button which sets a function in a trend when it is pressed.
The function is:

/* Standard headers */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

/* Local headers */
#include “ablibs.h”
#include “abimport.h”
#include “proto.h”

#define SAMPLES 1000

int dibujar( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo){

int j;
short trendData[SAMPLES];
PtArg_t args[3];

/* eliminate 'unreferenced' warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

for (j = 0; j< SAMPLES; j++){
	trendData[j] = j;
}

PtSetArg(&args[0], Pt_ARG_TREND_MIN, 0, 0);
PtSetArg(&args[1], Pt_ARG_TREND_MAX, 1005, 0);
PtSetArg(&args[2], Pt_ARG_TREND_INC, 1, 0);
PtSetResources(ABW_pantalla, 3, args);
PtTrendChangeData(ABW_pantalla, (short const*)trendData, 0, 1000)
return (Pt_CONTINUE);

}

when I press the button (widget in this function) it supposed that a line from left bottom to right top could be drawn in trend widget but instead of this a reverse triangle is drawn.
I don’t know what I’m doing wrong.

Moreover, i want refresh the function in the trend when i push the button. I read something about PtFlush() but I don’t understand how it works.
Thanks.

P.D. Sorry for my poor English. If someone needs any explanation ask me for it.

Hello Gareth_00,
Actually there is no reason to expect that the line in this case will go from left bottom to right top corner. Please consider the following fragment from PtTrendChangeData description:
“If last_sample + nsamples - 1 is outside the range of samples for the widget, some initial portion of the new data is discardedâ€

Hi everybody!

Currently Im start to work with QNX and PhAB. i read some documents to have idea of how this development environment works but when i tried to test this code i can’t seen nothing over the Trend Component, What could be the problem?. The code its linked to a Button with activate callback code type.

Thanks a lot for the help.

It’s rather hard to answer a question like this “What could be the problem?” without some source code.

Hi Maschoen, thanks for your reply

The code is the same that above:

/* Local headers */
#include "ablibs.h"
#include "abimport.h"
#include "proto.h"
#include <photon/PtTrend.h>

void Graphic0(void);
void dibujar(void);

#define SAMPLES 500

int
Graphic( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )

	{

	/* eliminate 'unreferenced' warnings */
	widget = widget, apinfo = apinfo, cbinfo = cbinfo;

	

	PtWidget_t *this_window;
	this_window = ApGetInstance(widget);
	//Graphic0();
	dibujar();
	PtFlush();
	return( Pt_CONTINUE );

	}



void Graphic0(void)
	{
	short data[10];

	data[0] = 2;
	data[1] = 12;
	data[2] = 32;
	data[3] = 72;
	data[4] = 12;
	data[5] = 2;
	data[6] = 12;
	data[7] = 32;
	data[8] = 72;
	data[9] = 12;


	printf("Running...\n");

	PtSetResource(ABW_base_Trend0,Pt_ARG_TREND_MIN,0,0);
	PtSetResource(ABW_base_Trend0,Pt_ARG_TREND_MAX,100,0);
	PtSetResource(ABW_base_Trend0,Pt_ARG_TREND_INC,10,0);
	PtTrendChangeData(ABW_base_Trend0,(short const *)&data,0,10);

	}


void dibujar(void)
	{

	static int i = 0;

	int j;
	short trendData[SAMPLES];
	PtArg_t args[13];


	i++;
	for (j = 0; j< SAMPLES; j++)
		{
			if ( (i%2) == 0 )
				{
				trendData[j] = j;
				}
			else
				{
				trendData[j] = SAMPLES - j;
				}

		}

	PtSetArg(&args[0], Pt_ARG_TREND_MIN, 0, 0);
	PtSetArg(&args[1], Pt_ARG_TREND_MAX, SAMPLES+10, 0);
	PtSetArg(&args[2], Pt_ARG_TREND_INC, 1, 0);
	PtSetResources(ABW_base_Trend0, 3, args);
	PtTrendChangeData(ABW_base_Trend0, (short const*)trendData, 0, SAMPLES);
	}

The “Graphic” method is called when the button is pressed. Thanks in advance for your help.

Regards,

Well here’s what I did. I created a new PhAB project. I put in a trend widget that I called base_Trend0. I put in a button. I set the Activate callback on the button to call Graphics().
When I press the button continually, the image changes between two graphs. One is a line with positive slope and the other a line with negative slope. That seems to be what the code is trying to do. So I think maybe you don’t have something connected right. I can post the project if you like.

Silly me, I should just attach it.