Skip navigation.
Home
The QNX Community Portal

View topic - PtTrend help

PtTrend help

Isn't the name clear?

PtTrend help

Postby gareth_00 » Mon Jan 28, 2008 4:21 pm

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.
gareth_00
Active Member
 
Posts: 14
Joined: Thu Jun 14, 2007 10:59 am

RE: PtTrend help

Postby ysinitsky » Fri Apr 04, 2008 7:35 pm

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

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â€
ysinitsky
Senior Member
 
Posts: 164
Joined: Wed Dec 14, 2005 8:46 pm

RE: PtTrend help

Postby ala » Fri Oct 22, 2010 10:38 pm

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.
ala
New Member
 
Posts: 2
Joined: Fri Oct 22, 2010 9:49 pm

RE: PtTrend help

Postby maschoen » Sat Oct 23, 2010 7:00 pm

It's rather hard to answer a question like this "What could be the problem?" without some source code.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Help with Trend Component!

Postby ala » Mon Oct 25, 2010 2:37 pm

Hi Maschoen, thanks for your reply

The code is the same that above:

Code: Select all
/* 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,
ala
New Member
 
Posts: 2
Joined: Fri Oct 22, 2010 9:49 pm

RE: Help with Trend Component!

Postby maschoen » Wed Oct 27, 2010 5:57 am

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.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Re: RE: Help with Trend Component!

Postby maschoen » Wed Oct 27, 2010 6:03 am

Silly me, I should just attach it.
Attachments
testgraph.zip
The test project
(6.12 KiB) Downloaded 113 times
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm


Return to GUI Programming

Who is online

Users browsing this forum: No registered users and 1 guest