Programming NXC-VOL4
undrtkr
Posts: 35
This is the first time I've had to program one of these devices and unfortunately it has been shipped to site before I've had a chance to play with it. Looking at the quick start guide I think I have an idea of how to ramp the channels but I wanted to run by some code with you guys first to make sure it will work.
The plan is to ramp all four channels simultaneously with the same volume level. I plan on setting a variable to ramp between 0-255 and send it out to the card. I'm not interesting in parsing the volume state from the card. Here is the basic code I plan to use.
DEFINE_DEVICE
dvVolume1 = 5002:1:0 //Port 1 for NXC-VOL4 Card
dvVolume2 = 5002:2:0 //Port 2 for NXC-VOL4 Card
dvTP1 = 10001:1:0
vdvVolume = 33002:1:0 //Virtual Device for Volume
DEFINE_COMBINE
(vdvVolume, dvVolume1, dvVolume1)
DEFINE_CONSTANT
cVolumeMin = 0
cVolumeMax = 255
cVolumeRampSpeed = 8
DEFINE_VARIABLE
PERSISTENT INTEGER nVolumeLevel //Tracks Volume Level Status
DEFINE_EVENT
BUTTON_EVENT[dvTP1,8] //Volume Up
BUTTON_EVENT[dvTP1,9] //Volume Down
{
PUSH:
{
SELECT
{
ACTIVE(BUTTON.INPUT.CHANNEL = 8):
{
IF(nVolumeLevel < cVolumeMax)
{ //Will not Ramp Volume Up if Volume Max has Been Reached
IF(nVolumeLevel < (cVolumeMax - cVolumeRampSpeed))
{ //If Threshold isn't met Volume Level is Incremented by Volume Speed
nVolumeLevel = nVolumeLevel + cVolumeRampSpeed
}
ELSE
{ //If Threshold is met Volume Level is Incremented by 1
nVolumeLevel = nVolumeLevel + 1
}
}
}
ACTIVE(BUTTON.INPUT.CHANNEL = 9):
{
IF(nVolumeLevel > cVolumeMin)
{ //Will not Ramp Volume Down if Volume Min has Been Reached
IF(nVolumeLevel > (cVolumeMin + cVolumeRampSpeed))
{ //If Threshold isn't met Volume Level is Decreased by Volume Speed
nVolumeLevel = nVolumeLevel - cVolumeRampSpeed
}
ELSE
{ //If Threshold is met Volume Level is Decreased by 1
nVolumeLevel = nVolumeLevel - 1
}
}
}
}
SEND_COMMAND vdvVolume, "'P0L',ITOA(nVolumeLevel)" //Send Level to NXC-VOL4
SEND_LEVEL dvTP1,1,nVolumeLevel //Bargraph on Touch panel
}
}
The plan is to ramp all four channels simultaneously with the same volume level. I plan on setting a variable to ramp between 0-255 and send it out to the card. I'm not interesting in parsing the volume state from the card. Here is the basic code I plan to use.
DEFINE_DEVICE
dvVolume1 = 5002:1:0 //Port 1 for NXC-VOL4 Card
dvVolume2 = 5002:2:0 //Port 2 for NXC-VOL4 Card
dvTP1 = 10001:1:0
vdvVolume = 33002:1:0 //Virtual Device for Volume
DEFINE_COMBINE
(vdvVolume, dvVolume1, dvVolume1)
DEFINE_CONSTANT
cVolumeMin = 0
cVolumeMax = 255
cVolumeRampSpeed = 8
DEFINE_VARIABLE
PERSISTENT INTEGER nVolumeLevel //Tracks Volume Level Status
DEFINE_EVENT
BUTTON_EVENT[dvTP1,8] //Volume Up
BUTTON_EVENT[dvTP1,9] //Volume Down
{
PUSH:
{
SELECT
{
ACTIVE(BUTTON.INPUT.CHANNEL = 8):
{
IF(nVolumeLevel < cVolumeMax)
{ //Will not Ramp Volume Up if Volume Max has Been Reached
IF(nVolumeLevel < (cVolumeMax - cVolumeRampSpeed))
{ //If Threshold isn't met Volume Level is Incremented by Volume Speed
nVolumeLevel = nVolumeLevel + cVolumeRampSpeed
}
ELSE
{ //If Threshold is met Volume Level is Incremented by 1
nVolumeLevel = nVolumeLevel + 1
}
}
}
ACTIVE(BUTTON.INPUT.CHANNEL = 9):
{
IF(nVolumeLevel > cVolumeMin)
{ //Will not Ramp Volume Down if Volume Min has Been Reached
IF(nVolumeLevel > (cVolumeMin + cVolumeRampSpeed))
{ //If Threshold isn't met Volume Level is Decreased by Volume Speed
nVolumeLevel = nVolumeLevel - cVolumeRampSpeed
}
ELSE
{ //If Threshold is met Volume Level is Decreased by 1
nVolumeLevel = nVolumeLevel - 1
}
}
}
}
SEND_COMMAND vdvVolume, "'P0L',ITOA(nVolumeLevel)" //Send Level to NXC-VOL4
SEND_LEVEL dvTP1,1,nVolumeLevel //Bargraph on Touch panel
}
}
0
Comments
Now, having said that, and if you agree, there is a very simple way to accomplish what your seeking.
Here's an example
DEFINE_DEVICE
dvTP_1 = 10001:01;0
dvVOL_CARD_PORT_1 = 5002:01:0
dvVOL_CARD_PORT_2 = 5002:02:0
DEFINE_VARIABLE
vTP_BUTTON_PUSHED
PERSISTENT vVOLUME_CURRENT_LEVEL_1
DEFINE_EVENT
BUTTON_EVENT[dvTP_1,1] // VOLUME UP
BUTTON_EVENT[dvTP_1,2] // VOLUME DOWN
{
PUSH:
{
vTP_BUTTON_PUSHED=BUTTON.INPUT.CHANNEL
TO[dvTP_1,vTP_BUTTON_PUSHED] // FEEDBACK TO TOUCH PANEL
TO[dvVOL_CARD_PORT_1,vTP_BUTTON_PUSHED+3] // 4=VOL RAMP UP ON CH 1 5=VOL RAMP DOWN ON CH 1
} // END PUSH:
} // END BUTTON_EVFNT
LEVEL_EVENT[dvVOL_CARD_PORT_1,1] // this sends same level to other three channels - keeps them the same
{
vVOLUME_CURRENT_LEVEL_1=LEVEL.VALUE // Gets current vol feedback from CH 1
SEND_LEVEL dvVOL_CARD_PORT_1,2,vVOLUME_CURRENT_LEVEL_1SEND_LEVEL dvVOL_CARD_PORT_2,1,vVOLUME_CURRENT_LEVEL_1
SEND_LEVEL dvVOL_CARD_PORT_2,2,vVOLUME_CURRENT_LEVEL_1
} // END LEVEL_EVENT
You could also include a send_level to the touch panel to display the current level of the vol card to the user.
If you use the device to change the level it will trap the top and bottom of the level for you. You don't have to worry about going below zero or above 255.
Hope that helps