[Reference] Creating your own library in Waspmote API

Everything about programming the platform and using the Waspmote API
Post Reply
libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

[Reference] Creating your own library in Waspmote API

Post by libelium-dev » Fri Jan 17, 2014 9:46 am

Hi all,

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

Who is online

Users browsing this forum: No registered users and 1 guest