6.2.1.18 Add API.md

6.2.1.18 20181019
 * Add more API callbacks and document API.md
This commit is contained in:
Theo Arends 2018-10-19 12:53:22 +02:00
parent d505c49e2f
commit 613ffde5c0
6 changed files with 105 additions and 21 deletions

64
sonoff/API.md Normal file
View File

@ -0,0 +1,64 @@
## Sonoff-Tasmota basic API information
Sonoff-Tasmota can easily be extended by developers using provided function pointers as callback Ids. This document lists the available callback function Ids. See the wiki (https://github.com/arendst/Sonoff-Tasmota/wiki/Sensor-API) for more information.
Callback availability can be checked by searching for either XdrvCall, XsnsCall, XdspCall and XnrgCall.
## Driver, Sensor and Energy Callback Ids
The following table lists Callback Ids and their availability for a Driver, Sensor or Energy service.
Callback Id | Bool | Version | xdrv | xsns | xnrg | Description
----------------------------|------|----------|------|------|------|----------------------------------
FUNC_MODULE_INIT | x | 6.2.1.17 | x | | | Init module specific parameters
FUNC_PRE_INIT | | | x | | x | Once GPIO have been established
FUNC_INIT | | | x | x | x | At end of initialisation
FUNC_LOOP | | | x | | | In main loop
FUNC_EVERY_50_MSECOND | | | x | x | |
FUNC_EVERY_100_MSECOND | | | x | x | |
FUNC_EVERY_200_MSECOND | | | | x | x |
FUNC_EVERY_250_MSECOND | | | x | | |
FUNC_EVERY_SECOND | | | x | x | x |
FUNC_PREP_BEFORE_TELEPERIOD | | | | x | | Deprecated. Use a FUNC_EVERY_
FUNC_JSON_APPEND | | | | x | | Extend teleperiod JSON text
FUNC_WEB_APPEND | | | | x | | Extend webgui ajax info
FUNC_SAVE_BEFORE_RESTART | | | | x | | Just before a planned restart
FUNC_COMMAND | x | | x | x | | When a command is not recognized
FUNC_MQTT_SUBSCRIBE | | 5.12.0k | x | | | At end of MQTT subscriptions
FUNC_MQTT_INIT | | 5.12.0k | x | | | Once at end of MQTT connection
FUNC_MQTT_DATA | x | 5.12.0k | x | | | Before decoding command
FUNC_SET_POWER | | | x | | | Before setting relays
FUNC_SET_DEVICE_POWER | x | 6.2.1.18 | x | | | Set relay
FUNC_SHOW_SENSOR | | | x | | | When FUNC_JSON_APPEND completes
FUNC_RULES_PROCESS | x | 6.0.0 | x | | | Process specific rule
FUNC_SERIAL | x | | x | | x | Process serial data
FUNC_FREE_MEM | | | x | | | Show free memory for debugging
FUNC_BUTTON_PRESSED | x | 6.2.1.18 | x | | | When a button is pressed
FUNC_WEB_ADD_BUTTON | | 6.2.1.14 | x | | | Add a Configuration Button to GUI
FUNC_WEB_ADD_MAIN_BUTTON | | 6.2.1.14 | x | | | Add a main button to GUI
FUNC_WEB_ADD_HANDLER | | 6.2.1.14 | x | | | Add a webserver handler
## Display Call back Ids
The following table lists all Callback Ids for a Display service.
Callback Id | Bool | Version | Description
------------------------------|------|----------|---------------------
FUNC_DISPLAY_INIT_DRIVER | | 6.1.1.7 |
FUNC_DISPLAY_INIT | | 6.1.1.7 |
FUNC_DISPLAY_EVERY_50_MSECOND | | 6.1.1.7 |
FUNC_DISPLAY_EVERY_SECOND | | 6.1.1.7 |
FUNC_DISPLAY_MODEL | x | 6.1.1.7 |
FUNC_DISPLAY_MODE | | 6.1.1.7 |
FUNC_DISPLAY_POWER | | 6.1.1.7 |
FUNC_DISPLAY_CLEAR | | 6.1.1.7 |
FUNC_DISPLAY_DRAW_FRAME | | 6.1.1.7 |
FUNC_DISPLAY_DRAW_HLINE | | 6.1.1.7 |
FUNC_DISPLAY_DRAW_VLINE | | 6.1.1.7 |
FUNC_DISPLAY_DRAW_LINE | | 6.1.1.7 |
FUNC_DISPLAY_DRAW_CIRCLE | | 6.1.1.7 |
FUNC_DISPLAY_FILL_CIRCLE | | 6.1.1.7 |
FUNC_DISPLAY_DRAW_RECTANGLE | | 6.1.1.7 |
FUNC_DISPLAY_FILL_RECTANGLE | | 6.1.1.7 |
FUNC_DISPLAY_TEXT_SIZE | | 6.1.1.7 |
FUNC_DISPLAY_FONT_SIZE | | 6.1.1.7 |
FUNC_DISPLAY_ROTATION | | 6.1.1.7 |
FUNC_DISPLAY_DRAW_STRING | | 6.1.1.7 |
FUNC_DISPLAY_ONOFF | | 6.1.1.7 |

View File

@ -1,4 +1,7 @@
/* 6.2.1.17 20181017
/* 6.2.1.18 20181019
* Add more API callbacks and document API.md
*
* 6.2.1.17 20181017
* Enable updated non-blocking PubSubClient as default MQTT client
* Update TasmotaModbus and TasmotaSerial libraries for support of serial 8N2 communication
* Add support for Pzem-003/017 DC Energy monitoring module (#3694)

View File

@ -212,9 +212,10 @@ enum LightTypes {LT_BASIC, LT_PWM1, LT_PWM2, LT_PWM3, LT_PWM4, LT_PWM5, LT_PWM6,
enum LichtSubtypes {LST_NONE, LST_SINGLE, LST_COLDWARM, LST_RGB, LST_RGBW, LST_RGBWC};
enum LichtSchemes {LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MAX};
enum XsnsFunctions {FUNC_MODULE_INIT, FUNC_PRE_INIT, FUNC_INIT, FUNC_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_100_MSECOND, FUNC_EVERY_200_MSECOND, FUNC_EVERY_250_MSECOND, FUNC_EVERY_SECOND, FUNC_PREP_BEFORE_TELEPERIOD,
FUNC_JSON_APPEND, FUNC_WEB_APPEND, FUNC_SAVE_BEFORE_RESTART, FUNC_COMMAND, FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA, FUNC_SET_POWER, FUNC_SHOW_SENSOR,
FUNC_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM, FUNC_WEB_ADD_BUTTON, FUNC_WEB_ADD_MAIN_BUTTON, FUNC_WEB_ADD_HANDLER};
enum XsnsFunctions {FUNC_MODULE_INIT, FUNC_PRE_INIT, FUNC_INIT, FUNC_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_100_MSECOND, FUNC_EVERY_200_MSECOND, FUNC_EVERY_250_MSECOND, FUNC_EVERY_SECOND,
FUNC_PREP_BEFORE_TELEPERIOD, FUNC_JSON_APPEND, FUNC_WEB_APPEND, FUNC_SAVE_BEFORE_RESTART, FUNC_COMMAND,
FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA, FUNC_SET_POWER, FUNC_SET_DEVICE_POWER, FUNC_SHOW_SENSOR,
FUNC_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM, FUNC_BUTTON_PRESSED, FUNC_WEB_ADD_BUTTON, FUNC_WEB_ADD_MAIN_BUTTON, FUNC_WEB_ADD_HANDLER};
const uint8_t kDefaultRfCode[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48, 0x2E, 0x1A, 0x00 };

View File

@ -340,9 +340,12 @@ void SetDevicePower(power_t rpower, int source)
}
XdrvMailbox.index = rpower;
XdrvMailbox.payload = source;
if (XdrvCall(FUNC_SET_POWER)) {
XdrvCall(FUNC_SET_POWER); // Signal power state
XdrvMailbox.index = rpower;
XdrvMailbox.payload = source;
if (XdrvCall(FUNC_SET_DEVICE_POWER)) { // Set power state and stop if serviced
// Serviced
}
else if ((SONOFF_DUAL == Settings.module) || (CH4 == Settings.module)) {
Serial.write(0xA0);
@ -1703,7 +1706,12 @@ void ButtonHandler()
}
if (button_present) {
if (SONOFF_4CHPRO == Settings.module) {
XdrvMailbox.index = button_index;
XdrvMailbox.payload = button;
if (XdrvCall(FUNC_BUTTON_PRESSED)) {
// Serviced
}
else if (SONOFF_4CHPRO == Settings.module) {
if (holdbutton[button_index]) { holdbutton[button_index]--; }
boolean button_pressed = false;
@ -1724,18 +1732,6 @@ void ButtonHandler()
}
}
}
#ifdef USE_TUYA_DIMMER
else if (TUYA_DIMMER == Settings.module) {
if ((PRESSED == button) && (NOT_PRESSED == lastbutton[button_index])) {
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_BUTTON "%d " D_LEVEL_10), button_index +1);
AddLog(LOG_LEVEL_DEBUG);
if (!Settings.flag.button_restrict) {
snprintf_P(scmnd, sizeof(scmnd), D_CMND_WIFICONFIG " %d", 2);
ExecuteCommand(scmnd, SRC_BUTTON);
}
}
}
#endif
else {
if ((PRESSED == button) && (NOT_PRESSED == lastbutton[button_index])) {
if (Settings.flag.button_single) { // Allow only single button press for immediate action
@ -2462,6 +2458,7 @@ void GpioInit()
}
if (XdrvCall(FUNC_MODULE_INIT)) {
// Serviced
}
else if (SONOFF_DUAL == Settings.module) {
Settings.flag.mqtt_serial = 0;

View File

@ -20,7 +20,7 @@
#ifndef _SONOFF_VERSION_H_
#define _SONOFF_VERSION_H_
#define VERSION 0x06020111
#define VERSION 0x06020112
#define D_PROGRAMNAME "Sonoff-Tasmota"
#define D_AUTHOR "Theo Arends"

View File

@ -231,6 +231,22 @@ void TuyaInit()
Serial.flush();
}
boolean TuyaButtonPressed()
{
if ((PRESSED == XdrvMailbox.payload) && (NOT_PRESSED == lastbutton[XdrvMailbox.index])) {
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_BUTTON "%d " D_LEVEL_10), XdrvMailbox.index +1);
AddLog(LOG_LEVEL_DEBUG);
if (!Settings.flag.button_restrict) {
char scmnd[20];
snprintf_P(scmnd, sizeof(scmnd), D_CMND_WIFICONFIG " %d", 2);
ExecuteCommand(scmnd, SRC_BUTTON);
}
}
return true; // Serviced here
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
@ -252,9 +268,12 @@ boolean Xdrv16(byte function)
case FUNC_LOOP:
TuyaSerialInput();
break;
case FUNC_SET_POWER:
case FUNC_SET_DEVICE_POWER:
result = TuyaSetPower();
break;
case FUNC_BUTTON_PRESSED:
result = TuyaButtonPressed();
break;
}
}
return result;