Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Weather data value to rotation
Forum Updated to NodeBB v4.3 + New Features

Weather data value to rotation

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 2 Posters 429 Views
  • 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.
  • MarkkyboyM Offline
    MarkkyboyM Offline
    Markkyboy
    wrote on last edited by
    #1

    I've made a barometer gauge, starting from 970 hPa (from: -130 degrees/angle) --> 1070 hPa (to: +130 degrees/angle)

    I'm using Openweathermap.org to get actual pressure data (shown bottom of image)

    How do I calculate the angle of the needle using the pressure data?, I guess it's a job for javascript and as such, have searched exstensively but haven't found anything relevant and am not really sure how to tackle it. Any info/ideas gratefully received.

    Screenshot_20220516_001.png

    Don't just sit there standing around, pick up a shovel and sweep up!

    I live by the sea, not in it.

    J.HilkJ 1 Reply Last reply
    0
    • MarkkyboyM Markkyboy

      @J-Hilk said in Weather data value to rotation:

      template<typename typeIn, typename typeOut>
      auto mapToRange(typeIn value,
      typeIn inMax = std::numeric_limits<typeIn>::max(),
      typeIn inMin = std::numeric_limits<typeIn>::min(),
      typeOut outMax = std::numeric_limits<typeOut>::max(),
      typeOut outMin = std::numeric_limits<typeOut>::min() ){
      //Mapping follows: Y = (X-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew
      auto mapped = (static_cast<double>(value) - inMin) / (inMax - inMin) * (outMax - outMin) + outMin;

      return static_cast<typeOut>(mapped);
      

      }

      Thank you, but how do I use that in the QML side of things?, I'm using a Repeater with Rotation (origin.x, origin.y, angle) inside CircularSlider.

      I have added your data to my main.cpp successfully, but where to go from there?

          CircularSlider {
              id: barometer
              width: 400
              height: width
              interactive: false
              minValue:    -130
              maxValue:    130 
              startAngle:  -130
              endAngle:    130 
              anchors.centerIn: parent
              value:  0
      
              Repeater {
                  id: ind
                  model: 1
                  Rectangle {
                      z: 2
                      id: indicator
                      width: 3
                      height: 160
                      color: "orange"
                      smooth: true
                      antialiasing: true
                      transform: [ Translate {
                              x: barometer.width / 2 - width / 2
                              y: 35
                          },
                          Rotation {
                              origin.x: barometer.width / 2
                              origin.y: barometer.height / 2
                              angle: barometer.angle
                          }
                      ]
                  }
              }
      
      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #4

      @Markkyboy quote from my previous post:

      //Mapping follows: Y = (X-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew

      just implement that in QML if you don't want to use the c++/template


      function mapToRange(x, maxRangeOld, minRangeOld,maxRangeNew, minRangeNew)
          {
              return (x-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew
          }
      
      
      CircularSlider {
                 id: barometer
                 width: 400
                 height: width
                 interactive: false
                 minValue:    -130
                 maxValue:    130
                 startAngle:  -130
                 endAngle:    130
                 anchors.centerIn: parent
                 value:  0
                 //Mapping follows: Y = (X-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew
                 angle: mapToRange(value,1070, 970, 130, -130)
      
      ....
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      MarkkyboyM 2 Replies Last reply
      2
      • MarkkyboyM Markkyboy

        I've made a barometer gauge, starting from 970 hPa (from: -130 degrees/angle) --> 1070 hPa (to: +130 degrees/angle)

        I'm using Openweathermap.org to get actual pressure data (shown bottom of image)

        How do I calculate the angle of the needle using the pressure data?, I guess it's a job for javascript and as such, have searched exstensively but haven't found anything relevant and am not really sure how to tackle it. Any info/ideas gratefully received.

        Screenshot_20220516_001.png

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #2

        @Markkyboy

        taken from my function collection:

        template<typename typeIn, typename typeOut>
        auto mapToRange(typeIn value,
                            typeIn inMax = std::numeric_limits<typeIn>::max(),
                            typeIn inMin = std::numeric_limits<typeIn>::min(),
                            typeOut outMax = std::numeric_limits<typeOut>::max(),
                            typeOut outMin = std::numeric_limits<typeOut>::min() ){
            //Mapping follows: Y = (X-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew
            auto mapped = (static_cast<double>(value) - inMin) / (inMax - inMin) * (outMax - outMin) +  outMin;
        
            return static_cast<typeOut>(mapped);
        }
        
        int main(int argc, char *argv[])
        {
        
            for(int i{970}; i < 1071; i++){
                int result = mapToRange<int,int>(i,970, 1070, -130, 130);
                qDebug() << i << "to" << result;
            }
        }
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        MarkkyboyM 1 Reply Last reply
        0
        • J.HilkJ J.Hilk

          @Markkyboy

          taken from my function collection:

          template<typename typeIn, typename typeOut>
          auto mapToRange(typeIn value,
                              typeIn inMax = std::numeric_limits<typeIn>::max(),
                              typeIn inMin = std::numeric_limits<typeIn>::min(),
                              typeOut outMax = std::numeric_limits<typeOut>::max(),
                              typeOut outMin = std::numeric_limits<typeOut>::min() ){
              //Mapping follows: Y = (X-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew
              auto mapped = (static_cast<double>(value) - inMin) / (inMax - inMin) * (outMax - outMin) +  outMin;
          
              return static_cast<typeOut>(mapped);
          }
          
          int main(int argc, char *argv[])
          {
          
              for(int i{970}; i < 1071; i++){
                  int result = mapToRange<int,int>(i,970, 1070, -130, 130);
                  qDebug() << i << "to" << result;
              }
          }
          
          MarkkyboyM Offline
          MarkkyboyM Offline
          Markkyboy
          wrote on last edited by Markkyboy
          #3

          @J-Hilk said in Weather data value to rotation:

          template<typename typeIn, typename typeOut>
          auto mapToRange(typeIn value,
          typeIn inMax = std::numeric_limits<typeIn>::max(),
          typeIn inMin = std::numeric_limits<typeIn>::min(),
          typeOut outMax = std::numeric_limits<typeOut>::max(),
          typeOut outMin = std::numeric_limits<typeOut>::min() ){
          //Mapping follows: Y = (X-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew
          auto mapped = (static_cast<double>(value) - inMin) / (inMax - inMin) * (outMax - outMin) + outMin;

          return static_cast<typeOut>(mapped);
          

          }

          Thank you, but how do I use that in the QML side of things?, I'm using a Repeater with Rotation (origin.x, origin.y, angle) inside CircularSlider.

          I have added your data to my main.cpp successfully, but where to go from there?

              CircularSlider {
                  id: barometer
                  width: 400
                  height: width
                  interactive: false
                  minValue:    -130
                  maxValue:    130 
                  startAngle:  -130
                  endAngle:    130 
                  anchors.centerIn: parent
                  value:  0
          
                  Repeater {
                      id: ind
                      model: 1
                      Rectangle {
                          z: 2
                          id: indicator
                          width: 3
                          height: 160
                          color: "orange"
                          smooth: true
                          antialiasing: true
                          transform: [ Translate {
                                  x: barometer.width / 2 - width / 2
                                  y: 35
                              },
                              Rotation {
                                  origin.x: barometer.width / 2
                                  origin.y: barometer.height / 2
                                  angle: barometer.angle
                              }
                          ]
                      }
                  }
          

          Don't just sit there standing around, pick up a shovel and sweep up!

          I live by the sea, not in it.

          J.HilkJ 1 Reply Last reply
          0
          • MarkkyboyM Markkyboy

            @J-Hilk said in Weather data value to rotation:

            template<typename typeIn, typename typeOut>
            auto mapToRange(typeIn value,
            typeIn inMax = std::numeric_limits<typeIn>::max(),
            typeIn inMin = std::numeric_limits<typeIn>::min(),
            typeOut outMax = std::numeric_limits<typeOut>::max(),
            typeOut outMin = std::numeric_limits<typeOut>::min() ){
            //Mapping follows: Y = (X-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew
            auto mapped = (static_cast<double>(value) - inMin) / (inMax - inMin) * (outMax - outMin) + outMin;

            return static_cast<typeOut>(mapped);
            

            }

            Thank you, but how do I use that in the QML side of things?, I'm using a Repeater with Rotation (origin.x, origin.y, angle) inside CircularSlider.

            I have added your data to my main.cpp successfully, but where to go from there?

                CircularSlider {
                    id: barometer
                    width: 400
                    height: width
                    interactive: false
                    minValue:    -130
                    maxValue:    130 
                    startAngle:  -130
                    endAngle:    130 
                    anchors.centerIn: parent
                    value:  0
            
                    Repeater {
                        id: ind
                        model: 1
                        Rectangle {
                            z: 2
                            id: indicator
                            width: 3
                            height: 160
                            color: "orange"
                            smooth: true
                            antialiasing: true
                            transform: [ Translate {
                                    x: barometer.width / 2 - width / 2
                                    y: 35
                                },
                                Rotation {
                                    origin.x: barometer.width / 2
                                    origin.y: barometer.height / 2
                                    angle: barometer.angle
                                }
                            ]
                        }
                    }
            
            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by J.Hilk
            #4

            @Markkyboy quote from my previous post:

            //Mapping follows: Y = (X-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew

            just implement that in QML if you don't want to use the c++/template


            function mapToRange(x, maxRangeOld, minRangeOld,maxRangeNew, minRangeNew)
                {
                    return (x-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew
                }
            
            
            CircularSlider {
                       id: barometer
                       width: 400
                       height: width
                       interactive: false
                       minValue:    -130
                       maxValue:    130
                       startAngle:  -130
                       endAngle:    130
                       anchors.centerIn: parent
                       value:  0
                       //Mapping follows: Y = (X-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew
                       angle: mapToRange(value,1070, 970, 130, -130)
            
            ....
            

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            MarkkyboyM 2 Replies Last reply
            2
            • J.HilkJ J.Hilk

              @Markkyboy quote from my previous post:

              //Mapping follows: Y = (X-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew

              just implement that in QML if you don't want to use the c++/template


              function mapToRange(x, maxRangeOld, minRangeOld,maxRangeNew, minRangeNew)
                  {
                      return (x-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew
                  }
              
              
              CircularSlider {
                         id: barometer
                         width: 400
                         height: width
                         interactive: false
                         minValue:    -130
                         maxValue:    130
                         startAngle:  -130
                         endAngle:    130
                         anchors.centerIn: parent
                         value:  0
                         //Mapping follows: Y = (X-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew
                         angle: mapToRange(value,1070, 970, 130, -130)
              
              ....
              
              MarkkyboyM Offline
              MarkkyboyM Offline
              Markkyboy
              wrote on last edited by
              #5

              @J-Hilk said in Weather data value to rotation:

              //Mapping follows: Y = (X-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew

              So close, but I now get; ReferenceError: ivalue is not defined

              Don't just sit there standing around, pick up a shovel and sweep up!

              I live by the sea, not in it.

              J.HilkJ 1 Reply Last reply
              0
              • MarkkyboyM Markkyboy

                @J-Hilk said in Weather data value to rotation:

                //Mapping follows: Y = (X-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew

                So close, but I now get; ReferenceError: ivalue is not defined

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #6

                @Markkyboy please, you should by able to fix my typo 😅


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                2
                • J.HilkJ J.Hilk

                  @Markkyboy quote from my previous post:

                  //Mapping follows: Y = (X-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew

                  just implement that in QML if you don't want to use the c++/template


                  function mapToRange(x, maxRangeOld, minRangeOld,maxRangeNew, minRangeNew)
                      {
                          return (x-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew
                      }
                  
                  
                  CircularSlider {
                             id: barometer
                             width: 400
                             height: width
                             interactive: false
                             minValue:    -130
                             maxValue:    130
                             startAngle:  -130
                             endAngle:    130
                             anchors.centerIn: parent
                             value:  0
                             //Mapping follows: Y = (X-minRangeOld)/(maxRangeOld-minRangeOld) * (maxRangeNew-minRangeNew) + minRangeNew
                             angle: mapToRange(value,1070, 970, 130, -130)
                  
                  ....
                  
                  MarkkyboyM Offline
                  MarkkyboyM Offline
                  Markkyboy
                  wrote on last edited by
                  #7

                  @J-Hilk - sorry, scrap that last comment, I changed it to value and now it works!, yay!!, thank you @J-Hilk, you sir are a genius!! :)

                  Don't just sit there standing around, pick up a shovel and sweep up!

                  I live by the sea, not in it.

                  1 Reply Last reply
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved