mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
OpenHab bugfix, optimization, SCALE_VOLUME_100 opt.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -892,7 +892,7 @@ void Input::analogPoll(short cause) {
|
|||||||
|
|
||||||
if ((store->bounce<ANALOG_STATE_ATTEMPTS-1 || mappedInputVal == min || mappedInputVal ==max )&& (inputVal != store->currentValue))//confirmed change
|
if ((store->bounce<ANALOG_STATE_ATTEMPTS-1 || mappedInputVal == min || mappedInputVal ==max )&& (inputVal != store->currentValue))//confirmed change
|
||||||
{
|
{
|
||||||
onAnalogChanged(mappedInputVal/10.);
|
onAnalogChanged(itemCmd().Tens(mappedInputVal));
|
||||||
// store->currentValue = mappedInputVal;
|
// store->currentValue = mappedInputVal;
|
||||||
store->currentValue = inputVal;
|
store->currentValue = inputVal;
|
||||||
}
|
}
|
||||||
@@ -954,12 +954,12 @@ if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::onAnalogChanged(float newValue) {
|
void Input::onAnalogChanged(itemCmd newValue) {
|
||||||
debugSerial << F("IN:") << (pin) << F("=") << newValue << endl;
|
debugSerial << F("IN:") << (pin) << F("="); newValue.debugOut();
|
||||||
|
|
||||||
// New tyle unified activities
|
// New tyle unified activities
|
||||||
aJsonObject *act = aJson.getObjectItem(inputObj, "act");
|
aJsonObject *act = aJson.getObjectItem(inputObj, "act");
|
||||||
executeCommand(act,-1,itemCmd(newValue));
|
executeCommand(act,-1,newValue);
|
||||||
|
|
||||||
// Legacy
|
// Legacy
|
||||||
aJsonObject *item = aJson.getObjectItem(inputObj, "item");
|
aJsonObject *item = aJson.getObjectItem(inputObj, "item");
|
||||||
@@ -978,19 +978,15 @@ void Input::onAnalogChanged(float newValue) {
|
|||||||
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||||
char strVal[16];
|
char strVal[16];
|
||||||
//itoa(newValue,strVal,10);
|
newValue.toString(strVal,sizeof(strVal),SEND_PARAMETERS);
|
||||||
printFloatValueToStr(newValue, strVal);
|
|
||||||
if (mqttClient.connected() && !ethernetIdleCount)
|
if (mqttClient.connected() && !ethernetIdleCount)
|
||||||
mqttClient.publish(addrstr, strVal, true);
|
mqttClient.publish(addrstr, strVal, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item && item->type == aJson_String) {
|
if (item && item->type == aJson_String) {
|
||||||
//int intNewValue = round(newValue);
|
|
||||||
Item it(item->valuestring);
|
Item it(item->valuestring);
|
||||||
if (it.isValid()) {
|
if (it.isValid()) it.Ctrl(newValue);
|
||||||
//it.Ctrl(0, 1, &intNewValue, true);
|
|
||||||
it.Ctrl(itemCmd(newValue));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ e-mail anklimov@gmail.com
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <aJSON.h>
|
#include <aJSON.h>
|
||||||
#include "modules/in_ccs811_hdc1080.h"
|
#include "modules/in_ccs811_hdc1080.h"
|
||||||
|
#include "itemCmd.h"
|
||||||
|
|
||||||
#define IN_ACTIVE_HIGH 2 // High level = PUSHED/ CLOSED/ ON othervise :Low Level. Use INPUT mode instead of INPUT_PULLUP for digital pin
|
#define IN_ACTIVE_HIGH 2 // High level = PUSHED/ CLOSED/ ON othervise :Low Level. Use INPUT mode instead of INPUT_PULLUP for digital pin
|
||||||
#define IN_ANALOG 64 // Analog input
|
#define IN_ANALOG 64 // Analog input
|
||||||
@@ -141,7 +142,7 @@ public:
|
|||||||
boolean isValid();
|
boolean isValid();
|
||||||
|
|
||||||
void onContactChanged(int newValue);
|
void onContactChanged(int newValue);
|
||||||
void onAnalogChanged(float newValue);
|
void onAnalogChanged(itemCmd newValue);
|
||||||
|
|
||||||
int Poll(short cause);
|
int Poll(short cause);
|
||||||
void setup();
|
void setup();
|
||||||
|
|||||||
@@ -476,12 +476,8 @@ int cmd = txt2cmd(payload);
|
|||||||
debugSerial<<F("Txt2Cmd:")<<cmd<<endl;
|
debugSerial<<F("Txt2Cmd:")<<cmd<<endl;
|
||||||
|
|
||||||
itemCmd st(ST_VOID,cmd);
|
itemCmd st(ST_VOID,cmd);
|
||||||
bool set255flag=true;
|
|
||||||
|
|
||||||
switch (suffixCode) {
|
switch (suffixCode) {
|
||||||
case S_NOTFOUND:
|
|
||||||
set255flag=false;
|
|
||||||
break;
|
|
||||||
case S_HSV:
|
case S_HSV:
|
||||||
cmd=CMD_HSV;
|
cmd=CMD_HSV;
|
||||||
break;
|
break;
|
||||||
@@ -526,20 +522,15 @@ st.setSuffix(suffixCode);
|
|||||||
switch (i) //Number of params
|
switch (i) //Number of params
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
if (set255flag) st=Par0;
|
st=Par0;
|
||||||
else st.Percents(Par0.getInt());
|
|
||||||
break;
|
break;
|
||||||
case 2: st.HS(Par0.getInt(),Par[0]);
|
case 2: st.HS(Par0.getInt(),Par[0]);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if (set255flag)
|
|
||||||
st.HSV255(Par0.getInt(),Par[0],Par[1]);
|
st.HSV255(Par0.getInt(),Par[0],Par[1]);
|
||||||
else st.HSV(Par0.getInt(),Par[0],Par[1]);
|
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
if (set255flag)
|
|
||||||
st.HSV255(Par0.getInt(),Par[0],Par[1]);
|
st.HSV255(Par0.getInt(),Par[0],Par[1]);
|
||||||
else st.HSV(Par0.getInt(),Par[0],Par[1]);
|
|
||||||
st.setColorTemp(Par[2]);
|
st.setColorTemp(Par[2]);
|
||||||
break;
|
break;
|
||||||
default:;
|
default:;
|
||||||
@@ -613,6 +604,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem)
|
|||||||
|
|
||||||
bool chActive = (isActive()>0);
|
bool chActive = (isActive()>0);
|
||||||
bool toExecute = (chActive>0); // execute if channel is active now
|
bool toExecute = (chActive>0); // execute if channel is active now
|
||||||
|
bool scale100 = false;
|
||||||
debugSerial<<endl;
|
debugSerial<<endl;
|
||||||
|
|
||||||
if (itemType != CH_GROUP )
|
if (itemType != CH_GROUP )
|
||||||
@@ -739,6 +731,7 @@ int Item::Ctrl(itemCmd cmd, char* subItem)
|
|||||||
{
|
{
|
||||||
case S_NOTFOUND: //For empty (universal) OPENHAB suffix - turn ON/OFF automatically
|
case S_NOTFOUND: //For empty (universal) OPENHAB suffix - turn ON/OFF automatically
|
||||||
toExecute=true;
|
toExecute=true;
|
||||||
|
scale100=true; //openHab topic format
|
||||||
if (chActive>0 && !cmd.getInt()) st.Cmd(CMD_OFF);
|
if (chActive>0 && !cmd.getInt()) st.Cmd(CMD_OFF);
|
||||||
if (chActive==0 && cmd.getInt()) st.Cmd(CMD_ON);
|
if (chActive==0 && cmd.getInt()) st.Cmd(CMD_ON);
|
||||||
setCmd(st.getCmd());
|
setCmd(st.getCmd());
|
||||||
@@ -746,16 +739,16 @@ int Item::Ctrl(itemCmd cmd, char* subItem)
|
|||||||
|
|
||||||
// continue processing as SET
|
// continue processing as SET
|
||||||
case S_SET:
|
case S_SET:
|
||||||
// case S_ESET:
|
|
||||||
// if previous color was in RGB notation but new value is HSV - discard previous val and change type;
|
// if previous color was in RGB notation but new value is HSV - discard previous val and change type;
|
||||||
if ((st.getArgType() == ST_RGB || st.getArgType() == ST_RGBW) &&
|
if ((st.getArgType() == ST_RGB || st.getArgType() == ST_RGBW) &&
|
||||||
/*(cmd.getArgType() == ST_HSV ) || */(cmd.getArgType() == ST_HSV255))
|
(cmd.getArgType() == ST_HSV255))
|
||||||
st.setArgType(cmd.getArgType());
|
st.setArgType(cmd.getArgType());
|
||||||
|
|
||||||
if (itemType == CH_GROUP && cmd.isColor()) st.setArgType(ST_HSV255);//Extend storage for group channel
|
if (itemType == CH_GROUP && cmd.isColor()) st.setArgType(ST_HSV255);//Extend storage for group channel
|
||||||
|
|
||||||
//Convert value to most approptiate type for channel
|
//Convert value to most approptiate type for channel
|
||||||
st.assignFrom(cmd,getChanType());
|
st.assignFrom(cmd,getChanType());
|
||||||
|
if (scale100 || SCALE_VOLUME_100) st.scale100();
|
||||||
st.saveItem(this);
|
st.saveItem(this);
|
||||||
SendStatus(SEND_PARAMETERS | SEND_DEFFERED);
|
SendStatus(SEND_PARAMETERS | SEND_DEFFERED);
|
||||||
|
|
||||||
@@ -1178,10 +1171,11 @@ int Item::VacomSetFan(itemCmd st) {
|
|||||||
node.begin(addr, modbusSerial);
|
node.begin(addr, modbusSerial);
|
||||||
|
|
||||||
if (val) {
|
if (val) {
|
||||||
node.writeSingleRegister(2001 - 1, 4 + 1);//delay(500);
|
result=node.writeSingleRegister(2001 - 1, 4 + 1);//delay(500);
|
||||||
//node.writeSingleRegister(2001-1,1);
|
//node.writeSingleRegister(2001-1,1);
|
||||||
} else node.writeSingleRegister(2001 - 1, 0);
|
} else result=node.writeSingleRegister(2001 - 1, 0);
|
||||||
delay(50);
|
delay(100);
|
||||||
|
if (result == node.ku8MBSuccess) debugSerial << F("MB ok")<<endl;
|
||||||
result = node.writeSingleRegister(2003 - 1, val * 100);
|
result = node.writeSingleRegister(2003 - 1, val * 100);
|
||||||
modbusBusy = 0;
|
modbusBusy = 0;
|
||||||
|
|
||||||
@@ -1196,7 +1190,7 @@ int Item::VacomSetFan(itemCmd st) {
|
|||||||
///move to float todo
|
///move to float todo
|
||||||
int Item::VacomSetHeat(itemCmd st)
|
int Item::VacomSetHeat(itemCmd st)
|
||||||
{
|
{
|
||||||
int val=st.getPercents();
|
float val=st.getFloat();
|
||||||
int cmd=st.getCmd();
|
int cmd=st.getCmd();
|
||||||
|
|
||||||
uint8_t result;
|
uint8_t result;
|
||||||
@@ -1229,7 +1223,7 @@ int addr;
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
regval = round(((float) val - b) * 10 / a);
|
regval = round(( val - b) * 10 / a);
|
||||||
}
|
}
|
||||||
|
|
||||||
//debugSerial<<regval);
|
//debugSerial<<regval);
|
||||||
@@ -1659,7 +1653,7 @@ int Item::SendStatus(int sendFlags) {
|
|||||||
|
|
||||||
setTopic(addrstr,sizeof(addrstr),T_OUT);
|
setTopic(addrstr,sizeof(addrstr),T_OUT);
|
||||||
strncat(addrstr, itemArr->name, sizeof(addrstr)-1);
|
strncat(addrstr, itemArr->name, sizeof(addrstr)-1);
|
||||||
st.toString(valstr, sizeof(valstr), SEND_PARAMETERS,100);
|
st.toString(valstr, sizeof(valstr), SEND_PARAMETERS,true);
|
||||||
|
|
||||||
if (sendFlags & SEND_PARAMETERS && st.getCmd() != CMD_OFF && st.getCmd() != CMD_HALT)
|
if (sendFlags & SEND_PARAMETERS && st.getCmd() != CMD_OFF && st.getCmd() != CMD_HALT)
|
||||||
{
|
{
|
||||||
@@ -1700,7 +1694,7 @@ int Item::SendStatus(int sendFlags) {
|
|||||||
st.toString(valstr, sizeof(valstr), SEND_PARAMETERS|SEND_COMMAND);
|
st.toString(valstr, sizeof(valstr), SEND_PARAMETERS|SEND_COMMAND);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
st.toString(valstr, sizeof(valstr), SEND_PARAMETERS);
|
st.toString(valstr, sizeof(valstr), SEND_PARAMETERS,(SCALE_VOLUME_100));
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (st.getArgType()) {
|
switch (st.getArgType()) {
|
||||||
@@ -1708,10 +1702,6 @@ int Item::SendStatus(int sendFlags) {
|
|||||||
case ST_RGBW:
|
case ST_RGBW:
|
||||||
strncat_P(addrstr, SET_P, sizeof(addrstr));
|
strncat_P(addrstr, SET_P, sizeof(addrstr));
|
||||||
break;
|
break;
|
||||||
// case ST_PERCENTS255:
|
|
||||||
// case ST_HSV255:
|
|
||||||
// strncat_P(addrstr, ESET_P, sizeof(addrstr));
|
|
||||||
// break;
|
|
||||||
default:
|
default:
|
||||||
strncat_P(addrstr, SET_P, sizeof(addrstr));
|
strncat_P(addrstr, SET_P, sizeof(addrstr));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ uint8_t itemCmd::getStoragetypeByChanType(short chanType)
|
|||||||
case CH_MOTOR:
|
case CH_MOTOR:
|
||||||
case CH_PWM:
|
case CH_PWM:
|
||||||
case CH_RELAY:
|
case CH_RELAY:
|
||||||
|
case CH_VC:
|
||||||
return ST_PERCENTS255;
|
return ST_PERCENTS255;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -339,7 +340,8 @@ itemCmd itemCmd::assignFrom(itemCmd from, short chanType)
|
|||||||
param.v=constrain(from.param.asInt32,0,255);
|
param.v=constrain(from.param.asInt32,0,255);
|
||||||
break;
|
break;
|
||||||
case ST_TENS:
|
case ST_TENS:
|
||||||
param.v=map(from.param.asInt32,0,2550,0,255);
|
param.v=constrain(from.param.asInt32/10,0,255);
|
||||||
|
break;
|
||||||
case ST_HSV255:
|
case ST_HSV255:
|
||||||
param.h=from.param.h;
|
param.h=from.param.h;
|
||||||
param.s=from.param.s;
|
param.s=from.param.s;
|
||||||
@@ -458,7 +460,7 @@ itemCmd itemCmd::assignFrom(itemCmd from, short chanType)
|
|||||||
switch (from.cmd.itemArgType)
|
switch (from.cmd.itemArgType)
|
||||||
{
|
{
|
||||||
case ST_PERCENTS255:
|
case ST_PERCENTS255:
|
||||||
vol=map(from.param.v,0,255,0,100);
|
vol=from.param.v;
|
||||||
break;
|
break;
|
||||||
case ST_INT32:
|
case ST_INT32:
|
||||||
case ST_UINT32:
|
case ST_UINT32:
|
||||||
@@ -965,7 +967,7 @@ int itemCmd::doMappingCmd(aJsonObject *mappingData)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char * itemCmd::toString(char * Buffer, int bufLen, int sendFlags, int base )
|
char * itemCmd::toString(char * Buffer, int bufLen, int sendFlags, bool scale100 )
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!Buffer || !bufLen) return NULL;
|
if (!Buffer || !bufLen) return NULL;
|
||||||
@@ -986,7 +988,7 @@ char * itemCmd::toString(char * Buffer, int bufLen, int sendFlags, int base )
|
|||||||
{ short colorTemp;
|
{ short colorTemp;
|
||||||
|
|
||||||
case ST_PERCENTS255:
|
case ST_PERCENTS255:
|
||||||
snprintf(argPtr, bufLen, "%u", map (param.v,0,255,0,base));
|
snprintf(argPtr, bufLen, "%u", (scale100)?map (param.v,0,255,0,100):param.v);
|
||||||
break;
|
break;
|
||||||
case ST_UINT32:
|
case ST_UINT32:
|
||||||
snprintf(argPtr, bufLen, "%lu", param.asUint32);
|
snprintf(argPtr, bufLen, "%lu", param.asUint32);
|
||||||
@@ -1000,10 +1002,10 @@ char * itemCmd::toString(char * Buffer, int bufLen, int sendFlags, int base )
|
|||||||
case ST_HSV255:
|
case ST_HSV255:
|
||||||
colorTemp=getColorTemp();
|
colorTemp=getColorTemp();
|
||||||
|
|
||||||
if (colorTemp<0)
|
if (colorTemp<0 || scale100)
|
||||||
snprintf(argPtr, bufLen, "%d,%d,%d", param.h, param.s, map (param.v,0,255,0,base));
|
snprintf(argPtr, bufLen, "%d,%d,%d", param.h, param.s, (scale100)?map (param.v,0,255,0,100):param.v);
|
||||||
else
|
else
|
||||||
snprintf(argPtr, bufLen, "%d,%d,%d,%d", param.h, param.s, map (param.v,0,255,0,base), colorTemp);
|
snprintf(argPtr, bufLen, "%d,%d,%d,%d", param.h, param.s, (scale100)?map (param.v,0,255,0,100):param.v, colorTemp);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case ST_HS:
|
case ST_HS:
|
||||||
@@ -1050,3 +1052,15 @@ char * itemCmd::toString(char * Buffer, int bufLen, int sendFlags, int base )
|
|||||||
toString(buf,sizeof(buf));
|
toString(buf,sizeof(buf));
|
||||||
debugSerial<<buf<<F(" AT:")<<getArgType()<<F(" Suff:")<<getSuffix()<<endl;
|
debugSerial<<buf<<F(" AT:")<<getArgType()<<F(" Suff:")<<getSuffix()<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool itemCmd::scale100()
|
||||||
|
{
|
||||||
|
switch (cmd.itemArgType)
|
||||||
|
{
|
||||||
|
case ST_PERCENTS255:
|
||||||
|
case ST_HSV255:
|
||||||
|
param.v=constrain(map(param.v,0,100,0,255),0,255);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -210,7 +210,7 @@ public:
|
|||||||
uint8_t getCmd();
|
uint8_t getCmd();
|
||||||
uint8_t getArgType();
|
uint8_t getArgType();
|
||||||
uint8_t getCmdParam();
|
uint8_t getCmdParam();
|
||||||
char * toString(char * Buffer, int bufLen, int sendFlags = SEND_COMMAND | SEND_PARAMETERS, int base = 255);
|
char * toString(char * Buffer, int bufLen, int sendFlags = SEND_COMMAND | SEND_PARAMETERS, bool scale100 = false);
|
||||||
|
|
||||||
bool isCommand();
|
bool isCommand();
|
||||||
bool isValue();
|
bool isValue();
|
||||||
@@ -224,7 +224,7 @@ public:
|
|||||||
int doReverseMapping (aJsonObject *mappingData);
|
int doReverseMapping (aJsonObject *mappingData);
|
||||||
int doMappingCmd(aJsonObject *mappingData);
|
int doMappingCmd(aJsonObject *mappingData);
|
||||||
int doReverseMappingCmd (aJsonObject *mappingData);
|
int doReverseMappingCmd (aJsonObject *mappingData);
|
||||||
|
bool scale100();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,10 @@
|
|||||||
#define CONTROLLER TM1809
|
#define CONTROLLER TM1809
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef SCALE_VOLUME_100
|
||||||
|
#define SCALE_VOLUME_100 false
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef DATA_PIN
|
#ifndef DATA_PIN
|
||||||
#define DATA_PIN 4
|
#define DATA_PIN 4
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user