mirror of https://github.com/arendst/Tasmota.git
Add ANALOG#A0div10 trigger to rules
5.12.0n * Add ANALOG#A0div10 trigger to rules to be used in rule like on analog#a0div10 do publish cmnd/ailight/dimmer %value% endon
This commit is contained in:
parent
c835235141
commit
44598e5fc4
|
@ -2,6 +2,7 @@
|
||||||
* Change ESP8266 Analog JSON message from {"Analog0:123"} to {"ANALOG":{"A0:123"}} to accomodate rules (#2560)
|
* Change ESP8266 Analog JSON message from {"Analog0:123"} to {"ANALOG":{"A0:123"}} to accomodate rules (#2560)
|
||||||
* Change Counter JSON message from {"Counter1":0,"Counter3":0} to {"COUNTER":{"C1":0,"C3":0}} to accomodate rules
|
* Change Counter JSON message from {"Counter1":0,"Counter3":0} to {"COUNTER":{"C1":0,"C3":0}} to accomodate rules
|
||||||
* Change ADS1115 JSON message from {"ADS1115":{"Analog0":123,"Analog1":123}} to {"ADS1115":{"A0":123,"A1":123}}
|
* Change ADS1115 JSON message from {"ADS1115":{"Analog0":123,"Analog1":123}} to {"ADS1115":{"A0":123,"A1":123}}
|
||||||
|
* Add ANALOG#A0div10 trigger to rules to be used in rule like on analog#a0div10 do publish cmnd/ailight/dimmer %value% endon
|
||||||
*
|
*
|
||||||
* 5.12.0m
|
* 5.12.0m
|
||||||
* Reinit timers to accomodate random window (#2447)
|
* Reinit timers to accomodate random window (#2447)
|
||||||
|
|
|
@ -1386,7 +1386,10 @@ void RtcInit()
|
||||||
* ADC support
|
* ADC support
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void AdcShow(boolean json)
|
uint8_t adc_counter = 0;
|
||||||
|
uint16_t adc_last_value = 0;
|
||||||
|
|
||||||
|
uint16_t AdcRead()
|
||||||
{
|
{
|
||||||
uint16_t analog = 0;
|
uint16_t analog = 0;
|
||||||
for (byte i = 0; i < 32; i++) {
|
for (byte i = 0; i < 32; i++) {
|
||||||
|
@ -1394,6 +1397,26 @@ void AdcShow(boolean json)
|
||||||
delay(1);
|
delay(1);
|
||||||
}
|
}
|
||||||
analog >>= 5;
|
analog >>= 5;
|
||||||
|
return analog;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdcEvery50ms()
|
||||||
|
{
|
||||||
|
adc_counter++;
|
||||||
|
if (!(adc_counter % 4)) {
|
||||||
|
uint16_t new_value = AdcRead();
|
||||||
|
if ((new_value < adc_last_value -10) || (new_value > adc_last_value +10)) {
|
||||||
|
adc_last_value = new_value;
|
||||||
|
uint16_t value = adc_last_value / 10;
|
||||||
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"ANALOG\":{\"A0div10\":%d}}"), (0 == value) ? 1 : (value > 99) ? 100 : value);
|
||||||
|
RulesProcess();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AdcShow(boolean json)
|
||||||
|
{
|
||||||
|
uint16_t analog = AdcRead();
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"ANALOG\":{\"A0\":%d}"), mqtt_data, analog);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s,\"ANALOG\":{\"A0\":%d}"), mqtt_data, analog);
|
||||||
|
@ -1416,6 +1439,9 @@ boolean Xsns02(byte function)
|
||||||
|
|
||||||
if (pin[GPIO_ADC0] < 99) {
|
if (pin[GPIO_ADC0] < 99) {
|
||||||
switch (function) {
|
switch (function) {
|
||||||
|
case FUNC_EVERY_50_MSECOND:
|
||||||
|
AdcEvery50ms();
|
||||||
|
break;
|
||||||
case FUNC_JSON_APPEND:
|
case FUNC_JSON_APPEND:
|
||||||
AdcShow(1);
|
AdcShow(1);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue