mirror of https://github.com/arendst/Tasmota.git
Verbal clarifications and functions added.
parent
e5fcbc3c7e
commit
06b2e925c0
|
@ -27,14 +27,14 @@ Any sensor driver needs a callback function following the scheme
|
||||||
* @post None.
|
* @post None.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
boolean Xsns<driverID>(byte function)
|
boolean Xsns<driverID>(byte callback_id)
|
||||||
{
|
{
|
||||||
// ???
|
// ???
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
|
|
||||||
// Check which function is called by Tasmota
|
// Check which function is called by Tasmota
|
||||||
switch (function) {
|
switch (callback_id) {
|
||||||
case <function>:
|
case <callback_id>:
|
||||||
<code>
|
<code>
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -45,17 +45,45 @@ boolean Xsns<driverID>(byte function)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Function IDs
|
### Callback IDs
|
||||||
|
|
||||||
#### FUNC_INIT
|
#### FUNC_INIT
|
||||||
FUNC_INIT initializes a sensor driver
|
This callback ID is called when sensor drivers should be initialized.
|
||||||
|
|
||||||
#### FUNC_EVERY_50_MSECOND
|
#### FUNC_EVERY_50_MSECOND
|
||||||
FUNC_EVERY_50_MSECOND is called every 50 milliseconds, e.g. for near real-time operation
|
This callback ID is called every 50 milliseconds, e.g. for near real-time operation
|
||||||
|
|
||||||
#### FUNC_JSON_APPEND
|
#### FUNC_JSON_APPEND
|
||||||
FUNC_JSON_APPEND is called to append telemetry data to the MQTT JSON string when `TELEPERIOD` is due.
|
This callback ID is called when `TELEPERIOD` is due to append telemetry data to the MQTT JSON string, e.g.
|
||||||
|
```
|
||||||
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"MPR121%c\":{\"Button%i\":%i}}"), pS->id[i], j, BITC(i,j));
|
||||||
|
```
|
||||||
|
|
||||||
#### FUNC_WEB_APPEND
|
#### FUNC_WEB_APPEND
|
||||||
FUNC_WEB_APPEND is called to add HTML code to the Tasmota web-interface main page.
|
This callback ID is called when HTML code should be added to the Tasmota web-interface main page, e.g.
|
||||||
It should be wrapped in `#ifdef USE_WEBSERVER ... #endif // USE_WEBSERVER`
|
```
|
||||||
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{s}MPR121%c Button%d{m}%d{e}"), mqtt_data, pS->id[i], j, BITC(i,j));
|
||||||
|
```
|
||||||
|
It should be wrapped in `#ifdef USE_WEBSERVER ... #endif // USE_WEBSERVER`
|
||||||
|
|
||||||
|
### Useful functions
|
||||||
|
#### `int snprintf_P(char * __s, size_t __n, const char * format_string, char* text)`
|
||||||
|
This function formats text like `printf()`.
|
||||||
|
|
||||||
|
#### `void MqttPublishPrefixTopic_P(uint8_t prefix, const char* subtopic, boolean retained)`
|
||||||
|
This function publishes MQTT messages immediately, e.g.
|
||||||
|
```
|
||||||
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"MPR121%c\":{\"Button%i\":%i}}"), pS->id[i], j, BITC(i,j));
|
||||||
|
MqttPublishPrefixTopic_P(RESULT_OR_STAT, mqtt_data);
|
||||||
|
```
|
||||||
|
#### void AddLog(byte loglevel)
|
||||||
|
```
|
||||||
|
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "MPR121(%c) " D_FOUND_AT " 0x%X"), pS->id[i], pS->i2c_addr[i]);
|
||||||
|
AddLog(LOG_LEVEL_INFO);
|
||||||
|
```
|
||||||
|
#### void AddLogSerial(byte loglevel)
|
||||||
|
```
|
||||||
|
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "MPR121(%c) " D_FOUND_AT " 0x%X"), pS->id[i], pS->i2c_addr[i]);
|
||||||
|
AddLogSerial(LOG_LEVEL_INFO);
|
||||||
|
```
|
||||||
|
#### void AddLogMissed(char *sensor, uint8_t misses)
|
Loading…
Reference in New Issue