Added module template file
This commit is contained in:
parent
79fc6cd9f5
commit
719f31b0c1
2 changed files with 114 additions and 0 deletions
21
extras/ModuleTemplate.cpp
Normal file
21
extras/ModuleTemplate.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "<module_name>.h"
|
||||
|
||||
<module_name>::<module_name>(Module* mod) {
|
||||
/*
|
||||
Constructor implementation MUST assign the provided "mod" pointer to the private "_mod" pointer.
|
||||
*/
|
||||
_mod = mod;
|
||||
}
|
||||
|
||||
uint8_t <module_name>::begin() {
|
||||
/*
|
||||
"begin" method implementation MUST call the "init" method with appropriate settings.
|
||||
*/
|
||||
_mod->init();
|
||||
|
||||
/*
|
||||
"begin" method SHOULD implement some sort of mechanism to verify the connection between Arduino and the module.
|
||||
|
||||
For example, sending AT command for UART modules, or reading a version register for SPI/I2C modules
|
||||
*/
|
||||
}
|
93
extras/ModuleTemplate.h
Normal file
93
extras/ModuleTemplate.h
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
KiteLib Module Template header file
|
||||
|
||||
Before opening pull request, please make sure that:
|
||||
1. All files MUST be compiled without errors using default Arduino IDE settings.
|
||||
2. Example sketches MUST be working correctly and MUST be stable enough to run for prolonged periods of time.
|
||||
3. Writing style SHOULD be at least somewhat consistent.
|
||||
4. Comments SHOULD be in place for the most important chunks of code and SHOULD be free of typos.
|
||||
5. To indent, 2 spaces MUST be used.
|
||||
|
||||
If at any point you are unsure about the required style, please refer to the rest of the modules.
|
||||
*/
|
||||
|
||||
#ifndef _KITELIB_<module_name>_H
|
||||
#define _KITELIB_<module_name>_H
|
||||
|
||||
/*
|
||||
Header file for each module MUST include Module.h.
|
||||
The header file MAY include additional header files.
|
||||
*/
|
||||
#include "Module.h"
|
||||
|
||||
/*
|
||||
Only use the following include if the module implements methods for OSI transport layer control.
|
||||
This concerns only modules similar to e.g. ESP8266.
|
||||
|
||||
In this case, your class MUST implement all virtual methods of TransportLayer class.
|
||||
*/
|
||||
//#include "../protocols/TransportLayer.h"
|
||||
|
||||
/*
|
||||
Register map
|
||||
Definition of SPI/I2C register map MAY be placed here. The register map MAY have two parts:
|
||||
|
||||
1 - Address map: only defines register names and addresses. Register names MUST match names in
|
||||
official documentation (datasheets etc.).
|
||||
2 - Variable map: defines variables inside register. This functions as a bit range map for a specific register.
|
||||
Bit range (MSB and LSB) as well as short description for each variable MUST be provided in a comment.
|
||||
|
||||
See RF69 and SX127x header files for examples of register maps.
|
||||
*/
|
||||
// <module_name> register map | spaces up to this point
|
||||
#define <module_name>_REG_<register_name> 0x00
|
||||
|
||||
// <module_name>_REG_<register_name> MSB LSB DESCRIPTION
|
||||
#define <module_name>_<register_variable> 0b00000000 // 7 0 <description>
|
||||
|
||||
|
||||
/*
|
||||
Module class definition
|
||||
|
||||
The module class MAY inherit from the following classes:
|
||||
|
||||
1 - ISerial: Interface for Arduino Serial class, intended as a thin wrapper for modules that directly take
|
||||
Serial input (e.g. HC-05).
|
||||
2 - TransportLayer: In case the module implements methods for OSI transport layer control (e.g. ESP8266).
|
||||
*/
|
||||
class <module_name> {
|
||||
public:
|
||||
/*
|
||||
Constructor MUST have only one parameter "Module* mod".
|
||||
The class MAY implement additional overloaded constructors.
|
||||
*/
|
||||
// constructor
|
||||
<module_name>(Module* module);
|
||||
|
||||
/*
|
||||
The class MUST implement at least one basic method called "begin".
|
||||
The "begin" method MUST initialize the module and return the status as uint8_t type.
|
||||
*/
|
||||
// basic methods
|
||||
uint8_t begin();
|
||||
|
||||
/*
|
||||
The class MAY implement additional methods.
|
||||
All implemented methods SHOULD return the status as uint8_t type.
|
||||
*/
|
||||
|
||||
private:
|
||||
/*
|
||||
The class MUST contain private member "Module* _mod"
|
||||
*/
|
||||
Module* _mod;
|
||||
|
||||
/*
|
||||
The class MAY contain additional private variables and/or methods.
|
||||
Private member variables MUST have a name prefixed with "_" (underscore, ASCII 0x5F)
|
||||
|
||||
Usually, these are variables for saving module configuration, or methods that do not have to be exposed to the end user.
|
||||
*/
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue