Home AMX User Forum NetLinx Studio

Mistake - can you find it?

This was a stooooooopid mistake I made a few days ago and after thinking about what I did to maybe cause the issue - it made sense. Here's the symptoms of the problem: commands being sent out three times (i.e. one button press sent the same command three times.)

Here's the relevant code:
INTEGER nIR_MBR_COMMANDS[]=
{
	   1	// Play
	,  2	// Stop
	,  3	// Pause
	,  4	// FFWD
	,  5	// RWD
	,  6	// Skip +
	,  7	// Skip -
	,  8	// Record
	,  9	// Power Toggle
	, 10	// 0
	, 11	// 1
	, 12	// 2
	, 13	// 3
	, 14	// 4
	, 15	// 5
	, 16	// 6
	, 17	// 7
	, 18	// 8
	, 19	// 9
	, 20	// 10+
	, 21	// Enter
	, 22	// Ch +
	, 23	// Ch -
	, 00	// Discrete Power On
	, 00	// Discrete Power Off
	, 29	// 
	, 30	// 
	, 31	// 
	, 32	// 
	, 33	// 
	, 34	// 
	, 35	// 
	, 36	// 
	, 37	// 
	, 38	// 
	, 39	// 
	, 40	// 
	, 41	// 
	, 42	// 
	, 43	// 
	, 44	// Menu
	, 45	// Up
	, 46	// Down
	, 47	// Left
	, 48	// Right
	, 49	// Select
	, 50	// Exit / Cancel / Clear
	, 51	// Info
	, 52	// Guide
	, 53	// 
	, 54	// 
	, 55	// Last / Jump
	, 56	// 
	, 57	// 
	, 58	// 
	, 59	// 
	, 60	// 
	, 61	// 
	, 62	// 
	, 63	// 
	, 64	// 
	, 65	// 
	, 66	// 
	, 67	// 
	, 68	// 
	, 69	// 
	, 70	// 
	, 71	// 
	, 72	// 
	, 73	// 
	, 74	// 
	, 75	// 
	, 76	// 
	, 77	// 
	, 78	// 
	, 79	// 
	, 80	// 
	, 81	// 
	, 82	// 
	, 83	// 
	, 84	// 
	, 85	// 
	, 86	// 
	, 87	// 
	, 88	// 
	, 89	// 
	, 90	// 
}          


DEFINE_EVENT
BUTTON_EVENT[dvIR,nIR_MBR_COMMANDS]	// Bedroom (1-100)
{
	PUSH:
	{
		LOCAL_VAR INTEGER nPNL;
		LOCAL_VAR INTEGER nBTN
		STACK_VAR INTEGER iSRC;
		nPNL = 4
		nBTN = BUTTON.INPUT.CHANNEL
		
		iSRC = nAV_ZONE_SOURCE[nZONE_MBR];
		
		// MANAGE DEVICE CONTROL
		SWITCH(iSRC)
		{
			// SATELLITE COMMANDS
			CASE nSRC_SAT_ALT:		
			{
				SELECT
				{
					ACTIVE(nBTN>=45 && nBTN<=48):	// CONTINUOUS IR OUTPUT (up,down,left,right)
						TO[dvSAT_MGR,nBTN]
					// All other buttons
					ACTIVE(1):
						SEND_COMMAND dvSAT_MGR,"'SP',nBTN"
				}
			}
			
			
			
			// TIVO COMMANDS
			CASE nSRC_TIVO:	
				SEND_COMMAND dvSAT_TIVO,"'SP',nBTN"
			
			// VCR COMMANDS
			CASE nSRC_VCR:		
				SEND_COMMAND dvVCR,"'SP',nBTN"
		}
	}
}

Comments

  • mpullinmpullin Posts: 949
    I see it! Should I post the answer or should I be DISCRETE about it?
    *dr. evil pinky finger thing*
  • Spire_JeffSpire_Jeff Posts: 1,917
    I see 0 things wrong with this code. I mean seriously, do you expect me to catch EVERYTHING?

    ;)

    Jeff
  • jjamesjjames Posts: 2,908
    Ehh - we can post the answer at the end of the day - let everyone get a chance to see it. But yeah, just a STOOOOOPID mistake. Kickin' myself in the butt for this one.
  • Oh, oh, I see it too. ;)

    --John
  • jjamesjjames Posts: 2,908
    Ok - is it REALLY that obvious?
  • Spire_JeffSpire_Jeff Posts: 1,917
    It would be fun if there was a question of the week. (Maybe we could go with two questions, one for beginners and one for more experienced programmers)

    I'm just trying to figure out the best format for such a thing. So far I think that the first correct response poster is responsible to come up with the new question for the next week. I am also thinking that only requests for clarification on the question (as long as such clarification isn't the answer) should be allowed on the first day. After the first 24 hrs is up, first correct post wins :)

    The question does not have to be multiple choice. It could be something like: Write code necessary to toggle the state of a button with code 200 on dvPanelFB when button 3 is pushed on dvPanel, but it should only have one goal or lesson to be learned (ie no specing a system and having the forum write it for you :) )

    This could be a fun way to keep the brain turning and I always find that helping others is a good way to reinforce personal knowledge. Plus, everyone likes a competition.

    Anyone else think this is a good idea, or should I get a little more sleep? :)

    Jeff
  • mpullinmpullin Posts: 949
    jjames wrote: »
    Ok - is it REALLY that obvious?
    In all seriousness, not really, I had to look at it for 2-3 min.
  • mpullinmpullin Posts: 949
    QOTW thread
    Spire_Jeff wrote: »
    It would be fun if there was a question of the week. (Maybe we could go with two questions, one for beginners and one for more experienced programmers)

    I'm just trying to figure out the best format for such a thing. So far I think that the first correct response poster is responsible to come up with the new question for the next week. I am also thinking that only requests for clarification on the question (as long as such clarification isn't the answer) should be allowed on the first day. After the first 24 hrs is up, first correct post wins :)

    How about a special kind of thread where,
    1. If you have not posted in the thread, you are only allowed to see the original post.
    2. After you post you can see your post, and the posts of all others before you. Some kind of alert reminds you that by responding to the post you are submitting your final answer.
    3. Editing posts in this type of thread would be forbidden.

    Any requests for clarification should be made as PMs to the poster and the poster could edit the original post. After a while the poster could "close" the read, at which point anyone can view any post, but still no editing (except by the original poster).

    Seems pretty implementable. What do you think, AMXforums admin dudes? Can we have it?
  • Joe HebertJoe Hebert Posts: 2,159
    mpullin wrote: »
    What do you think, AMXforums admin dudes?
    Dude? Um, you obviously haven?t had the pleasure. 110% non dude. Heck 1000% non dude. :)
  • jjamesjjames Posts: 2,908
    Joe Hebert wrote: »
    Dude? Um, you obviously haven?t had the pleasure. 110% non dude. Heck 1000% non dude. :)
    Are you saying he should have said "dudette"? :D
  • Joe HebertJoe Hebert Posts: 2,159
    jjames wrote: »
    Are you saying he should have said "dudette"? :D
    I?d avoid any form of dude and lean more towards something like goddess. :D
  • [Deleted User][Deleted User] Administrator Posts: 0
    You got that right-
    Looking in to it!
  • jweatherjweather Posts: 320
    jjames wrote: »
    Ok - is it REALLY that obvious?

    Only to everyone except you... seriously. It would work the same way for any of us making the same mistake, though, because we wouldn't be looking at that section expecting to see a bug, we would be looking at it thinking "of course it's zero, there's no mapping for that function". It's always easier to find someone else's bugs than it is to find your own. I think Murphy's Law comes into at some point -- the longer you stare at a piece of code, the more likely it is that someone looking over your shoulder will see the bug in 5 seconds.

    Jeremy
  • jjamesjjames Posts: 2,908
    Gotcha!

    Well, alright. I guess time is up. For those who didn't see the problem or couldn't quite pinpoint it - as someone else has said to me before: no wonder why in UI modules they use 9999 for unused buttons. The reason being is that 0 (zero) is what I call a "wildcard." Since there were two zeros in my array (power on & power off) those got activated as well. So - when a button was pressed, the event flow was like this.
    BUTTON_EVENT[dvIR,[the actual button that was pressed]]
    {
     PUSH: {//Code fired}
    }
    
    BUTTON_EVENT[dvIR,0]
    {
     PUSH: {//Code fired}
    }
    
    BUTTON_EVENT[dvIR,0]
    {
     PUSH: {//Code fired}
    }
    

    Would anyone disagree with my reasoning or maybe someone has a better way of explaining it?
  • jweather wrote: »
    the longer you stare at a piece of code, the more likely it is that someone looking over your shoulder will see the bug in 5 seconds.
    Jeremy
    I definitely agree there. There was one post I made where I couldn't figure out what I was doing wrong in my code, and it was as simple as forgetting to define a variable type in my function header. I stared at code for 20 minutes not being able to see the error, then mpullin pointed it out and I couldn't believe I didn't see it right away.

    If you search through the forums for help with fixing errors, most of them are like that.

    By the way, in addition to your 00 wildcard issue, you're also missing positions 26-28 after it in your array, but I assume that's probably from transferring the code to the post.

    --John
  • jjamesjjames Posts: 2,908
    Ugh - man oh man . . . thanks for pointing that out! It's older code and I must have accidentally removed those entries when fixing it. Luckily they're out of town for the next 9 weeks so I can make that change and they probably won't even know it. It shouldn't really matter though with the code - but again, thanks!
Sign In or Register to comment.