Home AMX User Forum AMX General Discussion

Help With Request Que Logic

OK, I have been writing code for about 2 days and I just wanted to see if anyone else has an idea on how to create the logic for this problem. I have 40 mics in a system. The mics have a button that sends a request to talk string to my NI and a kill request when pushed agian. As I receive the strings for requests I add the mic number to the end of an integer array. My question is when I recieve commands to kill a request what is the best way to search the integer array to find the location in the request que that the mic is at and remove it from the array. any help would be great thanks.

Comments

  • Joe HebertJoe Hebert Posts: 2,159
    Instead of adding or removing items from an array, one approach would be to set up an array with a length equal to the number of mics and treat each element in the array as a flag to indicate whether a mic is selected or not. Every time a user hits a mic button the appropriate mic will toggle its flag and then you can decide what to do based on the value of the flag.

    Here is some example code for 10 mics - I?m too lazy to type out 40 numbers. :) This example uses TP buttons to select or kill a mic.
    DEFINE_DEVICE
    
    dvTP	= 10001:1:0
    
    DEFINE_CONSTANT
    
    INTEGER nMicButtons[] = {101,102,103,104,105,106,107,108,109,110}
    
    DEFINE_VARIABLE
    
    INTEGER nMicFlags[] = {0,0,0,0,0,0,0,0,0,0}
    
    DEFINE_EVENT
    
    BUTTON_EVENT[dvTP,nMicButtons] {
    
       PUSH: {
       
          INTEGER index
          
          //find out which mic has been pushed
          index = GET_LAST(nMicButtons)
          
          //toggle the flag in the mic flag array
          nMicFlags[index] = !nMicFlags[index]
          
          IF (nMicFlags[index]) { //if a 1
    	 //do whatever you gotta do when a mic is selected
          }
          ELSE { //must be 0
    	 //do whatever you gotta do to kill the mic
          }
          
       }
    }
    
    HTH
  • samossamos Posts: 106
    Not what I need

    Joe,
    Thanks for the reply but I need to know the order in which the mics were pressed. The room is a meeting room for a State Senate building. I have on my touch screen buttons with each senators name and the ability to turn on or off any mics. They have asked for a button that will give the floor to the next senator in the que. so that the floor will be givin to the first senator how asks for the floor.
  • matt95gsrmatt95gsr Posts: 165
    How about something like the following?
    DEFINE_FUNCTION RemoveFromQueue(nMicNumber)
    {
    	local_var i,length,pos
    	length = Length_Array(nMicArray)
    	for (i=1;i<=length;i++)		// find the entry
    	{
    		if (nMicArray[i] = nMicNumber)
    		{	
    			pos = i
    			BREAK
    		}
    	}
    	for (i=pos;i<length;i++)		// remove it and compact array
    	{
    		nMicArray[i] = nMicArray[i+1]
    	}
    	set_length_array(nMicArray,length-1)
    }
    

    Don't know if that gets you any closer to what you're looking for, and it doesn't yet take into account what to do if the mic is listed more than once, but you're probably already handling that in the Add_to_Queue portion of your program I would suppose.
  • samossamos Posts: 106
    Thanks

    That is a great idea i appreciate your help. i think that is exactly what I need. I had created a char array and passed in the mic number and a break char ':' I then did a find string for example

    if(find_string(data.text,'23:',1))
    then remove it but I knew that I could do it with a integer array
  • matt95gsrmatt95gsr Posts: 165
    I'm glad that I could help out a bit. I think that was actually my first code post...I've been a bit of a lurker so far.
  • Joe HebertJoe Hebert Posts: 2,159
    samos wrote:
    Joe,
    Thanks for the reply but I need to know the order in which the mics were pressed.
    Sorry about that. I misunderstood what you were trying to accomplish. I?ll blame it on the 4 hours of sleep I?ve had in the last two days. I?m glad matt95gsr was paying attention.
    matt95gsr wrote:
    I think that was actually my first code post...I've been a bit of a lurker so far.
    Keep posting! :)


    Sleepless in Saint Charles?
Sign In or Register to comment.