XTension Logo

An online tutorial


Here's the Attachments handler for the
SwitchLinc Preset Dim Function


All you need to do is copy everything below, and Paste that into your XTension Attachments Script, and save ....

PLEASE note that the SwitchLinc has changed since the original version, and it could be that you have one of the earlier models. If the following procedure doesn't work for you, then please use the 'original' version that follows this one...
=========================================================
-- Preset Dim for SwitchLinc
-- sample call: SetSwitchLincLevel( "Lamp", 75 ) [where 75 is a percentage 0-100]
-----
on SetSwitchLincLevel(unitName, levelValue)

set saveLog to log mode -- set logging level to reduce 'noise'...
set logging "exceptions"

-- first scale the levelValue to 0-31
set PDlevel to CalcSWint(levelValue)

-- set the unit to the specified level
preset unitName to level PDlevel -- set the level

-- delay 60 -- NOTE comment about the 'delay' verb below ***

-- tell the switchlinc to save the 'preset level'
send only address "P16"
send only address "N16"
send only address "M16"
send only address "O16"
send only address "O16"

send address for unitName -- send address only of the unit

-- NOTE: you may not want to turn the light off here...
turnoff unitName -- turn the light back off

write log unitName & " preset level set to " & levelValue

set logging saveLog -- restore logging preferences

end SetSwitchLincLevel


-- Send the "Clear" sequence for SwitchLincs
on SWclear()
send only address "O16"
send only address "N16"
send only address "M16"
send only address "P16"
send only address "M16"
end SWclear


-- Calculate the Preset Dim integer level from a given Percentage
-- sample call : CalcSWint(levelValue)

on CalcSWint(SWpct)
set SWint to SWpct div 3 -- integer divide!
if (SWint is greater than 31) then
set SWint to 31
end if
if (SWint is less than 0) then
set SWint to 0
end if
return SWint
end CalcSWint

The line above is the last line of the latest handler....

========================================================
-----
-----
HERE is the "Original" version of the SwitchLinc preset dim handler :

-- Preset Dim for SwitchLinc
-- sample call: SetSwitchLincLevel( "Lamp", 75 ) [where 75 is a percentage 0-100]
-----
on SetSwitchLincLevel(unitName, levelValue)

set saveLog to log mode -- set logging level to reduce 'noise'...
set logging "exceptions"

-- first scale the levelValue to 0-31
set PDlevel to CalcSWint(levelValue)

-- transmit the "clear" sequence
SWclear()

-- set the unit to the specified level
preset unitName to level PDlevel -- set the level
-- delay 60 -- NOTE below ***

-- tell the switchlinc to save the 'preset level'
send only address "P16"
send only address "N16"
send only address "M16"
send only address "O16"
send only address "M16"

dim unitName to levelValue with no script

-- NOTE: you may not want to turn the light off here...
turnoff unitName -- turn the light back off
write log unitName & " preset level set to " & levelValue

set logging saveLog -- restore logging preferences

end SetSwitchLincLevel


-- Send the "Clear" sequence for SwitchLincs
on SWclear()
send only address "O16"
send only address "N16"
send only address "M16"
send only address "P16"
send only address "M16"
end SWclear


-- Calculate the Preset Dim integer level from a given Percentage
-- sample call : CalcSWint(levelValue)

on CalcSWint(SWpct)
set SWint to SWpct div 3 -- integer divide!
if (SWint is greater than 31) then
set SWint to 31
end if
if (SWint is less than 0) then
set SWint to 0
end if
return SWint
end CalcSWint

The line above is the last line of the handler....

** NOTE about "Delay" :
There are TWO different Delay verbs.
One is from Sand Hill, and the other is a newer verb from Apple.
The original delay verb assumed an argument of 1/60ths of a second.
The newer delay verb assumes an argument of "Seconds".
You need to alter the argument so that you get ONE second of delay.

You can determine which verb you're using by the following:

write log "starting delay test"
delay 10
write log "if the delay was 10 seconds, you have the new Delay verb."


Back
Back to the Tutorial
tutorials
tutorial index


Copyright 2007, Sand Hill Engineering All rights reserved.

Mac Made

Last modified: October 12, 2003
Michael Ferguson, webmaster@shed.com