Skip to content
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. General Discussion
  3. Move functions
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

Move functions

Scheduled Pinned Locked Moved General Discussion
6 Posts 3 Posters 1.2k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    moskovskiy82
    wrote on last edited by
    #1

    I have merged two sketches together.

    The first one was on switches and the second one was if/else if
    So the first sketch was something like

    Switch
    case1
    case2
    End switch
    
    Sendcommand();
    Send status();
    

    And after moving in the second sketch it became

    Switch
    case1
    case2
    newcase3
    newcase4
    End switch
    
    Sendcommand();
    Send status();
    

    So now - everytime i issue commands that satisfy newcase3 and 4 - these two functions get executed. So i wonder how i can git rid of that... Can i just move them to the end of switch1 and 2 code?

    mfalkviddM dbemowskD 2 Replies Last reply
    0
    • M moskovskiy82

      I have merged two sketches together.

      The first one was on switches and the second one was if/else if
      So the first sketch was something like

      Switch
      case1
      case2
      End switch
      
      Sendcommand();
      Send status();
      

      And after moving in the second sketch it became

      Switch
      case1
      case2
      newcase3
      newcase4
      End switch
      
      Sendcommand();
      Send status();
      

      So now - everytime i issue commands that satisfy newcase3 and 4 - these two functions get executed. So i wonder how i can git rid of that... Can i just move them to the end of switch1 and 2 code?

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by mfalkvidd
      #2

      @moskovskiy82 yes

      You might want/need to add them to the default: case as well, if they should be run even if case1: and case2: didn't happen.

      1 Reply Last reply
      0
      • M moskovskiy82

        I have merged two sketches together.

        The first one was on switches and the second one was if/else if
        So the first sketch was something like

        Switch
        case1
        case2
        End switch
        
        Sendcommand();
        Send status();
        

        And after moving in the second sketch it became

        Switch
        case1
        case2
        newcase3
        newcase4
        End switch
        
        Sendcommand();
        Send status();
        

        So now - everytime i issue commands that satisfy newcase3 and 4 - these two functions get executed. So i wonder how i can git rid of that... Can i just move them to the end of switch1 and 2 code?

        dbemowskD Offline
        dbemowskD Offline
        dbemowsk
        wrote on last edited by
        #3

        @moskovskiy82 I am a bit confused on your question. Can you post your whole sketch and explain more of what you want/don't want to happen?

        Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
        Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

        1 Reply Last reply
        0
        • M Offline
          M Offline
          moskovskiy82
          wrote on last edited by
          #4

          Ok this is the part of sketch in question.
          You can see there are two functions in the end
          sendHeatpumpCommand();
          sendNewStateToGateway();
          They only concern HVAC and send an update to the AC. But they get called each time i change for example brightness for the RGB strip

          void receive(const MyMessage &message) {
            if (message.isAck()) {
               Serial.println("This is an ack from gateway");
               //return;
            }
          
            Serial.print("Incoming message for: ");
            Serial.print(message.sensor);
            int val; //RGB VAR  
            String recvData = message.data;
            recvData.trim();
          
            Serial.print(", New status: ");
            Serial.println(recvData);
            switch (message.type) 
            {
              case V_HVAC_SPEED:
                Serial.println("V_HVAC_SPEED");
          
                if(recvData.equalsIgnoreCase("auto")) 
              {
               FAN_STATE = 0;
               HA_FAN_STATE = "Auto";
              }
                else if(recvData.equalsIgnoreCase("min")) 
                {
                   FAN_STATE = 1;
                   HA_FAN_STATE = "Min";
                  }
                else if(recvData.equalsIgnoreCase("normal")) 
                {
                   FAN_STATE = 2;
                   HA_FAN_STATE = "Normal";
                  }
                else if(recvData.equalsIgnoreCase("max")) 
                {
                   FAN_STATE = 3;
                   HA_FAN_STATE = "Max";
                  }
              break;
              case V_HVAC_SETPOINT_COOL:
                Serial.println("V_HVAC_SETPOINT_COOL");
                TEMP_STATE = message.getFloat();
                Serial.println(TEMP_STATE);
              break;
              case V_HVAC_FLOW_STATE:
                Serial.println("V_HVAC_FLOW_STATE");
                if (recvData.equalsIgnoreCase("coolon")) 
                {
                   POWER_STATE = 1;
                   MODE_STATE = MODE_COOL;
                   HA_MODE_STATE = "CoolOn";
                  }
                else if (recvData.equalsIgnoreCase("heaton")) 
                {
                   POWER_STATE = 1;
                   MODE_STATE = MODE_HEAT;
                   HA_MODE_STATE = "HeatOn";
                  }
                else if (recvData.equalsIgnoreCase("autochangeover")) 
                {
                   POWER_STATE = 1;
                   MODE_STATE = MODE_AUTO;
                   HA_MODE_STATE = "AutoChangeOver";
                  }
                else if (recvData.equalsIgnoreCase("off"))
                {
                   POWER_STATE = 0;
                   HA_MODE_STATE = "Off";
                  }
                initialValueSent = true;
              break;
            case V_RGB:
               {
               Serial.println( "V_RGB command: " );
               Serial.println(message.data);
               long number = (long) strtol( message.data, NULL, 16);
               // Save old value
               strcpy(rgbstring, message.data);
               // Split it up into r, g, b values
               red = number >> 16;
               green = number >> 8 & 0xFF;
               blue = number & 0xFF;
               send_status();
               set_hw_status();
              }
            break;
            case V_LIGHT:
              {
               Serial.println( "V_LIGHT command: " );
               Serial.println(message.data);
               val = atoi(message.data);
               if (val == 0 or val == 1) 
              {
                   on_off_status = val;
                   send_status();
                   set_hw_status();
                  }
              }
            break;
            case V_DIMMER: 
              {
              Serial.print( "V_DIMMER command: " );
              Serial.println(message.data);
              val = atoi(message.data);
              if (val >= 0 and val <=100) 
              {
                dimmerlevel = val;
                send_status();
                set_hw_status();
              }
              }
            break;
            case V_VAR1:
              {
              Serial.print( "V_VAR1 command: " );
              Serial.println(message.data);
              val = atoi(message.data);
              if (val >= 0 and val <= 2000) 
              {
                fadespeed = val;
              }
              }
            break;
            }  
            
            sendHeatpumpCommand();
            sendNewStateToGateway();
          }
          
          mfalkviddM 1 Reply Last reply
          0
          • M moskovskiy82

            Ok this is the part of sketch in question.
            You can see there are two functions in the end
            sendHeatpumpCommand();
            sendNewStateToGateway();
            They only concern HVAC and send an update to the AC. But they get called each time i change for example brightness for the RGB strip

            void receive(const MyMessage &message) {
              if (message.isAck()) {
                 Serial.println("This is an ack from gateway");
                 //return;
              }
            
              Serial.print("Incoming message for: ");
              Serial.print(message.sensor);
              int val; //RGB VAR  
              String recvData = message.data;
              recvData.trim();
            
              Serial.print(", New status: ");
              Serial.println(recvData);
              switch (message.type) 
              {
                case V_HVAC_SPEED:
                  Serial.println("V_HVAC_SPEED");
            
                  if(recvData.equalsIgnoreCase("auto")) 
                {
                 FAN_STATE = 0;
                 HA_FAN_STATE = "Auto";
                }
                  else if(recvData.equalsIgnoreCase("min")) 
                  {
                     FAN_STATE = 1;
                     HA_FAN_STATE = "Min";
                    }
                  else if(recvData.equalsIgnoreCase("normal")) 
                  {
                     FAN_STATE = 2;
                     HA_FAN_STATE = "Normal";
                    }
                  else if(recvData.equalsIgnoreCase("max")) 
                  {
                     FAN_STATE = 3;
                     HA_FAN_STATE = "Max";
                    }
                break;
                case V_HVAC_SETPOINT_COOL:
                  Serial.println("V_HVAC_SETPOINT_COOL");
                  TEMP_STATE = message.getFloat();
                  Serial.println(TEMP_STATE);
                break;
                case V_HVAC_FLOW_STATE:
                  Serial.println("V_HVAC_FLOW_STATE");
                  if (recvData.equalsIgnoreCase("coolon")) 
                  {
                     POWER_STATE = 1;
                     MODE_STATE = MODE_COOL;
                     HA_MODE_STATE = "CoolOn";
                    }
                  else if (recvData.equalsIgnoreCase("heaton")) 
                  {
                     POWER_STATE = 1;
                     MODE_STATE = MODE_HEAT;
                     HA_MODE_STATE = "HeatOn";
                    }
                  else if (recvData.equalsIgnoreCase("autochangeover")) 
                  {
                     POWER_STATE = 1;
                     MODE_STATE = MODE_AUTO;
                     HA_MODE_STATE = "AutoChangeOver";
                    }
                  else if (recvData.equalsIgnoreCase("off"))
                  {
                     POWER_STATE = 0;
                     HA_MODE_STATE = "Off";
                    }
                  initialValueSent = true;
                break;
              case V_RGB:
                 {
                 Serial.println( "V_RGB command: " );
                 Serial.println(message.data);
                 long number = (long) strtol( message.data, NULL, 16);
                 // Save old value
                 strcpy(rgbstring, message.data);
                 // Split it up into r, g, b values
                 red = number >> 16;
                 green = number >> 8 & 0xFF;
                 blue = number & 0xFF;
                 send_status();
                 set_hw_status();
                }
              break;
              case V_LIGHT:
                {
                 Serial.println( "V_LIGHT command: " );
                 Serial.println(message.data);
                 val = atoi(message.data);
                 if (val == 0 or val == 1) 
                {
                     on_off_status = val;
                     send_status();
                     set_hw_status();
                    }
                }
              break;
              case V_DIMMER: 
                {
                Serial.print( "V_DIMMER command: " );
                Serial.println(message.data);
                val = atoi(message.data);
                if (val >= 0 and val <=100) 
                {
                  dimmerlevel = val;
                  send_status();
                  set_hw_status();
                }
                }
              break;
              case V_VAR1:
                {
                Serial.print( "V_VAR1 command: " );
                Serial.println(message.data);
                val = atoi(message.data);
                if (val >= 0 and val <= 2000) 
                {
                  fadespeed = val;
                }
                }
              break;
              }  
              
              sendHeatpumpCommand();
              sendNewStateToGateway();
            }
            
            mfalkviddM Offline
            mfalkviddM Offline
            mfalkvidd
            Mod
            wrote on last edited by
            #5

            @moskovskiy82 move them to just before break; in the cases you want them to run?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              moskovskiy82
              wrote on last edited by
              #6

              Thank you. Will do so and report back

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              6

              Online

              11.7k

              Users

              11.2k

              Topics

              113.0k

              Posts


              Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • OpenHardware.io
              • Categories
              • Recent
              • Tags
              • Popular