Home AMX User Forum AMXForums Archive Threads AMX Applications and Solutions

Converting a Data Event Variable to a Level

I am parsing out a light level form a lighting program and want to convert it to a level to send to a T.

How do I convert a variable to a value that can be sent to a TP Bargraph?

Comments

  • Have you tried SEND_LEVEL? Sounds like the right thing to do in your application.
  • davegrovdavegrov Posts: 114
    My Code

    STRING:
    {
    SELECT
    {
    ACTIVE(FIND_STRING(DATA.TEXT,'DL,',1)):
    {
    ltLevel = (RIGHT_STRING(DATA.TEXT,2))
    nLight = ((MID_STRING(DATA.TEXT,7,2))
    SEND_LEVEL dvTP_Lights, ATOI(nlight+9), ATOI(ltLevel)
    }
    }
    }
  • HedbergHedberg Posts: 671
    this is too funny, a month or so ago I had reason to look at a very similar question. Here's what I did (it works):
    		if(find_string(data.text,'DL,[',1))
    		{
    			remove_string(sTextBuffer,':',1)
    			nzone = atoi(sTextBuffer)
    			remove_string(sTextBuffer,',',1)
    			nlightLevel[nZone] = type_cast(type_cast(atoi(sTextBuffer)) * 2.55)
    			send_level dvTPLights, nLightLevelNbr[nZone], nLightLevel[nZone]
    		}
    

    Should we have a separate thread combining all these type of questions? Time's wasting.
  • davegrovdavegrov Posts: 114
    Still a novice here

    What does the TYPE_CAST do?

    I'm still stumped.


    ACTIVE(find_string(data.text,'DL,,50
    {
    stextBuffer=(DATA.TEXT)
    remove_string(sTextBuffer,':',1) // sTextBuffer Now = 4],50
    nLightzone= atoi(sTextBuffer) //nLightzone= ? sTextBuffer is =4],50
    remove_string(sTextBuffer,',',1) //sTextBuffer = 50
    nlightLevel[nLightzone] = type_cast(type_cast(atoi((sTextBuffer)) + 9))
    send_level dvTP_Lights, nlightLevel[nLightzone], nlightLevel[nLightzone]

    }
  • viningvining Posts: 4,368
    davegrov wrote:
    What does the TYPE_CAST do?
    Allows you to put a float or double into an integer w/o producing a compiler warning. The result of n x 2.55 would require a var delcared as a float or double to contain it. Type Cast allows you to scrap the decimal portion of the result w/o the warning.

    If the lights are 0-100 based I would forgo the multiplication and just make the bargragh 0-100 too and then send straight level values w/o conversion.
    //Request the current intensity of processor 1, link 1, MI address 0, RPM module 2, zone 4
    //                                    //DL, [01:01:00:02:04], 50  //RPM dimmer
    if(find_string(DATA.TEXT,'DL,[',1))   //DL, [01:04:03:05:07], 50  //H48 dimmer
         {
         STACK_VAR INTEGER nProcessor ;
         STACK_VAR INTEGER nLink ;
         STACK_VAR INTEGER nRouter ;
         STACK_VAR INTEGER nBus ;
         STACK_VAR INTEGER nDimmer ;
         STACK_VAR INTEGER nLevel ;
         
         nProcessor	= atoi(remove_string(DATA.TEXT,':',1)) ;
         nLink	= atoi(remove_string(DATA.TEXT,':',1)) ;
         if(nLink < 8)
    	  {
    	  nRouter = atoi(remove_string(DATA.TEXT,':',1)+1) ;//add 1 so it's not zero base
    	  nBus	  = atoi(remove_string(DATA.TEXT,':',1)) ;
    	  nDimmer = atoi(remove_string(DATA.TEXT,',',1)) ;
    	  }
         else //RF Dimmer
    	  {
    	  nRouter = 0 ; //no router for RF dimmers
    	  nBus	  = atoi(remove_string(DATA.TEXT,':',1)) ;
    	  nDimmer = atoi(remove_string(DATA.TEXT,',',1)) ;
    	  }
         nLevel = atoi(DATA.TEXT) ;
         
         //create a structure or array to hold values globally 
         nDimZone[(*do math on above vars based on your system configuration*)] = nLevel ;
         
         SEND_LEVEL dvTPLights,1 (*level channel*), nLevel ;
         }
    

    Now depending on the value received you may stil need to convert from ascii to integer like above.
Sign In or Register to comment.