Echelon Mini EVK User Manual

Page 67

Advertising
background image

#define DS18S20_CONVERT 0x44u
#define DS18S20_READ 0xBEu

// Get a temperature reading from the Touch temperature sensor
SNVT_temp_p GetTemperature(void) {
union {
SNVT_temp_p snvtTempP;
unsigned Bytes[2];
} CurrentTemperature;
CurrentTemperature.snvtTempP = 32767l;

if (touch_reset(ioThermometer)) {
(void) touch_byte(ioThermometer, DS18S20_SKIP_ROM);
(void) touch_byte(ioThermometer, DS18S20_READ);

CurrentTemperature.Bytes[1]
= touch_byte(ioThermometer, 0xFFu);
CurrentTemperature.Bytes[0]
= touch_byte(ioThermometer, 0xFFu);

if (touch_reset(ioThermometer)) {
// Scale the raw reading
CurrentTemperature.snvtTempP *= 50l;

// start the next conversion cycle:
(void) touch_byte(ioThermometer, DS18S20_SKIP_ROM);
(void) touch_byte(ioThermometer, DS18S20_CONVERT);
} else {
CurrentTemperature.snvtTempP = 32767l;
}
}
return CurrentTemperature.snvtTempP;
}

// Repeat every second
mtimer repeating readTimer = 1000;

// Read the temperature when the timer expires
when(timer_expires(readTimer)) {
SNVT_temp_p temperature;
static SNVT_temp_p lastTemperature;

temperature = GetTemperature();
if (temperature != lastTemperature) {
lastTemperature = temperature;

// Send network variable update
nvoTemperature = temperature;
}
}

// Call IsiTick() every 250 milliseconds
mtimer repeating isiTimer = 250;

when(timer_expires(isiTimer)) {
IsiTickS();
}

// Poll the service pin and use it as the ISI Connect button.
// Holding it down will cancel any pending enrollment.
#define LONG_SERVICE_PIN 50
mtimer repeating serviceTimer = 50;
unsigned ServicePinActivation;

Mini EVK User’s Guide

61

Advertising