Home AMX User Forum NetLinx Studio

Two Qs; Exponent and "device array"?

Now this will be my third post and my previous two were answered in a single line so I'm starting to feel a little... worried of asking questions that seem so simple. Not gonna happen this time, I've got TWO questions.

1) I'm nervous about asking this one but I can't seem to find documentation on it. How do I make an exponent? Normal programming its just a "^". Same in Studio?

A=10^B
B = 0 then A = 1
B = 1 then A = 10
B = 2 then A = 100

2) In a system with one controller I've got mutliple touch panels, say three. For each touch panel I have an AXI file where I define the button actions. All panels are the same so I'm certain I'm being redundant in creating a axi file for each panel. I'm certain I could something similar to...

BUTTON_EVENT[dvMastTP01,100]
BUTTON_EVENT[dvMastTP02,100]
BUTTON_EVENT[dvMastTP03,100]{
PUSH:{ A = 4 }
} //note, I haven't tried this

But the day where I want to add a 4th panel I'd have to manually enter BUTTON_EVENT[dvMastTP04,100] to each event. could I not set up a variable, somewhat like define_combine to do this?

allTP = {dvMastTP01,dvMastTP02,dvMastTP03}

BUTTON_EVENT[allTP,100]{
PUSH:{ A = 4 }
}

*If any TP pushes thier button 100 then "A" equals three. Would a problem occure if two seperate panels push their own button 100 simultaneously?




Thank you for your time.
Marc

Comments

  • jjamesjjames Posts: 2,908
    I'm not much of a math person, so I'm going to skip the first question and just jump onto the second.

    The *best* (IMO) way to handle multiple panels is doing the same things is to use a DEV array. You'd set them up like this:
    DEFINE_CONSTANT // or DEFINE_VARIABLE if you want
    DEV dv_TP[]=
    {
      dvMastTP01
     ,dvMastTP02
     ,dvMastTP03
     // add more as you want
    }
    
    BUTTON_EVENT[dv_TP,100]
    {
      // so on and so forth...
    }
    

    Now, you can use GET_LAST to determine which panel pressed button 100 (example: A = GET_LAST(dv_TP)), and do whatever you want. I'd stay away from DEVCHANs and they put you too much into a box. The key is flexibility (which you are finding out) - and using arrays is a great start.

    Also - I haven't seen your other posts, but if you're new to the programming world (or just getting started again after a while), do not hesitate to ask any questions. We've all been there before, and the best piece of advice is to just ask it - who knows, hopefully your question will help others out along the way.

    Oh, one more thing - for ease of readability and distinction of code snippets, include the CODE brackets (i.e. [ CODE ] and [/ CODE ] - remove spaces however!) when posting code.
  • DHawthorneDHawthorne Posts: 4,584
    No, the ^ is a bit-wise OR operator, not exponent. It won't give you the results you expect :). There isn't a native exponent operator in NetLinx (least, I don't think there is) ; you could just whip up a function for it though.
  • HedbergHedberg Posts: 671
    If it's a whole number exponent, it's pretty easy. If it's not, not so much. The simplest thing is to try a power series expansion. A search of the forums for "math library" will turn up a link to something useful.
  • PhreaKPhreaK Posts: 966
    You may find the NetLinx Common Libraries useful. In particular the math_power() function contained within the math library. At the moment it only works with single precision floating point bases and integer exponents, but if you need it to do something else feel free to change / improve it.
  • VMarcVMarc Posts: 10
    Done and done.
    Ty all very much for the answers. Got the Math.axi to work no problems and I'll work on the DEV array today.

    I don't think I've ever been on such a great and supportive forums. cudos to all.



    Marc
Sign In or Register to comment.