I'm writing an application library which will include references to other libraries that I've written wrapped up into one class.
The idea behind this class is to create a standard package which provides services to the author, for example, you would create an instance of the application class:
clsApp objApp( 1, 0, "my Application", "By Simon Platten, 29/01/2012" );
The first two parameters are the Major and Minor version number, followed by the application title, then an additional string which in the above is the author and build date.
The first line of the setup() is:
objApp.startupMsg(true);
The parameter is optional, true means show debug information, default is false. If set to true then the application start-up message is written to the serial port, which would take the form:
myApplication
By Simon Platten, 29/01/2012
Version: 1.0
You can write additional messages to the debug port using the method 'objApp.message()'
So far I've wrapped up my timer class, so to create a timer object use the method, 'createTimer'.
To service any object such as timers, call 'objApp.process()' from within loop(). I will be adding a class to manage events that will call callback functions when an event occurs. So far it doesn't do a lot.
Prototype, clsApp.h
/**
* File:
* clsApp.h
*
* Notes:
* This file contains the prototype for the class clsTimer.
*
* Methods:
* clsApp Class constructor
* createTimer Creates a new timer
* getDescription Access method to get the application description
* getTitle Access method to get the application title
* getMajor Access method to get the major version number
* getMinor Access method to get the minor version number
* message Writes a message to the debug port
* process Performs any critical processes, should be included in loop
* startupMsg Sends application start-up message to serial port
*
* Members:
* m_blnDebug Debug flag, true or false
* m_pstrTitle The application title
* m_pstrDesc The application description
* m_intMajor The major version number
* m_intMinor The minor version number
*
* History:
* 29/01/2012 Created by Simon Platten
*/
#ifndef APP_AIDS_H
#define APP_AIDS_H
#include <Arduino.h>
#include "clsTimer.h"
class clsApp {
private:
// Debug flag, true or false
bool m_blnDebug;
// The Major version number
int m_intMajor;
// The Minor version number
int m_intMinor;
// Application title
char* m_pstrTitle;
// Application description
char* m_pstrDesc;
public:
clsApp(int intMajor,
int intMinor,
char* pstrTitle = NULL,
char* pstrDesc = NULL);
// Creates a new timer
clsTimer* createTimer(unsigned uintInitial,
void (*pCallback)(clsTimer* pTimer),
void *pData = NULL,
unsigned uintRepeat = 0);
// Access method to get the application description
char* getDescription();
// Access method to get the major version number
int getMajor();
// Access method to get the minor version number
int getMinor();
// Access method to get the application title
char* getTitle();
// Writes a message to the debug port
void message(char* pstrMessage);
// Performs any critical processes, should be included in loop()
void process();
// Sends application start-up message to serial port
void startupMsg(bool blnDebug = true);
};
#endif
Implementation, clsApp.cpp
/**
* File:
* clsApp.cpp
*
* Notes:
* This file contains the implementation of the class clsApp.
*
* History:
* 29/01/2012 Created by Simon Platten
*/
#include "clsApp.h"
/**
* Application constructor
*
* Paramters:
* pstrTitle, pointer to the application title
* pstrDesc, pointer to the application description
* intMajor, Major version number
* intMinor, Minor version number
*/
clsApp::clsApp(int intMajor,
int intMinor,
char* pstrTitle,
char* pstrDesc) {
m_pstrTitle = pstrTitle;
m_pstrDesc = pstrDesc;
m_intMajor = intMajor;
m_intMinor = intMinor;
}
/**
* Creates a new timer
*
* Parameters:
* uintInitial,the initial expiration time in ms
* pCallback, the routine to call when the timer expires
* pData, pointer to data block accessible for this timer
* uintRepeat, optional, repeat time in ms for subequent calls
*
* Returns:
* Pointer to the new timer object
*/
clsTimer* clsApp::createTimer(unsigned uintInitial,
void (*pCallback)(clsTimer* pTimer),
void *pData,
unsigned uintRepeat) {
return new clsTimer(uintInitial, pCallback, pData, uintRepeat);
}
/**
* Access method to get the application description
*/
char* clsApp::getDescription() {
return m_pstrDesc;
}
/**
* Access method to get the major version number
*/
int clsApp::getMajor() {
return m_intMajor;
}
/**
* Access method to get the minor version number
*/
int clsApp::getMinor() {
return m_intMinor;
}
/**
* Access method to get the application title
*/
char* clsApp::getTitle() {
return m_pstrTitle;
}
/**
* Writes a message to the debug port
*/
void clsApp::message(char* pstrMessage) {
if ( pstrMessage != NULL ) {
Serial.println( pstrMessage );
}
}
/**
* Performs any critical processes, should be included in loop
*/
void clsApp::process() {
// Service any timers
clsTimer::serviceTimers();
}
/**
* Sends application start-up message to serial port
*/
void clsApp::startupMsg(bool blnDebug) {
// Set debug status
m_blnDebug = blnDebug;
// Set-up serial port for debugging and information
Serial.begin(115200);
if ( m_pstrTitle != NULL ) {
Serial.println( m_pstrTitle );
}
if ( m_pstrDesc != NULL ) {
Serial.println( m_pstrDesc );
}
Serial.print( "Version: ");
Serial.print( m_intMajor );
Serial.print( "." );
Serial.println( m_intMinor );
}