ADICON Support Forum Applied Digital, Inc.
Page 1 of 1 1
Topic Options
#18485 - 07/13/07 05:49 PM Code review request
cjett Offline
newbie


Registered: 06/26/07
Posts: 7
I am programming my Ocelot to control a matrix audio/high-def video switcher made by VideoStorm through it's serial port. The trigger sensors are both IR as well as audio sensors coming from Sonos ZonePlayers which will trip two separate Bobcat-c's (code currently only has one, as the other is on order) and will in turn switch to the correct inputs, as well as turn on the appropriate amps, powered speakers, etc, through serial and some IR. The IR is through a Xantech whole house IR system.

The purpose is to get away from unwieldy remote macros, and IR switching that just plain does not happen/gets missed... as well as automate the Sonos system to turn on the right amps without having to pick up one remote for the amp and then the Sonos remote.

So... my code. I have some concerns about the timers I have implemented to put in a short delay... I found I needed a short delay for my Videostorm to recognize the two different serial commands that I need to send it with each master IR receipt. BTW... I have it set at 3 seconds... even though my documentation says 2 seconds. Is there any better way to do this? Thanks in advance.

0001 - IF Module #1 (null) Turns ON // If Living Room Sonos turns on via Audio Sensor
0002 - OR Receive IR IR #4, from Ocelot // Or if Living Room Sonos master IR is received
0003 - THEN Send Ocelot Message 35 w/ Variable #0 // Change VideoStorm to output 1, input 2 optical
0004 - IF Receive IR IR #8, from Ocelot // Or if Bedroom Sonos Master IR is received
0005 - THEN Send Ocelot Message 53 w/ Variable #0 // Change VideoStorm to output 2, input 3 optical
0006 - IF Receive IR IR #1, from Ocelot // If Living room TiVo master IR is received
0007 - THEN Send Ocelot Message 0 w/ Variable #0 // Change Videostorm Video to Output 1, Input 1
0008 - THEN Timer #0 = 1 // Start timer 0
0009 - IF Timer #0 becomes > 3 // When timer 0 reaches 2 secs. continue
0010 - THEN Timer #0 = 0 // Reset timer 0 to 0
0011 - THEN Send Ocelot Message 33 w/ Variable #0 // Change Videostrom Audio to Output 1, Input 1, Optical
0012 - IF Receive IR IR #2, from Ocelot // If Living room DVD master IR is received
0013 - THEN Ocelot, Zone 0 IR IR #20 // Send IR to DVD to Power on
0014 - THEN Send Ocelot Message 1 w/ Variable #0 // Change Videostorm Video to Output 1, Input 2
0015 - THEN Timer #1 = 1 // Start timer 1
0016 - IF Timer #1 becomes > 3 // When timer 1 reaches 2 secs. continue
0017 - THEN Timer #1 = 0 // Reset timer 1 to 0
0018 - THEN Send Ocelot Message 32 w/ Variable #0 // Change Videostorm Audio to Output 1, Input 1, Digital
0019 - IF Receive IR IR #3, from Ocelot // If Living room Xbox master IR is received
0020 - THEN Ocelot, Zone 0 IR IR #22 // Send IR to Xbox to Power on
0021 - THEN Send Ocelot Message 2 w/ Variable #0 // Change Videostorm Video to Output 1, Input 3
0022 - THEN Timer #2 = 1 // Start timer 2
0023 - IF Timer #2 becomes > 3 // When timer 2 reaches 2 secs. continue
0024 - THEN Timer #2 = 0 // Reset timer 2 to 0
0025 - THEN Send Ocelot Message 39 w/ Variable #0 // Change Videostorm Audio to Output 1, Input 4, Optical
0026 - IF Receive IR IR #5, from Ocelot // If Bedroom TiVo master IR is received
0027 - THEN Send Ocelot Message 8 w/ Variable #0 // Change Videostorm Video to Output 2, Input 1
0028 - THEN Timer #3 = 1 // Start timer 3
0029 - IF Timer #3 becomes > 3 // When timer 3 reaches 2 secs. continue
0030 - THEN Timer #3 = 0 // Reset timer 3 to 0
0031 - THEN Send Ocelot Message 49 w/ Variable #0 // Change Videostrom Audio to Output 2, Input 1, Optical
0032 - IF Receive IR IR #6, from Ocelot // If Bedroom DVD master IR is received
0033 - THEN Ocelot, Zone 0 IR IR #10 // Send IR to DVD to Power on
0034 - THEN Send Ocelot Message 9 w/ Variable #0 // Change Videostorm Video to Output 2, Input 2
0035 - THEN Timer #4 = 1 // Start timer 4
0036 - IF Timer #4 becomes > 3 // When timer 4 reaches 2 secs. continue
0037 - THEN Timer #4 = 0 // Reset timer 4 to 0
0038 - THEN Send Ocelot Message 48 w/ Variable #0 // Change Videostorm Audio to Output 2, Input 1, Digital
0039 - IF Receive IR IR #7, from Ocelot // If Bedroom Xbox master IR is received
0040 - THEN Ocelot, Zone 0 IR IR #12 // Send IR to Xbox to Power on
0041 - THEN Send Ocelot Message 10 w/ Variable #0 // Change Videostorm Video to Output 2, Input 3
0042 - THEN Timer #5 = 1 // Start timer 5
0043 - IF Timer #5 becomes > 3 // When timer 5 reaches 2 secs. continue
0044 - THEN Timer #5 = 0 // Reset timer 5 to 0
0045 - THEN Send Ocelot Message 55 w/ Variable #0 // Change Videostorm Audio to Output 2, Input 4, Optical
0046 - IF Receive IR IR #9, from Ocelot // If Bedroom Night master IR is received
0047 - THEN Ocelot, Zone 0 IR IR #15 // Send IR to BR Speaker to Power on
0048 - THEN Send Ocelot Message 55 w/ Variable #0 // Change Videostorm Audio to Output 2, Input 4, Optical
0049 - THEN Ocelot, Zone 0 IR IR #12 // Send IR to Xbox to Power on
0050 - THEN Timer #6 = 1 // Start timer 6
0051 - THEN Timer #7 = 1 // Start timer 7
0052 - IF Timer #6 becomes > 3 // When timer 3 reaches 3 seconds continue
0053 - THEN Timer #6 = 0 // Reset timer 6 to 0
0054 - THEN Ocelot, Zone 0 IR IR #20 // Send IR to BR speaker Input DVD
0055 - IF Timer #7 becomes > 25 // When timer 7 reaches 25 secinds continue
0056 - THEN Timer #7 = 0 // Reset timer 7 to 0
0057 - THEN Ocelot, Zone 0 IR IR #28 // Send IR to BR speaker stereo
0058 - THEN Ocelot, Zone 0 IR IR #14 // Send IR to Xbox to start night
0059 - THEN Ocelot, Zone 0 IR IR #35 // Send IR to BR speaker to set volume level to B setting
0060 - End Program // End

Top
#18486 - 07/13/07 08:11 PM Re: Code review request [Re: cjett]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
Looks good to me.

The important thing is that it needs to be reliable, so the extra second of delay can make a big difference.

One small program effeciency improvement you can make is in the last routine near the end. You could use a single timer (Timer 6) to do both steps by letting it run and stopping it only when the last step is reached:

0049 - THEN Ocelot, Zone 0 IR IR #12 // Send IR to Xbox to Power on
0050 - THEN Timer #6 = 1 // Start timer 6
deleted
0052 - IF Timer #6 becomes > 3 // When timer 3 reaches 3 seconds continue
deleted
0054 - THEN Ocelot, Zone 0 IR IR #20 // Send IR to BR speaker Input DVD
0055 - IF Timer #6 becomes > 25 // When timer 6 reaches 25 seconds continue
0056 - THEN Timer #6 = 0 // Reset timer 6 to 0
0057 - THEN Ocelot, Zone 0 IR IR #28 // Send IR to BR speaker stereo
0058 - THEN Ocelot, Zone 0 IR IR #14 // Send IR to Xbox to start night
0059 - THEN Ocelot, Zone 0 IR IR #35 // Send IR to BR speaker to set volume level to B setting
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#18487 - 07/19/07 08:05 PM Re: Code review request [Re: Guy Lavoie]
cjett Offline
newbie


Registered: 06/26/07
Posts: 7
Thanks again guy... it's been working pretty well, and with a few delay/timing tweaks it's pretty much flawless now. Trying to put a few more "smarts" into it, and having one potential issue that I need your insight on.

I want to incorporate a 15 minute timer which if a bobcat-c is tripped, will start the timer. However, this bobcat-c will likely turn on and off. What I want to happen is if the bobcat-c opens and starts the timer, then it closes again... I want the timer to reset to 1 and start over again. I think this may have to do "is off"/"turns off" and likely another set timer to 0... just not sure exactly where to put it. Thanks in advance... questionable code below.


0078 - IF Module #1 -BOBCAT-C Input #0 Turns OFF // If Living room Sonos turns OFF
0079 - THEN Timer #8 = 1 // Start timer 8
0080 - IF Timer #8 is > 450 // When timer 8 reaches 15 minutes
0081 - THEN Timer #8 = 0 // Reset timer 8 to 0
0082 - THEN Send Module #3 -BOBCAT-A Message 112 w/ Variable #0 // Turn Amp Zone 2 OFF
0083 - THEN Send Module #3 -BOBCAT-A Message 98 w/ Variable #0 // Turn Amp OFF
0084 - IF Module #2 -BOBCAT-C Input #0 Turns OFF // If Bedroom Sonos turns OFF
0085 - THEN Timer #9 = 1 // Start timer 9
0086 - IF Timer #9 becomes > 450 // When timer 9 reaches 15 minutes
0087 - THEN Timer #9 = 0 //
0088 - THEN Ocelot, Zone 0 IR IR #16 // Send IR to BR speaker to trun OFF
0089 - End Program // End Program

Top
#18488 - 07/21/07 08:56 PM Re: Code review request [Re: cjett]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
Your first routine will already restart the timer at 1 if the input turns off again. The first two lines (78 and 79) will do this. So all you really need is:

0078 - IF Module #1 -BOBCAT-C Input #0 Turns OFF // If Living room Sonos turns OFF
0079 - THEN Timer #8 = 1 // Start timer 8
0080 - IF Timer #8 is > 450 // When timer 8 reaches 15 minutes
0081 - THEN Timer #8 = 0 // Reset timer 8 to 0
0082 - THEN Send Module #3 -BOBCAT-A Message 112 w/ Variable #0 // Turn Amp Zone 2 OFF
0083 - THEN Send Module #3 -BOBCAT-A Message 98 w/ Variable #0 // Turn Amp OFF
0084 - End Program // End Program
_________________________
"If you don't know what you're doing, do it neatly..."

Top
#18489 - 07/21/07 10:53 PM Re: Code review request [Re: Guy Lavoie]
cjett Offline
newbie


Registered: 06/26/07
Posts: 7
Your lines 78 to 84 look the same to me. Is this correct? Just not sure if my code is correct, or you mistyped (mis-copied)your reply.

The second section in my code is another Bobcat C attached to a second sonos unit (another zone)doing the same as the first one... It's just repeating.

Thanks again Guy... and welcome back.

cjett

Top
#18490 - 07/22/07 01:07 PM Re: Code review request [Re: cjett]
Guy Lavoie Administrator Offline
Beyond All Hope
*****

Registered: 12/21/02
Posts: 6548
Loc: Montreal, QC, Canada
Yes, they are the same. I had not noticed that you were listing two routines for two different bobcats... Your discussion was mentioning the use of two timers and I thought that this was an example of that. Duh! Taking vacation does that to me!
_________________________
"If you don't know what you're doing, do it neatly..."

Top
Page 1 of 1 1


Moderator:  Dan Smith, Monte G, ADI Tech Support, Guy Lavoie 
Hop to:
Who's Online
0 registered and 56 anonymous users online.
Recent Posts
am pm
by edr
05/05/17 05:25 PM
Shout Box

Newest Members
brigiel, vevevie, zhutree, 416, saiqul
3003 Registered Users
Forum Stats
3003 Members
19 Forums
3999 Topics
23425 Posts

Max Online: 132 @ 11/13/16 10:07 AM
May
Su M Tu W Th F Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31