Tablet protocol reader...

Hi this is one of my first sketch, it's not finished, just wanted to know if i m on the right track, and some advice on how i continue it,

It's a sketch which read the input of a serial Tablet ( like a wacom thing ), define statuts ( pen hovering, pen pressing, or no pen ) and then the coordinate, the protocol is in 5 bytes.

/* Topaz Tablet drawing app
This a program that reads the five bytes protocol from a Serial Topaz Tablet and then
converting them in three variables : Statut, x,y and draw the result if the statuts is set to "draw" and print value of the statut,x, and y.
*/
// Define constant

#define TOPAZ_PACKET	5

// Declares variables

int buffer[5];
int topaztablet = 0;
int statut = 0;
int x = 0;
int y = 0;
int packetlen = 0;
int packet = 0;

void draw(int x, int y) // prototype, not yet used in the sketch.

// Will be called when a good data packet is recognized with the statut draw and then draw.
{
   // code
}



void setup() // Setup of the tablet and the arduino input
{

Serial.begin (19200);

}

void loop () // Read incoming bytes.
{
  Serial.available();
  packet = Serial.read();
  
  if (packetlen > 0);
  {
packetlen = 0;
  }
  if (packetlen < TOPAZ_PACKET);
 {
   packetlen++;
 }
 if (packetlen == TOPAZ_PACKET);
 {
   packetlen = buffer[5];
  }

  }

Please edit so your code example is in code brackets, otherwise we can't read its indentation.

You are on the wrong track.

/* Topaz Tablet drawing app
This a program that reads the five bytes protocol from a Serial Topaz Tablet and then
converting them in three variables : Statut, x,y and draw the result if the statuts is set to "draw" and print value of the statut,x, and y.
*/

// CONSTANTS 
//
#define TOPAZ_PACKET	5


// VARIABLES
//
int buffer[5];
int buflen =0;  // how far is buffer filled 


/////////////////////////////////////////
//
// CODE STARTS HERE
//
void setup() 
{
  Serial.begin (19200);
}


void loop () 
{
  // COLLECT PACKET 
  while ( Serial.available() > 0 && buflen < TOPAZ_PACKET )    
  { 
    buffer[buflen ] = Serial.read();
    buflen++;
  }

  // PROCESS PACKET
  if ( buflen == TOPAZ_PACKET )  // do we have a full buffer?
  {
    // reset buflen so next packet can be collected
    buflen = 0;

    // parse the content of buffer and do you thing
    ...   
    
  }

}

your turn :wink:

Ok, i think i have reached my limits, i ll study more because, i feel stuck.
I was reading from the tablet developper reference that the draw ( first byte from the 5 bytes packet when pen is down ) expected value is "241" (240 when pen is near but not down, and 176 for no pen near at all ), but when i monitor using hyperterminal, the hex i see for draw is 87, i ve converted it to everything and nothing match the mysterious "241"...

i ve tried to continue the code, but obviously i'm doing stuff the wrong way.

any help is welcome.

Regards

/* Topaz Tablet drawing app
This a program that reads the five bytes protocol from a Serial Topaz Tablet and then
converting them in three variables : Statut, x,y and draw the result if the statuts is set to "draw" and print value of the statut,x, and y.
*/

// CONSTANTS 
//
#define TOPAZ_PACKET	 5


// VARIABLES

int buffer[5];
int buflen =0;  // how far is buffer filled 
int statuts = 0;
int subcol = 0;
int numcol = 0;
int subline = 0;
int numline = 0;
int x = 0;
int y = 0;
/////////////////////////////////////////
//
// CODE STARTS HERE
//
void setup() 
{
  Serial.begin (19200);
}


void loop () 
{
  // COLLECT PACKET 
  while ( Serial.available() > 0 && buflen < TOPAZ_PACKET )    
  { 
    buffer[buflen ] = Serial.read();
    buflen++;
  }

  // PROCESS PACKET
  if ( buflen == TOPAZ_PACKET )  // do we have a full buffer?
  {
    // reset buflen so next packet can be collected
    
    buflen = 0;
    statuts = buffer[0];
    subcol = buffer [1];
    numcol = buffer [2];
    subline = buffer [3];
    numline = buffer [4];
  }
    
    if ( buffer[0] == 176, 240, 241 )
    {
      x = 0;
      y = 0;
    
      x = ((((numcol*128)+subcol)/4)-37);
    }
      if ( x > 128 )
      {
        x = 128;
      }
      y = ((((numline*128)+subline)/5)-10);
   drawing (statuts, x, y);  
  }
  int drawing (statuts, x, y)
  {
  // code about drawing
  }
   
      

   
       
    
  }

}