aboutsummaryrefslogtreecommitdiffstats
path: root/cphidgetled.c
diff options
context:
space:
mode:
authorJonathan McCrohan <jmccrohan@gmail.com>2012-10-19 19:38:06 +0100
committerJonathan McCrohan <jmccrohan@gmail.com>2012-10-19 19:38:06 +0100
commit8f3c91e91b634adaca77dac6cf314445cceefc78 (patch)
tree8a779a28ccfbbfae413f6f7df21fb0a8650d3747 /cphidgetled.c
parentbd7a4f258643bf72d5e97f86f0f2272b381ed1ba (diff)
downloadlibphidget21-8f3c91e91b634adaca77dac6cf314445cceefc78.tar.gz
Imported Upstream version 2.1.8.20120912upstream/2.1.8.20120912
Diffstat (limited to 'cphidgetled.c')
-rw-r--r--cphidgetled.c559
1 files changed, 381 insertions, 178 deletions
diff --git a/cphidgetled.c b/cphidgetled.c
index 4bcbfc6..5c7bfd5 100644
--- a/cphidgetled.c
+++ b/cphidgetled.c
@@ -15,14 +15,15 @@ CPHIDGETCLEARVARS(LED)
for(i=0;i<LED_MAXLEDS;i++)
{
phid->changedLED_Power[i] = PUNK_BOOL;
- phid->LED_Power[i] = PUNI_INT;
- phid->nextLED_Power[i] = PUNK_INT;
+ phid->LED_Power[i] = PUNI_DBL;
+ phid->LED_CurrentLimit[i] = PUNI_DBL;
+ phid->nextLED_Power[i] = PUNK_DBL;
- phid->LED_PowerEcho[i] = PUNK_INT;
+ phid->LED_PowerEcho[i] = PUNK_DBL;
phid->outputEnabledEcho[i] = PUNK_BOOL;
phid->ledOpenDetectEcho[i] = PUNK_BOOL;
- phid->lastLED_Power[i] = PUNK_INT;
+ phid->lastLED_Power[i] = PUNK_DBL;
}
phid->voltage = PHIDGET_LED_VOLTAGE_2_75V;
phid->currentLimit = PHIDGET_LED_CURRENT_LIMIT_20mA;
@@ -45,47 +46,44 @@ CPHIDGETINIT(LED)
TESTPTR(phid);
//set data arrays to unknown
- switch(phid->phid.deviceIDSpec)
+ switch(phid->phid.deviceUID)
{
- case PHIDID_LED_64:
+ case PHIDUID_LED_64:
for(i=0;i<phid->phid.attr.led.numLEDs;i++)
{
phid->changedLED_Power[i] = PFALSE;
- phid->LED_Power[i] = PUNK_INT;
- phid->nextLED_Power[i] = PUNK_INT;
+ phid->LED_Power[i] = PUNK_DBL;
+ phid->nextLED_Power[i] = PUNK_DBL;
}
break;
- case PHIDID_LED_64_ADV:
- if ((phid->phid.deviceVersion >= 100) && (phid->phid.deviceVersion < 200))
+ case PHIDUID_LED_64_ADV:
+ case PHIDUID_LED_64_ADV_M3:
+ for(i=0;i<phid->phid.attr.led.numLEDs;i++)
{
- for(i=0;i<phid->phid.attr.led.numLEDs;i++)
- {
- phid->changedLED_Power[i] = PFALSE;
- phid->LED_Power[i] = PUNK_INT;
- phid->nextLED_Power[i] = PUNK_INT;
-
- phid->LED_PowerEcho[i] = PUNK_INT;
- phid->outputEnabledEcho[i] = PUNK_BOOL;
- phid->ledOpenDetectEcho[i] = PUNK_BOOL;
-
- phid->lastLED_Power[i] = PUNK_INT;
- }
- phid->voltage = PHIDGET_LED_VOLTAGE_2_75V;
- phid->currentLimit = PHIDGET_LED_CURRENT_LIMIT_20mA;
-
- phid->faultEcho = PUNK_BOOL;
- phid->powerGoodEcho = PUNK_BOOL;
- phid->PGoodErrState = PFALSE;
- phid->outputEnableEcho = PUNK_BOOL;
- phid->voltageEcho = -1;
- phid->currentLimitEcho = -1;
-
- phid->TSDCount=0;
- phid->TSDClearCount = 0;
- phid->lastOutputPacket = 0;
+ phid->changedLED_Power[i] = PFALSE;
+ phid->LED_Power[i] = PUNK_DBL;
+ phid->LED_CurrentLimit[i] = PUNK_DBL;
+ phid->nextLED_Power[i] = PUNK_DBL;
+
+ phid->LED_PowerEcho[i] = PUNK_DBL;
+ phid->outputEnabledEcho[i] = PUNK_BOOL;
+ phid->ledOpenDetectEcho[i] = PUNK_BOOL;
+
+ phid->lastLED_Power[i] = PUNK_DBL;
}
- else
- return EPHIDGET_BADVERSION;
+ phid->voltage = PHIDGET_LED_VOLTAGE_2_75V;
+ phid->currentLimit = PHIDGET_LED_CURRENT_LIMIT_20mA;
+
+ phid->faultEcho = PUNK_BOOL;
+ phid->powerGoodEcho = PUNK_BOOL;
+ phid->PGoodErrState = PFALSE;
+ phid->outputEnableEcho = PUNK_BOOL;
+ phid->voltageEcho = -1;
+ phid->currentLimitEcho = -1;
+
+ phid->TSDCount=0;
+ phid->TSDClearCount = 0;
+ phid->lastOutputPacket = 0;
break;
default:
return EPHIDGET_UNEXPECTED;
@@ -94,9 +92,10 @@ CPHIDGETINIT(LED)
phid->controlPacketWaiting = PFALSE;
//issue a read - fill in data
- switch(phid->phid.deviceIDSpec)
+ switch(phid->phid.deviceUID)
{
- case PHIDID_LED_64_ADV:
+ case PHIDUID_LED_64_ADV:
+ case PHIDUID_LED_64_ADV_M3:
//need two reads to get the full state
CPhidget_read((CPhidgetHandle)phid);
CPhidget_read((CPhidgetHandle)phid);
@@ -114,7 +113,7 @@ CPHIDGETINIT(LED)
if(phid->currentLimitEcho != -1)
phid->currentLimit = phid->currentLimitEcho;
break;
- case PHIDID_LED_64:
+ case PHIDUID_LED_64:
default:
break;
}
@@ -131,9 +130,9 @@ CPHIDGETDATA(LED)
TESTPTR(phid);
TESTPTR(buffer);
- switch(phid->phid.deviceIDSpec)
+ switch(phid->phid.deviceUID)
{
- case PHIDID_LED_64_ADV:
+ case PHIDUID_LED_64_ADV:
if ((phid->phid.deviceVersion >= 100) && (phid->phid.deviceVersion < 200))
{
switch(buffer[0] & 0x80)
@@ -199,7 +198,7 @@ CPHIDGETDATA(LED)
{
double ledPowerTemp;
ledPowerTemp = ((double)buffer[i+17] / 127.0) * 100.0;
- phid->LED_PowerEcho[i] = round(ledPowerTemp);
+ phid->LED_PowerEcho[i] = ledPowerTemp;
}
//We can guess that the fault is a TSD if there is no LOD
@@ -248,7 +247,7 @@ CPHIDGETDATA(LED)
{
double ledPowerTemp;
ledPowerTemp = ((double)buffer[i-23] / 127.0) * 100.0;
- phid->LED_PowerEcho[i] = round(ledPowerTemp);
+ phid->LED_PowerEcho[i] = ledPowerTemp;
}
break;
@@ -257,7 +256,9 @@ CPHIDGETDATA(LED)
else
return EPHIDGET_UNEXPECTED;
break;
- case PHIDID_LED_64:
+ case PHIDUID_LED_64_ADV_M3:
+ break;
+ case PHIDUID_LED_64:
default:
return EPHIDGET_UNEXPECTED;
}
@@ -286,175 +287,296 @@ CGETPACKET(LED)
CThread_mutex_lock(&phid->phid.outputLock);
- switch(phid->phid.deviceIDSpec)
+ switch(phid->phid.deviceUID)
{
- case PHIDID_LED_64:
- if ((phid->phid.deviceVersion >= 100) && (phid->phid.deviceVersion < 300))
+ case PHIDUID_LED_64:
+ //construct the packet, with up to 4 LED sets
+ for (i = 0; i < phid->phid.attr.led.numLEDs; i++)
{
+ if (phid->changedLED_Power[i] && numLeds < 4) {
+ phid->LED_Power[i] = phid->nextLED_Power[i];
+ phid->changedLED_Power[i] = PFALSE;
+ phid->nextLED_Power[i] = PUNK_DBL;
+ buf[numLeds*2] = i;
+ //0-100 -> 0-63
+ buf[numLeds*2+1] = (unsigned char)round((phid->LED_Power[i] / 100.0) * 63.0);
+ numLeds++;
+ phid->changeRequests--;
+ }
+ }
- //construct the packet, with up to 4 LED sets
+ //fill up any remaining buffer space with valid data - sending 0's will mess things up
+ for(numLeds=numLeds;numLeds<4;numLeds++)
+ {
+ buf[numLeds*2] = buf[(numLeds-1)*2];
+ buf[numLeds*2+1] = buf[(numLeds-1)*2+1];
+ }
+ break;
+ case PHIDUID_LED_64_ADV:
+ //control packet
+ if(phid->controlPacketWaiting)
+ {
+
+ buf[0] = LED64_CONTROL_PACKET;
+
+ buf[1] = 0;
+
+ switch(phid->currentLimit)
+ {
+ case PHIDGET_LED_CURRENT_LIMIT_20mA:
+ break;
+ case PHIDGET_LED_CURRENT_LIMIT_40mA:
+ buf[1] |= LED64_CURSELA_FLAG;
+ break;
+ case PHIDGET_LED_CURRENT_LIMIT_60mA:
+ buf[1] |= LED64_CURSELB_FLAG;
+ break;
+ case PHIDGET_LED_CURRENT_LIMIT_80mA:
+ buf[1] |= (LED64_CURSELA_FLAG | LED64_CURSELB_FLAG);
+ break;
+ }
+
+ switch(phid->voltage)
+ {
+ case PHIDGET_LED_VOLTAGE_1_7V:
+ break;
+ case PHIDGET_LED_VOLTAGE_2_75V:
+ buf[1] |= LED64_PWRSELA_FLAG;
+ break;
+ case PHIDGET_LED_VOLTAGE_3_9V:
+ buf[1] |= LED64_PWRSELB_FLAG;
+ break;
+ case PHIDGET_LED_VOLTAGE_5_0V:
+ buf[1] |= (LED64_PWRSELA_FLAG | LED64_PWRSELB_FLAG);
+ break;
+ }
+
+ phid->controlPacketWaiting = PFALSE;
+ }
+ //LED packet
+ else
+ {
+ int bright_packet = PFALSE;
+ int output_upper = PFALSE;
+ int output_lower = PFALSE;
+ //decide if we need to use a normal brightness packet, or if we can use a high efficiency output packet
for (i = 0; i < phid->phid.attr.led.numLEDs; i++)
{
- if (phid->changedLED_Power[i] && numLeds < 4) {
- phid->LED_Power[i] = phid->nextLED_Power[i];
- phid->changedLED_Power[i] = PFALSE;
- phid->nextLED_Power[i] = PUNK_INT;
- buf[numLeds*2] = i;
- //0-100 -> 0-63
- buf[numLeds*2+1] = (unsigned char)round((phid->LED_Power[i] / 100.0) * 63.0);
- numLeds++;
- phid->changeRequests--;
+ if(phid->changedLED_Power[i])
+ {
+ if((phid->nextLED_Power[i] != phid->lastLED_Power[i]) && phid->nextLED_Power[i] != 0)
+ bright_packet = PTRUE;
+ else
+ {
+ if(i<32)
+ output_lower = PTRUE;
+ else
+ output_upper = PTRUE;
+ }
}
}
- //fill up any remaining buffer space with valid data - sending 0's will mess things up
- for(numLeds=numLeds;numLeds<4;numLeds++)
+ //only sends brightness changes - not changes between 0 and a brightness
+ if(bright_packet)
+ {
+ //construct the packet, with up to 4 LED sets
+ for (i = 0; i < phid->phid.attr.led.numLEDs; i++)
+ {
+ if (phid->changedLED_Power[i] && numLeds < 4 && phid->nextLED_Power[i] != 0) {
+ phid->LED_Power[i] = phid->nextLED_Power[i];
+ phid->lastLED_Power[i] = phid->nextLED_Power[i];
+ phid->changedLED_Power[i] = PFALSE;
+ phid->nextLED_Power[i] = PUNK_DBL;
+ buf[numLeds*2] = i;
+ //0-100 -> 0-127
+ buf[numLeds*2+1] = (unsigned char)round((phid->LED_Power[i] / 100.0) * 127.0);
+ if(buf[numLeds*2+1])
+ buf[numLeds*2+1] |= 0x80; //this turns the LED on when set brightness > 0;
+ numLeds++;
+ phid->changeRequests--;
+ }
+ }
+
+ //fill up any remaining buffer space with valid data - sending 0's will mess things up
+ //this just replicates data - doesn't send anything
+ for(numLeds=numLeds;numLeds<4;numLeds++)
+ {
+ buf[numLeds*2] = buf[(numLeds-1)*2];
+ buf[numLeds*2+1] = buf[(numLeds-1)*2+1];
+ }
+ }
+ else
{
- buf[numLeds*2] = buf[(numLeds-1)*2];
- buf[numLeds*2+1] = buf[(numLeds-1)*2+1];
+ //send lower packet
+ if((phid->lastOutputPacket == 0 && output_lower) || (phid->lastOutputPacket != 0 && !output_upper))
+ {
+ buf[0] = LED64_OUTLOW_PACKET;
+ for(i = 0;i<32;i++)
+ {
+ if(phid->changedLED_Power[i])
+ {
+ phid->changeRequests--;
+ phid->LED_Power[i] = phid->nextLED_Power[i];
+ phid->changedLED_Power[i] = PFALSE;
+ phid->nextLED_Power[i] = PUNK_DBL;
+ }
+ if(phid->LED_Power[i] > 0)
+ buf[i/8 + 1] |= (1 << (i%8));
+ }
+ phid->lastOutputPacket = 1;
+ }
+ //send upper packet
+ else
+ {
+ buf[0] = LED64_OUTHIGH_PACKET;
+ for(i = 32;i<64;i++)
+ {
+ if(phid->changedLED_Power[i])
+ {
+ phid->changeRequests--;
+ phid->LED_Power[i] = phid->nextLED_Power[i];
+ phid->changedLED_Power[i] = PFALSE;
+ phid->nextLED_Power[i] = PUNK_DBL;
+ }
+ if(phid->LED_Power[i] > 0)
+ buf[i/8 - 3] |= (1 << (i%8));
+ }
+ phid->lastOutputPacket = 0;
+ }
}
}
- else
- return EPHIDGET_UNEXPECTED;
break;
- case PHIDID_LED_64_ADV:
- if ((phid->phid.deviceVersion >= 100) && (phid->phid.deviceVersion < 200))
+ case PHIDUID_LED_64_ADV_M3:
+ //control packet
+ if(phid->controlPacketWaiting)
{
- //control packet
- if(phid->controlPacketWaiting)
+ buf[0] = LED64_M3_CONTROL_PACKET;
+
+ //TODO: we're getting rid of this probably
+ switch(phid->currentLimit)
+ {
+ case PHIDGET_LED_CURRENT_LIMIT_20mA:
+ break;
+ case PHIDGET_LED_CURRENT_LIMIT_40mA:
+ buf[0] |= LED64_CURSELA_FLAG;
+ break;
+ case PHIDGET_LED_CURRENT_LIMIT_60mA:
+ buf[0] |= LED64_CURSELB_FLAG;
+ break;
+ case PHIDGET_LED_CURRENT_LIMIT_80mA:
+ buf[0] |= (LED64_CURSELA_FLAG | LED64_CURSELB_FLAG);
+ break;
+ }
+
+ switch(phid->voltage)
{
+ case PHIDGET_LED_VOLTAGE_1_7V:
+ break;
+ case PHIDGET_LED_VOLTAGE_2_75V:
+ buf[0] |= LED64_PWRSELA_FLAG;
+ break;
+ case PHIDGET_LED_VOLTAGE_3_9V:
+ buf[0] |= LED64_PWRSELB_FLAG;
+ break;
+ case PHIDGET_LED_VOLTAGE_5_0V:
+ buf[0] |= (LED64_PWRSELA_FLAG | LED64_PWRSELB_FLAG);
+ break;
+ }
- buf[0] = LED64_CONTROL_PACKET;
+ for(i=0;i<64;i++)
+ {
+ int value;
+ int bufIndex = (i*6)/8 + 1;
- buf[1] = 0;
+ //Default is 20 mA
+ if(phid->LED_CurrentLimit[i] == PUNK_DBL)
+ phid->LED_CurrentLimit[i] = 20;
+ value = round((phid->LED_CurrentLimit[i] / LED64_M3_CURRENTLIMIT) * 63.0);
- switch(phid->currentLimit)
+ switch(i%4)
{
- case PHIDGET_LED_CURRENT_LIMIT_20mA:
+ case 0:
+ buf[bufIndex] |= (value & 0x3F);
break;
- case PHIDGET_LED_CURRENT_LIMIT_40mA:
- buf[1] |= LED64_CURSELA_FLAG;
+ case 1:
+ buf[bufIndex] |= ((value << 6) & 0xC0);
+ buf[bufIndex+1] |= ((value >> 2) & 0x0F);
break;
- case PHIDGET_LED_CURRENT_LIMIT_60mA:
- buf[1] |= LED64_CURSELB_FLAG;
+ case 2:
+ buf[bufIndex] |= ((value << 4) & 0xF0);
+ buf[bufIndex+1] |= ((value >> 4) & 0x03);
break;
- case PHIDGET_LED_CURRENT_LIMIT_80mA:
- buf[1] |= (LED64_CURSELA_FLAG | LED64_CURSELB_FLAG);
+ case 3:
+ buf[bufIndex] |= ((value << 2) & 0xFC);
break;
}
-
- switch(phid->voltage)
+ }
+
+ phid->controlPacketWaiting = PFALSE;
+ }
+ //LED packet
+ else
+ {
+ int output_upper = PFALSE;
+ int output_lower = PFALSE;
+ int startIndex;
+
+ for (i = 0; i < phid->phid.attr.led.numLEDs; i++)
+ {
+ if(phid->changedLED_Power[i])
{
- case PHIDGET_LED_VOLTAGE_1_7V:
- break;
- case PHIDGET_LED_VOLTAGE_2_75V:
- buf[1] |= LED64_PWRSELA_FLAG;
- break;
- case PHIDGET_LED_VOLTAGE_3_9V:
- buf[1] |= LED64_PWRSELB_FLAG;
- break;
- case PHIDGET_LED_VOLTAGE_5_0V:
- buf[1] |= (LED64_PWRSELA_FLAG | LED64_PWRSELB_FLAG);
- break;
+ if(i<32)
+ output_lower = PTRUE;
+ else
+ output_upper = PTRUE;
}
+ }
- phid->controlPacketWaiting = PFALSE;
+ //send lower packet
+ if((phid->lastOutputPacket == 0 && output_lower) || (phid->lastOutputPacket != 0 && !output_upper))
+ {
+ buf[0] = LED64_M3_OUT_LOW_PACKET;
+ startIndex=0;
+ phid->lastOutputPacket = 1;
}
- //LED packet
+ //send upper packet
else
{
- int bright_packet = PFALSE;
- int output_upper = PFALSE;
- int output_lower = PFALSE;
- //decide if we need to use a normal brightness packet, or if we can use a high efficiency output packet
- for (i = 0; i < phid->phid.attr.led.numLEDs; i++)
+ buf[0] = LED64_M3_OUT_HIGH_PACKET;
+ startIndex=32;
+ phid->lastOutputPacket = 0;
+ }
+
+ for(i = startIndex;i<startIndex+32;i++)
+ {
+ int value;
+ int bufIndex = (i*12)/8 + 1;
+
+ if(phid->changedLED_Power[i])
{
- if(phid->changedLED_Power[i])
- {
- if((phid->nextLED_Power[i] != phid->lastLED_Power[i]) && phid->nextLED_Power[i] != 0)
- bright_packet = PTRUE;
- else
- {
- if(i<32)
- output_lower = PTRUE;
- else
- output_upper = PTRUE;
- }
- }
+ phid->changeRequests--;
+ phid->LED_Power[i] = phid->nextLED_Power[i];
+ phid->changedLED_Power[i] = PFALSE;
+ phid->nextLED_Power[i] = PUNK_DBL;
}
- //only sends brightness changes - not changes between 0 and a brightness
- if(bright_packet)
- {
- //construct the packet, with up to 4 LED sets
- for (i = 0; i < phid->phid.attr.led.numLEDs; i++)
- {
- if (phid->changedLED_Power[i] && numLeds < 4 && phid->nextLED_Power[i] != 0) {
- phid->LED_Power[i] = phid->nextLED_Power[i];
- phid->lastLED_Power[i] = phid->nextLED_Power[i];
- phid->changedLED_Power[i] = PFALSE;
- phid->nextLED_Power[i] = PUNK_INT;
- buf[numLeds*2] = i;
- //0-100 -> 0-127
- buf[numLeds*2+1] = (unsigned char)round((phid->LED_Power[i] / 100.0) * 127.0);
- if(buf[numLeds*2+1])
- buf[numLeds*2+1] |= 0x80; //this turns the LED on when set brightness > 0;
- numLeds++;
- phid->changeRequests--;
- }
- }
+ //Default is 0 %
+ if(phid->LED_Power[i] == PUNK_DBL)
+ phid->LED_Power[i] = 0;
+ value = round((phid->LED_Power[i] / 100.0) * 4095.0);
- //fill up any remaining buffer space with valid data - sending 0's will mess things up
- //this just replicates data - doesn't send anything
- for(numLeds=numLeds;numLeds<4;numLeds++)
- {
- buf[numLeds*2] = buf[(numLeds-1)*2];
- buf[numLeds*2+1] = buf[(numLeds-1)*2+1];
- }
+ if(i%2 == 0)
+ {
+ buf[bufIndex] |= (value & 0xFF);
+ buf[bufIndex+1] |= ((value >> 8) & 0x0F);
}
else
{
- //send lower packet
- if((phid->lastOutputPacket == 0 && output_lower) || (phid->lastOutputPacket != 0 && !output_upper))
- {
- buf[0] = LED64_OUTLOW_PACKET;
- for(i = 0;i<32;i++)
- {
- if(phid->changedLED_Power[i])
- {
- phid->changeRequests--;
- phid->LED_Power[i] = phid->nextLED_Power[i];
- phid->changedLED_Power[i] = PFALSE;
- phid->nextLED_Power[i] = PUNK_INT;
- }
- if(phid->LED_Power[i] > 0)
- buf[i/8 + 1] |= (1 << (i%8));
- }
- phid->lastOutputPacket = 1;
- }
- //send upper packet
- else
- {
- buf[0] = LED64_OUTHIGH_PACKET;
- for(i = 32;i<64;i++)
- {
- if(phid->changedLED_Power[i])
- {
- phid->changeRequests--;
- phid->LED_Power[i] = phid->nextLED_Power[i];
- phid->changedLED_Power[i] = PFALSE;
- phid->nextLED_Power[i] = PUNK_INT;
- }
- if(phid->LED_Power[i] > 0)
- buf[i/8 - 3] |= (1 << (i%8));
- }
- phid->lastOutputPacket = 0;
- }
+ buf[bufIndex] |= ((value << 4) & 0xF0);
+ buf[bufIndex+1] |= ((value >> 4) & 0xFF);
}
}
}
- else
- return EPHIDGET_UNEXPECTED;
break;
default:
return EPHIDGET_UNEXPECTED;
@@ -474,7 +596,7 @@ CGETPACKET(LED)
//sendpacket - sends a packet to the device asynchronously, blocking if the 1-packet queue is full
// -every LED has its own 1 state mini-queue
static int CCONV CPhidgetLED_sendpacket(CPhidgetLEDHandle phid,
- unsigned int index, unsigned int power)
+ unsigned int index, double power)
{
int waitReturn;
CThread_mutex_lock(&phid->phid.writelock);
@@ -551,9 +673,14 @@ CGETINDEX(LED,DiscreteLED,int)
TESTDEVICETYPE(PHIDCLASS_LED)
TESTATTACHED
TESTINDEX(phid.attr.led.numLEDs)
- TESTMASGN(LED_Power[Index], PUNK_INT)
+ if(phid->LED_Power[Index] == PUNK_DBL)
+ {
+ *pVal = PUNK_INT;
+ return EPHIDGET_UNKNOWNVAL;
+ }
- MASGN(LED_Power[Index])
+ *pVal = round(phid->LED_Power[Index]);
+ return EPHIDGET_OK;
}
CSETINDEX(LED,DiscreteLED,int)
TESTPTR(phid)
@@ -565,11 +692,87 @@ CSETINDEX(LED,DiscreteLED,int)
if(CPhidget_statusFlagIsSet(phid->phid.status, PHIDGET_REMOTE_FLAG))
ADDNETWORKKEYINDEXED(Brightness, "%d", LED_Power);
else
+ return CPhidgetLED_sendpacket(phid, Index, (double)newVal);
+
+ return EPHIDGET_OK;
+}
+
+CGETINDEX(LED,Brightness,double)
+ TESTPTRS(phid,pVal)
+ TESTDEVICETYPE(PHIDCLASS_LED)
+ TESTATTACHED
+ TESTINDEX(phid.attr.led.numLEDs)
+ TESTMASGN(LED_Power[Index], PUNK_DBL)
+
+ *pVal = phid->LED_Power[Index];
+ return EPHIDGET_OK;
+}
+CSETINDEX(LED,Brightness,double)
+ TESTPTR(phid)
+ TESTDEVICETYPE(PHIDCLASS_LED)
+ TESTATTACHED
+ TESTINDEX(phid.attr.led.numLEDs)
+ TESTRANGE(0, 100)
+
+ if(CPhidget_statusFlagIsSet(phid->phid.status, PHIDGET_REMOTE_FLAG))
+ ADDNETWORKKEYINDEXED(Brightness, "%lf", LED_Power);
+ else
return CPhidgetLED_sendpacket(phid, Index, newVal);
return EPHIDGET_OK;
}
+CGETINDEX(LED,CurrentLimitIndexed,double)
+ TESTPTRS(phid,pVal)
+ TESTDEVICETYPE(PHIDCLASS_LED)
+ TESTATTACHED
+ TESTINDEX(phid.attr.led.numLEDs)
+
+ switch(phid->phid.deviceUID)
+ {
+ case PHIDUID_LED_64_ADV_M3:
+ TESTMASGN(LED_CurrentLimit[Index], PUNK_DBL)
+
+ *pVal = phid->LED_CurrentLimit[Index];
+ return EPHIDGET_OK;
+ case PHIDUID_LED_64_ADV:
+ case PHIDUID_LED_64:
+ default:
+ return EPHIDGET_UNSUPPORTED;
+ }
+}
+CSETINDEX(LED,CurrentLimitIndexed,double)
+ TESTPTR(phid)
+ TESTDEVICETYPE(PHIDCLASS_LED)
+ TESTATTACHED
+ TESTINDEX(phid.attr.led.numLEDs)
+
+ switch(phid->phid.deviceIDSpec)
+ {
+ case PHIDID_LED_64_ADV:
+ TESTRANGE(0, LED64_M3_CURRENTLIMIT)
+
+ if(CPhidget_statusFlagIsSet(phid->phid.status, PHIDGET_REMOTE_FLAG))
+ ADDNETWORKKEYINDEXED(CurrentLimitIndexed, "%lf", LED_CurrentLimit);
+ else
+ {
+ CThread_mutex_lock(&phid->phid.writelock);
+ CThread_mutex_lock(&phid->phid.outputLock);
+ phid->LED_CurrentLimit[Index] = newVal;
+ phid->controlPacketWaiting = PTRUE;
+ CThread_mutex_unlock(&phid->phid.outputLock);
+ CThread_set_event(&phid->phid.writeAvailableEvent);
+ CThread_mutex_unlock(&phid->phid.writelock);
+ }
+ break;
+ case PHIDID_LED_64:
+ default:
+ return EPHIDGET_UNSUPPORTED;
+ }
+
+ return EPHIDGET_OK;
+}
+
CGET(LED,CurrentLimit,CPhidgetLED_CurrentLimit)
TESTPTRS(phid,pVal)
TESTDEVICETYPE(PHIDCLASS_LED)