From 097506d8c5520449dd5f8d4ad2613fa7756abc28 Mon Sep 17 00:00:00 2001 From: Fisch Date: Sun, 12 Apr 2020 14:53:42 +0200 Subject: [PATCH] reduce code size --- .../mixercontroller_w5100_pio/src/main.cpp | 126 ++++++++++++------ 1 file changed, 86 insertions(+), 40 deletions(-) diff --git a/controller/mixercontroller_w5100_pio/src/main.cpp b/controller/mixercontroller_w5100_pio/src/main.cpp index ee36b57..bc4928d 100644 --- a/controller/mixercontroller_w5100_pio/src/main.cpp +++ b/controller/mixercontroller_w5100_pio/src/main.cpp @@ -28,6 +28,8 @@ boolean getMute(uint8_t pbit); 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)); #define LEDPIN 9 //PB1 = D9 = Pin15 Adafruit_NeoPixel leds = Adafruit_NeoPixel(9, LEDPIN, NEO_GRB + NEO_KHZ800); @@ -45,6 +47,7 @@ uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x06}; #define CLIENT_ID "Mixer" EthernetClient ethClient; PubSubClient mqttClient; +String mqttdevname="audiomixer/"; long last_send=0; @@ -196,7 +199,9 @@ void setup() { poti_set=analogRead(PIN_POT); + #ifdef DEBUG Serial.println("Ready"); + #endif last_send = millis(); @@ -236,7 +241,7 @@ void loop() { if (useethernet){ if (!mqttClient.connected()) { if (loopmillis-last_mqttreconnectattempt > MQTTRECONNECTDELAY) { - Serial.println("Reconnecting to mqtt"); + Serial.println("Recon. mqtt"); reconnect(); last_mqttreconnectattempt=loopmillis; } @@ -415,8 +420,6 @@ void loop() { if ( loopmillis > last_serialdebug+INTERVAL_SERIALDEBUG){ last_serialdebug=loopmillis; - - Serial.print(" set="); Serial.print(poti_set); Serial.print(" is="); @@ -436,9 +439,6 @@ void loop() { wheelpos+=5; leds.show(); - - - } if (loopmillis%5001==0) { @@ -479,16 +479,12 @@ void callback(char* topic, byte* payload, unsigned int length) { //} //if (strncmp((const char*)topic, "audiomixer/volume/set",sizeof(topic)) == 0) { + + if (String(topic).equals("audiomixer/volume/set")){ - //Serial.println("republish"); - float _floatvalue = spayload.toFloat(); _floatvalue=constrain(_floatvalue,0.0,100.0); - /*Serial.print("Volume string="); - Serial.println(spayload); - Serial.print("setvalue="); - Serial.println(_floatvalue);*/ poti_set=constrain(map(_floatvalue,0.0,100.0,POT_MIN,POT_MAX),POT_MIN,POT_MAX); //set new poti position poti_reachedposition=false; //aim for new position @@ -507,6 +503,7 @@ void callback(char* topic, byte* payload, unsigned int length) { } //publish all states + /* for (uint8_t i=0;i