Let's resume a simple process of creating your own library for Waspm0te API.
- First of all, go to the path: xxx/wapmote-pro-ide-xx/libraries and create a folder with the name of your new library, for example myLibrary.
- Then create inside two files: myLibrary.cpp and myLibrary.h.
- Then, define inside your own class, starting from these templates:
myLibrary.cpp template wrote:/******************************************************************************
* Includes
******************************************************************************/
#ifndef __WPROGRAM_H__
#include <WaspClasses.h>
#endif
#include "myLibrary.h"
/******************************************************************************
* User API
******************************************************************************/
/******************************************************************************
* PRIVATE FUNCTIONS *
******************************************************************************/
/******************************************************************************
* PUBLIC FUNCTIONS
******************************************************************************/
myLibrary::myLibrary(){
}
void myLibrary::ON()
{
}
/// Preinstantiate Objects /////////////////////////////////////////////////////
myLibrary myObject = myLibrary();myLibrary.h template wrote:/*! \def myLibrary_h
\brief The library flag
*/
#ifndef myLibrary_h
#define myLibrary_h
/******************************************************************************
* Includes
******************************************************************************/
#include <inttypes.h>
/******************************************************************************
* Definitions & Declarations
******************************************************************************/
/******************************************************************************
* Class
******************************************************************************/
//! myLibrary Class
/*!
defines all the variables and functions used
*/
class myLibrary
{
/// private methods //////////////////////////
private:
/// public methods and attributes ////////////
public:
myLibrary();
void ON();
};
extern myLibrary myObject;
#endif - Then define your class, adding necessary methods, variables, etc.
- save it and open Waspmote IDE and a new Sketch. If you go to sketch/import library, you can choose "myLibrary" and the line #include <myLibrary.h> will appear in your sketch.
- Now you can use the predefined class object myObject to call myLibrary methods.
// Put your libraries here (#include ...)
#include <myLibrary.h>
void setup()
{
// put your setup code here, to run once:
myObject.ON();
}
void loop()
{
// put your main code here, to run repeatedly:
}