Library to allo USB PTP device to be hosted by the mbed platform

Dependents:   class_project_main

PIMA15740/PIMAArray.h

Committer:
jakowisp
Date:
2013-08-23
Revision:
0:98cf19bcd828
Child:
1:71c0e9dc153d

File content as of revision 0:98cf19bcd828:


#include "mallocdebug.h"

/**
*  Class PIMA array
*
*
*
*/
class PIMAArray {
public:
  /**
  *   Constructor
  *  @params: None
  *
  */
  PIMAArray() {
     numberOfElements=0;
     codes=NULL;
  };
  
  ~PIMAArray() {
    if( codes !=NULL)
        free(codes);
  };

 int FillArray(uint8_t *currentPtr) {
     SetNumberOfElements(*((uint32_t *)currentPtr));
     SetCodes((uint16_t *)(currentPtr+4));
     return (2*numberOfElements) + 4;
}

 void SetNumberOfElements(uint8_t length) {
     this->numberOfElements=length;
     if( codes !=NULL)
        free(codes);
     codes = (uint16_t *) malloc(sizeof(uint16_t)*length);
 };
 
 void SetCodes(uint16_t *buffer){
     if(buffer!=NULL && codes !=NULL)
       for(int i=0;i<this->numberOfElements;i++)
           codes[i]=buffer[i];
 };
  
   uint32_t numberOfElements;
   uint16_t *codes;
};