Specifications

AVIDdirector-M2M Technical Reference Guide
February 5, 2009 ©AVIDwireless 2004-2009 All Rights Reserved Page 40 of 55
boolean retFlag; // return status of a command
boolean triggerResponse; // set true if there is a change of value
int ttl1Value = -1, ttl3Value = -1, ttl4Value =-1;
boolean isDebug = Logger.isDebug(); // cache the debug value
while(threadRunning && demoM2mletEnabled) {
isDebug = Logger.isDebug(); // update the debug value in case it changed
// go through the sensors and send a new reading if it changed
for (int device=0; device < sensors.length; device++) {
if (sensors[device] != null) {
// sensors are fast to poll, so do them all the time
try {
// read the value and set it
if (sensors[device].isAnalogInput()) { // analog input sensor
value = sensors[device].readPinAnalog();
} else { // digital sensor
value = sensors[device].readPinDig();
}
// update the value on the sensor and see if we triggered anything
triggerResponse = sensors[device].updateValue(value);
// handle any special things for these devices
switch (device) {
case 0: { // Pot
// change the Light intensity to 0 to 62 from 0 to 4096
if ((value <= (ttl1Value-10)) || (value >= (ttl1Value+10))) {
lightIntensity = (value / 66); // 0 to 62
lamp.writePinAnalog(lightIntensity);
ttl1Value = value;
}
break;
}
case 1: { // Round pushbotton, only signal when pushed down
if (value != ttl3Value) {
// set the Green LED but invert the value
if (oldDemoBoard) {
greenLed.writePinDig((value==0)?1:0); // old demo board
inverting
} else {
greenLed.writePinDig( value);
}
ttl3Value = value;
}
break;
}
case 2: { // Switch pushbotton, signal either way
if (value != ttl4Value) {
redLed.writePinDig(value);
ttl4Value = value;
}
break;
}
} // switch
if (triggerResponse) {
if (isDebug) Logger.debugln(NAME,sensors[device].getDeviceAddress()+
" value = "+value+" triggered a percept message to portal");
// send the correct percept for the device
if (sensors[device].isAnalogInput())
perceptMessage =
M2MXML_Messages.createPerceptString(sensors[device].
getDeviceAddress(),
value,PerceptRequest.PERCEPT_TYPE_SIMPLE, null );
else
perceptMessage =
M2MXML_Messages.createPerceptString(sensors[device].