mirror of https://github.com/arendst/Tasmota.git
Refactor blacklist
This commit is contained in:
parent
98cbf2587a
commit
8c13dae8b4
|
@ -25,51 +25,61 @@ typedef struct {
|
|||
uint16_t lcid;
|
||||
} tBlArray;
|
||||
|
||||
//const char BlacklistText[] PROGMEM = "Stop war - Free Ukrain|Stop war - Free Ukrain|";
|
||||
const char BlacklistText[] PROGMEM = "Stop war, Free Ukrain";
|
||||
//const char BlacklistText[] PROGMEM = "Stop war, Help Ukrain|Stop war, Help Ukrain|";
|
||||
const char BlacklistText[] PROGMEM = "Стоп войну, помоги Украине"; // Stop war, Help Ukraine
|
||||
|
||||
// lat_tl lon_tl lat_br lon_br lcid
|
||||
tBlArray BlArray[] { 5900, 3200, 5300, 4400, 1049, // Around Moscow
|
||||
5450, 2633, 5280, 2900, 1049 // Around Minsk
|
||||
tBlArray BlArray[] { 5900, 3200, 5300, 4400, 1049, // Around Moscow
|
||||
5450, 2633, 5280, 2900, 1049 // Around Minsk
|
||||
};
|
||||
|
||||
uint8_t blist_show = 0;
|
||||
uint8_t blist_loc;
|
||||
uint8_t blist_show;
|
||||
|
||||
void BListEverySecond(void) {
|
||||
if (Rtc.utc_time < 1648771200) { // Only until 2022-04-01
|
||||
if (0 == (TasmotaGlobal.uptime % 20)) { // Only every 20 seconds
|
||||
if (TasmotaGlobal.power) { // Only if any power on
|
||||
uint32_t latitude = Settings->latitude / 10000;
|
||||
uint32_t longitude = Settings->longitude / 10000;
|
||||
uint32_t count = sizeof(BlArray) / sizeof(tBlArray);
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
// Currently only supports top-right quarter of the earth
|
||||
if ((LANGUAGE_LCID == BlArray[i].lcid) && // Check language id
|
||||
(latitude < BlArray[i].latitude_tl) && // Check user set latitude and longitude against table
|
||||
(latitude > BlArray[i].latitude_br) &&
|
||||
(longitude > BlArray[i].longitude_tl) &&
|
||||
(longitude < BlArray[i].longitude_br)) {
|
||||
|
||||
// char bl_text[100];
|
||||
// snprintf_P(bl_text, sizeof(bl_text), PSTR("Power0 0")); // Turn all power off - annoying
|
||||
// snprintf_P(bl_text, sizeof(bl_text), PSTR("Restart 1")); // Restart - more annoying
|
||||
// snprintf_P(bl_text, sizeof(bl_text), PSTR("Reset 1")); // Reset - disastrous
|
||||
// ExecuteCommand(bl_text, SRC_IGNORE);
|
||||
|
||||
// char bl_text[100];
|
||||
// AddLog(LOG_LEVEL_NONE, PSTR("**** %s ****"), GetTextIndexed(bl_text, sizeof(bl_text), i, BlacklistText));
|
||||
AddLog(LOG_LEVEL_NONE, PSTR("**** %s ****"), BlacklistText);
|
||||
blist_show = i +1; // Set GUI message id
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (0 == (TasmotaGlobal.uptime % 10)) { // Only every 10 seconds
|
||||
blist_show = 0; // Reset GUI message id after 10 seconds
|
||||
void BListDetect(void) {
|
||||
blist_loc = 0;
|
||||
blist_show = 0;
|
||||
int latitude = Settings->latitude / 10000;
|
||||
int longitude = Settings->longitude / 10000;
|
||||
uint32_t count = sizeof(BlArray) / sizeof(tBlArray);
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
// Currently only supports top-right quarter of the earth
|
||||
if ((LANGUAGE_LCID == BlArray[i].lcid) && // Check language id
|
||||
(latitude < BlArray[i].latitude_tl) && // Check user set latitude and longitude against table
|
||||
(latitude > BlArray[i].latitude_br) &&
|
||||
(longitude > BlArray[i].longitude_tl) &&
|
||||
(longitude < BlArray[i].longitude_br)) {
|
||||
blist_loc = i +1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BListEverySecond(void) {
|
||||
if (Rtc.utc_time < 1648771200) { // Only until 2022-04-01
|
||||
if (0 == (TasmotaGlobal.uptime % 20)) { // Only every 20 seconds
|
||||
if (TasmotaGlobal.power) { // Only if any power on
|
||||
|
||||
// char bl_text[100];
|
||||
// snprintf_P(bl_text, sizeof(bl_text), PSTR("Power0 0")); // Turn all power off - annoying
|
||||
// snprintf_P(bl_text, sizeof(bl_text), PSTR("Restart 1")); // Restart - more annoying
|
||||
// snprintf_P(bl_text, sizeof(bl_text), PSTR("Reset 1")); // Reset - disastrous
|
||||
// ExecuteCommand(bl_text, SRC_IGNORE);
|
||||
|
||||
// char bl_text[100];
|
||||
// AddLog(LOG_LEVEL_NONE, PSTR("**** %s ****"), GetTextIndexed(bl_text, sizeof(bl_text), i, BlacklistText));
|
||||
AddLog(LOG_LEVEL_NONE, PSTR("**** Stop war, Help Ukrain ****"));
|
||||
blist_show = blist_loc; // Set GUI message id
|
||||
}
|
||||
} else if (0 == (TasmotaGlobal.uptime % 10)) { // Only every 10 seconds
|
||||
blist_show = 0; // Reset GUI message id after 10 seconds
|
||||
}
|
||||
} else {
|
||||
blist_loc = 0; // Stop blacklist
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
void BListShow(bool json) {
|
||||
if (blist_show) {
|
||||
// char bl_text[100];
|
||||
|
@ -77,6 +87,7 @@ void BListShow(bool json) {
|
|||
WSContentSend_P(PSTR("{s}**** %s ****{m}{e}"), BlacklistText);
|
||||
}
|
||||
}
|
||||
#endif // USE_WEBSERVER
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Interface
|
||||
|
@ -85,15 +96,20 @@ void BListShow(bool json) {
|
|||
bool Xdrv96(uint8_t function) {
|
||||
bool result = false;
|
||||
|
||||
switch (function) {
|
||||
case FUNC_EVERY_SECOND:
|
||||
BListEverySecond();
|
||||
break;
|
||||
if (FUNC_INIT == function) {
|
||||
BListDetect();
|
||||
}
|
||||
else if (blist_loc) {
|
||||
switch (function) {
|
||||
case FUNC_EVERY_SECOND:
|
||||
BListEverySecond();
|
||||
break;
|
||||
#ifdef USE_WEBSERVER
|
||||
case FUNC_WEB_SENSOR:
|
||||
BListShow(0);
|
||||
break;
|
||||
case FUNC_WEB_SENSOR:
|
||||
BListShow(0);
|
||||
break;
|
||||
#endif // USE_WEBSERVER
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue