mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-24 11:16:34 +00:00
Merge branch 'development' into pre-release-850
This commit is contained in:
commit
33a44f7a39
@ -546,7 +546,7 @@ void Arduino_ST7789::DisplayOnff(int8_t on) {
|
||||
writecommand(ST7789_DISPON); //Display on
|
||||
if (_bp>=0) {
|
||||
#ifdef ST7789_DIMMER
|
||||
ledcWrite(ESP32_PWM_CHANNEL,255);
|
||||
ledcWrite(ESP32_PWM_CHANNEL,dimmer);
|
||||
#else
|
||||
digitalWrite(_bp,HIGH);
|
||||
#endif
|
||||
@ -564,7 +564,8 @@ void Arduino_ST7789::DisplayOnff(int8_t on) {
|
||||
}
|
||||
|
||||
// dimmer 0-100
|
||||
void Arduino_ST7789::dim(uint8_t dimmer) {
|
||||
void Arduino_ST7789::dim(uint8_t dim) {
|
||||
dimmer = dim;
|
||||
if (dimmer>15) dimmer=15;
|
||||
dimmer=((float)dimmer/15.0)*255.0;
|
||||
#ifdef ESP32
|
||||
|
@ -161,7 +161,7 @@ class Arduino_ST7789 : public Renderer {
|
||||
boolean _hwSPI;
|
||||
boolean _SPI9bit;
|
||||
boolean _DCbit;
|
||||
|
||||
uint8_t dimmer;
|
||||
int8_t _cs, _dc, _rst, _sid, _sclk, _bp;
|
||||
|
||||
#if defined(USE_FAST_IO)
|
||||
|
@ -41,7 +41,7 @@ int FT5206_Class::begin(TwoWire &port, uint8_t addr)
|
||||
}
|
||||
_readByte(FT5206_CHIPID_REG, 1, &val);
|
||||
//Serial.printf("chip id %d\n",val );
|
||||
if ((val != FT6206_CHIPID) && (val != FT6236_CHIPID) && (val != FT6236U_CHIPID) && (val != FT5206U_CHIPID)) {
|
||||
if ((val != FT6206_CHIPID) && (val != FT6236_CHIPID) && (val != FT6236U_CHIPID) && (val != FT5206U_CHIPID) && (val != FT5316_CHIPID) ) {
|
||||
return false;
|
||||
}
|
||||
_init = true;
|
||||
|
@ -49,6 +49,8 @@ github:https://github.com/lewisxhe/FT5206_Library
|
||||
#define FT6236U_CHIPID 0x64
|
||||
#define FT5206U_CHIPID 0x64
|
||||
|
||||
#define FT5316_CHIPID 0x0a
|
||||
|
||||
#define DEVIDE_MODE 0x00
|
||||
#define TD_STATUS 0x02
|
||||
#define TOUCH1_XH 0x03
|
||||
|
@ -1,159 +0,0 @@
|
||||
#include <Wire.h>
|
||||
#include <FT6236.h>
|
||||
|
||||
/*
|
||||
* This is a static library so we need to make sure we process stuff as quick as possible
|
||||
* as we do not want it to interfere with the RTOS by delaying routines unnecessarily.
|
||||
* So, no delay()'s etc and opto the code as much as possible.
|
||||
* ^^^ Need to be on TODO list to go through and make sure everything is as opto as
|
||||
* possible
|
||||
*/
|
||||
|
||||
uint8_t FT6236buf[FT6236_BUFFER_SIZE];
|
||||
uint8_t FT6236_i2c_addr = 0x38;
|
||||
uint8_t lenLibVersion = 0;
|
||||
uint8_t firmwareId = 0;
|
||||
|
||||
struct tbuttonregister {
|
||||
uint16_t BUTTONID;
|
||||
uint16_t xmin;
|
||||
uint16_t xmax;
|
||||
uint16_t ymin;
|
||||
uint16_t ymax;
|
||||
} buttonregister[FT6236_MAX_BUTTONS]; // we're limiting to 16 buttons for now - can reduce or increase later as needed.
|
||||
|
||||
uint8_t buttoncount = 0;
|
||||
|
||||
void FT6236flushbuttonregister(void) {
|
||||
uint16_t bid;
|
||||
for (bid=0;bid<FT6236_MAX_BUTTONS;bid++) {
|
||||
buttonregister[bid].BUTTONID=0;
|
||||
buttonregister[bid].xmin=0;
|
||||
buttonregister[bid].xmax=0;
|
||||
buttonregister[bid].ymin=0;
|
||||
buttonregister[bid].ymax=0;
|
||||
}
|
||||
buttoncount=0;
|
||||
}
|
||||
|
||||
void FT6236registerbutton(uint16_t buttonid,uint16_t xmin,uint16_t ymin,uint16_t xmax, uint16_t ymax) {
|
||||
buttonregister[buttoncount].BUTTONID=buttonid;
|
||||
buttonregister[buttoncount].xmin=xmin;
|
||||
buttonregister[buttoncount].xmax=xmax;
|
||||
buttonregister[buttoncount].ymin=ymin;
|
||||
buttonregister[buttoncount].ymax=ymax;
|
||||
buttoncount++;
|
||||
}
|
||||
|
||||
uint16_t FT6236GetButtonMask(void) {
|
||||
uint16 bid;
|
||||
TouchLocation tl[2];
|
||||
uint8_t count = FT6236readTouchLocation(tl,2);
|
||||
if (count > 0) {
|
||||
uint16_t x = tl[0].x;
|
||||
uint16_t y = tl[0].y;
|
||||
for (bid=0;bid<buttoncount;bid++) {
|
||||
if (x >= buttonregister[bid].xmin) {
|
||||
if (x <= buttonregister[bid].xmax) {
|
||||
if (y >= buttonregister[bid].ymin) {
|
||||
if (y <= buttonregister[bid].ymax) {
|
||||
return buttonregister[bid].BUTTONID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FT6236begin(uint8_t i2c_addr) {
|
||||
FT6236_i2c_addr=i2c_addr;
|
||||
Wire.begin();
|
||||
FT6236writeTouchRegister(0,FT6236_MODE_NORMAL);
|
||||
lenLibVersion = FT6236readTouchAddr(0x0a1, FT6236buf, 2 );
|
||||
firmwareId = FT6236readTouchRegister( 0xa6 );
|
||||
}
|
||||
|
||||
void FT6236writeTouchRegister(uint8_t reg, uint8_t val)
|
||||
{
|
||||
Wire.beginTransmission(FT6236_i2c_addr);
|
||||
Wire.write(reg); // register 0
|
||||
Wire.write(val); // value
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
uint8_t FT6236readTouchRegister(uint8_t reg)
|
||||
{
|
||||
Wire.beginTransmission(FT6236_i2c_addr);
|
||||
Wire.write(reg); // register 0
|
||||
uint8_t retVal = Wire.endTransmission();
|
||||
uint8_t returned = Wire.requestFrom(FT6236_i2c_addr,uint8_t(1)); // request 6 uint8_ts from slave device #2
|
||||
if (Wire.available())
|
||||
{
|
||||
retVal = Wire.read();
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
uint8_t FT6236readTouchAddr( uint8_t regAddr, uint8_t * pBuf, uint8_t len )
|
||||
{
|
||||
Wire.beginTransmission(FT6236_i2c_addr);
|
||||
Wire.write( regAddr ); // register 0
|
||||
uint8_t retVal = Wire.endTransmission();
|
||||
uint8_t returned = Wire.requestFrom(FT6236_i2c_addr, len); // request 1 bytes from slave device #2
|
||||
uint8_t i;
|
||||
for (i = 0; (i < len) && Wire.available(); i++) {
|
||||
pBuf[i] = Wire.read();
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
uint8_t FT6236readTouchLocation( TouchLocation * pLoc, uint8_t num )
|
||||
{
|
||||
uint8_t retVal = 0;
|
||||
uint8_t i;
|
||||
uint8_t k;
|
||||
do
|
||||
{
|
||||
if (!pLoc) break; // must have a buffer
|
||||
if (!num) break; // must be able to take at least one
|
||||
uint8_t status = FT6236readTouchRegister(2);
|
||||
static uint8_t tbuf[40];
|
||||
if ((status & 0x0f) == 0) break; // no points detected
|
||||
uint8_t hitPoints = status & 0x0f;
|
||||
FT6236readTouchAddr( 0x03, tbuf, hitPoints*6);
|
||||
for (k=0,i = 0; (i < hitPoints*6)&&(k < num); k++, i += 6) {
|
||||
pLoc[k].x = (tbuf[i+0] & 0x0f) << 8 | tbuf[i+1];
|
||||
pLoc[k].y = (tbuf[i+2] & 0x0f) << 8 | tbuf[i+3];
|
||||
}
|
||||
retVal = k;
|
||||
} while (0);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
uint32_t FT6236dist(const TouchLocation & loc)
|
||||
{
|
||||
uint32_t retVal = 0;
|
||||
uint32_t x = loc.x;
|
||||
uint32_t y = loc.y;
|
||||
retVal = x*x + y*y;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
uint32_t FT6236dist(const TouchLocation & loc1, const TouchLocation & loc2)
|
||||
{
|
||||
uint32_t retVal = 0;
|
||||
uint32_t x = loc1.x - loc2.x;
|
||||
uint32_t y = loc1.y - loc2.y;
|
||||
retVal = sqrt(x*x + y*y);
|
||||
return retVal;
|
||||
}
|
||||
*/
|
||||
|
||||
bool FT6236sameLoc( const TouchLocation & loc, const TouchLocation & loc2 )
|
||||
{
|
||||
return FT6236dist(loc,loc2) < 50;
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
#ifndef FT6236
|
||||
#define FT6236
|
||||
|
||||
#define FT6236_MODE_NORMAL 0x00
|
||||
#define FT6236_MODE_TEST 0x04
|
||||
#define FT6236_MODE_SYSTEM 0x01
|
||||
|
||||
#define FT6236_BUFFER_SIZE 0x1E // 30 bytes buffer
|
||||
#define FT6236_MAX_BUTTONS 1 // 50 buttons should be enough for just about any page
|
||||
|
||||
struct TouchLocation {
|
||||
uint16_t y; // we swop x and y in position because we're using the screen in portrait mode
|
||||
uint16_t x;
|
||||
};
|
||||
|
||||
void FT6236flushbuttonregister(void);
|
||||
void FT6236registerbutton(uint16_t buttonid,uint16_t xmin,uint16_t ymin,uint16_t xmax, uint16_t ymax);
|
||||
uint16_t FT6236GetButtonMask(void);
|
||||
void FT6236begin(uint8_t i2c_addr);
|
||||
uint8_t FT6236readTouchRegister( uint8_t reg );
|
||||
uint8_t FT6236readTouchLocation( TouchLocation * pLoc, uint8_t num );
|
||||
uint8_t FT6236readTouchAddr( uint8_t regAddr, uint8_t * pBuf, uint8_t len );
|
||||
void FT6236writeTouchRegister( uint8_t reg, uint8_t val);
|
||||
uint32_t FT6236dist(const TouchLocation & loc);
|
||||
uint32_t FT6236dist(const TouchLocation & loc1, const TouchLocation & loc2);
|
||||
bool FT6236sameLoc( const TouchLocation & loc, const TouchLocation & loc2 );
|
||||
|
||||
#endif
|
@ -519,4 +519,5 @@ void VButton::xdrawButton(bool inverted) {
|
||||
wr_redir=0;
|
||||
}
|
||||
|
||||
|
||||
/* END OF FILE */
|
||||
|
@ -46,9 +46,23 @@ private:
|
||||
uint8_t font;
|
||||
};
|
||||
|
||||
typedef union {
|
||||
uint8_t data;
|
||||
struct {
|
||||
uint8_t spare0 : 1;
|
||||
uint8_t spare1 : 1;
|
||||
uint8_t spare2 : 1;
|
||||
uint8_t spare3 : 1;
|
||||
uint8_t disable : 1;
|
||||
uint8_t on_off : 1;
|
||||
uint8_t is_pushbutton : 1;
|
||||
uint8_t is_virtual : 1;
|
||||
};
|
||||
} TButton_State;
|
||||
|
||||
class VButton : public Adafruit_GFX_Button {
|
||||
public:
|
||||
uint8_t vpower;
|
||||
TButton_State vpower;
|
||||
void xdrawButton(bool inverted);
|
||||
};
|
||||
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "открит шум"
|
||||
#define D_AS3935_DISTDET "открито смущение"
|
||||
#define D_AS3935_INTNOEV "Прекъсване без Събитие!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "слушане..."
|
||||
#define D_AS3935_ON "Вкл."
|
||||
#define D_AS3935_OFF "Изкл."
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -812,7 +812,7 @@
|
||||
#define D_AS3935_GAIN "Rauschpegel:"
|
||||
#define D_AS3935_ENERGY "Energie:"
|
||||
#define D_AS3935_DISTANCE "Entfernung:"
|
||||
#define D_AS3935_DISTURBER "Störsingal:"
|
||||
#define D_AS3935_DISTURBER "Entstörer:"
|
||||
#define D_AS3935_VRMS "µVrms:"
|
||||
#define D_AS3935_APRX "ca.:"
|
||||
#define D_AS3935_AWAY "entfernt"
|
||||
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "Rauschen entdeckt"
|
||||
#define D_AS3935_DISTDET "Störer entdeckt"
|
||||
#define D_AS3935_INTNOEV "Interrupt ohne Grund!"
|
||||
#define D_AS3935_FLICKER "IRQ Pin flackerd!"
|
||||
#define D_AS3935_POWEROFF "Ausgeschaltet"
|
||||
#define D_AS3935_NOMESS "lausche..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ Pin flicker!"
|
||||
#define D_AS3935_POWEROFF "Powerd Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "Ruido detectado"
|
||||
#define D_AS3935_DISTDET "Perturbancia detectada"
|
||||
#define D_AS3935_INTNOEV "Interrupción sin evento!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "Escuchando..."
|
||||
#define D_AS3935_ON "Encendido"
|
||||
#define D_AS3935_OFF "Apagado"
|
||||
|
@ -814,6 +814,8 @@
|
||||
#define D_AS3935_NOISE "bruit détecté"
|
||||
#define D_AS3935_DISTDET "interférence détectée"
|
||||
#define D_AS3935_INTNOEV "Interruption sans évenement!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "en écoute..."
|
||||
#define D_AS3935_ON "Actif"
|
||||
#define D_AS3935_OFF "Inactif"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
it-IT.h - localization for Italian - Italy for Tasmota
|
||||
|
||||
Copyright (C) 2020 Gennaro Tortone - some mods by Antonio Fragola - Updated by bovirus - rev. 19.08.2020
|
||||
Copyright (C) 2020 Gennaro Tortone - some mods by Antonio Fragola - Updated by bovirus - rev. 02.09.2020
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -351,8 +351,8 @@
|
||||
#define D_UPLOAD_STARTED "Caricamento..."
|
||||
#define D_UPGRADE_STARTED "Aggiornamento..."
|
||||
#define D_UPLOAD_DONE "Caricamento completato"
|
||||
#define D_UPLOAD_TRANSFER "Upload transfer"
|
||||
#define D_TRANSFER_STARTED "Transfer started"
|
||||
#define D_UPLOAD_TRANSFER "Trasferimento caricamento"
|
||||
#define D_TRANSFER_STARTED "Trasferimento avviato"
|
||||
#define D_UPLOAD_ERR_1 "Nessun file selezionato"
|
||||
#define D_UPLOAD_ERR_2 "Spazio insufficiente"
|
||||
#define D_UPLOAD_ERR_3 "Magic byte non corrispondente a 0xE9"
|
||||
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "rilevato rumore"
|
||||
#define D_AS3935_DISTDET "rilevato disturbatore"
|
||||
#define D_AS3935_INTNOEV "Interrupt senza evento!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "in ascolto..."
|
||||
#define D_AS3935_ON "ON"
|
||||
#define D_AS3935_OFF "OFF"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "noise detected"
|
||||
#define D_AS3935_DISTDET "disturber detected"
|
||||
#define D_AS3935_INTNOEV "Interrupt with no Event!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "listening..."
|
||||
#define D_AS3935_ON "On"
|
||||
#define D_AS3935_OFF "Off"
|
||||
|
@ -823,6 +823,8 @@
|
||||
#define D_AS3935_NOISE "偵測到雜訊"
|
||||
#define D_AS3935_DISTDET "偵測到干擾物"
|
||||
#define D_AS3935_INTNOEV "沒有任何事件觸發中斷!"
|
||||
#define D_AS3935_FLICKER "IRQ flicker!"
|
||||
#define D_AS3935_POWEROFF "Power Off"
|
||||
#define D_AS3935_NOMESS "聽取中..."
|
||||
#define D_AS3935_ON "開啟"
|
||||
#define D_AS3935_OFF "關閉"
|
||||
|
@ -282,9 +282,9 @@ typedef union {
|
||||
struct {
|
||||
uint8_t nf_autotune : 1; // Autotune the NF Noise Level
|
||||
uint8_t dist_autotune : 1; // Autotune Disturber on/off
|
||||
uint8_t nf_autotune_both : 1; // Autotune over both Areas: INDOORS/OUDOORS
|
||||
uint8_t nf_autotune_both : 1; // Autotune over both Areas: INDOORS/OUDOORS
|
||||
uint8_t mqtt_only_Light_Event : 1; // mqtt only if lightning Irq
|
||||
uint8_t spare4 : 1;
|
||||
uint8_t suppress_irq_no_Event : 1; // suppress mqtt "IRQ with no Event". (Chip Bug)
|
||||
uint8_t spare5 : 1;
|
||||
uint8_t spare6 : 1;
|
||||
uint8_t spare7 : 1;
|
||||
|
@ -323,7 +323,7 @@ void CmndBacklog(void)
|
||||
backlog.add(blcommand);
|
||||
}
|
||||
#else
|
||||
backlog[backlog_index] = String(blcommand);
|
||||
backlog[backlog_index] = blcommand;
|
||||
backlog_index++;
|
||||
if (backlog_index >= MAX_BACKLOG) backlog_index = 0;
|
||||
#endif
|
||||
|
@ -60,9 +60,9 @@
|
||||
#ifdef USE_DISCOVERY
|
||||
#include <ESP8266mDNS.h> // MQTT, Webserver, Arduino OTA
|
||||
#endif // USE_DISCOVERY
|
||||
#ifdef USE_I2C
|
||||
//#ifdef USE_I2C
|
||||
#include <Wire.h> // I2C support library
|
||||
#endif // USE_I2C
|
||||
//#endif // USE_I2C
|
||||
#ifdef USE_SPI
|
||||
#include <SPI.h> // SPI support, TFT
|
||||
#endif // USE_SPI
|
||||
@ -339,6 +339,7 @@ void BacklogLoop(void) {
|
||||
#else
|
||||
backlog_mutex = true;
|
||||
ExecuteCommand((char*)backlog[backlog_pointer].c_str(), SRC_BACKLOG);
|
||||
backlog[backlog_pointer] = (const char*) nullptr; // force deallocation of the String internal memory
|
||||
backlog_pointer++;
|
||||
if (backlog_pointer >= MAX_BACKLOG) { backlog_pointer = 0; }
|
||||
backlog_mutex = false;
|
||||
|
@ -228,7 +228,7 @@ enum UserSelectablePins {
|
||||
GPIO_CC1101_GDO2, // CC1101 pin for RX
|
||||
GPIO_HRXL_RX, // Data from MaxBotix HRXL sonar range sensor
|
||||
GPIO_ELECTRIQ_MOODL_TX, // ElectriQ iQ-wifiMOODL Serial TX
|
||||
GPIO_AS3935,
|
||||
GPIO_AS3935, // Franklin Lightning Sensor
|
||||
GPIO_PMS5003_TX, // Plantower PMS5003 Serial interface
|
||||
GPIO_BOILER_OT_RX, // OpenTherm Boiler RX pin
|
||||
GPIO_BOILER_OT_TX, // OpenTherm Boiler TX pin
|
||||
@ -710,7 +710,7 @@ const uint8_t kGpioNiceList[] PROGMEM = {
|
||||
GPIO_DYP_RX,
|
||||
#endif
|
||||
#ifdef USE_AS3935
|
||||
GPIO_AS3935,
|
||||
GPIO_AS3935, // AS3935 IRQ Pin
|
||||
#endif
|
||||
#ifdef USE_TELEINFO
|
||||
GPIO_TELEINFO_RX,
|
||||
|
@ -111,7 +111,7 @@ enum UserSelectablePins {
|
||||
GPIO_CC1101_GDO0, GPIO_CC1101_GDO2, // CC1101 Serial interface
|
||||
GPIO_HRXL_RX, // Data from MaxBotix HRXL sonar range sensor
|
||||
GPIO_ELECTRIQ_MOODL_TX, // ElectriQ iQ-wifiMOODL Serial TX
|
||||
GPIO_AS3935,
|
||||
GPIO_AS3935, // Franklin Lightning Sensor
|
||||
GPIO_ADC_INPUT, // Analog input
|
||||
GPIO_ADC_TEMP, // Analog Thermistor
|
||||
GPIO_ADC_LIGHT, // Analog Light sensor
|
||||
@ -557,7 +557,7 @@ const uint16_t kGpioNiceList[] PROGMEM = {
|
||||
AGPIO(GPIO_DYP_RX),
|
||||
#endif
|
||||
#ifdef USE_AS3935
|
||||
AGPIO(GPIO_AS3935),
|
||||
AGPIO(GPIO_AS3935), // AS3935 IRQ Pin
|
||||
#endif
|
||||
#ifdef USE_TELEINFO
|
||||
AGPIO(GPIO_TELEINFO_RX),
|
||||
|
@ -2781,9 +2781,10 @@ void HandleUploadLoop(void)
|
||||
} else
|
||||
#endif // USE_RF_FLASH
|
||||
#ifdef USE_TASMOTA_CLIENT
|
||||
if ((WEMOS == my_module_type) && (upload.buf[0] == ':')) { // Check if this is a ARDUINO CLIENT hex file
|
||||
if (TasmotaClient_Available() && (upload.buf[0] == ':')) { // Check if this is a ARDUINO CLIENT hex file
|
||||
Update.end(); // End esp8266 update session
|
||||
Web.upload_file_type = UPL_TASMOTACLIENT;
|
||||
|
||||
Web.upload_error = TasmotaClient_UpdateInit(); // 0
|
||||
if (Web.upload_error != 0) { return; }
|
||||
} else
|
||||
|
@ -300,12 +300,35 @@ struct T_INDEX {
|
||||
};
|
||||
|
||||
struct M_FILT {
|
||||
#ifdef LARGE_ARRAYS
|
||||
uint16_t numvals;
|
||||
uint16_t index;
|
||||
#else
|
||||
uint8_t numvals;
|
||||
uint8_t index;
|
||||
#endif // LARGE_ARRAYS
|
||||
float maccu;
|
||||
float rbuff[1];
|
||||
};
|
||||
|
||||
|
||||
#ifdef LARGE_ARRAYS
|
||||
#undef AND_FILT_MASK
|
||||
#undef OR_FILT_MASK
|
||||
#define AND_FILT_MASK 0x7fff
|
||||
#define OR_FILT_MASK 0x8000
|
||||
#undef MAX_ARRAY_SIZE
|
||||
#define MAX_ARRAY_SIZE 1000
|
||||
#else
|
||||
#undef AND_FILT_MASK
|
||||
#undef OR_FILT_MASK
|
||||
#define AND_FILT_MASK 0x7f
|
||||
#define OR_FILT_MASK 0x80
|
||||
#undef MAX_ARRAY_SIZE
|
||||
#define MAX_ARRAY_SIZE 127
|
||||
#endif
|
||||
|
||||
|
||||
typedef union {
|
||||
uint8_t data;
|
||||
struct {
|
||||
@ -462,6 +485,8 @@ void RulesTeleperiod(void) {
|
||||
#define SCRIPT_SKIP_SPACES while (*lp==' ' || *lp=='\t') lp++;
|
||||
#define SCRIPT_SKIP_EOL while (*lp==SCRIPT_EOL) lp++;
|
||||
|
||||
float *Get_MFAddr(uint8_t index,uint16_t *len,uint16_t *ipos);
|
||||
|
||||
// allocates all variables and presets them
|
||||
int16_t Init_Scripter(void) {
|
||||
char *script;
|
||||
@ -543,12 +568,16 @@ char *script;
|
||||
if ((*lp=='m' || *lp=='M') && *(lp+1)==':') {
|
||||
uint8_t flg=*lp;
|
||||
lp+=2;
|
||||
if (*lp=='p' && *(lp+1)==':') {
|
||||
vtypes[vars].bits.is_permanent=1;
|
||||
lp+=2;
|
||||
}
|
||||
if (flg=='M') mfilt[numflt].numvals=8;
|
||||
else mfilt[numflt].numvals=5;
|
||||
vtypes[vars].bits.is_filter=1;
|
||||
mfilt[numflt].index=0;
|
||||
if (flg=='M') {
|
||||
mfilt[numflt].numvals|=0x80;
|
||||
mfilt[numflt].numvals|=OR_FILT_MASK;
|
||||
}
|
||||
vtypes[vars].index=numflt;
|
||||
numflt++;
|
||||
@ -587,9 +616,13 @@ char *script;
|
||||
while (*op==' ') op++;
|
||||
if (isdigit(*op)) {
|
||||
// lenght define follows
|
||||
uint8_t flen=atoi(op);
|
||||
mfilt[numflt-1].numvals&=0x80;
|
||||
mfilt[numflt-1].numvals|=flen&0x7f;
|
||||
uint16_t flen=atoi(op);
|
||||
if (flen>MAX_ARRAY_SIZE) {
|
||||
// limit array size
|
||||
flen=MAX_ARRAY_SIZE;
|
||||
}
|
||||
mfilt[numflt-1].numvals&=OR_FILT_MASK;
|
||||
mfilt[numflt-1].numvals|=flen&AND_FILT_MASK;
|
||||
}
|
||||
}
|
||||
|
||||
@ -635,11 +668,11 @@ char *script;
|
||||
|
||||
uint16_t fsize=0;
|
||||
for (count=0; count<numflt; count++) {
|
||||
fsize+=sizeof(struct M_FILT)+((mfilt[count].numvals&0x7f)-1)*sizeof(float);
|
||||
fsize+=sizeof(struct M_FILT)+((mfilt[count].numvals&AND_FILT_MASK)-1)*sizeof(float);
|
||||
}
|
||||
|
||||
// now copy vars to memory
|
||||
uint16_t script_mem_size=
|
||||
uint32_t script_mem_size=
|
||||
// number and number shadow vars
|
||||
(sizeof(float)*nvars)+
|
||||
(sizeof(float)*nvars)+
|
||||
@ -733,7 +766,7 @@ char *script;
|
||||
for (count=0; count<numflt; count++) {
|
||||
struct M_FILT *mflp=(struct M_FILT*)mp;
|
||||
mflp->numvals=mfilt[count].numvals;
|
||||
mp+=sizeof(struct M_FILT)+((mfilt[count].numvals&0x7f)-1)*sizeof(float);
|
||||
mp+=sizeof(struct M_FILT)+((mfilt[count].numvals&AND_FILT_MASK)-1)*sizeof(float);
|
||||
}
|
||||
|
||||
glob_script_mem.numvars=vars;
|
||||
@ -760,12 +793,21 @@ char *script;
|
||||
for (uint8_t count=0; count<glob_script_mem.numvars; count++) {
|
||||
if (vtp[count].bits.is_permanent && !vtp[count].bits.is_string) {
|
||||
uint8_t index=vtp[count].index;
|
||||
if (!isnan(*fp)) {
|
||||
glob_script_mem.fvars[index]=*fp;
|
||||
if (vtp[count].bits.is_filter) {
|
||||
// preset array
|
||||
uint16_t len=0;
|
||||
float *fa=Get_MFAddr(index,&len,0);
|
||||
while (len--) {
|
||||
*fa++=*fp++;
|
||||
}
|
||||
} else {
|
||||
*fp=glob_script_mem.fvars[index];
|
||||
if (!isnan(*fp)) {
|
||||
glob_script_mem.fvars[index]=*fp;
|
||||
} else {
|
||||
*fp=glob_script_mem.fvars[index];
|
||||
}
|
||||
fp++;
|
||||
}
|
||||
fp++;
|
||||
}
|
||||
}
|
||||
sp=(char*)fp;
|
||||
@ -947,7 +989,7 @@ void ws2812_set_array(float *array ,uint32_t len, uint32_t offset) {
|
||||
|
||||
|
||||
|
||||
float median_array(float *array,uint8_t len) {
|
||||
float median_array(float *array,uint16_t len) {
|
||||
uint8_t ind[len];
|
||||
uint8_t mind=0,index=0,flg;
|
||||
float min=FLT_MAX;
|
||||
@ -975,45 +1017,48 @@ float median_array(float *array,uint8_t len) {
|
||||
}
|
||||
|
||||
|
||||
float *Get_MFAddr(uint8_t index,uint8_t *len,uint8_t *ipos) {
|
||||
float *Get_MFAddr(uint8_t index,uint16_t *len,uint16_t *ipos) {
|
||||
*len=0;
|
||||
uint8_t *mp=(uint8_t*)glob_script_mem.mfilt;
|
||||
for (uint8_t count=0; count<MAXFILT; count++) {
|
||||
struct M_FILT *mflp=(struct M_FILT*)mp;
|
||||
if (count==index) {
|
||||
*len=mflp->numvals&0x7f;
|
||||
*len=mflp->numvals&AND_FILT_MASK;
|
||||
if (ipos) *ipos=mflp->index;
|
||||
return mflp->rbuff;
|
||||
}
|
||||
mp+=sizeof(struct M_FILT)+((mflp->numvals&0x7f)-1)*sizeof(float);
|
||||
mp+=sizeof(struct M_FILT)+((mflp->numvals&AND_FILT_MASK)-1)*sizeof(float);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
float Get_MFVal(uint8_t index,uint8_t bind) {
|
||||
float Get_MFVal(uint8_t index,int16_t bind) {
|
||||
uint8_t *mp=(uint8_t*)glob_script_mem.mfilt;
|
||||
for (uint8_t count=0; count<MAXFILT; count++) {
|
||||
struct M_FILT *mflp=(struct M_FILT*)mp;
|
||||
if (count==index) {
|
||||
uint8_t maxind=mflp->numvals&0x7f;
|
||||
uint16_t maxind=mflp->numvals&AND_FILT_MASK;
|
||||
if (!bind) {
|
||||
return mflp->index;
|
||||
}
|
||||
if (bind<0) {
|
||||
return maxind;
|
||||
}
|
||||
if (bind<1 || bind>maxind) bind=maxind;
|
||||
return mflp->rbuff[bind-1];
|
||||
}
|
||||
mp+=sizeof(struct M_FILT)+((mflp->numvals&0x7f)-1)*sizeof(float);
|
||||
mp+=sizeof(struct M_FILT)+((mflp->numvals&AND_FILT_MASK)-1)*sizeof(float);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Set_MFVal(uint8_t index,uint8_t bind,float val) {
|
||||
void Set_MFVal(uint8_t index,uint16_t bind,float val) {
|
||||
uint8_t *mp=(uint8_t*)glob_script_mem.mfilt;
|
||||
for (uint8_t count=0; count<MAXFILT; count++) {
|
||||
struct M_FILT *mflp=(struct M_FILT*)mp;
|
||||
if (count==index) {
|
||||
uint8_t maxind=mflp->numvals&0x7f;
|
||||
uint16_t maxind=mflp->numvals&AND_FILT_MASK;
|
||||
if (!bind) {
|
||||
mflp->index=val;
|
||||
} else {
|
||||
@ -1022,7 +1067,7 @@ void Set_MFVal(uint8_t index,uint8_t bind,float val) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
mp+=sizeof(struct M_FILT)+((mflp->numvals&0x7f)-1)*sizeof(float);
|
||||
mp+=sizeof(struct M_FILT)+((mflp->numvals&AND_FILT_MASK)-1)*sizeof(float);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1032,15 +1077,15 @@ float Get_MFilter(uint8_t index) {
|
||||
for (uint8_t count=0; count<MAXFILT; count++) {
|
||||
struct M_FILT *mflp=(struct M_FILT*)mp;
|
||||
if (count==index) {
|
||||
if (mflp->numvals&0x80) {
|
||||
if (mflp->numvals&OR_FILT_MASK) {
|
||||
// moving average
|
||||
return mflp->maccu/(mflp->numvals&0x7f);
|
||||
return mflp->maccu/(mflp->numvals&AND_FILT_MASK);
|
||||
} else {
|
||||
// median, sort array indices
|
||||
return median_array(mflp->rbuff,mflp->numvals);
|
||||
}
|
||||
}
|
||||
mp+=sizeof(struct M_FILT)+((mflp->numvals&0x7f)-1)*sizeof(float);
|
||||
mp+=sizeof(struct M_FILT)+((mflp->numvals&AND_FILT_MASK)-1)*sizeof(float);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1050,13 +1095,13 @@ void Set_MFilter(uint8_t index, float invar) {
|
||||
for (uint8_t count=0; count<MAXFILT; count++) {
|
||||
struct M_FILT *mflp=(struct M_FILT*)mp;
|
||||
if (count==index) {
|
||||
if (mflp->numvals&0x80) {
|
||||
if (mflp->numvals&OR_FILT_MASK) {
|
||||
// moving average
|
||||
mflp->maccu-=mflp->rbuff[mflp->index];
|
||||
mflp->maccu+=invar;
|
||||
mflp->rbuff[mflp->index]=invar;
|
||||
mflp->index++;
|
||||
if (mflp->index>=(mflp->numvals&0x7f)) mflp->index=0;
|
||||
if (mflp->index>=(mflp->numvals&AND_FILT_MASK)) mflp->index=0;
|
||||
} else {
|
||||
// median
|
||||
mflp->rbuff[mflp->index]=invar;
|
||||
@ -1065,7 +1110,7 @@ void Set_MFilter(uint8_t index, float invar) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
mp+=sizeof(struct M_FILT)+((mflp->numvals&0x7f)-1)*sizeof(float);
|
||||
mp+=sizeof(struct M_FILT)+((mflp->numvals&AND_FILT_MASK)-1)*sizeof(float);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2140,7 +2185,7 @@ chknext:
|
||||
}
|
||||
} else {
|
||||
if (index>glob_script_mem.si_num) {
|
||||
fvar=glob_script_mem.si_num;
|
||||
index=glob_script_mem.si_num;
|
||||
}
|
||||
strlcpy(str,glob_script_mem.last_index_string+(index*glob_script_mem.max_ssize),glob_script_mem.max_ssize);
|
||||
}
|
||||
@ -2691,7 +2736,7 @@ chknext:
|
||||
if (index<1 || index>MAXBUTTONS) index=1;
|
||||
index--;
|
||||
if (buttons[index]) {
|
||||
fvar=buttons[index]->vpower&0x80;
|
||||
fvar=buttons[index]->vpower.on_off;
|
||||
} else {
|
||||
fvar=-1;
|
||||
}
|
||||
@ -2807,7 +2852,7 @@ chknext:
|
||||
#if defined(USE_TTGO_WATCH) && defined(USE_FT5206)
|
||||
if (!strncmp(vname,"wtch(",5)) {
|
||||
lp=GetNumericResult(lp+5,OPER_EQU,&fvar,0);
|
||||
fvar=FT5206_touched(fvar);
|
||||
fvar=Touch_Status(fvar);
|
||||
lp++;
|
||||
len=0;
|
||||
goto exit;
|
||||
@ -3430,7 +3475,7 @@ int16_t Run_Scripter(const char *type, int8_t tlen, char *js) {
|
||||
int16_t Run_script_sub(const char *type, int8_t tlen, JsonObject *jo) {
|
||||
uint8_t vtype=0,sindex,xflg,floop=0,globvindex,fromscriptcmd=0;
|
||||
char *lp_next;
|
||||
int8_t globaindex,saindex;
|
||||
int16_t globaindex,saindex;
|
||||
struct T_INDEX ind;
|
||||
uint8_t operand,lastop,numeric=1,if_state[IF_NEST],if_exe[IF_NEST],if_result[IF_NEST],and_or,ifstck=0;
|
||||
if_state[ifstck]=0;
|
||||
@ -3762,7 +3807,7 @@ int16_t Run_script_sub(const char *type, int8_t tlen, JsonObject *jo) {
|
||||
if ((vtype&STYPE)==0) {
|
||||
// numeric result
|
||||
if (glob_script_mem.type[ind.index].bits.is_filter) {
|
||||
uint8_t len=0;
|
||||
uint16_t len=0;
|
||||
float *fa=Get_MFAddr(index,&len,0);
|
||||
//Serial.printf(">> 2 %d\n",(uint32_t)*fa);
|
||||
if (fa && len) ws2812_set_array(fa,len,fvar);
|
||||
@ -4175,12 +4220,26 @@ void Scripter_save_pvars(void) {
|
||||
for (uint8_t count=0; count<glob_script_mem.numvars; count++) {
|
||||
if (vtp[count].bits.is_permanent && !vtp[count].bits.is_string) {
|
||||
uint8_t index=vtp[count].index;
|
||||
mlen+=sizeof(float);
|
||||
if (mlen>PMEM_SIZE) {
|
||||
vtp[count].bits.is_permanent=0;
|
||||
return;
|
||||
if (vtp[count].bits.is_filter) {
|
||||
// save array
|
||||
uint16_t len=0;
|
||||
float *fa=Get_MFAddr(index,&len,0);
|
||||
mlen+=sizeof(float)*len;
|
||||
if (mlen>glob_script_mem.script_pram_size) {
|
||||
vtp[count].bits.is_permanent=0;
|
||||
return;
|
||||
}
|
||||
while (len--) {
|
||||
*fp++=*fa++;
|
||||
}
|
||||
} else {
|
||||
mlen+=sizeof(float);
|
||||
if (mlen>glob_script_mem.script_pram_size) {
|
||||
vtp[count].bits.is_permanent=0;
|
||||
return;
|
||||
}
|
||||
*fp++=glob_script_mem.fvars[index];
|
||||
}
|
||||
*fp++=glob_script_mem.fvars[index];
|
||||
}
|
||||
}
|
||||
char *cp=(char*)fp;
|
||||
@ -4190,7 +4249,7 @@ void Scripter_save_pvars(void) {
|
||||
char *sp=glob_script_mem.glob_snp+(index*glob_script_mem.max_ssize);
|
||||
uint8_t slen=strlen(sp);
|
||||
mlen+=slen+1;
|
||||
if (mlen>PMEM_SIZE) {
|
||||
if (mlen>glob_script_mem.script_pram_size) {
|
||||
vtp[count].bits.is_permanent=0;
|
||||
return;
|
||||
}
|
||||
@ -6013,6 +6072,9 @@ const char SCRIPT_MSG_GOPT4[] PROGMEM =
|
||||
const char SCRIPT_MSG_GOPT5[] PROGMEM =
|
||||
"new Date(0,1,1,%d,%d)";
|
||||
|
||||
const char SCRIPT_MSG_GOPT6[] PROGMEM =
|
||||
"title:'%s',isStacked:false,vAxis:{viewWindow:{min:%d,max:%d}}%s";
|
||||
|
||||
const char SCRIPT_MSG_GTE1[] PROGMEM = "'%s'";
|
||||
|
||||
#define GLIBS_MAIN 1<<0
|
||||
@ -6022,11 +6084,11 @@ const char SCRIPT_MSG_GTE1[] PROGMEM = "'%s'";
|
||||
|
||||
#define MAX_GARRAY 4
|
||||
|
||||
char *gc_get_arrays(char *lp, float **arrays, uint8_t *ranum, uint8_t *rentries, uint8_t *ipos) {
|
||||
char *gc_get_arrays(char *lp, float **arrays, uint8_t *ranum, uint16_t *rentries, uint16_t *ipos) {
|
||||
struct T_INDEX ind;
|
||||
uint8_t vtype;
|
||||
uint8 entries=0;
|
||||
uint8_t cipos=0;
|
||||
uint16 entries=0;
|
||||
uint16_t cipos=0;
|
||||
|
||||
uint8_t anum=0;
|
||||
while (anum<MAX_GARRAY) {
|
||||
@ -6042,9 +6104,9 @@ uint8_t cipos=0;
|
||||
//Serial.printf("numeric %d - %d \n",ind.index,index);
|
||||
if (glob_script_mem.type[ind.index].bits.is_filter) {
|
||||
//Serial.printf("numeric array\n");
|
||||
uint8_t len=0;
|
||||
uint16_t len=0;
|
||||
float *fa=Get_MFAddr(index,&len,&cipos);
|
||||
//Serial.printf(">> 2 %d\n",(uint32_t)*fa);
|
||||
//Serial.printf(">> 2 %d\n",len);
|
||||
if (fa && len>=entries) {
|
||||
if (!entries) {
|
||||
entries = len;
|
||||
@ -6295,12 +6357,12 @@ void ScriptWebShow(char mc) {
|
||||
|
||||
} else {
|
||||
if (mc=='w') {
|
||||
WSContentSend_PD(PSTR("%s"),tmp);
|
||||
WSContentSend_PD(PSTR("%s"),lin);
|
||||
} else {
|
||||
if (optflg) {
|
||||
WSContentSend_PD(PSTR("<div>%s</div>"),tmp);
|
||||
WSContentSend_PD(PSTR("<div>%s</div>"),lin);
|
||||
} else {
|
||||
WSContentSend_PD(PSTR("{s}%s{e}"),tmp);
|
||||
WSContentSend_PD(PSTR("{s}%s{e}"),lin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6388,8 +6450,8 @@ exgc:
|
||||
|
||||
float *arrays[MAX_GARRAY];
|
||||
uint8_t anum=0;
|
||||
uint8 entries=0;
|
||||
uint8 ipos=0;
|
||||
uint16_t entries=0;
|
||||
uint16_t ipos=0;
|
||||
lp=gc_get_arrays(lp, &arrays[0], &anum, &entries, &ipos);
|
||||
|
||||
if (anum>nanum) {
|
||||
@ -6434,10 +6496,19 @@ exgc:
|
||||
lp=GetStringResult(lp,OPER_EQU,label,0);
|
||||
SCRIPT_SKIP_SPACES
|
||||
|
||||
int8_t todflg=-1;
|
||||
int16_t divflg=1;
|
||||
int16_t todflg=-1;
|
||||
if (!strncmp(label,"cnt",3)) {
|
||||
todflg=atoi(&label[3]);
|
||||
if (todflg>=entries) todflg=entries-1;
|
||||
} else {
|
||||
uint16 segments=1;
|
||||
for (uint32_t cnt=0; cnt<strlen(label); cnt++) {
|
||||
if (label[cnt]=='|') {
|
||||
segments++;
|
||||
}
|
||||
}
|
||||
divflg=entries/segments;
|
||||
}
|
||||
|
||||
uint32_t aind=ipos;
|
||||
@ -6452,7 +6523,7 @@ exgc:
|
||||
todflg=0;
|
||||
}
|
||||
} else {
|
||||
GetTextIndexed(lbl, sizeof(lbl), aind, label);
|
||||
GetTextIndexed(lbl, sizeof(lbl), aind/divflg, label);
|
||||
}
|
||||
WSContentSend_PD(lbl);
|
||||
WSContentSend_PD("',");
|
||||
@ -6495,6 +6566,17 @@ exgc:
|
||||
lp=GetNumericResult(lp,OPER_EQU,&max2,0);
|
||||
SCRIPT_SKIP_SPACES
|
||||
snprintf_P(options,sizeof(options),SCRIPT_MSG_GOPT3,header,(uint32_t)max1,(uint32_t)max2,func);
|
||||
} else {
|
||||
SCRIPT_SKIP_SPACES
|
||||
if (*lp!=')') {
|
||||
float max1;
|
||||
lp=GetNumericResult(lp,OPER_EQU,&max1,0);
|
||||
SCRIPT_SKIP_SPACES
|
||||
float max2;
|
||||
lp=GetNumericResult(lp,OPER_EQU,&max2,0);
|
||||
SCRIPT_SKIP_SPACES
|
||||
snprintf_P(options,sizeof(options),SCRIPT_MSG_GOPT6,header,(uint32_t)max1,(uint32_t)max2,func);
|
||||
}
|
||||
}
|
||||
|
||||
if (ctype=='g') {
|
||||
|
@ -23,7 +23,6 @@
|
||||
#define XDRV_13 13
|
||||
|
||||
#include <renderer.h>
|
||||
#include <FT6236.h>
|
||||
|
||||
Renderer *renderer;
|
||||
|
||||
@ -757,7 +756,28 @@ void DisplayText(void)
|
||||
|
||||
#ifdef USE_TOUCH_BUTTONS
|
||||
case 'b':
|
||||
{ int16_t num,gxp,gyp,gxs,gys,outline,fill,textcolor,textsize;
|
||||
{ int16_t num,gxp,gyp,gxs,gys,outline,fill,textcolor,textsize; uint8_t dflg=1;
|
||||
if (*cp=='e' || *cp=='d') {
|
||||
// enable disable
|
||||
uint8_t dis=0;
|
||||
if (*cp=='d') dis=1;
|
||||
cp++;
|
||||
var=atoiv(cp,&num);
|
||||
num=num%MAXBUTTONS;
|
||||
cp+=var;
|
||||
if (buttons[num]) {
|
||||
buttons[num]->vpower.disable=dis;
|
||||
if (!dis) {
|
||||
if (buttons[num]->vpower.is_virtual) buttons[num]->xdrawButton(buttons[num]->vpower.on_off);
|
||||
else buttons[num]->xdrawButton(bitRead(power,num));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (*cp=='-') {
|
||||
cp++;
|
||||
dflg=0;
|
||||
}
|
||||
var=atoiv(cp,&num);
|
||||
cp+=var;
|
||||
cp++;
|
||||
@ -797,16 +817,23 @@ void DisplayText(void)
|
||||
if (renderer) {
|
||||
buttons[num]= new VButton();
|
||||
if (buttons[num]) {
|
||||
buttons[num]->vpower=bflags;
|
||||
buttons[num]->initButtonUL(renderer,gxp,gyp,gxs,gys,renderer->GetColorFromIndex(outline),\
|
||||
renderer->GetColorFromIndex(fill),renderer->GetColorFromIndex(textcolor),bbuff,textsize);
|
||||
renderer->GetColorFromIndex(fill),renderer->GetColorFromIndex(textcolor),bbuff,textsize);
|
||||
if (!bflags) {
|
||||
// power button
|
||||
buttons[num]->xdrawButton(bitRead(power,num));
|
||||
if (dflg) buttons[num]->xdrawButton(bitRead(power,num));
|
||||
buttons[num]->vpower.is_virtual=0;
|
||||
} else {
|
||||
// virtual button
|
||||
buttons[num]->vpower&=0x7f;
|
||||
buttons[num]->xdrawButton(buttons[num]->vpower&0x80);
|
||||
buttons[num]->vpower.is_virtual=1;
|
||||
if (bflags==2) {
|
||||
// push
|
||||
buttons[num]->vpower.is_pushbutton=1;
|
||||
} else {
|
||||
// toggle
|
||||
buttons[num]->vpower.is_pushbutton=0;
|
||||
}
|
||||
if (dflg) buttons[num]->xdrawButton(buttons[num]->vpower.on_off);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2019,7 +2046,146 @@ void AddValue(uint8_t num,float fval) {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif // USE_GRAPH
|
||||
|
||||
#ifdef USE_FT5206
|
||||
|
||||
// touch panel controller
|
||||
#undef FT5206_address
|
||||
#define FT5206_address 0x38
|
||||
|
||||
#include <FT5206.h>
|
||||
FT5206_Class *touchp;
|
||||
TP_Point pLoc;
|
||||
|
||||
|
||||
extern VButton *buttons[];
|
||||
bool FT5206_found;
|
||||
|
||||
bool Touch_Init(TwoWire &i2c) {
|
||||
FT5206_found = false;
|
||||
touchp = new FT5206_Class();
|
||||
if (touchp->begin(i2c, FT5206_address)) {
|
||||
I2cSetActiveFound(FT5206_address, "FT5206");
|
||||
FT5206_found = true;
|
||||
}
|
||||
return FT5206_found;
|
||||
}
|
||||
|
||||
uint32_t Touch_Status(uint32_t sel) {
|
||||
if (FT5206_found) {
|
||||
switch (sel) {
|
||||
case 0:
|
||||
return touchp->touched();
|
||||
case 1:
|
||||
return pLoc.x;
|
||||
case 2:
|
||||
return pLoc.y;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_TOUCH_BUTTONS
|
||||
void Touch_MQTT(uint8_t index, const char *cp) {
|
||||
ResponseTime_P(PSTR(",\"FT5206\":{\"%s%d\":\"%d\"}}"), cp, index+1, buttons[index]->vpower.on_off);
|
||||
MqttPublishTeleSensor();
|
||||
}
|
||||
|
||||
void Touch_RDW_BUTT(uint32_t count, uint32_t pwr) {
|
||||
buttons[count]->xdrawButton(pwr);
|
||||
if (pwr) buttons[count]->vpower.on_off = 1;
|
||||
else buttons[count]->vpower.on_off = 0;
|
||||
}
|
||||
|
||||
// check digitizer hit
|
||||
void Touch_Check(void(*rotconvert)(int16_t *x, int16_t *y)) {
|
||||
uint16_t temp;
|
||||
uint8_t rbutt=0;
|
||||
uint8_t vbutt=0;
|
||||
|
||||
|
||||
if (touchp->touched()) {
|
||||
// did find a hit
|
||||
pLoc = touchp->getPoint(0);
|
||||
|
||||
if (renderer) {
|
||||
|
||||
rotconvert(&pLoc.x, &pLoc.y);
|
||||
|
||||
//AddLog_P2(LOG_LEVEL_INFO, PSTR("touch %d - %d"), pLoc.x, pLoc.y);
|
||||
// now must compare with defined buttons
|
||||
for (uint8_t count=0; count<MAXBUTTONS; count++) {
|
||||
if (buttons[count] && !buttons[count]->vpower.disable) {
|
||||
if (buttons[count]->contains(pLoc.x, pLoc.y)) {
|
||||
// did hit
|
||||
buttons[count]->press(true);
|
||||
if (buttons[count]->justPressed()) {
|
||||
if (!buttons[count]->vpower.is_virtual) {
|
||||
uint8_t pwr=bitRead(power, rbutt);
|
||||
if (!SendKey(KEY_BUTTON, rbutt+1, POWER_TOGGLE)) {
|
||||
ExecuteCommandPower(rbutt+1, POWER_TOGGLE, SRC_BUTTON);
|
||||
Touch_RDW_BUTT(count, !pwr);
|
||||
}
|
||||
} else {
|
||||
// virtual button
|
||||
const char *cp;
|
||||
if (!buttons[count]->vpower.is_pushbutton) {
|
||||
// toggle button
|
||||
buttons[count]->vpower.on_off ^= 1;
|
||||
cp="TBT";
|
||||
} else {
|
||||
// push button
|
||||
buttons[count]->vpower.on_off = 1;
|
||||
cp="PBT";
|
||||
}
|
||||
buttons[count]->xdrawButton(buttons[count]->vpower.on_off);
|
||||
Touch_MQTT(count,cp);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!buttons[count]->vpower.is_virtual) {
|
||||
rbutt++;
|
||||
} else {
|
||||
vbutt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// no hit
|
||||
for (uint8_t count=0; count<MAXBUTTONS; count++) {
|
||||
if (buttons[count]) {
|
||||
buttons[count]->press(false);
|
||||
if (buttons[count]->justReleased()) {
|
||||
if (buttons[count]->vpower.is_virtual) {
|
||||
if (buttons[count]->vpower.is_pushbutton) {
|
||||
// push button
|
||||
buttons[count]->vpower.on_off = 0;
|
||||
Touch_MQTT(count,"PBT");
|
||||
buttons[count]->xdrawButton(buttons[count]->vpower.on_off);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!buttons[count]->vpower.is_virtual) {
|
||||
// check if power button stage changed
|
||||
uint8_t pwr = bitRead(power, rbutt);
|
||||
uint8_t vpwr = buttons[count]->vpower.on_off;
|
||||
if (pwr != vpwr) {
|
||||
Touch_RDW_BUTT(count, pwr);
|
||||
}
|
||||
rbutt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
pLoc.x = 0;
|
||||
pLoc.y = 0;
|
||||
}
|
||||
}
|
||||
#endif // USE_TOUCH_BUTTONS
|
||||
#endif // USE_FT5206
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Interface
|
||||
|
@ -458,6 +458,10 @@ void TasmotaClient_Init(void) {
|
||||
}
|
||||
}
|
||||
|
||||
bool TasmotaClient_Available(void) {
|
||||
return TClient.SerialEnabled;
|
||||
}
|
||||
|
||||
void TasmotaClient_Show(void) {
|
||||
if ((TClient.type) && (TClientSettings.features.func_json_append)) {
|
||||
char buffer[100];
|
||||
|
@ -27,18 +27,12 @@
|
||||
#define COLORED 1
|
||||
#define UNCOLORED 0
|
||||
|
||||
// touch panel controller
|
||||
#define FT6236_address 0x38
|
||||
|
||||
// using font 8 is opional (num=3)
|
||||
// very badly readable, but may be useful for graphs
|
||||
#define USE_TINY_FONT
|
||||
|
||||
|
||||
#include <ILI9488.h>
|
||||
#include <FT6236.h>
|
||||
|
||||
TouchLocation ili9488_pLoc;
|
||||
uint8_t ili9488_ctouch_counter = 0;
|
||||
|
||||
// currently fixed
|
||||
@ -47,13 +41,7 @@ uint8_t ili9488_ctouch_counter = 0;
|
||||
extern uint8_t *buffer;
|
||||
extern uint8_t color_type;
|
||||
ILI9488 *ili9488;
|
||||
|
||||
#ifdef USE_TOUCH_BUTTONS
|
||||
extern VButton *buttons[];
|
||||
#endif
|
||||
|
||||
extern const uint16_t picture[];
|
||||
uint8_t FT6236_found;
|
||||
|
||||
/*********************************************************************************************/
|
||||
|
||||
@ -126,131 +114,52 @@ void ILI9488_InitDriver()
|
||||
#endif
|
||||
|
||||
color_type = COLOR_COLOR;
|
||||
// start digitizer with fixed adress
|
||||
|
||||
if (I2cEnabled(XI2C_38) && I2cSetDevice(FT6236_address)) {
|
||||
FT6236begin(FT6236_address);
|
||||
FT6236_found=1;
|
||||
I2cSetActiveFound(FT6236_address, "FT6236");
|
||||
} else {
|
||||
FT6236_found=0;
|
||||
}
|
||||
|
||||
// start digitizer
|
||||
#ifdef USE_FT5206
|
||||
Touch_Init(Wire);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_FT5206
|
||||
#ifdef USE_TOUCH_BUTTONS
|
||||
void ILI9488_MQTT(uint8_t count,const char *cp) {
|
||||
ResponseTime_P(PSTR(",\"RA8876\":{\"%s%d\":\"%d\"}}"), cp,count+1,(buttons[count]->vpower&0x80)>>7);
|
||||
MqttPublishTeleSensor();
|
||||
}
|
||||
|
||||
void ILI9488_RDW_BUTT(uint32_t count,uint32_t pwr) {
|
||||
buttons[count]->xdrawButton(pwr);
|
||||
if (pwr) buttons[count]->vpower|=0x80;
|
||||
else buttons[count]->vpower&=0x7f;
|
||||
}
|
||||
// check digitizer hit
|
||||
void FT6236Check() {
|
||||
uint16_t temp;
|
||||
uint8_t rbutt=0,vbutt=0;
|
||||
ili9488_ctouch_counter++;
|
||||
if (2 == ili9488_ctouch_counter) {
|
||||
// every 100 ms should be enough
|
||||
ili9488_ctouch_counter=0;
|
||||
if (FT6236readTouchLocation(&ili9488_pLoc,1)) {
|
||||
// did find a hit
|
||||
if (renderer) {
|
||||
uint8_t rot=renderer->getRotation();
|
||||
switch (rot) {
|
||||
case 0:
|
||||
temp=ili9488_pLoc.y;
|
||||
ili9488_pLoc.y=renderer->height()-ili9488_pLoc.x;
|
||||
ili9488_pLoc.x=temp;
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
case 3:
|
||||
temp=ili9488_pLoc.y;
|
||||
ili9488_pLoc.y=ili9488_pLoc.x;
|
||||
ili9488_pLoc.x=renderer->width()-temp;
|
||||
break;
|
||||
}
|
||||
// now must compare with defined buttons
|
||||
for (uint8_t count=0; count<MAXBUTTONS; count++) {
|
||||
if (buttons[count]) {
|
||||
uint8_t bflags=buttons[count]->vpower&0x7f;
|
||||
if (buttons[count]->contains(ili9488_pLoc.x,ili9488_pLoc.y)) {
|
||||
// did hit
|
||||
buttons[count]->press(true);
|
||||
if (buttons[count]->justPressed()) {
|
||||
if (!bflags) {
|
||||
uint8_t pwr=bitRead(power,rbutt);
|
||||
if (!SendKey(KEY_BUTTON, rbutt+1, POWER_TOGGLE)) {
|
||||
ExecuteCommandPower(rbutt+1, POWER_TOGGLE, SRC_BUTTON);
|
||||
ILI9488_RDW_BUTT(count,!pwr);
|
||||
}
|
||||
} else {
|
||||
// virtual button
|
||||
const char *cp;
|
||||
if (bflags==1) {
|
||||
// toggle button
|
||||
buttons[count]->vpower^=0x80;
|
||||
cp="TBT";
|
||||
} else {
|
||||
// push button
|
||||
buttons[count]->vpower|=0x80;
|
||||
cp="PBT";
|
||||
}
|
||||
buttons[count]->xdrawButton(buttons[count]->vpower&0x80);
|
||||
ILI9488_MQTT(count,cp);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!bflags) {
|
||||
rbutt++;
|
||||
} else {
|
||||
vbutt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
void ILI9488_RotConvert(int16_t *x, int16_t *y) {
|
||||
int16_t temp;
|
||||
if (renderer) {
|
||||
uint8_t rot=renderer->getRotation();
|
||||
switch (rot) {
|
||||
case 0:
|
||||
temp=*y;
|
||||
*y=renderer->height()-*x;
|
||||
*x=temp;
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
case 3:
|
||||
temp=*y;
|
||||
*y=*x;
|
||||
*x=renderer->width()-temp;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// no hit
|
||||
for (uint8_t count=0; count<MAXBUTTONS; count++) {
|
||||
if (buttons[count]) {
|
||||
uint8_t bflags=buttons[count]->vpower&0x7f;
|
||||
buttons[count]->press(false);
|
||||
if (buttons[count]->justReleased()) {
|
||||
uint8_t bflags=buttons[count]->vpower&0x7f;
|
||||
if (bflags>0) {
|
||||
if (bflags>1) {
|
||||
// push button
|
||||
buttons[count]->vpower&=0x7f;
|
||||
ILI9488_MQTT(count,"PBT");
|
||||
}
|
||||
buttons[count]->xdrawButton(buttons[count]->vpower&0x80);
|
||||
}
|
||||
}
|
||||
if (!bflags) {
|
||||
// check if power button stage changed
|
||||
uint8_t pwr=bitRead(power,rbutt);
|
||||
uint8_t vpwr=(buttons[count]->vpower&0x80)>>7;
|
||||
if (pwr!=vpwr) {
|
||||
ILI9488_RDW_BUTT(count,pwr);
|
||||
}
|
||||
rbutt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
ili9488_pLoc.x=0;
|
||||
ili9488_pLoc.y=0;
|
||||
}
|
||||
}
|
||||
|
||||
// check digitizer hit
|
||||
void ILI9488_CheckTouch(void) {
|
||||
ili9488_ctouch_counter++;
|
||||
if (2 == ili9488_ctouch_counter) {
|
||||
// every 100 ms should be enough
|
||||
ili9488_ctouch_counter = 0;
|
||||
Touch_Check(ILI9488_RotConvert);
|
||||
}
|
||||
}
|
||||
#endif // USE_TOUCH_BUTTONS
|
||||
#endif // USE_FT5206
|
||||
|
||||
|
||||
/*********************************************************************************************/
|
||||
/*********************************************************************************************\
|
||||
* Interface
|
||||
@ -270,7 +179,9 @@ bool Xdsp08(uint8_t function)
|
||||
break;
|
||||
case FUNC_DISPLAY_EVERY_50_MSECOND:
|
||||
#ifdef USE_TOUCH_BUTTONS
|
||||
if (FT6236_found) FT6236Check();
|
||||
if (FT5206_found) {
|
||||
ILI9488_CheckTouch();
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
@ -27,29 +27,17 @@
|
||||
#define COLORED 1
|
||||
#define UNCOLORED 0
|
||||
|
||||
// touch panel controller
|
||||
#define FT5316_address 0x38
|
||||
|
||||
// using font 8 is opional (num=3)
|
||||
// very badly readable, but may be useful for graphs
|
||||
#define USE_TINY_FONT
|
||||
|
||||
#include <RA8876.h>
|
||||
#include <FT6236.h>
|
||||
|
||||
TouchLocation ra8876_pLoc;
|
||||
uint8_t ra8876_ctouch_counter = 0;
|
||||
|
||||
#ifdef USE_TOUCH_BUTTONS
|
||||
extern VButton *buttons[];
|
||||
#endif
|
||||
|
||||
extern uint8_t *buffer;
|
||||
extern uint8_t color_type;
|
||||
RA8876 *ra8876;
|
||||
|
||||
uint8_t FT5316_found;
|
||||
|
||||
/*********************************************************************************************/
|
||||
void RA8876_InitDriver()
|
||||
{
|
||||
@ -114,147 +102,41 @@ void RA8876_InitDriver()
|
||||
#endif
|
||||
color_type = COLOR_COLOR;
|
||||
|
||||
if (I2cEnabled(XI2C_39) && I2cSetDevice(FT5316_address)) {
|
||||
FT6236begin(FT5316_address);
|
||||
FT5316_found=1;
|
||||
I2cSetActiveFound(FT5316_address, "FT5316");
|
||||
} else {
|
||||
FT5316_found=0;
|
||||
}
|
||||
#ifdef USE_FT5206
|
||||
Touch_Init(Wire);
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_TOUCH_BUTTONS
|
||||
void RA8876_MQTT(uint8_t count,const char *cp) {
|
||||
ResponseTime_P(PSTR(",\"RA8876\":{\"%s%d\":\"%d\"}}"), cp,count+1,(buttons[count]->vpower&0x80)>>7);
|
||||
MqttPublishTeleSensor();
|
||||
}
|
||||
|
||||
void RA8876_RDW_BUTT(uint32_t count,uint32_t pwr) {
|
||||
buttons[count]->xdrawButton(pwr);
|
||||
if (pwr) buttons[count]->vpower|=0x80;
|
||||
else buttons[count]->vpower&=0x7f;
|
||||
#ifdef USE_FT5206
|
||||
#ifdef USE_TOUCH_BUTTONS
|
||||
|
||||
// no rotation support
|
||||
void RA8876_RotConvert(int16_t *x, int16_t *y) {
|
||||
int16_t temp;
|
||||
if (renderer) {
|
||||
*x=*x*renderer->width()/800;
|
||||
*y=*y*renderer->height()/480;
|
||||
|
||||
*x = renderer->width() - *x;
|
||||
*y = renderer->height() - *y;
|
||||
}
|
||||
}
|
||||
|
||||
// check digitizer hit
|
||||
void FT5316Check() {
|
||||
uint16_t temp;
|
||||
uint8_t rbutt=0,vbutt=0;
|
||||
ra8876_ctouch_counter++;
|
||||
if (2 == ra8876_ctouch_counter) {
|
||||
// every 100 ms should be enough
|
||||
ra8876_ctouch_counter=0;
|
||||
// panel has 800x480
|
||||
if (FT6236readTouchLocation(&ra8876_pLoc,1)) {
|
||||
ra8876_pLoc.x=ra8876_pLoc.x*RA8876_TFTWIDTH/800;
|
||||
ra8876_pLoc.y=ra8876_pLoc.y*RA8876_TFTHEIGHT/480;
|
||||
// did find a hit
|
||||
|
||||
if (renderer) {
|
||||
|
||||
// rotation not supported
|
||||
ra8876_pLoc.x=RA8876_TFTWIDTH-ra8876_pLoc.x;
|
||||
ra8876_pLoc.y=RA8876_TFTHEIGHT-ra8876_pLoc.y;
|
||||
|
||||
/*
|
||||
uint8_t rot=renderer->getRotation();
|
||||
switch (rot) {
|
||||
case 0:
|
||||
//temp=pLoc.y;
|
||||
pLoc.x=renderer->width()-pLoc.x;
|
||||
pLoc.y=renderer->height()-pLoc.y;
|
||||
//pLoc.x=temp;
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
case 3:
|
||||
temp=pLoc.y;
|
||||
pLoc.y=pLoc.x;
|
||||
pLoc.x=renderer->width()-temp;
|
||||
break;
|
||||
}
|
||||
*/
|
||||
//AddLog_P2(LOG_LEVEL_INFO, PSTR(">> %d,%d"),ra8876_pLoc.x,ra8876_pLoc.y);
|
||||
|
||||
|
||||
//Serial.printf("loc x: %d , loc y: %d\n",pLoc.x,pLoc.y);
|
||||
|
||||
// now must compare with defined buttons
|
||||
for (uint8_t count=0; count<MAXBUTTONS; count++) {
|
||||
if (buttons[count]) {
|
||||
uint8_t bflags=buttons[count]->vpower&0x7f;
|
||||
if (buttons[count]->contains(ra8876_pLoc.x,ra8876_pLoc.y)) {
|
||||
// did hit
|
||||
buttons[count]->press(true);
|
||||
if (buttons[count]->justPressed()) {
|
||||
if (!bflags) {
|
||||
// real button
|
||||
uint8_t pwr=bitRead(power,rbutt);
|
||||
if (!SendKey(KEY_BUTTON, rbutt+1, POWER_TOGGLE)) {
|
||||
ExecuteCommandPower(rbutt+1, POWER_TOGGLE, SRC_BUTTON);
|
||||
RA8876_RDW_BUTT(count,!pwr);
|
||||
}
|
||||
} else {
|
||||
// virtual button
|
||||
const char *cp;
|
||||
if (bflags==1) {
|
||||
// toggle button
|
||||
buttons[count]->vpower^=0x80;
|
||||
cp="TBT";
|
||||
} else {
|
||||
// push button
|
||||
buttons[count]->vpower|=0x80;
|
||||
cp="PBT";
|
||||
}
|
||||
buttons[count]->xdrawButton(buttons[count]->vpower&0x80);
|
||||
RA8876_MQTT(count,cp);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!bflags) {
|
||||
rbutt++;
|
||||
} else {
|
||||
vbutt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// no hit
|
||||
for (uint8_t count=0; count<MAXBUTTONS; count++) {
|
||||
if (buttons[count]) {
|
||||
uint8_t bflags=buttons[count]->vpower&0x7f;
|
||||
buttons[count]->press(false);
|
||||
if (buttons[count]->justReleased()) {
|
||||
if (bflags>0) {
|
||||
if (bflags>1) {
|
||||
// push button
|
||||
buttons[count]->vpower&=0x7f;
|
||||
RA8876_MQTT(count,"PBT");
|
||||
}
|
||||
buttons[count]->xdrawButton(buttons[count]->vpower&0x80);
|
||||
}
|
||||
}
|
||||
if (!bflags) {
|
||||
// check if power button stage changed
|
||||
uint8_t pwr=bitRead(power,rbutt);
|
||||
uint8_t vpwr=(buttons[count]->vpower&0x80)>>7;
|
||||
if (pwr!=vpwr) {
|
||||
RA8876_RDW_BUTT(count,pwr);
|
||||
}
|
||||
rbutt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
ra8876_pLoc.x=0;
|
||||
ra8876_pLoc.y=0;
|
||||
void RA8876_CheckTouch(void) {
|
||||
ra8876_ctouch_counter++;
|
||||
if (2 == ra8876_ctouch_counter) {
|
||||
// every 100 ms should be enough
|
||||
ra8876_ctouch_counter = 0;
|
||||
Touch_Check(RA8876_RotConvert);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // USE_TOUCH_BUTTONS
|
||||
#endif // USE_TOUCH_BUTTONS
|
||||
#endif // USE_FT5206
|
||||
|
||||
/*
|
||||
void testall() {
|
||||
ra8876->clearScreen(0);
|
||||
@ -452,8 +334,8 @@ bool Xdsp10(uint8_t function)
|
||||
result = true;
|
||||
break;
|
||||
case FUNC_DISPLAY_EVERY_50_MSECOND:
|
||||
#ifdef USE_TOUCH_BUTTONS
|
||||
if (FT5316_found) FT5316Check();
|
||||
#ifdef USE_FT5206
|
||||
if (FT5206_found) RA8876_CheckTouch();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//#ifdef USE_SPI
|
||||
#ifdef USE_SPI
|
||||
#ifdef USE_DISPLAY
|
||||
#ifdef USE_DISPLAY_ST7789
|
||||
@ -50,12 +51,6 @@ extern uint8_t color_type;
|
||||
Arduino_ST7789 *st7789;
|
||||
|
||||
#ifdef USE_FT5206
|
||||
#ifdef USE_TOUCH_BUTTONS
|
||||
extern VButton *buttons[];
|
||||
#endif
|
||||
FT5206_Class *touchp;
|
||||
uint8_t FT5206_found;
|
||||
TP_Point st7789_pLoc;
|
||||
uint8_t st7789_ctouch_counter = 0;
|
||||
#endif // USE_FT5206
|
||||
|
||||
@ -142,155 +137,51 @@ void ST7789_InitDriver()
|
||||
#define SDA_2 23
|
||||
#define SCL_2 32
|
||||
Wire1.begin(SDA_2, SCL_2, 400000);
|
||||
touchp = new FT5206_Class();
|
||||
if (touchp->begin(Wire1, FT5206_address)) {
|
||||
FT5206_found=1;
|
||||
//I2cSetDevice(FT5206_address);
|
||||
I2cSetActiveFound(FT5206_address, "FT5206");
|
||||
} else {
|
||||
FT5206_found=0;
|
||||
}
|
||||
Touch_Init(Wire1);
|
||||
#endif // USE_FT5206
|
||||
#endif // ESP32
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef ESP32
|
||||
#ifdef USE_FT5206
|
||||
#ifdef USE_TOUCH_BUTTONS
|
||||
void ST7789_MQTT(uint8_t count,const char *cp) {
|
||||
ResponseTime_P(PSTR(",\"ST7789\":{\"%s%d\":\"%d\"}}"), cp,count+1,(buttons[count]->vpower&0x80)>>7);
|
||||
MqttPublishTeleSensor();
|
||||
}
|
||||
|
||||
uint32_t FT5206_touched(uint32_t sel) {
|
||||
if (touchp) {
|
||||
switch (sel) {
|
||||
void ST7789_RotConvert(int16_t *x, int16_t *y) {
|
||||
int16_t temp;
|
||||
if (renderer) {
|
||||
uint8_t rot=renderer->getRotation();
|
||||
switch (rot) {
|
||||
case 0:
|
||||
return touchp->touched();
|
||||
break;
|
||||
case 1:
|
||||
return st7789_pLoc.x;
|
||||
temp=*y;
|
||||
*y=renderer->height()-*x;
|
||||
*x=temp;
|
||||
break;
|
||||
case 2:
|
||||
return st7789_pLoc.y;
|
||||
*x=renderer->width()-*x;
|
||||
*y=renderer->height()-*y;
|
||||
break;
|
||||
case 3:
|
||||
temp=*y;
|
||||
*y=*x;
|
||||
*x=renderer->width()-temp;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ST7789_RDW_BUTT(uint32_t count,uint32_t pwr) {
|
||||
buttons[count]->xdrawButton(pwr);
|
||||
if (pwr) buttons[count]->vpower|=0x80;
|
||||
else buttons[count]->vpower&=0x7f;
|
||||
}
|
||||
// check digitizer hit
|
||||
void FT5206Check() {
|
||||
uint16_t temp;
|
||||
uint8_t rbutt=0,vbutt=0;
|
||||
void ST7789_CheckTouch() {
|
||||
st7789_ctouch_counter++;
|
||||
if (2 == st7789_ctouch_counter) {
|
||||
// every 100 ms should be enough
|
||||
st7789_ctouch_counter=0;
|
||||
|
||||
if (touchp->touched()) {
|
||||
// did find a hit
|
||||
st7789_pLoc = touchp->getPoint(0);
|
||||
if (renderer) {
|
||||
uint8_t rot=renderer->getRotation();
|
||||
switch (rot) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
temp=st7789_pLoc.y;
|
||||
st7789_pLoc.y=renderer->height()-st7789_pLoc.x;
|
||||
st7789_pLoc.x=temp;
|
||||
break;
|
||||
case 2:
|
||||
st7789_pLoc.x=renderer->width()-st7789_pLoc.x;
|
||||
st7789_pLoc.y=renderer->height()-st7789_pLoc.y;
|
||||
break;
|
||||
case 3:
|
||||
temp=st7789_pLoc.y;
|
||||
st7789_pLoc.y=st7789_pLoc.x;
|
||||
st7789_pLoc.x=renderer->width()-temp;
|
||||
break;
|
||||
}
|
||||
//AddLog_P2(LOG_LEVEL_INFO, PSTR("touch %d - %d"), st7789_pLoc.x, st7789_pLoc.y);
|
||||
// now must compare with defined buttons
|
||||
for (uint8_t count=0; count<MAXBUTTONS; count++) {
|
||||
if (buttons[count]) {
|
||||
uint8_t bflags=buttons[count]->vpower&0x7f;
|
||||
if (buttons[count]->contains(st7789_pLoc.x,st7789_pLoc.y)) {
|
||||
// did hit
|
||||
buttons[count]->press(true);
|
||||
if (buttons[count]->justPressed()) {
|
||||
if (!bflags) {
|
||||
uint8_t pwr=bitRead(power,rbutt);
|
||||
if (!SendKey(KEY_BUTTON, rbutt+1, POWER_TOGGLE)) {
|
||||
ExecuteCommandPower(rbutt+1, POWER_TOGGLE, SRC_BUTTON);
|
||||
ST7789_RDW_BUTT(count,!pwr);
|
||||
}
|
||||
} else {
|
||||
// virtual button
|
||||
const char *cp;
|
||||
if (bflags==1) {
|
||||
// toggle button
|
||||
buttons[count]->vpower^=0x80;
|
||||
cp="TBT";
|
||||
} else {
|
||||
// push button
|
||||
buttons[count]->vpower|=0x80;
|
||||
cp="PBT";
|
||||
}
|
||||
buttons[count]->xdrawButton(buttons[count]->vpower&0x80);
|
||||
ST7789_MQTT(count,cp);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!bflags) {
|
||||
rbutt++;
|
||||
} else {
|
||||
vbutt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// no hit
|
||||
for (uint8_t count=0; count<MAXBUTTONS; count++) {
|
||||
if (buttons[count]) {
|
||||
uint8_t bflags=buttons[count]->vpower&0x7f;
|
||||
buttons[count]->press(false);
|
||||
if (buttons[count]->justReleased()) {
|
||||
uint8_t bflags=buttons[count]->vpower&0x7f;
|
||||
if (bflags>0) {
|
||||
if (bflags>1) {
|
||||
// push button
|
||||
buttons[count]->vpower&=0x7f;
|
||||
ST7789_MQTT(count,"PBT");
|
||||
}
|
||||
buttons[count]->xdrawButton(buttons[count]->vpower&0x80);
|
||||
}
|
||||
}
|
||||
if (!bflags) {
|
||||
// check if power button stage changed
|
||||
uint8_t pwr=bitRead(power,rbutt);
|
||||
uint8_t vpwr=(buttons[count]->vpower&0x80)>>7;
|
||||
if (pwr!=vpwr) {
|
||||
ST7789_RDW_BUTT(count,pwr);
|
||||
}
|
||||
rbutt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
st7789_pLoc.x=0;
|
||||
st7789_pLoc.y=0;
|
||||
if (2 == st7789_ctouch_counter) {
|
||||
// every 100 ms should be enough
|
||||
st7789_ctouch_counter = 0;
|
||||
Touch_Check(ST7789_RotConvert);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // USE_TOUCH_BUTTONS
|
||||
#endif // USE_FT5206
|
||||
#endif // ESP32
|
||||
@ -317,7 +208,7 @@ bool Xdsp12(uint8_t function)
|
||||
#ifdef USE_FT5206
|
||||
#ifdef USE_TOUCH_BUTTONS
|
||||
if (FT5206_found) {
|
||||
FT5206Check();
|
||||
ST7789_CheckTouch();
|
||||
}
|
||||
#endif
|
||||
#endif // USE_FT5206
|
||||
|
@ -31,15 +31,8 @@
|
||||
#define D_NAME_AS3935 "AS3935"
|
||||
#define AS3935_ADDR 0x03
|
||||
|
||||
// Reg mask shift
|
||||
#define IRQ_TBL 0x03, 0x0F, 0
|
||||
#define ENERGY_RAW_1 0x04, 0xFF, 0
|
||||
#define ENERGY_RAW_2 0x05, 0xFF, 0
|
||||
#define ENERGY_RAW_3 0x06, 0x1F, 0
|
||||
#define LGHT_DIST 0x07, 0x3F, 0
|
||||
#define DISP_TRCO 0x08, 0x20, 5
|
||||
#define DISP_LCO 0x08, 0x80, 7
|
||||
#define TUNE_CAPS 0x08, 0x0F, 0
|
||||
// I2C Registers Reg mask shift
|
||||
#define PWR_REG 0x00, 0x01, 0
|
||||
#define AFE_GB 0x00, 0x3E, 0
|
||||
#define WDTH 0x01, 0x0F, 0
|
||||
#define NF_LEVEL 0x01, 0x70, 4
|
||||
@ -47,12 +40,32 @@
|
||||
#define MIN_NUM_LIGH 0x02, 0x30, 4
|
||||
#define DISTURBER 0x03, 0x20, 5
|
||||
#define LCO_FDIV 0x03, 0xC0, 6
|
||||
#define IRQ_TBL 0x03, 0x0F, 0
|
||||
#define ENERGY_RAW_1 0x04, 0xFF, 0
|
||||
#define ENERGY_RAW_2 0x05, 0xFF, 0
|
||||
#define ENERGY_RAW_3 0x06, 0x1F, 0
|
||||
#define LGHT_DIST 0x07, 0x3F, 0
|
||||
#define DISP_TRCO 0x08, 0x20, 5 // should 31.250 kHz with devide 16
|
||||
#define DISP_SRCO 0x08, 0x40, 6 // 1,1 MHz
|
||||
#define DISP_LCO 0x08, 0x80, 7 // 32.768 kHz
|
||||
#define TUNE_CAPS 0x08, 0x0F, 0
|
||||
#define CAL_TRCO_NOK 0x3A, 0x40, 6 // 1 = NOK
|
||||
#define CAL_TRCO_DONE 0x3A, 0x80, 7 // 0 = OK
|
||||
#define CAL_SRCO_NOK 0x3B, 0x40, 6
|
||||
#define CAL_SRCO_DONE 0x3B, 0x80, 7
|
||||
|
||||
// I2C Commands
|
||||
#define RESET_DEFAULT 0x3C, 0x96
|
||||
#define CALIBATE_RCO 0x3D, 0x96
|
||||
|
||||
// NF-Level
|
||||
#define INDOORS 0x24
|
||||
#define OUTDOORS 0x1C
|
||||
|
||||
// Global
|
||||
const char HTTP_SNS_UNIT_KILOMETER[] PROGMEM = D_UNIT_KILOMETER;
|
||||
// Load Settings Mask
|
||||
#define SETREG00MASK 0x3E // For Power On
|
||||
#define SETREG03MASK 0xF0 // For LCO and Disturber
|
||||
|
||||
// Http
|
||||
const char HTTP_SNS_AS3935_ENERGY[] PROGMEM = "{s}" D_NAME_AS3935 " " D_AS3935_ENERGY " {m}%d{e}";
|
||||
const char HTTP_SNS_AS3935_DISTANZ[] PROGMEM = "{s}" D_NAME_AS3935 " " D_AS3935_DISTANCE " {m}%u " D_UNIT_KILOMETER "{e}";
|
||||
@ -66,15 +79,18 @@ const char HTTP_SNS_AS3935_DIST_ON[] PROGMEM = "{s}%s " D_AS3935_DISTURBER " {m}
|
||||
const char HTTP_SNS_AS3935_DIST_OFF[] PROGMEM = "{s}%s " D_AS3935_DISTURBER " {m}" D_AS3935_OFF " {e}";
|
||||
const char* const HTTP_SNS_AS3935_DISTURBER[] PROGMEM = {HTTP_SNS_AS3935_DIST_OFF, HTTP_SNS_AS3935_DIST_ON};
|
||||
// http Messages
|
||||
const char HTTP_SNS_AS3935_EMPTY[] PROGMEM = "{s}%s: " D_AS3935_NOMESS "{e}";
|
||||
const char HTTP_SNS_AS3935_OUT[] PROGMEM = "{s}%s: " D_AS3935_OUT "{e}";
|
||||
const char HTTP_SNS_AS3935_NOT[] PROGMEM = "{s}%s: " D_AS3935_NOT "{e}";
|
||||
const char HTTP_SNS_AS3935_ABOVE[] PROGMEM = "{s}%s: " D_AS3935_ABOVE "{e}";
|
||||
const char HTTP_SNS_AS3935_NOISE[] PROGMEM = "{s}%s: " D_AS3935_NOISE "{e}";
|
||||
const char HTTP_SNS_AS3935_DISTURB[] PROGMEM = "{s}%s: " D_AS3935_DISTDET "{e}";
|
||||
const char HTTP_SNS_AS3935_INTNOEV[] PROGMEM = "{s}%s: " D_AS3935_INTNOEV "{e}";
|
||||
const char HTTP_SNS_AS3935_MSG[] PROGMEM = "{s}%s: " D_AS3935_LIGHT " " D_AS3935_APRX " %d " D_UNIT_KILOMETER " " D_AS3935_AWAY "{e}";
|
||||
const char* const HTTP_SNS_AS3935_TABLE_1[] PROGMEM = { HTTP_SNS_AS3935_EMPTY, HTTP_SNS_AS3935_MSG, HTTP_SNS_AS3935_OUT, HTTP_SNS_AS3935_NOT, HTTP_SNS_AS3935_ABOVE, HTTP_SNS_AS3935_NOISE, HTTP_SNS_AS3935_DISTURB, HTTP_SNS_AS3935_INTNOEV };
|
||||
const char HTTP_SNS_AS3935_EMPTY[] PROGMEM = "{s}%s " D_AS3935_NOMESS "{e}";
|
||||
const char HTTP_SNS_AS3935_OUT[] PROGMEM = "{s}%s " D_AS3935_OUT "{e}";
|
||||
const char HTTP_SNS_AS3935_NOT[] PROGMEM = "{s}%s " D_AS3935_NOT "{e}";
|
||||
const char HTTP_SNS_AS3935_ABOVE[] PROGMEM = "{s}%s " D_AS3935_ABOVE "{e}";
|
||||
const char HTTP_SNS_AS3935_NOISE[] PROGMEM = "{s}%s " D_AS3935_NOISE "{e}";
|
||||
const char HTTP_SNS_AS3935_DISTURB[] PROGMEM = "{s}%s " D_AS3935_DISTDET "{e}";
|
||||
const char HTTP_SNS_AS3935_INTNOEV[] PROGMEM = "{s}%s " D_AS3935_INTNOEV "{e}";
|
||||
const char HTTP_SNS_AS3935_FLICKER[] PROGMEM = "{s}%s " D_AS3935_FLICKER "{e}";
|
||||
const char HTTP_SNS_AS3935_POWEROFF[] PROGMEM = "{s}%s " D_AS3935_POWEROFF "{e}";
|
||||
|
||||
const char HTTP_SNS_AS3935_MSG[] PROGMEM = "{s}%s " D_AS3935_LIGHT " " D_AS3935_APRX " %d " D_UNIT_KILOMETER " " D_AS3935_AWAY "{e}";
|
||||
const char* const HTTP_SNS_AS3935_TABLE_1[] PROGMEM = { HTTP_SNS_AS3935_EMPTY, HTTP_SNS_AS3935_MSG, HTTP_SNS_AS3935_OUT, HTTP_SNS_AS3935_NOT, HTTP_SNS_AS3935_ABOVE, HTTP_SNS_AS3935_NOISE, HTTP_SNS_AS3935_DISTURB, HTTP_SNS_AS3935_INTNOEV, HTTP_SNS_AS3935_FLICKER, HTTP_SNS_AS3935_POWEROFF };
|
||||
// Json
|
||||
const char JSON_SNS_AS3935_EVENTS[] PROGMEM = ",\"%s\":{\"" D_JSON_EVENT "\":%d,\"" D_JSON_DISTANCE "\":%d,\"" D_JSON_ENERGY "\":%u,\"" D_JSON_STAGE "\":%d}";
|
||||
// Json Command
|
||||
@ -84,13 +100,17 @@ const char* const S_JSON_AS3935_COMMAND_CAL[] PROGMEM = {"" D_AS3935_CAL_FAIL ""
|
||||
|
||||
const char S_JSON_AS3935_COMMAND_STRING[] PROGMEM = "{\"" D_NAME_AS3935 "\":{\"%s\":%s}}";
|
||||
const char S_JSON_AS3935_COMMAND_NVALUE[] PROGMEM = "{\"" D_NAME_AS3935 "\":{\"%s\":%d}}";
|
||||
const char S_JSON_AS3935_COMMAND_SETTINGS[] PROGMEM = "{\"" D_NAME_AS3935 "\":{\"Gain\":%s,\"NFfloor\":%d,\"uVrms\":%d,\"Tunecaps\":%d,\"MinNumLight\":%d,\"Rejektion\":%d,\"Wdthreshold\":%d,\"MinNFstage\":%d,\"NFAutoTime\":%d,\"DisturberAutoTime\":%d,\"Disturber\":%s,\"NFauto\":%s,\"Disturberauto\":%s,\"NFautomax\":%s,\"Mqttlightevent\":%s}}";
|
||||
const char S_JSON_AS3935_COMMAND_SETTINGS[] PROGMEM = "{\"AS3935_Settings\":{\"Gain\":%s,\"NFfloor\":%d,\"uVrms\":%d,\"Tunecaps\":%d,\"MinNumLight\":%d,\"Rejektion\":%d,\"Wdthreshold\":%d,\"MinNFstage\":%d,\"NFAutoTime\":%d,\"DisturberAutoTime\":%d,\"Disturber\":%s,\"NFauto\":%s,\"Disturberauto\":%s,\"NFautomax\":%s,\"Mqttlightevent\":%s,\"Mqttnoirqevent\":%s}}";
|
||||
|
||||
const char kAS3935_Commands[] PROGMEM = "setnf|setminstage|setml|default|setgain|settunecaps|setrej|setwdth|disttime|nftime|disturber|autonf|autodisturber|autonfmax|mqttevent|settings|calibrate";
|
||||
const char kAS3935_Commands[] PROGMEM = "power|setnf|setminstage|setml|default|setgain|settunecaps|setrej|setwdth|disttime|nftime|disturber|autonf|autodisturber|autonfmax|lightevent|noirqevent|settings|calibrate";
|
||||
|
||||
const uint8_t AS3935_VrmsIndoor[] PROGMEM = { 28, 45, 62, 78, 95, 112, 130, 146 };
|
||||
const uint16_t AS3935_VrmsOutdoor[] PROGMEM = { 390, 630, 860, 1100, 1140, 1570, 1800, 2000 };
|
||||
|
||||
enum AS3935_Commands { // commands for Console
|
||||
CMND_AS3935_POWER, // Power on/off the device (1 Bit)
|
||||
CMND_AS3935_SET_NF, // Noise Floor Level, value from 0-7 (3 Bit)
|
||||
CMND_AS3935_SET_MINNF, // Set Min Noise Floor Level when Autotune is active Value von 0-15
|
||||
CMND_AS3935_SET_MINNF, // Set Min Noise Floor Level when Autotune is active Value from 0-15
|
||||
CMND_AS3935_SET_MINLIGHT, // Minimum number of lightning 0=1/1=5/2=9/3=16 Lightnings
|
||||
CMND_AS3935_SET_DEF, // set default for Sensor and Settings
|
||||
CMND_AS3935_SET_GAIN, // Set Inddoor/Outdoor
|
||||
@ -104,24 +124,25 @@ enum AS3935_Commands { // commands for Console
|
||||
CMND_AS3935_DIST_AUTOTUNE, // Autotune Disturber on/off
|
||||
CMND_AS3935_NF_ATUNE_BOTH, // Autotune over both Areas: INDOORS/OUDOORS
|
||||
CMND_AS3935_MQTT_LIGHT_EVT, // mqtt only if lightning Irq
|
||||
CMND_AS3935_MQTT_NO_IRQ_EVT, // suppress mqtt "IRQ with no Event"
|
||||
CMND_AS3935_SETTINGS, // Json output of all settings
|
||||
CMND_AS3935_CALIBRATE // caps autocalibrate
|
||||
};
|
||||
};
|
||||
|
||||
struct AS3935STRUCT
|
||||
{
|
||||
bool autodist_activ = false;
|
||||
struct {
|
||||
bool active = false;
|
||||
bool http_count_start = false;
|
||||
bool poweroff = false;
|
||||
volatile bool detected = false;
|
||||
volatile bool dispLCO = 0;
|
||||
uint8_t icount = 0;
|
||||
volatile bool dispLCO = false;
|
||||
volatile uint8_t icount = 0;
|
||||
uint8_t irq = 0;
|
||||
uint8_t mqtt_irq = 0;
|
||||
uint8_t http_irq = 0;
|
||||
uint8_t http_count_start = 0;
|
||||
uint8_t mqtt_event = 0;
|
||||
uint8_t http_event = 0;
|
||||
uint8_t http_time = 0;
|
||||
uint8_t http_count = 0;
|
||||
int16_t http_distance = 0;
|
||||
int16_t distance = 0;
|
||||
uint16_t http_timer = 0;
|
||||
uint16_t http_count = 0;
|
||||
uint16_t nftimer = 0;
|
||||
uint16_t disttimer = 0;
|
||||
uint32_t intensity = 0;
|
||||
@ -129,16 +150,16 @@ struct AS3935STRUCT
|
||||
volatile uint32_t pulse = 0;
|
||||
} as3935_sensor;
|
||||
|
||||
uint8_t as3935_active = 0;
|
||||
|
||||
void ICACHE_RAM_ATTR AS3935Isr() {
|
||||
void ICACHE_RAM_ATTR AS3935Isr(void) {
|
||||
as3935_sensor.detected = true;
|
||||
as3935_sensor.icount++;
|
||||
}
|
||||
|
||||
// we have to store 5 Bytes in the eeprom. Register 8 is mapped to Byte 4
|
||||
uint8_t AS3935ReadRegister(uint8_t reg, uint8_t mask, uint8_t shift) {
|
||||
uint8_t data = I2cRead8(AS3935_ADDR, reg);
|
||||
if (reg == 0x08) Settings.as3935_sensor_cfg[4] = data;
|
||||
if (reg < 0x04) Settings.as3935_sensor_cfg[reg] = data;
|
||||
if (reg <= 0x03) Settings.as3935_sensor_cfg[reg] = data;
|
||||
return ((data & mask) >> shift);
|
||||
}
|
||||
|
||||
@ -150,12 +171,12 @@ void AS3935WriteRegister(uint8_t reg, uint8_t mask, uint8_t shift, uint8_t data)
|
||||
data |= currentReg;
|
||||
I2cWrite8(AS3935_ADDR, reg, data);
|
||||
if (reg == 0x08) Settings.as3935_sensor_cfg[4] = I2cRead8(AS3935_ADDR, reg);
|
||||
if (reg < 0x04) Settings.as3935_sensor_cfg[reg] = I2cRead8(AS3935_ADDR, reg);
|
||||
if (reg <= 0x03) Settings.as3935_sensor_cfg[reg] = I2cRead8(AS3935_ADDR, reg);
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
// Autotune Caps
|
||||
void ICACHE_RAM_ATTR AS3935CountFreq() {
|
||||
void ICACHE_RAM_ATTR AS3935CountFreq(void) {
|
||||
if (as3935_sensor.dispLCO)
|
||||
as3935_sensor.pulse++;
|
||||
}
|
||||
@ -163,52 +184,161 @@ void ICACHE_RAM_ATTR AS3935CountFreq() {
|
||||
bool AS3935AutoTuneCaps(uint8_t irqpin) {
|
||||
int32_t maxtune = 17500; // there max 3.5 % tol
|
||||
uint8_t besttune;
|
||||
uint8_t oldvalue = AS3935GetTuneCaps();
|
||||
AS3935WriteRegister(LCO_FDIV, 0); // Fdiv 16
|
||||
delay(2);
|
||||
for (uint8_t tune = 0; tune < 16; tune++) {
|
||||
AS3935WriteRegister(TUNE_CAPS, tune);
|
||||
delay(2);
|
||||
AS3935WriteRegister(DISP_LCO,1);
|
||||
AS3935WriteRegister(DISP_LCO, 1);
|
||||
delay(1);
|
||||
as3935_sensor.dispLCO = true;
|
||||
as3935_sensor.pulse = 0;
|
||||
attachInterrupt(digitalPinToInterrupt(irqpin), AS3935CountFreq, RISING);
|
||||
delay(200); // 100ms callback not work accurat for fequ. measure
|
||||
delay(50);
|
||||
as3935_sensor.dispLCO = false;
|
||||
detachInterrupt(irqpin);
|
||||
AS3935WriteRegister(DISP_LCO,0);
|
||||
int32_t currentfreq = 500000 - ((as3935_sensor.pulse * 5) * 16);
|
||||
AS3935WriteRegister(DISP_LCO, 0);
|
||||
int32_t currentfreq = 500000 - ((as3935_sensor.pulse * 20) * 16);
|
||||
if(currentfreq < 0) currentfreq = -currentfreq;
|
||||
if(maxtune > currentfreq) {
|
||||
maxtune = currentfreq;
|
||||
besttune = tune;
|
||||
}
|
||||
}
|
||||
if (maxtune >= 17500) // max. 3.5%
|
||||
if (maxtune >= 17500) { // max. 3.5%
|
||||
AS3935SetTuneCaps(oldvalue);
|
||||
return false;
|
||||
}
|
||||
AS3935SetTuneCaps(besttune);
|
||||
return true;
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
// functions
|
||||
void AS3935CalibrateRCO() {
|
||||
I2cWrite8(AS3935_ADDR, 0x3D, 0x96);
|
||||
AS3935WriteRegister(DISP_TRCO, 1);
|
||||
bool AS3935CalRCOResult(void) {
|
||||
if(AS3935ReadRegister(CAL_SRCO_NOK) || AS3935ReadRegister(CAL_TRCO_NOK)) {
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR("I2C: AS3935 Fatal Failure of TRCO or SRCO calibration"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AS3935CalibrateRCO(void) {
|
||||
detachInterrupt(Pin(GPIO_AS3935)); // Prevent AS3935Isr from RCO Calibration
|
||||
I2cWrite8(AS3935_ADDR, CALIBATE_RCO); // Cal TRCO & SRCO
|
||||
AS3935WriteRegister(DISP_TRCO, 1); // need for Power up
|
||||
delay(2);
|
||||
AS3935WriteRegister(DISP_TRCO, 0);
|
||||
if(!AS3935CalRCOResult())
|
||||
return false;
|
||||
attachInterrupt(digitalPinToInterrupt(Pin(GPIO_AS3935)), AS3935Isr, RISING);
|
||||
return true;
|
||||
}
|
||||
|
||||
void AS3935Reset(void) {
|
||||
I2cWrite8(AS3935_ADDR, RESET_DEFAULT);
|
||||
delay(2);
|
||||
}
|
||||
|
||||
void AS3935PwrDown(void) {
|
||||
AS3935WriteRegister(PWR_REG ,1);
|
||||
detachInterrupt(Pin(GPIO_AS3935));
|
||||
as3935_sensor.poweroff = true;
|
||||
as3935_sensor.mqtt_event = 9;
|
||||
as3935_sensor.http_event = 9;
|
||||
as3935_sensor.intensity = 0;
|
||||
as3935_sensor.distance = 0;
|
||||
}
|
||||
|
||||
void AS3935PwrUp(void) {
|
||||
AS3935WriteRegister(PWR_REG ,0);
|
||||
AS3935CalibrateRCO();
|
||||
as3935_sensor.poweroff = false;
|
||||
as3935_sensor.mqtt_event = 0;
|
||||
as3935_sensor.http_event = 0;
|
||||
}
|
||||
|
||||
uint8_t AS3935GetPwrStat(void) {
|
||||
if (AS3935ReadRegister(PWR_REG))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t AS3935GetIRQ(void) {
|
||||
delay(2);
|
||||
return AS3935ReadRegister(IRQ_TBL);
|
||||
}
|
||||
|
||||
uint8_t AS3935TranslIrq(uint8_t irq, uint8_t distance) {
|
||||
switch(irq) {
|
||||
case 0: return 7; // Interrupt with no IRQ
|
||||
case 1: return 5; // Noise level too high
|
||||
case 4: return 6; // Disturber detected
|
||||
case 8:
|
||||
if (distance == -1) return 2; // Lightning out of Distance
|
||||
else if (distance == 0) return 3; // Distance cannot be determined
|
||||
else if (distance == 1) return 4; // Storm is Overhead
|
||||
else return 1; // Lightning with Distance detected
|
||||
}
|
||||
return 0; // Fix GCC 10.1 warning
|
||||
}
|
||||
|
||||
uint8_t AS3935GetDistance(void) {
|
||||
return AS3935ReadRegister(LGHT_DIST);
|
||||
}
|
||||
|
||||
int16_t AS3935CalcDistance(void) {
|
||||
uint8_t dist = AS3935GetDistance();
|
||||
switch (dist) {
|
||||
case 0x3F: return -1; // Out of Range
|
||||
case 0x00: return 0; // Distance cannot be determined
|
||||
case 0x01: return 1; // Storm is Overhead
|
||||
default:
|
||||
if (40 < dist) return 40; // limited because higher is not accurate
|
||||
return dist;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t AS3935GetIntensity(void) {
|
||||
uint32_t energy_raw = (AS3935ReadRegister(ENERGY_RAW_3) << 8);
|
||||
energy_raw |= AS3935ReadRegister(ENERGY_RAW_2);
|
||||
energy_raw <<= 8;
|
||||
energy_raw |= AS3935ReadRegister(ENERGY_RAW_1);
|
||||
return energy_raw;
|
||||
}
|
||||
|
||||
uint8_t AS3935GetTuneCaps(void) {
|
||||
return AS3935ReadRegister(TUNE_CAPS);
|
||||
}
|
||||
|
||||
void AS3935SetTuneCaps(uint8_t tune) {
|
||||
AS3935WriteRegister(TUNE_CAPS, tune);
|
||||
delay(2);
|
||||
AS3935CalibrateRCO();
|
||||
}
|
||||
|
||||
uint8_t AS3935GetDisturber(void) {
|
||||
return AS3935ReadRegister(DISTURBER);
|
||||
}
|
||||
|
||||
void AS3935SetDisturber(uint8_t stat) {
|
||||
AS3935WriteRegister(DISTURBER, stat);
|
||||
}
|
||||
|
||||
uint8_t AS3935GetMinLights(void) {
|
||||
return AS3935ReadRegister(MIN_NUM_LIGH);
|
||||
}
|
||||
|
||||
void AS3935SetMinLights(uint8_t stat) {
|
||||
AS3935WriteRegister(MIN_NUM_LIGH, stat);
|
||||
}
|
||||
|
||||
uint8_t AS3935TransMinLights(uint8_t min_lights) {
|
||||
if (5 > min_lights) {
|
||||
return 0;
|
||||
} else if (9 > min_lights) {
|
||||
return 1;
|
||||
} else if (16 > min_lights) {
|
||||
return 2;
|
||||
} else {
|
||||
return 3;
|
||||
}
|
||||
if (5 > min_lights) return 0;
|
||||
else if (9 > min_lights) return 1;
|
||||
else if (16 > min_lights) return 2;
|
||||
else return 3;
|
||||
}
|
||||
|
||||
uint8_t AS3935TranslMinLightsInt(uint8_t min_lights) {
|
||||
@ -221,146 +351,7 @@ uint8_t AS3935TranslMinLightsInt(uint8_t min_lights) {
|
||||
return 0; // Fix GCC 10.1 warning
|
||||
}
|
||||
|
||||
uint8_t AS3935TranslIrq(uint8_t irq, uint8_t distance) {
|
||||
switch(irq) {
|
||||
case 0: return 7; // Interrupt with no IRQ
|
||||
case 1: return 5; // Noise level too high
|
||||
case 4: return 6; // Disturber detected
|
||||
case 8:
|
||||
if (distance == -1) return 2; // Lightning out of Distance
|
||||
else if (distance == 0) return 3; // Distance cannot be determined
|
||||
else if (distance == 1) return 4; // Storm is Overhead
|
||||
else return 1; // Lightning with Distance detected
|
||||
}
|
||||
return 0; // Fix GCC 10.1 warning
|
||||
}
|
||||
|
||||
void AS3935CalcVrmsLevel(uint16_t &vrms, uint8_t &stage)
|
||||
{
|
||||
uint8_t room = AS3935GetGain();
|
||||
uint8_t nflev = AS3935GetNoiseFloor();
|
||||
if (room == 0x24)
|
||||
{
|
||||
switch (nflev){
|
||||
case 0x00:
|
||||
vrms = 28;
|
||||
break;
|
||||
case 0x01:
|
||||
vrms = 45;
|
||||
break;
|
||||
case 0x02:
|
||||
vrms = 62;
|
||||
break;
|
||||
case 0x03:
|
||||
vrms = 78;
|
||||
break;
|
||||
case 0x04:
|
||||
vrms = 95;
|
||||
break;
|
||||
case 0x05:
|
||||
vrms = 112;
|
||||
break;
|
||||
case 0x06:
|
||||
vrms = 130;
|
||||
break;
|
||||
case 0x07:
|
||||
vrms = 146;
|
||||
break;
|
||||
}
|
||||
stage = nflev;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (nflev)
|
||||
{
|
||||
case 0x00:
|
||||
vrms = 390;
|
||||
break;
|
||||
case 0x01:
|
||||
vrms = 630;
|
||||
break;
|
||||
case 0x02:
|
||||
vrms = 860;
|
||||
break;
|
||||
case 0x03:
|
||||
vrms = 1100;
|
||||
break;
|
||||
case 0x04:
|
||||
vrms = 1140;
|
||||
break;
|
||||
case 0x05:
|
||||
vrms = 1570;
|
||||
break;
|
||||
case 0x06:
|
||||
vrms = 1800;
|
||||
break;
|
||||
case 0x07:
|
||||
vrms = 2000;
|
||||
break;
|
||||
}
|
||||
stage = nflev + 8;
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
uint8_t AS3935GetIRQ() {
|
||||
delay(2);
|
||||
return AS3935ReadRegister(IRQ_TBL);
|
||||
}
|
||||
|
||||
uint8_t AS3935GetDistance() {
|
||||
return AS3935ReadRegister(LGHT_DIST);
|
||||
}
|
||||
|
||||
int16_t AS3935CalcDistance() {
|
||||
uint8_t dist = AS3935GetDistance();
|
||||
switch (dist) {
|
||||
case 0x3F: return -1; // Out of Range
|
||||
case 0x01: return 1; // Storm is Overhead
|
||||
case 0x00: return 0; // Distance cannot be determined
|
||||
default:
|
||||
if (40 < dist){
|
||||
return 40;// limited because higher is not accurate
|
||||
}
|
||||
return dist;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t AS3935GetIntensity() {
|
||||
uint32_t nrgy_raw = (AS3935ReadRegister(ENERGY_RAW_3) << 8);
|
||||
nrgy_raw |= AS3935ReadRegister(ENERGY_RAW_2);
|
||||
nrgy_raw <<= 8;
|
||||
nrgy_raw |= AS3935ReadRegister(ENERGY_RAW_1);
|
||||
return nrgy_raw;
|
||||
}
|
||||
|
||||
uint8_t AS3935GetTuneCaps() {
|
||||
return AS3935ReadRegister(TUNE_CAPS);
|
||||
}
|
||||
|
||||
void AS3935SetTuneCaps(uint8_t tune) {
|
||||
AS3935WriteRegister(TUNE_CAPS, tune);
|
||||
delay(2);
|
||||
AS3935CalibrateRCO();
|
||||
}
|
||||
|
||||
uint8_t AS3935GetDisturber() {
|
||||
return AS3935ReadRegister(DISTURBER);
|
||||
}
|
||||
|
||||
void AS3935SetDisturber(uint8_t stat) {
|
||||
AS3935WriteRegister(DISTURBER, stat);
|
||||
}
|
||||
|
||||
uint8_t AS3935GetMinLights() {
|
||||
return AS3935ReadRegister(MIN_NUM_LIGH);
|
||||
}
|
||||
|
||||
void AS3935SetMinLights(uint8_t stat) {
|
||||
AS3935WriteRegister(MIN_NUM_LIGH, stat);
|
||||
}
|
||||
|
||||
uint8_t AS3935GetNoiseFloor() {
|
||||
uint8_t AS3935GetNoiseFloor(void) {
|
||||
return AS3935ReadRegister(NF_LEVEL);
|
||||
}
|
||||
|
||||
@ -368,7 +359,7 @@ void AS3935SetNoiseFloor(uint8_t noise) {
|
||||
AS3935WriteRegister(NF_LEVEL , noise);
|
||||
}
|
||||
|
||||
uint8_t AS3935GetGain() {
|
||||
uint8_t AS3935GetGain(void) {
|
||||
if (AS3935ReadRegister(AFE_GB) == OUTDOORS)
|
||||
return OUTDOORS;
|
||||
return INDOORS;
|
||||
@ -378,13 +369,25 @@ void AS3935SetGain(uint8_t room) {
|
||||
AS3935WriteRegister(AFE_GB, room);
|
||||
}
|
||||
|
||||
uint8_t AS3935GetGainInt() {
|
||||
uint8_t AS3935GetGainInt(void) {
|
||||
if (AS3935ReadRegister(AFE_GB) == OUTDOORS)
|
||||
return 1;
|
||||
return 0;
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t AS3935GetSpikeRejection() {
|
||||
void AS3935CalcVrmsLevel(uint16_t &vrms, uint8_t &stage) {
|
||||
uint8_t room = AS3935GetGain();
|
||||
uint8_t nflev = AS3935GetNoiseFloor();
|
||||
if (room == INDOORS) {
|
||||
vrms = pgm_read_byte(AS3935_VrmsIndoor + nflev);
|
||||
stage = nflev;
|
||||
} else {
|
||||
vrms = pgm_read_word(AS3935_VrmsOutdoor + nflev);
|
||||
stage = nflev + 8;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t AS3935GetSpikeRejection(void) {
|
||||
return AS3935ReadRegister(SPIKE_REJECT);
|
||||
}
|
||||
|
||||
@ -392,7 +395,7 @@ void AS3935SetSpikeRejection(uint8_t rej) {
|
||||
AS3935WriteRegister(SPIKE_REJECT, rej);
|
||||
}
|
||||
|
||||
uint8_t AS3935GetWdth() {
|
||||
uint8_t AS3935GetWdth(void) {
|
||||
return AS3935ReadRegister(WDTH);
|
||||
}
|
||||
|
||||
@ -400,17 +403,15 @@ void AS3935SetWdth(uint8_t wdth) {
|
||||
AS3935WriteRegister(WDTH, wdth);
|
||||
}
|
||||
|
||||
bool AS3935AutoTune(){
|
||||
bool AS3935AutoTune(void) {
|
||||
detachInterrupt(Pin(GPIO_AS3935));
|
||||
bool result = AS3935AutoTuneCaps(Pin(GPIO_AS3935));
|
||||
attachInterrupt(digitalPinToInterrupt(Pin(GPIO_AS3935)), AS3935Isr, RISING);
|
||||
return result;
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
// Noise Floor autofunctions
|
||||
bool AS3935LowerNoiseFloor() {
|
||||
uint8_t noise = AS3935GetNoiseFloor();
|
||||
bool AS3935LowerNoiseFloor(void) {
|
||||
uint16_t vrms;
|
||||
uint8_t stage;
|
||||
AS3935CalcVrmsLevel(vrms, stage);
|
||||
@ -421,6 +422,7 @@ bool AS3935LowerNoiseFloor() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
uint8_t noise = AS3935GetNoiseFloor();
|
||||
if (0 < noise && stage > Settings.as3935_parameter.nf_autotune_min) {
|
||||
noise--;
|
||||
AS3935SetNoiseFloor(noise);
|
||||
@ -429,7 +431,7 @@ bool AS3935LowerNoiseFloor() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AS3935RaiseNoiseFloor() {
|
||||
bool AS3935RaiseNoiseFloor(void) {
|
||||
uint8_t noise = AS3935GetNoiseFloor();
|
||||
uint8_t room = AS3935GetGain();
|
||||
if (Settings.as3935_functions.nf_autotune_both) {
|
||||
@ -449,22 +451,25 @@ bool AS3935RaiseNoiseFloor() {
|
||||
|
||||
/********************************************************************************************/
|
||||
// init functions
|
||||
bool AS3935SetDefault() {
|
||||
I2cWrite8(AS3935_ADDR, 0x3C, 0x96); // Set default
|
||||
delay(2);
|
||||
bool AS3935SetDefault(void) {
|
||||
AS3935Reset();
|
||||
AS3935SetDisturber(1); // Disturber on by default
|
||||
AS3935SetNoiseFloor(7); // NF High on by default
|
||||
Settings.as3935_sensor_cfg[0] = I2cRead8(AS3935_ADDR, 0x00);
|
||||
Settings.as3935_sensor_cfg[1] = I2cRead8(AS3935_ADDR, 0x01);
|
||||
Settings.as3935_sensor_cfg[2] = I2cRead8(AS3935_ADDR, 0x02);
|
||||
Settings.as3935_sensor_cfg[3] = I2cRead8(AS3935_ADDR, 0x03);
|
||||
Settings.as3935_sensor_cfg[4] = I2cRead8(AS3935_ADDR, 0x08);
|
||||
// set all eeprom functions and values to default
|
||||
Settings.as3935_functions.data = 0x00;
|
||||
Settings.as3935_parameter.nf_autotune_min = 0x00;
|
||||
Settings.as3935_parameter.nf_autotune_time = 4;
|
||||
Settings.as3935_parameter.dist_autotune_time = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void AS3935InitSettings() {
|
||||
if(Settings.as3935_functions.nf_autotune){
|
||||
void AS3935InitSettings(void) {
|
||||
if(Settings.as3935_functions.nf_autotune) {
|
||||
if(Settings.as3935_parameter.nf_autotune_min) {
|
||||
if (Settings.as3935_parameter.nf_autotune_min > 7) {
|
||||
AS3935SetGain(OUTDOORS);
|
||||
@ -475,114 +480,137 @@ void AS3935InitSettings() {
|
||||
}
|
||||
}
|
||||
}
|
||||
I2cWrite8(AS3935_ADDR, 0x00, Settings.as3935_sensor_cfg[0]);
|
||||
I2cWrite8(AS3935_ADDR, 0x00, Settings.as3935_sensor_cfg[0] & SETREG00MASK);
|
||||
I2cWrite8(AS3935_ADDR, 0x01, Settings.as3935_sensor_cfg[1]);
|
||||
I2cWrite8(AS3935_ADDR, 0x02, Settings.as3935_sensor_cfg[2]);
|
||||
I2cWrite8(AS3935_ADDR, 0x03, Settings.as3935_sensor_cfg[3]);
|
||||
I2cWrite8(AS3935_ADDR, 0x03, Settings.as3935_sensor_cfg[3] & SETREG03MASK);
|
||||
I2cWrite8(AS3935_ADDR, 0x08, Settings.as3935_sensor_cfg[4]);
|
||||
delay(2);
|
||||
}
|
||||
|
||||
void AS3935Setup(void) {
|
||||
bool AS3935Setup(void) {
|
||||
if (Settings.as3935_sensor_cfg[0] == 0x00) {
|
||||
AS3935SetDefault();
|
||||
} else {
|
||||
AS3935InitSettings();
|
||||
}
|
||||
AS3935CalibrateRCO();
|
||||
return AS3935CalibrateRCO();
|
||||
}
|
||||
|
||||
bool AS3935init() {
|
||||
uint8_t ret = I2cRead8(AS3935_ADDR, 0x00);
|
||||
if(INDOORS == ret || OUTDOORS == ret) // 0x24
|
||||
bool AS3935init(void) {
|
||||
AS3935Reset();
|
||||
uint8_t afe_gb = I2cRead8(AS3935_ADDR, 0x00) & SETREG00MASK;
|
||||
if(INDOORS == afe_gb)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void AS3935Detect(void) {
|
||||
if (I2cActive(AS3935_ADDR)) return;
|
||||
if (AS3935init())
|
||||
{
|
||||
if (!I2cSetDevice(AS3935_ADDR)) return;
|
||||
if (AS3935init()) {
|
||||
I2cSetActiveFound(AS3935_ADDR, D_NAME_AS3935);
|
||||
pinMode(Pin(GPIO_AS3935), INPUT);
|
||||
attachInterrupt(digitalPinToInterrupt(Pin(GPIO_AS3935)), AS3935Isr, RISING);
|
||||
AS3935Setup();
|
||||
as3935_active = 1;
|
||||
if (PinUsed(GPIO_AS3935)) {
|
||||
pinMode(Pin(GPIO_AS3935), INPUT);
|
||||
if (!AS3935Setup()) return;
|
||||
as3935_sensor.active = true;
|
||||
} else {
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR("I2C: AS3935 GPIO Pin not defined!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AS3935EverySecond() {
|
||||
if (as3935_sensor.detected) {
|
||||
as3935_sensor.irq = AS3935GetIRQ(); // 1 =Noise, 4 = Disturber, 8 = storm
|
||||
switch (as3935_sensor.irq) {
|
||||
case 1:
|
||||
if (Settings.as3935_functions.nf_autotune) {
|
||||
if (AS3935RaiseNoiseFloor()) as3935_sensor.nftimer = 0;
|
||||
void AS3935EverySecond(void) {
|
||||
if (!as3935_sensor.poweroff) { // Power Off
|
||||
if (as3935_sensor.detected) {
|
||||
as3935_sensor.detected = false;
|
||||
as3935_sensor.irq = AS3935GetIRQ(); // 1 = Noise, 4 = Disturber, 8 = storm
|
||||
|
||||
if (10 > as3935_sensor.icount) {
|
||||
switch (as3935_sensor.irq) {
|
||||
case 1:
|
||||
if (Settings.as3935_functions.nf_autotune) {
|
||||
if (AS3935RaiseNoiseFloor())
|
||||
as3935_sensor.nftimer = 0;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (Settings.as3935_functions.dist_autotune) {
|
||||
AS3935SetDisturber(1);
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
as3935_sensor.intensity = AS3935GetIntensity();
|
||||
as3935_sensor.distance = AS3935CalcDistance();
|
||||
as3935_sensor.http_intensity = as3935_sensor.intensity;
|
||||
as3935_sensor.http_distance = as3935_sensor.distance;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (Settings.as3935_functions.dist_autotune) {
|
||||
AS3935SetDisturber(1);
|
||||
as3935_sensor.autodist_activ = true;
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
as3935_sensor.intensity = AS3935GetIntensity();
|
||||
as3935_sensor.distance = AS3935CalcDistance();
|
||||
as3935_sensor.http_intensity = as3935_sensor.intensity;
|
||||
as3935_sensor.http_distance = as3935_sensor.distance;
|
||||
break;
|
||||
}
|
||||
// http show
|
||||
as3935_sensor.http_irq = AS3935TranslIrq(as3935_sensor.irq, as3935_sensor.distance);
|
||||
// mqtt publish
|
||||
as3935_sensor.mqtt_irq = as3935_sensor.http_irq;
|
||||
switch (as3935_sensor.mqtt_irq) {
|
||||
// http show
|
||||
as3935_sensor.http_event = AS3935TranslIrq(as3935_sensor.irq, as3935_sensor.distance);
|
||||
} else {
|
||||
as3935_sensor.http_event = 8; // flicker detected
|
||||
}
|
||||
|
||||
// mqtt publish
|
||||
as3935_sensor.mqtt_event = as3935_sensor.http_event;
|
||||
|
||||
switch (as3935_sensor.mqtt_event) {
|
||||
case 5:
|
||||
case 6:
|
||||
if (!Settings.as3935_functions.mqtt_only_Light_Event) {
|
||||
if (!Settings.as3935_functions.mqtt_only_Light_Event) {
|
||||
MqttPublishSensor();
|
||||
as3935_sensor.http_timer = 10;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
as3935_sensor.http_timer = 60;
|
||||
as3935_sensor.http_time = 10;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
if (!Settings.as3935_functions.suppress_irq_no_Event) {
|
||||
MqttPublishSensor();
|
||||
as3935_sensor.http_time = 10;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
as3935_sensor.http_time = 30;
|
||||
MqttPublishSensor();
|
||||
}
|
||||
// clear mqtt events for Teleperiod
|
||||
as3935_sensor.intensity = 0;
|
||||
as3935_sensor.distance = 0;
|
||||
as3935_sensor.mqtt_irq = 0;
|
||||
// start http times
|
||||
as3935_sensor.http_count_start = 1;
|
||||
as3935_sensor.http_count = 0;
|
||||
as3935_sensor.icount++; // Int counter
|
||||
as3935_sensor.detected = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (as3935_sensor.http_count_start) as3935_sensor.http_count++;
|
||||
// clear Http
|
||||
if (as3935_sensor.http_count > as3935_sensor.http_timer) {
|
||||
as3935_sensor.http_count_start = 0;
|
||||
as3935_sensor.http_intensity = 0;
|
||||
as3935_sensor.http_distance = 0;
|
||||
as3935_sensor.http_irq = 0;
|
||||
}
|
||||
// Noise Floor Autotune function
|
||||
if (Settings.as3935_functions.nf_autotune) {
|
||||
as3935_sensor.nftimer++;
|
||||
if (as3935_sensor.nftimer > Settings.as3935_parameter.nf_autotune_time * 60) {
|
||||
AS3935LowerNoiseFloor();
|
||||
as3935_sensor.nftimer = 0;
|
||||
as3935_sensor.irq = 0;
|
||||
// clear mqtt events for Teleperiod
|
||||
as3935_sensor.intensity = 0;
|
||||
as3935_sensor.distance = 0;
|
||||
as3935_sensor.mqtt_event = 0;
|
||||
// start http times
|
||||
as3935_sensor.http_count_start = true;
|
||||
as3935_sensor.http_count = 0;
|
||||
}
|
||||
}
|
||||
// Disturber auto function
|
||||
if (Settings.as3935_functions.dist_autotune) {
|
||||
if (as3935_sensor.autodist_activ) as3935_sensor.disttimer++;
|
||||
if (as3935_sensor.disttimer >= Settings.as3935_parameter.dist_autotune_time * 60) {
|
||||
AS3935SetDisturber(0);
|
||||
as3935_sensor.disttimer = 0;
|
||||
as3935_sensor.autodist_activ = false;
|
||||
as3935_sensor.icount = 0;
|
||||
|
||||
// count http times
|
||||
if (as3935_sensor.http_count_start)
|
||||
as3935_sensor.http_count++;
|
||||
// clear Http Event
|
||||
if (as3935_sensor.http_count > as3935_sensor.http_time) {
|
||||
as3935_sensor.http_count_start = false;
|
||||
as3935_sensor.http_intensity = 0;
|
||||
as3935_sensor.http_distance = 0;
|
||||
as3935_sensor.http_event = 0;
|
||||
}
|
||||
// Noise Floor Autotune function
|
||||
if (Settings.as3935_functions.nf_autotune) {
|
||||
as3935_sensor.nftimer++;
|
||||
if (as3935_sensor.nftimer > Settings.as3935_parameter.nf_autotune_time * 60) {
|
||||
AS3935LowerNoiseFloor();
|
||||
as3935_sensor.nftimer = 0;
|
||||
}
|
||||
}
|
||||
// Disturber auto function
|
||||
if (Settings.as3935_functions.dist_autotune) {
|
||||
if (AS3935GetDisturber()) {
|
||||
as3935_sensor.disttimer++;
|
||||
}
|
||||
if (as3935_sensor.disttimer >= Settings.as3935_parameter.dist_autotune_time * 60) {
|
||||
AS3935SetDisturber(0);
|
||||
as3935_sensor.disttimer = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -593,6 +621,16 @@ bool AS3935Cmd(void) {
|
||||
if (!strncasecmp_P(XdrvMailbox.topic, PSTR(D_NAME_AS3935), name_len)) {
|
||||
uint32_t command_code = GetCommandCode(command, sizeof(command), XdrvMailbox.topic + name_len, kAS3935_Commands);
|
||||
switch (command_code) {
|
||||
case CMND_AS3935_POWER:
|
||||
if (XdrvMailbox.data_len) {
|
||||
if (!XdrvMailbox.payload) {
|
||||
AS3935PwrDown();
|
||||
} else {
|
||||
AS3935PwrUp();
|
||||
}
|
||||
}
|
||||
Response_P(S_JSON_AS3935_COMMAND_STRING, command, S_JSON_AS3935_COMMAND_ONOFF[AS3935GetPwrStat()]);
|
||||
break;
|
||||
case CMND_AS3935_SET_NF:
|
||||
if (XdrvMailbox.data_len) {
|
||||
if (15 >= XdrvMailbox.payload) {
|
||||
@ -712,6 +750,14 @@ bool AS3935Cmd(void) {
|
||||
}
|
||||
Response_P(S_JSON_AS3935_COMMAND_STRING, command, S_JSON_AS3935_COMMAND_ONOFF[Settings.as3935_functions.mqtt_only_Light_Event]);
|
||||
break;
|
||||
case CMND_AS3935_MQTT_NO_IRQ_EVT:
|
||||
if (XdrvMailbox.data_len) {
|
||||
if (2 > XdrvMailbox.payload) {
|
||||
Settings.as3935_functions.suppress_irq_no_Event = XdrvMailbox.payload;
|
||||
}
|
||||
}
|
||||
Response_P(S_JSON_AS3935_COMMAND_STRING, command, S_JSON_AS3935_COMMAND_ONOFF[Settings.as3935_functions.suppress_irq_no_Event]);
|
||||
break;
|
||||
case CMND_AS3935_SETTINGS: {
|
||||
if (!XdrvMailbox.data_len) {
|
||||
uint8_t gain = AS3935GetGainInt();
|
||||
@ -719,30 +765,31 @@ bool AS3935Cmd(void) {
|
||||
uint8_t stage;
|
||||
AS3935CalcVrmsLevel(vrms, stage);
|
||||
uint8_t nf_floor = AS3935GetNoiseFloor();
|
||||
uint8_t min_nf = Settings.as3935_parameter.nf_autotune_min;
|
||||
uint8_t tunecaps = AS3935GetTuneCaps();
|
||||
uint8_t minnumlight = AS3935TranslMinLightsInt(AS3935GetMinLights());
|
||||
uint8_t disturber = AS3935GetDisturber();
|
||||
uint8_t reinj = AS3935GetSpikeRejection();
|
||||
uint8_t wdth = AS3935GetWdth();
|
||||
uint8_t min_nf = Settings.as3935_parameter.nf_autotune_min;
|
||||
uint8_t nf_time = Settings.as3935_parameter.nf_autotune_time;
|
||||
uint8_t nfauto = Settings.as3935_functions.nf_autotune;
|
||||
uint8_t distauto = Settings.as3935_functions.dist_autotune;
|
||||
uint8_t nfautomax = Settings.as3935_functions.nf_autotune_both;
|
||||
uint8_t distauto = Settings.as3935_functions.dist_autotune;
|
||||
uint8_t jsonlight = Settings.as3935_functions.mqtt_only_Light_Event;
|
||||
uint8_t nf_time = Settings.as3935_parameter.nf_autotune_time;
|
||||
uint8_t dist_time =Settings.as3935_parameter.dist_autotune_time;
|
||||
Response_P(S_JSON_AS3935_COMMAND_SETTINGS, S_JSON_AS3935_COMMAND_GAIN[gain], nf_floor, vrms, tunecaps, minnumlight, reinj, wdth, min_nf, nf_time, dist_time, S_JSON_AS3935_COMMAND_ONOFF[disturber], S_JSON_AS3935_COMMAND_ONOFF[nfauto], S_JSON_AS3935_COMMAND_ONOFF[distauto], S_JSON_AS3935_COMMAND_ONOFF[nfautomax], S_JSON_AS3935_COMMAND_ONOFF[jsonlight]);
|
||||
uint8_t jsonirq = Settings.as3935_functions.suppress_irq_no_Event;
|
||||
uint8_t dist_time = Settings.as3935_parameter.dist_autotune_time;
|
||||
Response_P(S_JSON_AS3935_COMMAND_SETTINGS, S_JSON_AS3935_COMMAND_GAIN[gain], nf_floor, vrms, tunecaps, minnumlight, reinj, wdth, min_nf, nf_time, dist_time, S_JSON_AS3935_COMMAND_ONOFF[disturber], S_JSON_AS3935_COMMAND_ONOFF[nfauto], S_JSON_AS3935_COMMAND_ONOFF[distauto], S_JSON_AS3935_COMMAND_ONOFF[nfautomax], S_JSON_AS3935_COMMAND_ONOFF[jsonlight], S_JSON_AS3935_COMMAND_ONOFF[jsonirq]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CMND_AS3935_CALIBRATE: {
|
||||
bool calreslt;
|
||||
if (!XdrvMailbox.data_len) calreslt = AS3935AutoTune();
|
||||
Response_P(S_JSON_AS3935_COMMAND_NVALUE, S_JSON_AS3935_COMMAND_CAL[calreslt], AS3935GetTuneCaps());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
case CMND_AS3935_CALIBRATE: {
|
||||
bool calreslt;
|
||||
if (!XdrvMailbox.data_len) calreslt = AS3935AutoTune();
|
||||
Response_P(S_JSON_AS3935_COMMAND_NVALUE, S_JSON_AS3935_COMMAND_CAL[calreslt], AS3935GetTuneCaps());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
@ -750,13 +797,12 @@ bool AS3935Cmd(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void AH3935Show(bool json)
|
||||
{
|
||||
void AH3935Show(bool json) {
|
||||
if (json) {
|
||||
uint16_t vrms;
|
||||
uint8_t stage;
|
||||
AS3935CalcVrmsLevel(vrms, stage);
|
||||
ResponseAppend_P(JSON_SNS_AS3935_EVENTS, D_SENSOR_AS3935, as3935_sensor.mqtt_irq, as3935_sensor.distance, as3935_sensor.intensity, stage);
|
||||
ResponseAppend_P(JSON_SNS_AS3935_EVENTS, D_SENSOR_AS3935, as3935_sensor.mqtt_event, as3935_sensor.distance, as3935_sensor.intensity, stage);
|
||||
#ifdef USE_WEBSERVER
|
||||
} else {
|
||||
uint8_t gain = AS3935GetGainInt();
|
||||
@ -765,12 +811,13 @@ void AH3935Show(bool json)
|
||||
uint8_t stage;
|
||||
AS3935CalcVrmsLevel(vrms, stage);
|
||||
|
||||
WSContentSend_PD(HTTP_SNS_AS3935_TABLE_1[as3935_sensor.http_irq], D_NAME_AS3935, as3935_sensor.http_distance);
|
||||
WSContentSend_PD(HTTP_SNS_AS3935_TABLE_1[as3935_sensor.http_event], D_NAME_AS3935, as3935_sensor.http_distance);
|
||||
WSContentSend_PD(HTTP_SNS_AS3935_DISTANZ, as3935_sensor.http_distance);
|
||||
WSContentSend_PD(HTTP_SNS_AS3935_ENERGY, as3935_sensor.http_intensity);
|
||||
WSContentSend_PD(HTTP_SNS_AS3935_GAIN[gain], D_NAME_AS3935);
|
||||
WSContentSend_PD(HTTP_SNS_AS3935_DISTURBER[disturber], D_NAME_AS3935);
|
||||
WSContentSend_PD(HTTP_SNS_AS3935_VRMS, vrms, stage);
|
||||
|
||||
#endif // USE_WEBSERVER
|
||||
}
|
||||
}
|
||||
@ -779,16 +826,13 @@ void AH3935Show(bool json)
|
||||
* Interface
|
||||
\*********************************************************************************************/
|
||||
|
||||
bool Xsns67(uint8_t function)
|
||||
{
|
||||
bool Xsns67(uint8_t function) {
|
||||
if (!I2cEnabled(XI2C_48)) { return false; }
|
||||
|
||||
bool result = false;
|
||||
|
||||
if (FUNC_INIT == function) {
|
||||
AS3935Detect();
|
||||
}
|
||||
else if (as3935_active) {
|
||||
else if (as3935_sensor.active) {
|
||||
switch (function) {
|
||||
case FUNC_EVERY_SECOND:
|
||||
AS3935EverySecond();
|
||||
|
Loading…
x
Reference in New Issue
Block a user