fix mqtt send knob change
This commit is contained in:
parent
edff630fb9
commit
8387291255
|
@ -28,7 +28,8 @@ void setSelectionChannel(uint8_t i, boolean state);
|
|||
void setMuteChannel(uint8_t i, boolean state);
|
||||
void publishCurrentSetVolume();
|
||||
void publishAllStates(int pn, String pTopicname, boolean (*pgetBit) (uint8_t));
|
||||
void changeRelaisByNumber(uint8_t pn, String pTopicPrefix, String pTopic, String pspayload, void (*psetXChannel) (uint8_t, boolean));
|
||||
void changeRelaisByNumberTopic(uint8_t pn, String pTopicPrefix, String pTopic, String pspayload, void (*psetXChannel) (uint8_t, boolean));
|
||||
void setRelaisByNumber(uint8_t pn, String pTopicPrefix, uint8_t pnumber, bool pstate, void (*psetXChannel) (uint8_t, boolean));
|
||||
float getSetVolume();
|
||||
|
||||
#define LEDPIN 9 //PB1 = D9 = Pin15
|
||||
|
@ -304,7 +305,7 @@ void loop() {
|
|||
case 1: //mute
|
||||
if (menu_selectedChannel<=MENU_MAXCHANNEL) { //inside valid range
|
||||
//setMuteChannel(menu_selectedChannel,!getMute(menu_selectedChannel)); // mute/unmute menu_selectedChannel
|
||||
changeRelaisByNumber(NUMMUTECHANNELS,"audiomixer/mute_", ""+menu_selectedChannel, ""+!getMute(menu_selectedChannel), &setMuteChannel); //toggle
|
||||
setRelaisByNumber(NUMMUTECHANNELS,"audiomixer/mute_", menu_selectedChannel, !getMute(menu_selectedChannel), &setMuteChannel); //toggle
|
||||
}else{ //nothing selected
|
||||
menu_mode = 0; //return to volume mode
|
||||
}
|
||||
|
@ -313,7 +314,7 @@ void loop() {
|
|||
case 2: //group selection
|
||||
if (menu_selectedChannel<=MENU_MAXCHANNEL) { //inside valid range
|
||||
//setSelectionChannel(menu_selectedChannel,!getSelection(menu_selectedChannel)); // toggle selection menu_selectedChannel
|
||||
changeRelaisByNumber(NUMSELECTCHANNELS,"audiomixer/select_", ""+menu_selectedChannel, ""+!getSelection(menu_selectedChannel), &setSelectionChannel); //toggle
|
||||
setRelaisByNumber(NUMSELECTCHANNELS,"audiomixer/select_", menu_selectedChannel, !getSelection(menu_selectedChannel), &setSelectionChannel); //toggle
|
||||
}else{ //nothing selected
|
||||
menu_mode = 0; //return to volume mode
|
||||
}
|
||||
|
@ -615,10 +616,10 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
|||
publishAllStates(NUMSELECTCHANNELS,"select_", &getSelection);
|
||||
|
||||
}else if (String(topic).startsWith("audiomixer/mute_")) { //with range
|
||||
changeRelaisByNumber(NUMMUTECHANNELS,"audiomixer/mute_", topic, spayload, &setMuteChannel);
|
||||
changeRelaisByNumberTopic(NUMMUTECHANNELS,"audiomixer/mute_", topic, spayload, &setMuteChannel);
|
||||
|
||||
}else if (String(topic).startsWith("audiomixer/select_")) {
|
||||
changeRelaisByNumber(NUMSELECTCHANNELS,"audiomixer/select_", topic, spayload, &setSelectionChannel);
|
||||
changeRelaisByNumberTopic(NUMSELECTCHANNELS,"audiomixer/select_", topic, spayload, &setSelectionChannel);
|
||||
}
|
||||
|
||||
|
||||
|
@ -709,7 +710,7 @@ void publishAllStates(int pn, String pTopicname, boolean (*pgetBit) (uint8_t)){
|
|||
}
|
||||
}
|
||||
|
||||
void changeRelaisByNumber(uint8_t pn, String pTopicPrefix, String pTopic, String pspayload, void (*psetXChannel) (uint8_t, boolean))
|
||||
void changeRelaisByNumberTopic(uint8_t pn, String pTopicPrefix, String pTopic, String pspayload, void (*psetXChannel) (uint8_t, boolean))
|
||||
{
|
||||
uint8_t _index=255;
|
||||
for (uint8_t i=0; i<pn && _index==255; i++) {
|
||||
|
@ -720,16 +721,25 @@ void changeRelaisByNumber(uint8_t pn, String pTopicPrefix, String pTopic, String
|
|||
if (_index==255) {
|
||||
Serial.println("Index OOR");
|
||||
}else{ //index ok
|
||||
String pub_topic = pTopicPrefix+String(_index);
|
||||
if (pspayload.equalsIgnoreCase("false")) {
|
||||
psetXChannel(_index,false);
|
||||
mqttClient.publish((char*) pub_topic.c_str(), "false");
|
||||
}else if (pspayload.equalsIgnoreCase("true")) {
|
||||
psetXChannel(_index,true);
|
||||
mqttClient.publish((char*) pub_topic.c_str(), "true");
|
||||
bool _state=false;
|
||||
if (pspayload.equalsIgnoreCase("true")) {
|
||||
_state=true;
|
||||
}
|
||||
setRelaisByNumber(pn, pTopicPrefix, _index, _state, psetXChannel);
|
||||
}
|
||||
}
|
||||
|
||||
void setRelaisByNumber(uint8_t pn, String pTopicPrefix, uint8_t pnumber, bool pstate, void (*psetXChannel) (uint8_t, boolean))
|
||||
{
|
||||
String pub_topic = pTopicPrefix+String(pnumber);
|
||||
psetXChannel(pnumber,pstate);
|
||||
String _mqttpayload="false";
|
||||
if (pstate) { //True
|
||||
_mqttpayload="true";
|
||||
}
|
||||
mqttClient.publish((char*) pub_topic.c_str(), (char*) _mqttpayload.c_str()); //Publish
|
||||
}
|
||||
|
||||
|
||||
float getSetVolume() {
|
||||
return map(poti_set,POT_MIN,POT_MAX, 0.0,100.0); //get percentage from set poti value
|
||||
|
|
Loading…
Reference in New Issue