scripter add event result

This commit is contained in:
gemu2015 2020-07-16 17:15:12 +02:00
parent 66b3dc1cf2
commit 2ad758117d
2 changed files with 118 additions and 6 deletions

98
lib/LinkedList-1.2.3/LinkedList.h Normal file → Executable file
View File

@ -39,8 +39,11 @@ protected:
ListNode<T>* getNode(int index);
ListNode<T>* findEndOfSortedString(ListNode<T> *p, int (*cmp)(T &, T &));
public:
LinkedList();
LinkedList(int sizeIndex, T _t); //initiate list size and default value
~LinkedList();
/*
@ -65,7 +68,6 @@ public:
virtual bool unshift(T);
/*
Set the object at index, with T;
Increment _size;
*/
virtual bool set(int index, T);
/*
@ -94,6 +96,16 @@ public:
*/
virtual void clear();
/*
Sort the list, given a comparison function
*/
virtual void sort(int (*cmp)(T &, T &));
// add support to array brakets [] operator
inline T& operator[](int index);
inline T& operator[](size_t& i) { return this->get(i); }
inline const T& operator[](const size_t& i) const { return this->get(i); }
};
// Initialize LinkedList with false values
@ -157,7 +169,7 @@ ListNode<T>* LinkedList<T>::getNode(int index){
return current;
}
return false;
return NULL;
}
template<typename T>
@ -165,6 +177,13 @@ int LinkedList<T>::size(){
return _size;
}
template<typename T>
LinkedList<T>::LinkedList(int sizeIndex, T _t){
for (int i = 0; i < sizeIndex; i++){
add(_t);
}
}
template<typename T>
bool LinkedList<T>::add(int index, T _t){
@ -226,6 +245,12 @@ bool LinkedList<T>::unshift(T _t){
return true;
}
template<typename T>
T& LinkedList<T>::operator[](int index) {
return getNode(index)->data;
}
template<typename T>
bool LinkedList<T>::set(int index, T _t){
// Check if index position is in bounds
@ -322,4 +347,73 @@ void LinkedList<T>::clear(){
shift();
}
template<typename T>
void LinkedList<T>::sort(int (*cmp)(T &, T &)){
if(_size < 2) return; // trivial case;
for(;;) {
ListNode<T> **joinPoint = &root;
while(*joinPoint) {
ListNode<T> *a = *joinPoint;
ListNode<T> *a_end = findEndOfSortedString(a, cmp);
if(!a_end->next ) {
if(joinPoint == &root) {
last = a_end;
isCached = false;
return;
}
else {
break;
}
}
ListNode<T> *b = a_end->next;
ListNode<T> *b_end = findEndOfSortedString(b, cmp);
ListNode<T> *tail = b_end->next;
a_end->next = NULL;
b_end->next = NULL;
while(a && b) {
if(cmp(a->data, b->data) <= 0) {
*joinPoint = a;
joinPoint = &a->next;
a = a->next;
}
else {
*joinPoint = b;
joinPoint = &b->next;
b = b->next;
}
}
if(a) {
*joinPoint = a;
while(a->next) a = a->next;
a->next = tail;
joinPoint = &a->next;
}
else {
*joinPoint = b;
while(b->next) b = b->next;
b->next = tail;
joinPoint = &b->next;
}
}
}
}
template<typename T>
ListNode<T>* LinkedList<T>::findEndOfSortedString(ListNode<T> *p, int (*cmp)(T &, T &)) {
while(p->next && cmp(p->data, p->next->data) <= 0) {
p = p->next;
}
return p;
}
#endif

View File

@ -194,7 +194,7 @@ void LoadFile(const char *name,uint8_t *buf,uint32_t len) {
#define EPOCH_OFFSET 1546300800
enum {OPER_EQU=1,OPER_PLS,OPER_MIN,OPER_MUL,OPER_DIV,OPER_PLSEQU,OPER_MINEQU,OPER_MULEQU,OPER_DIVEQU,OPER_EQUEQU,OPER_NOTEQU,OPER_GRTEQU,OPER_LOWEQU,OPER_GRT,OPER_LOW,OPER_PERC,OPER_XOR,OPER_AND,OPER_OR,OPER_ANDEQU,OPER_OREQU,OPER_XOREQU,OPER_PERCEQU};
enum {SCRIPT_LOGLEVEL=1,SCRIPT_TELEPERIOD};
enum {SCRIPT_LOGLEVEL=1,SCRIPT_TELEPERIOD,SCRIPT_EVENT_HANDLED};
#ifdef USE_SCRIPT_FATFS
@ -379,6 +379,7 @@ struct SCRIPT_MEM {
#endif
} glob_script_mem;
bool event_handeled = false;
#ifdef USE_SCRIPT_GLOBVARS
@ -1573,6 +1574,11 @@ chknext:
fvar=UtcTime()-(uint32_t)EPOCH_OFFSET;
goto exit;
}
if (!strncmp(vname,"eres",4)) {
fvar=event_handeled;
tind->index=SCRIPT_EVENT_HANDLED;
goto exit_settable;
}
#ifdef USE_ENERGY_SENSOR
if (!strncmp(vname,"enrg[",5)) {
lp+=5;
@ -3901,6 +3907,9 @@ int16_t Run_script_sub(const char *type, int8_t tlen, JsonObject *jo) {
if (*dfvar>300) *dfvar=300;
Settings.tele_period=*dfvar;
break;
case SCRIPT_EVENT_HANDLED:
event_handeled=*dfvar;
break;
}
sysv_type=0;
}
@ -4063,7 +4072,9 @@ void ScripterEvery100ms(void) {
Run_Scripter(">T",2, mqtt_data);
}
}
if (fast_script==99) Run_Scripter(">F",2,0);
if (Settings.rule_enabled) {
if (fast_script==99) Run_Scripter(">F",2,0);
}
}
//mems[5] is 50 bytes in 6.5
@ -6619,6 +6630,7 @@ void cpy2lf(char *dst,uint32_t dstlen, char *src) {
bool Xdrv10(uint8_t function)
{
bool result = false;
event_handeled = false;
char *sprt;
switch (function) {
@ -6778,11 +6790,17 @@ bool Xdrv10(uint8_t function)
#ifdef SCRIPT_POWER_SECTION
if (bitRead(Settings.rule_enabled, 0)) Run_Scripter(">P",2,0);
#else
if (bitRead(Settings.rule_enabled, 0)) Run_Scripter(">E",2,0);
if (bitRead(Settings.rule_enabled, 0)) {
Run_Scripter(">E",2,0);
result=event_handeled;
}
#endif
break;
case FUNC_RULES_PROCESS:
if (bitRead(Settings.rule_enabled, 0)) Run_Scripter(">E",2,mqtt_data);
if (bitRead(Settings.rule_enabled, 0)) {
Run_Scripter(">E",2,mqtt_data);
result=event_handeled;
}
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_ADD_BUTTON: