mirror of https://github.com/arendst/Tasmota.git
fixes and enhancements (#18718)
* onewire fixes, webui radiobuttons * fix regression
This commit is contained in:
parent
e969bf0e0e
commit
242eb3074a
|
@ -4750,7 +4750,10 @@ extern void W8960_SetGain(uint8_t sel, uint16_t value);
|
|||
lp++;
|
||||
}
|
||||
}
|
||||
bool isint = is_int_var(lp);
|
||||
bool isint = false;
|
||||
if (*lp != '(') {
|
||||
isint = is_int_var(lp);
|
||||
}
|
||||
lp = GetNumericArgument(lp, OPER_EQU, &fvar, gv);
|
||||
char str[SCRIPT_MAXSSIZE];
|
||||
if (isint) {
|
||||
|
@ -7696,6 +7699,24 @@ getnext:
|
|||
|
||||
#ifdef USE_SCRIPT_ONEWIRE
|
||||
|
||||
bool script_OneWireCrc8(uint8_t *addr) {
|
||||
uint8_t crc = 0;
|
||||
uint8_t len = 8;
|
||||
|
||||
while (len--) {
|
||||
uint8_t inbyte = *addr++; // from 0 to 7
|
||||
for (uint32_t i = 8; i; i--) {
|
||||
uint8_t mix = (crc ^ inbyte) & 0x01;
|
||||
crc >>= 1;
|
||||
if (mix) {
|
||||
crc ^= 0x8C;
|
||||
}
|
||||
inbyte >>= 1;
|
||||
}
|
||||
}
|
||||
return (crc == *addr); // addr 8
|
||||
}
|
||||
|
||||
uint32_t script_ow(uint8_t sel, uint32_t val) {
|
||||
uint32_t res = 0;
|
||||
uint8_t bits;
|
||||
|
@ -7843,27 +7864,41 @@ ScriptOneWire *ow = &glob_script_mem.ow;
|
|||
}
|
||||
|
||||
if (ow->ds) {
|
||||
uint8_t data[9];
|
||||
ow->ds->reset();
|
||||
ow->ds->select(ow->ds_address[val - 1]);
|
||||
if (!bits) {
|
||||
ow->ds->write(0x44, 1);
|
||||
} else {
|
||||
ow->ds->write(0xbe, 1);
|
||||
delay(10);
|
||||
res = ow->ds->read();
|
||||
res |= ow->ds->read() << 8;
|
||||
for (uint32_t cnt = 0; cnt < 9; cnt++) {
|
||||
data[cnt] = ow->ds->read();
|
||||
}
|
||||
if (script_OneWireCrc8(data)) {
|
||||
res = data[0];
|
||||
res |= data[1] << 8;
|
||||
} else {
|
||||
res = 0;
|
||||
}
|
||||
ow->ds->reset();
|
||||
}
|
||||
} else {
|
||||
uint8_t data[9];
|
||||
ow->dsh->reset();
|
||||
ow->dsh->select(ow->ds_address[val - 1]);
|
||||
if (!bits) {
|
||||
ow->dsh->write(0x44, 1);
|
||||
} else {
|
||||
ow->dsh->write(0xbe, 1);
|
||||
delay(10);
|
||||
res = ow->dsh->read();
|
||||
res |= ow->dsh->read() << 8;
|
||||
for (uint32_t cnt = 0; cnt < 9; cnt++) {
|
||||
data[cnt] = ow->dsh->read();
|
||||
}
|
||||
if (script_OneWireCrc8(data)) {
|
||||
res = data[0];
|
||||
res |= data[1] << 8;
|
||||
} else {
|
||||
res = 0;
|
||||
}
|
||||
ow->dsh->reset();
|
||||
}
|
||||
}
|
||||
|
@ -8894,7 +8929,7 @@ void Script_Check_Hue(String *response) {
|
|||
}
|
||||
#ifdef SCRIPT_HUE_DEBUG
|
||||
if (response) {
|
||||
AddLog(LOG_LEVEL_DEBUG, PSTR("Hue: %d"), hue_devs);
|
||||
AddLog(LOG_LEVEL_INFO, PSTR("Hue: %d"), hue_devs);
|
||||
toLog(">>>>");
|
||||
toLog(response->c_str());
|
||||
toLog(response->c_str()+700); // Was MAX_LOGSZ
|
||||
|
@ -8926,20 +8961,33 @@ void Script_Handle_Hue(String path) {
|
|||
uint8_t device = DecodeLightId(atoi(path.c_str()));
|
||||
uint8_t index = device - TasmotaGlobal.devices_present - 1;
|
||||
|
||||
uint16_t args = Webserver->args();
|
||||
|
||||
#ifdef ESP82666
|
||||
char *json = (char*)Webserver->arg(args - 1).c_str();
|
||||
#else
|
||||
String request_arg = Webserver->arg(args - 1);
|
||||
char *json = (char*)request_arg.c_str();
|
||||
#endif
|
||||
|
||||
#ifdef SCRIPT_HUE_DEBUG
|
||||
AddLog(LOG_LEVEL_INFO, PSTR("Hue 0: %s - %d "),path.c_str(), device);
|
||||
AddLog(LOG_LEVEL_INFO, PSTR("Hue 1: %d, %s"), args, json);
|
||||
#endif
|
||||
if (Webserver->args()) {
|
||||
response = "[";
|
||||
|
||||
JsonParser parser((char*) Webserver->arg((Webserver->args())-1).c_str());
|
||||
JsonParser parser(json);
|
||||
JsonParserObject root = parser.getRootObject();
|
||||
JsonParserToken hue_on = root[PSTR("on")];
|
||||
if (hue_on) {
|
||||
|
||||
if (hue_on) {
|
||||
response += FPSTR(sHUE_LIGHT_RESPONSE_JSON);
|
||||
response.replace("{id", String(EncodeLightId(device)));
|
||||
response.replace("{cm", "on");
|
||||
|
||||
bool on = hue_on.getBool();
|
||||
if (on==false) {
|
||||
if (on == false) {
|
||||
glob_script_mem.fvars[hue_script[index].index[0] - 1] = 0;
|
||||
response.replace("{re", "false");
|
||||
} else {
|
||||
|
@ -10158,6 +10206,16 @@ const char SCRIPT_MSG_PULLDOWNb[] PROGMEM =
|
|||
const char SCRIPT_MSG_PULLDOWNc[] PROGMEM =
|
||||
"</select>";
|
||||
|
||||
const char SCRIPT_MSG_RADIOa[] PROGMEM =
|
||||
"%s<fieldset style='width:%dpx'><legend>%s</legend>";
|
||||
const char SCRIPT_MSG_RADIOa0[] PROGMEM =
|
||||
"%s<fieldset><legend>%s</legend>";
|
||||
const char SCRIPT_MSG_RADIOb[] PROGMEM =
|
||||
"<div align='left'><input type='radio' name='%s' onclick='seva(%d%,\"%s\")'%s>"
|
||||
"<label>%s</label></div>";
|
||||
const char SCRIPT_MSG_RADIOc[] PROGMEM =
|
||||
"</fieldset>";
|
||||
|
||||
const char SCRIPT_MSG_TEXTINP[] PROGMEM =
|
||||
"%s<label><b>%s</b><input type='text' value='%s' style='width:%dpx' onfocusin='pr(0)' onfocusout='pr(1)' onchange='siva(value,\"%s\")'></label>";
|
||||
|
||||
|
@ -10348,6 +10406,7 @@ uint32_t cnt;
|
|||
#define WSO_NODIV 2
|
||||
#define WSO_FORCEPLAIN 4
|
||||
#define WSO_FORCEMAIN 8
|
||||
#define WSO_FORCEGUI 16
|
||||
#define WSO_STOP_DIV 0x80
|
||||
|
||||
void WCS_DIV(uint8_t flag) {
|
||||
|
@ -10529,7 +10588,10 @@ const char *gc_str;
|
|||
strcpy_P(center, PSTR("<center>"));
|
||||
}
|
||||
|
||||
if ( ((!mc && (*lin != '$')) || (mc == 'w' && (*lin != '$'))) && (!(specopt & WSO_FORCEMAIN)) ) {
|
||||
bool dogui = ((!mc && (*lin != '$')) || (mc == 'w' && (*lin != '$'))) && (!(specopt & WSO_FORCEMAIN));
|
||||
|
||||
if ((dogui && !(specopt & WSO_FORCEGUI)) || (!dogui && (specopt & WSO_FORCEGUI))) {
|
||||
//if ( ((!mc && (*lin != '$')) || (mc == 'w' && (*lin != '$'))) && (!(specopt & WSO_FORCEMAIN)) || (specopt & WSO_FORCEGUI)) {
|
||||
// normal web section
|
||||
//AddLog(LOG_LEVEL_INFO, PSTR("normal %s"), lin);
|
||||
if (*lin == '@') {
|
||||
|
@ -10673,6 +10735,62 @@ const char *gc_str;
|
|||
}
|
||||
WSContentSend_P(SCRIPT_MSG_PULLDOWNc);
|
||||
WCS_DIV(specopt | WSO_STOP_DIV);
|
||||
} else if (!strncmp(lin, "rb(", 3)) {
|
||||
// radio buttons
|
||||
char *lp = lin + 3;
|
||||
char *slp = lp;
|
||||
TS_FLOAT val;
|
||||
lp = GetNumericArgument(lp, OPER_EQU, &val, 0);
|
||||
SCRIPT_SKIP_SPACES
|
||||
|
||||
char vname[16];
|
||||
ScriptGetVarname(vname, slp, sizeof(vname));
|
||||
|
||||
SCRIPT_SKIP_SPACES
|
||||
char pulabel[SCRIPT_MAXSSIZE];
|
||||
lp = GetStringArgument(lp, OPER_EQU, pulabel, 0);
|
||||
SCRIPT_SKIP_SPACES
|
||||
|
||||
glob_script_mem.glob_error = 0;
|
||||
int16_t tsiz = -1;
|
||||
TS_FLOAT fvar;
|
||||
char *slp1 = lp;
|
||||
lp = GetNumericArgument(lp, OPER_EQU, &fvar, 0);
|
||||
if (!glob_script_mem.glob_error) {
|
||||
tsiz = fvar;
|
||||
} else {
|
||||
lp = slp1;
|
||||
}
|
||||
|
||||
WCS_DIV(specopt);
|
||||
if (tsiz < 0) {
|
||||
WSContentSend_P(SCRIPT_MSG_RADIOa0, center, pulabel);
|
||||
} else {
|
||||
WSContentSend_P(SCRIPT_MSG_RADIOa, center, tsiz, pulabel);
|
||||
}
|
||||
|
||||
// get pu labels
|
||||
uint8_t index = 1;
|
||||
while (*lp) {
|
||||
SCRIPT_SKIP_SPACES
|
||||
lp = GetStringArgument(lp, OPER_EQU, pulabel, 0);
|
||||
char *cp;
|
||||
if (val == index) {
|
||||
cp = (char*)"checked";
|
||||
} else {
|
||||
cp = (char*)"";
|
||||
}
|
||||
WSContentSend_P(SCRIPT_MSG_RADIOb, vname, index, vname, cp, pulabel);
|
||||
SCRIPT_SKIP_SPACES
|
||||
if (*lp == ')') {
|
||||
lp++;
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
WSContentSend_P(SCRIPT_MSG_RADIOc);
|
||||
WCS_DIV(specopt | WSO_STOP_DIV);
|
||||
WSContentFlush();
|
||||
} else if (!strncmp(lin, "bu(", 3)) {
|
||||
char *lp = lin + 3;
|
||||
uint8_t bcnt = 0;
|
||||
|
@ -10880,11 +10998,11 @@ const char *gc_str;
|
|||
} else {
|
||||
// main section interface
|
||||
//AddLog(LOG_LEVEL_INFO, PSTR("main %s"), lin);
|
||||
if ( (*lin == mc) || (mc == 'z') || (specopt&WSO_FORCEMAIN)) {
|
||||
if ( (*lin == mc) || (mc == 'z') || (specopt & WSO_FORCEMAIN)) {
|
||||
|
||||
#ifdef USE_GOOGLE_CHARTS
|
||||
if (mc != 'z') {
|
||||
if (!(specopt&WSO_FORCEMAIN)) {
|
||||
if (!(specopt & WSO_FORCEMAIN)) {
|
||||
lin++;
|
||||
}
|
||||
}
|
||||
|
@ -11308,7 +11426,7 @@ exgc:
|
|||
#else
|
||||
|
||||
if (mc != 'z') {
|
||||
if (!(specopt&WSO_FORCEMAIN)) {
|
||||
if (!(specopt & WSO_FORCEMAIN)) {
|
||||
lin++;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue