Let's resume a simple process of creating your own library for Waspm0te API.
  1. 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.
  2. Then create inside two files: myLibrary.cpp and myLibrary.h.
  3. 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
  4. Then define your class, adding necessary methods, variables, etc.
  5. 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.
  6. 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:

}
Post Reply