rename mqtt topic mute to enable

This commit is contained in:
interfisch 2020-06-14 11:12:13 +02:00
parent d53044a4e1
commit 4994ed9ac3
1 changed files with 11 additions and 11 deletions

View File

@ -182,7 +182,7 @@ void setup() {
if (useethernet)
{
Serial.println("trying DHCP");
Serial.println("DHCP..");
if (Ethernet.begin(mac) == 0) { // setup ethernet communication using DHCP
useethernet=false;
//Unable to configure Ethernet using DHCP
@ -193,7 +193,7 @@ void setup() {
}else{
useethernet=true;
Serial.print("IP address: ");
Serial.print("IP: ");
Serial.println(Ethernet.localIP());
Serial.println();
@ -238,9 +238,9 @@ void reconnect() {
publishCurrentSetVolume();
mqttClient.publish("audiomixer/ip", ip.c_str()); //Publish own ip
mqttClient.subscribe("audiomixer/volume/set"); //subscribe to /set, republish without /set
mqttClient.subscribe("audiomixer/mute/set"); //without range
mqttClient.subscribe("audiomixer/enable/set"); //without range
for (uint8_t i=0;i<NUMMUTECHANNELS;i++) { //with range
String sub_topic="audiomixer/mute_"+String(i)+"/set";
String sub_topic="audiomixer/enable_"+String(i)+"/set";
mqttClient.subscribe((char*) sub_topic.c_str());
}
mqttClient.subscribe("audiomixer/select/set"); //without range
@ -305,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
setRelaisByNumber(NUMMUTECHANNELS,"audiomixer/mute_", menu_selectedChannel, !getMute(menu_selectedChannel), &setMuteChannel); //toggle
setRelaisByNumber(NUMMUTECHANNELS,"audiomixer/enable_", menu_selectedChannel, !getMute(menu_selectedChannel), &setMuteChannel); //toggle
}else{ //nothing selected
menu_mode = 0; //return to volume mode
}
@ -589,18 +589,18 @@ void callback(char* topic, byte* payload, unsigned int length) {
publishCurrentSetVolume();
}else if (String(topic).equals("audiomixer/mute/set")) { //withouth range
}else if (String(topic).equals("audiomixer/enable/set")) { //withouth range
//Serial.print("Mute string="); Serial.println(spayload);
uint16_t ipayload=spayload.toInt();
if (spayload.equalsIgnoreCase("false")) {
setMuteInt(0); //all unmuted
setMuteInt(0); //all muted
}else if (spayload.equalsIgnoreCase("true")) {
setMuteInt(pow(2,NUMMUTECHANNELS)-1); //all muted
}else if (ipayload>=0 && ipayload<((uint16_t)1<<NUMMUTECHANNELS)){ //in range
setMuteInt(ipayload); //set bits directly
}
publishAllStates(NUMMUTECHANNELS,"mute_", &getMute);
publishAllStates(NUMMUTECHANNELS,"enable_", &getMute);
}else if (String(topic).equals("audiomixer/select/set")) { //withouth range
//Serial.print("Select string="); Serial.println(spayload);
@ -615,8 +615,8 @@ void callback(char* topic, byte* payload, unsigned int length) {
publishAllStates(NUMSELECTCHANNELS,"select_", &getSelection);
}else if (String(topic).startsWith("audiomixer/mute_")) { //with range
changeRelaisByNumberTopic(NUMMUTECHANNELS,"audiomixer/mute_", topic, spayload, &setMuteChannel);
}else if (String(topic).startsWith("audiomixer/enable_")) { //with range
changeRelaisByNumberTopic(NUMMUTECHANNELS,"audiomixer/enable_", topic, spayload, &setMuteChannel);
}else if (String(topic).startsWith("audiomixer/select_")) {
changeRelaisByNumberTopic(NUMSELECTCHANNELS,"audiomixer/select_", topic, spayload, &setSelectionChannel);
@ -660,7 +660,7 @@ uint32_t Wheel(byte WheelPos) {
return leds.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void setMuteInt(uint8_t i) {
void setMuteInt(uint8_t i) { //low is muted
uint16_t mask=(( (uint16_t)1<<(NUMMUTECHANNELS))-1 )<<NUMSELECTCHANNELS;
srbits = ((i<<NUMSELECTCHANNELS) & mask) | (srbits & ~mask);
srShiftOut();