mirror of https://github.com/arendst/Tasmota.git
commit
c8b3b20df1
|
@ -56,6 +56,7 @@ uint8_t hk_services;
|
|||
|
||||
extern void Ext_Replace_Cmd_Vars(char *srcbuf, uint32_t srcsize, char *dstbuf, uint32_t dstsize);
|
||||
extern uint32_t Ext_UpdVar(char *vname, float *fvar, uint32_t mode);
|
||||
extern void Ext_toLog(char *str);
|
||||
|
||||
#define MAX_HAP_DEFS 16
|
||||
struct HAP_DESC {
|
||||
|
@ -64,6 +65,7 @@ struct HAP_DESC {
|
|||
char var2_name[12];
|
||||
char var3_name[12];
|
||||
char var4_name[12];
|
||||
char var5_name[12];
|
||||
uint8_t hap_cid;
|
||||
uint8_t type;
|
||||
hap_acc_t *accessory;
|
||||
|
@ -157,8 +159,8 @@ const struct HAP_CHAR_TABLE {
|
|||
{HAP_CHAR_UUID_CURRENT_RELATIVE_HUMIDITY,'f',0},
|
||||
{HAP_CHAR_UUID_CURRENT_AMBIENT_LIGHT_LEVEL,'f',0},
|
||||
{HAP_CHAR_UUID_BATTERY_LEVEL,'u',0},
|
||||
{HAP_CHAR_UUID_STATUS_LOW_BATTERY,'b',1},
|
||||
{HAP_CHAR_UUID_CHARGING_STATE,'b',2},
|
||||
{HAP_CHAR_UUID_STATUS_LOW_BATTERY,'u',1},
|
||||
{HAP_CHAR_UUID_CHARGING_STATE,'u',2},
|
||||
{HAP_CHAR_UUID_ON,'b',0},
|
||||
{HAP_CHAR_UUID_HUE,'f',1},
|
||||
{HAP_CHAR_UUID_SATURATION,'f',2},
|
||||
|
@ -282,7 +284,7 @@ void hap_update_from_vars(void) {
|
|||
new_val.u = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_STATUS_LOW_BATTERY);
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_CHARGING_STATE);
|
||||
if (Ext_UpdVar(hap_devs[cnt].var3_name, &fvar, 0)) {
|
||||
new_val.u = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
|
@ -332,6 +334,13 @@ void hap_update_from_vars(void) {
|
|||
new_val.u = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
if (hap_devs[cnt].var5_name[0]) {
|
||||
hc = hap_serv_get_char_by_uuid(hap_devs[cnt].service, HAP_CHAR_UUID_COLOR_TEMPERATURE);
|
||||
if (Ext_UpdVar(hap_devs[cnt].var5_name, &fvar, 0)) {
|
||||
new_val.u = fvar;
|
||||
hap_char_update_val(hc, &new_val);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -454,6 +463,7 @@ uint32_t str2c(char **sp, char *vp, uint32_t len) {
|
|||
} else {
|
||||
if (strlen(*sp)) {
|
||||
strlcpy(vp, *sp, len);
|
||||
*sp = lp + strlen(*sp);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -520,19 +530,16 @@ static void smart_outlet_thread_entry(void *p) {
|
|||
if (str2c(&lp1, hap_devs[index].var_name, sizeof(hap_devs[index].var_name))) {
|
||||
goto nextline;
|
||||
}
|
||||
if (hap_devs[index].hap_cid == HAP_CID_LIGHTING) {
|
||||
// get 3 add vars
|
||||
if (str2c(&lp1, hap_devs[index].var2_name, sizeof(hap_devs[index].var2_name))) {
|
||||
goto nextline;
|
||||
}
|
||||
if (str2c(&lp1, hap_devs[index].var3_name, sizeof(hap_devs[index].var3_name))) {
|
||||
goto nextline;
|
||||
}
|
||||
if (str2c(&lp1, hap_devs[index].var4_name, sizeof(hap_devs[index].var4_name))) {
|
||||
goto nextline;
|
||||
}
|
||||
}
|
||||
|
||||
hap_devs[index].var2_name[0] = 0;
|
||||
hap_devs[index].var3_name[0] = 0;
|
||||
hap_devs[index].var4_name[0] = 0;
|
||||
hap_devs[index].var5_name[0] = 0;
|
||||
|
||||
str2c(&lp1, hap_devs[index].var2_name, sizeof(hap_devs[index].var2_name));
|
||||
str2c(&lp1, hap_devs[index].var3_name, sizeof(hap_devs[index].var3_name));
|
||||
str2c(&lp1, hap_devs[index].var4_name, sizeof(hap_devs[index].var4_name));
|
||||
str2c(&lp1, hap_devs[index].var5_name, sizeof(hap_devs[index].var5_name));
|
||||
|
||||
hap_acc_cfg_t hap_cfg;
|
||||
hap_cfg.name = hap_devs[index].hap_name;
|
||||
|
@ -557,12 +564,20 @@ static void smart_outlet_thread_entry(void *p) {
|
|||
{ float fvar = 0;
|
||||
Ext_UpdVar(hap_devs[index].var_name, &fvar, 0);
|
||||
hap_devs[index].service = hap_serv_lightbulb_create(fvar);
|
||||
Ext_UpdVar(hap_devs[index].var2_name, &fvar, 0);
|
||||
ret |= hap_serv_add_char(hap_devs[index].service, hap_char_hue_create(fvar));
|
||||
Ext_UpdVar(hap_devs[index].var3_name, &fvar, 0);
|
||||
ret |= hap_serv_add_char(hap_devs[index].service, hap_char_saturation_create(fvar));
|
||||
if (hap_devs[index].var2_name[0]) {
|
||||
Ext_UpdVar(hap_devs[index].var2_name, &fvar, 0);
|
||||
ret |= hap_serv_add_char(hap_devs[index].service, hap_char_hue_create(fvar));
|
||||
}
|
||||
if (hap_devs[index].var3_name[0]) {
|
||||
Ext_UpdVar(hap_devs[index].var3_name, &fvar, 0);
|
||||
ret |= hap_serv_add_char(hap_devs[index].service, hap_char_saturation_create(fvar));
|
||||
}
|
||||
Ext_UpdVar(hap_devs[index].var4_name, &fvar, 0);
|
||||
ret |= hap_serv_add_char(hap_devs[index].service, hap_char_brightness_create(fvar));
|
||||
if (hap_devs[index].var5_name[0]) {
|
||||
Ext_UpdVar(hap_devs[index].var5_name, &fvar, 0);
|
||||
ret |= hap_serv_add_char(hap_devs[index].service, hap_char_color_temperature_create(fvar));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case HAP_CID_OUTLET:
|
||||
|
@ -681,14 +696,14 @@ nextline:
|
|||
// vTaskDelete(NULL);
|
||||
while (1) {
|
||||
delay(500);
|
||||
// hap_update_from_vars();
|
||||
hap_update_from_vars();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define HK_PASSCODE "111-11-111"
|
||||
int hap_loop_stop(void);
|
||||
extern void Ext_toLog(char *str);
|
||||
|
||||
|
||||
void homekit_main(char *desc, uint32_t flag ) {
|
||||
if (desc) {
|
||||
|
|
|
@ -67,8 +67,8 @@ keywords if then else endif, or, and are better readable for beginners (others m
|
|||
|
||||
#define MAX_SARRAY_NUM 32
|
||||
|
||||
//uint32_t EncodeLightId(uint8_t relay_id);
|
||||
//uint32_t DecodeLightId(uint32_t hue_id);
|
||||
uint32_t EncodeLightId(uint8_t relay_id);
|
||||
uint32_t DecodeLightId(uint32_t hue_id);
|
||||
|
||||
#define SPECIAL_EEPMODE_SIZE 6200
|
||||
|
||||
|
@ -776,7 +776,7 @@ char *script;
|
|||
|
||||
script_mem_size += 16;
|
||||
uint8_t *script_mem;
|
||||
script_mem = (uint8_t*)calloc(script_mem_size, 1);
|
||||
script_mem = (uint8_t*)special_malloc(script_mem_size);
|
||||
if (!script_mem) {
|
||||
if (imemptr) free(imemptr);
|
||||
return -4;
|
||||
|
@ -2175,7 +2175,7 @@ chknext:
|
|||
if (ef) {
|
||||
uint16_t fsiz = ef.size();
|
||||
if (fsiz<2048) {
|
||||
char *script = (char*)calloc(fsiz + 16, 1);
|
||||
char *script = (char*)special_malloc(fsiz + 16);
|
||||
if (script) {
|
||||
ef.read((uint8_t*)script,fsiz);
|
||||
execute_script(script);
|
||||
|
@ -3643,15 +3643,22 @@ int32_t UpdVar(char *vname, float *fvar, uint32_t mode) {
|
|||
if (vtype == NUM_RES || (vtype & STYPE) == 0) {
|
||||
if (mode) {
|
||||
// set var
|
||||
//AddLog(LOG_LEVEL_DEBUG, PSTR("write from homekit: %s - %d"), vname, (uint32_t)res);
|
||||
index = glob_script_mem.type[ind.index].index;
|
||||
glob_script_mem.fvars[index] = res;
|
||||
glob_script_mem.type[ind.index].bits.changed = 1;
|
||||
#ifdef USE_SCRIPT_GLOBVARS
|
||||
if (glob_script_mem.type[ind.index].bits.global) {
|
||||
script_udp_sendvar(vname, &res, 0);
|
||||
}
|
||||
#endif //USE_SCRIPT_GLOBVARS
|
||||
return 0;
|
||||
} else {
|
||||
// get var
|
||||
//index = glob_script_mem.type[ind.index].index;
|
||||
int32_t ret = glob_script_mem.type[ind.index].bits.hchanged;
|
||||
glob_script_mem.type[ind.index].bits.hchanged = 0;
|
||||
//AddLog(LOG_LEVEL_DEBUG, PSTR("read from homekit: %s - %d - %d"), vname, (uint32_t)*fvar, ret);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
|
@ -6357,7 +6364,8 @@ void ScriptGetSDCard(void) {
|
|||
if (!HttpCheckPriviledgedAccess()) { return; }
|
||||
|
||||
String stmp = Webserver->uri();
|
||||
char *cp = strstr_P(stmp.c_str(), PSTR("/sdc/"));
|
||||
|
||||
char *cp = strstr_P(stmp.c_str(), PSTR("/ufs/"));
|
||||
// if (cp) Serial.printf(">>>%s\n",cp);
|
||||
if (cp) {
|
||||
#ifdef ESP32
|
||||
|
@ -6365,13 +6373,15 @@ void ScriptGetSDCard(void) {
|
|||
#else
|
||||
cp += 5;
|
||||
#endif
|
||||
if (strstr_P(cp, PSTR("scrdmp.bmp"))) {
|
||||
SendFile(cp);
|
||||
return;
|
||||
} else {
|
||||
if (ufsp->exists(cp)) {
|
||||
if (ufsp) {
|
||||
if (strstr_P(cp, PSTR("scrdmp.bmp"))) {
|
||||
SendFile(cp);
|
||||
return;
|
||||
} else {
|
||||
if (ufsp->exists(cp)) {
|
||||
SendFile(cp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6392,7 +6402,6 @@ char buff[512];
|
|||
#ifdef USE_DISPLAY_DUMP
|
||||
char *sbmp = strstr_P(fname, PSTR("scrdmp.bmp"));
|
||||
if (sbmp) {
|
||||
mime = "image/bmp";
|
||||
sflg = 1;
|
||||
}
|
||||
#endif // USE_DISPLAY_DUMP
|
||||
|
@ -6419,7 +6428,7 @@ char buff[512];
|
|||
#define infoHeaderSize 40
|
||||
if (buffer) {
|
||||
uint8_t *bp = buffer;
|
||||
uint8_t *lbuf = (uint8_t*)calloc(Settings.display_width + 2, 3);
|
||||
uint8_t *lbuf = (uint8_t*)special_malloc(Settings.display_width + 2);
|
||||
uint8_t *lbp;
|
||||
uint8_t fileHeader[fileHeaderSize];
|
||||
createBitmapFileHeader(Settings.display_height , Settings.display_width , fileHeader);
|
||||
|
@ -7679,7 +7688,7 @@ bool Xdrv10(uint8_t function)
|
|||
// we have a file system
|
||||
AddLog(LOG_LEVEL_INFO,PSTR("UFILESYSTEM OK!"));
|
||||
char *script;
|
||||
script = (char*)calloc(UFSYS_SIZE + 4, 1);
|
||||
script = (char*)special_malloc(UFSYS_SIZE + 4);
|
||||
if (!script) break;
|
||||
glob_script_mem.script_ram = script;
|
||||
glob_script_mem.script_size = UFSYS_SIZE;
|
||||
|
@ -7850,6 +7859,10 @@ bool Xdrv10(uint8_t function)
|
|||
Webserver->on("/sfd", ScriptFullWebpage);
|
||||
}
|
||||
#endif // SCRIPT_FULL_WEBPAGE
|
||||
|
||||
#ifdef USE_UFILESYS
|
||||
Webserver->onNotFound(ScriptGetSDCard);
|
||||
#endif // USE_UFILESYS
|
||||
}
|
||||
break;
|
||||
#endif // USE_SCRIPT_WEB_DISPLAY
|
||||
|
@ -7858,7 +7871,6 @@ bool Xdrv10(uint8_t function)
|
|||
Webserver->on("/ta",HTTP_POST, HandleScriptTextareaConfiguration);
|
||||
Webserver->on("/exs", HTTP_POST,[]() { Webserver->sendHeader("Location","/exs");Webserver->send(303);}, script_upload_start);
|
||||
Webserver->on("/exs", HTTP_GET, ScriptExecuteUploadSuccess);
|
||||
break;
|
||||
#endif // USE_WEBSERVER
|
||||
case FUNC_SAVE_BEFORE_RESTART:
|
||||
if (bitRead(Settings.rule_enabled, 0)) {
|
||||
|
|
|
@ -123,6 +123,48 @@ void (* const DisplayCommand[])(void) PROGMEM = {
|
|||
&CmndDisplayScrollDelay, &CmndDisplayClock, &CmndDisplayTextNC, &CmndDisplayScrollText
|
||||
};
|
||||
|
||||
#ifdef USE_GRAPH
|
||||
|
||||
typedef union {
|
||||
uint8_t data;
|
||||
struct {
|
||||
uint8_t overlay : 1;
|
||||
uint8_t draw : 1;
|
||||
uint8_t nu3 : 1;
|
||||
uint8_t nu4 : 1;
|
||||
uint8_t nu5 : 1;
|
||||
uint8_t nu6 : 1;
|
||||
uint8_t nu7 : 1;
|
||||
uint8_t nu8 : 1;
|
||||
};
|
||||
} GFLAGS;
|
||||
|
||||
struct GRAPH {
|
||||
uint16_t xp;
|
||||
uint16_t yp;
|
||||
uint16_t xs;
|
||||
uint16_t ys;
|
||||
float ymin;
|
||||
float ymax;
|
||||
float range;
|
||||
uint32_t x_time; // time per x slice in milliseconds
|
||||
uint32_t last_ms;
|
||||
uint32_t last_ms_redrawn;
|
||||
int16_t decimation; // decimation or graph duration in minutes
|
||||
uint16_t dcnt;
|
||||
uint32_t summ;
|
||||
uint16_t xcnt;
|
||||
uint8_t *values;
|
||||
uint8_t xticks;
|
||||
uint8_t yticks;
|
||||
uint8_t last_val;
|
||||
uint8_t color_index;
|
||||
GFLAGS flags;
|
||||
};
|
||||
|
||||
struct GRAPH *graph[NUM_GRAPHS];
|
||||
#endif // USE_GRAPH
|
||||
|
||||
char *dsp_str;
|
||||
|
||||
uint16_t dsp_x;
|
||||
|
@ -2140,46 +2182,9 @@ void DrawAClock(uint16_t rad) {
|
|||
* Graphics
|
||||
\*********************************************************************************************/
|
||||
|
||||
|
||||
#ifdef USE_GRAPH
|
||||
|
||||
typedef union {
|
||||
uint8_t data;
|
||||
struct {
|
||||
uint8_t overlay : 1;
|
||||
uint8_t draw : 1;
|
||||
uint8_t nu3 : 1;
|
||||
uint8_t nu4 : 1;
|
||||
uint8_t nu5 : 1;
|
||||
uint8_t nu6 : 1;
|
||||
uint8_t nu7 : 1;
|
||||
uint8_t nu8 : 1;
|
||||
};
|
||||
} GFLAGS;
|
||||
|
||||
struct GRAPH {
|
||||
uint16_t xp;
|
||||
uint16_t yp;
|
||||
uint16_t xs;
|
||||
uint16_t ys;
|
||||
float ymin;
|
||||
float ymax;
|
||||
float range;
|
||||
uint32_t x_time; // time per x slice in milliseconds
|
||||
uint32_t last_ms;
|
||||
uint32_t last_ms_redrawn;
|
||||
int16_t decimation; // decimation or graph duration in minutes
|
||||
uint16_t dcnt;
|
||||
uint32_t summ;
|
||||
uint16_t xcnt;
|
||||
uint8_t *values;
|
||||
uint8_t xticks;
|
||||
uint8_t yticks;
|
||||
uint8_t last_val;
|
||||
uint8_t color_index;
|
||||
GFLAGS flags;
|
||||
};
|
||||
|
||||
struct GRAPH *graph[NUM_GRAPHS];
|
||||
|
||||
#define TICKLEN 4
|
||||
void ClrGraph(uint16_t num) {
|
||||
|
|
Loading…
Reference in New Issue