Public Member Functions | Protected Member Functions

Module Class Reference

The base class for all modules. More...

#include <module.h>

Inheritance diagram for Module:
AltEstimate Altimeter AnalogAccel AnalogGyro Camera Compass DcmAHRS FastServo FlightControl FlightMode GPS Kinematics LED MyModule PositionVTOL Receiver SerialComms Servo50Hz Tweaker

List of all members.

Public Member Functions

 Module ()
 Constructor.
virtual void Init ()
 perform your initialization here
virtual void Reference ()
 Reference.
virtual void ParamChanged (Socket *param)
 A parameter has changed.
virtual void Loop (const unsigned long &interval)
 The module's main loop.
virtual const char * GetName ()
 The rest of this stuff is used by the module manager and diagnostics.
virtual void PrintName (HardwareSerial &port)
 Print the module class name.
bool Poll (const long &time)
 Check if Loop() needs to be called.
SocketGetSocket (const char *name, const char *type=NULL)
 Find a socket of the given name.
bool ReplaceSocket (Socket *oldSocket, Socket *newSocket)
 Replace an existing socket with a new one.
SocketArrayGetSockets ()
 Get this module's sockets.
bool IsRunning ()
 Return true is this module is running it's Loop() function.
int8_t GetPriority ()
 Get this module's priority.
long GetMaxTime ()
 Get the maximum execution time in us.
int GetInterval ()
 Get the interval in ms.
void CheckTime (long time)
 Check and possibly update the maximum execution time.

Protected Member Functions

void SetInterval (unsigned int time)
 Set how often you want Loop() to be called (in ms).
void SetPriority (const int8_t priority)
 Set our priority.
void AddSocket (const char *name, Socket *socket)
 Add a socket/parameter to the sockets table.
void AddSocketArray (const char *names[], Socket8 sockets[], int n)
 Add an array of sockets.
void AddSocketArray (const char *names[], Socket16 sockets[], int n)
 Add an array of sockets.
void AddSocketArray (const char *names[], SocketF sockets[], int n)
 Add an array of sockets.
void ConnectPlugArray (const char *names[], PlugF plugs[], int n)
 Connect an array of plugs.
float GetTime (const unsigned long &interval)
 Calculate the time since we were last called in seconds.

Detailed Description

The base class for all modules.


Constructor & Destructor Documentation

Module::Module (  ) 

Constructor.

Only expose variables and parameters in your constructor. Do your initialisation in Init()


Member Function Documentation

void Module::AddSocket ( const char *  name,
Socket socket 
) [inline, protected]

Add a socket/parameter to the sockets table.

NOTE: name must be static. It MUST NOT be created on the stack.

void Module::AddSocketArray ( const char *  names[],
Socket8  sockets[],
int  n 
) [protected]

Add an array of sockets.

names and sockets must point to arrays of strings and sockets respectively. n defines how many sockets.

void Module::AddSocketArray ( const char *  names[],
Socket16  sockets[],
int  n 
) [protected]

Add an array of sockets.

names and sockets must point to arrays of strings and sockets respectively. n defines how many sockets.

void Module::AddSocketArray ( const char *  names[],
SocketF  sockets[],
int  n 
) [protected]

Add an array of sockets.

names and sockets must point to arrays of strings and sockets respectively .n defines how many sockets.

void Module::CheckTime ( long  time  )  [inline]

Check and possibly update the maximum execution time.

void Module::ConnectPlugArray ( const char *  names[],
PlugF  plugs[],
int  n 
) [protected]

Connect an array of plugs.

names and plugs must point to arrays of strings and sockets respectively. n defines how many plugs.

int Module::GetInterval (  )  [inline]

Get the interval in ms.

The interval defines how often Loop() is run

long Module::GetMaxTime (  )  [inline]

Get the maximum execution time in us.

virtual const char* Module::GetName (  )  [inline, virtual]

The rest of this stuff is used by the module manager and diagnostics.

Get the module class name. Automatically created by DECLARE_MODULE()

int8_t Module::GetPriority (  )  [inline]

Get this module's priority.

Socket* Module::GetSocket ( const char *  name,
const char *  type = NULL 
) [inline]

Find a socket of the given name.

Returns a pointer if this module has the socket. Otherwise returns false

SocketArray& Module::GetSockets (  )  [inline]

Get this module's sockets.

float Module::GetTime ( const unsigned long &  interval  )  [inline, protected]

Calculate the time since we were last called in seconds.

virtual void Module::Init (  )  [inline, virtual]

perform your initialization here

This includes connecting plugs and general initialization

Reimplemented in AnalogGyro, DcmAHRS, HMC5843, RotaryWing, SCP1000, SerialComms, and Servo50Hz.

bool Module::IsRunning (  )  [inline]

Return true is this module is running it's Loop() function.

virtual void Module::Loop ( const unsigned long &  interval  )  [inline, virtual]

The module's main loop.

This function is called at the rate specified by SetInterval()

Do most of your work here. Try to keep this code fast

Reimplemented in AnalogGyro, DcmAHRS, HMC5843, RotaryWing, SCP1000, SerialComms, and Servo50Hz.

virtual void Module::ParamChanged ( Socket param  )  [inline, virtual]

A parameter has changed.

Called when a parameter has been changed (read from EEPROM or via the comms link)

param points to the parameter that has changed.

Reimplemented in AnalogGyro, DcmAHRS, HMC5843, RotaryWing, SCP1000, and Servo50Hz.

bool Module::Poll ( const long &  time  ) 

Check if Loop() needs to be called.

returns true if Loop() was called

virtual void Module::PrintName ( HardwareSerial &  port  )  [inline, virtual]

Print the module class name.

Automatically created by DECLARE_MODULE()

virtual void Module::Reference (  )  [inline, virtual]

Reference.

Called when we are stationary and it is safe to re-reference sensors and clear PID accumulators etc. If at all possible, return fairly quickly from this, just in case we are in the air and reference has been called by mistake (e.g it may have been connected to a transmitter switch that was operated at the wrong moment.

Reimplemented in AnalogGyro, DcmAHRS, RotaryWing, and SCP1000.

bool Module::ReplaceSocket ( Socket oldSocket,
Socket newSocket 
) [inline]

Replace an existing socket with a new one.

Returns true if the socket was found and replaced

void Module::SetInterval ( unsigned int  time  )  [protected]

Set how often you want Loop() to be called (in ms).

Must be greather than 0

void Module::SetPriority ( const int8_t  priority  )  [inline, protected]

Set our priority.

0 is lowest, max 100

Priority -1 means never execute

Try to avoid having too many different priority levels. Increasing the number of priority levels increases the number of threads and memory usage. The theoretical maximum number of threads used is the number of different levels + 1. In practice it is generally lower.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines