Callback code example improved and typo fixed.

Rene Bartsch 2018-07-12 16:40:28 +02:00
parent 9045f5cb94
commit c83ede71cf
1 changed files with 45 additions and 14 deletions

@ -8,33 +8,64 @@ Sensor libraries are located in the `lib/` directory. Sensor drivers are located
Conditional compiling of a sensor driver is achieved by commenting/uncommenting a pre-processor directive of the scheme `USE_<driver_name>` in `user_config.h`. Accordingly the driver code has to be wrapped in `#ifdef USE_<driver_name> ... #endif // USE_<driver_name>`. Any Sensor driver must contain a pre-processor directive defining the driver ID by the scheme `#define XSNS_<driver_ID>`.
## Callback function
Any sensor driver needs a callback function following the scheme
```
// Define driver ID
#define XSNS_<driver_ID>
/**
* The function Xsns<driver_ID>() interfaces Tasmota with the driver.
* The callback function Xsns<driver_ID>() interfaces Tasmota with the sensor driver.
*
* It provides the Tasmota callback IDs.
*
* It provides the function IDs
* FUNC_INIT to initialize a driver,
* FUNC_EVERY_50_MSECOND for near real-time operation,
* FUNC_JSON_APPEND for telemetry data and
* FUNC_WEB_APPEND for displaying data in the Tasmota web-interface
* `
* @param byte function Tasmota function ID.
* @return boolean ???
* @pre None.
* @post None.
*
*/
boolean Xsns<driverID>(byte callback_id)
{
boolean Xsns<driverID>(byte callback_id) {
// ???
boolean result = false;
// Check which function is called by Tasmota
// Check which callback ID is called by Tasmota
switch (callback_id) {
case <callback_id>:
<code>
break;
case FUNC_PRE_INIT:
break;
case FUNC_INIT:
break;
case FUNC_LOOP:
break;
case FUNC_EVERY_50_MSECOND:
break;
case FUNC_EVERY_SECOND:
break;
case FUNC_PREP_BEFORE_TELEPERIOD:
break;
case FUNC_JSON_APPEND:
break;
case FUNC_WEB_APPEND:
break;
case FUNC_SAVE_BEFORE_RESTART:
break;
case FUNC_COMMAND:
break;
case FUNC_MQTT_SUBSCRIBE:
break;
case FUNC_MQTT_INIT:
break;
case FUNC_MQTT_DATA:
break;
case FUNC_SET_POWER:
break;
case FUNC_SHOW_SENSOR:
break;
case FUNC_RULES_PROCESS:
break;
case FUNC_FREE_MEM
break;
}
// Return boolean result
@ -126,4 +157,4 @@ AddLogSerial(LOG_LEVEL_INFO);
## Useful pre-processor directives
### PSTR("string")
This pre-processor directive save RAM by storing strings in flash instead of RAM
This pre-processor directive saves RAM by storing strings in flash instead of RAM.