Commit a309deee authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

sockitowm:temp28: modify reading temperature function so that it could be used…

sockitowm:temp28: modify reading temperature function so that it could be used in WRPC, no 1s delays, no floating point
parent 5892d062
......@@ -45,17 +45,19 @@
// FALSE(0) could not read the temperature, perhaps device is not
// in contact
//
int ReadTemperature28(int portnum, uchar *SerialNum, float *Temp)
uint8_t ReadTemperature28(uint8_t portnum, uint8_t *SerialNum, int16_t *Temp)
{
uchar rt=FALSE;
uchar send_block[30],lastcrc8 = 0;
int send_cnt, tsht, i, loop=0;
int power = 0;
uint8_t rt=FALSE;
uint8_t send_block[30],lastcrc8 = 0;
int send_cnt, tsht, i;
static int power = -1;
static uint8_t toggle = 0;
// set the device serial number to the counter device
owSerialNum(portnum,SerialNum,FALSE);
for (loop = 0; loop < 2; loop ++)
//we need to call this only once at the beginning
if(power==-1)
{
// check if the chip is connected to VDD
if (owAccess(portnum))
......@@ -63,28 +65,19 @@ int ReadTemperature28(int portnum, uchar *SerialNum, float *Temp)
owWriteByte(portnum,0xB4);
power = owReadByte(portnum);
}
// access the device
if (owAccess(portnum))
{
// send the convert command and if nesessary start power delivery
if (power) {
if (!owWriteBytePower(portnum,0x44))
return FALSE;
} else {
if (!owWriteByte(portnum,0x44))
return FALSE;
}
// sleep for 1 second
msDelay(1000);
if(toggle)
{
if( owAccess(portnum))
{
// turn off the 1-Wire Net strong pull-up
if (power) {
if (owLevel(portnum,MODE_NORMAL) != MODE_NORMAL)
return FALSE;
}
while(!owReadByte(portnum)){} //wait until conversion is done
// access the device
if (owAccess(portnum))
{
......@@ -113,15 +106,28 @@ int ReadTemperature28(int portnum, uchar *SerialNum, float *Temp)
tsht = tsht | send_block[1];
if (tsht & 0x00001000)
tsht = tsht | 0xffff0000;
*Temp = ((float) tsht)/16;
*Temp = (int16_t) tsht;
// success
rt = TRUE;
break;
//break;
}
}
}
}
}
// access the device
if (owAccess(portnum))
{
// send the convert command and if nesessary start power delivery
if (power) {
if (!owWriteBytePower(portnum,0x44))
return FALSE;
} else {
if (!owWriteByte(portnum,0x44))
return FALSE;
}
toggle=1;
}
// return the result flag rt
......
......@@ -28,4 +28,4 @@
//
// ---------------------------------------------------------------------------
int ReadTemperature28(int,uchar *,float *);
uint8_t ReadTemperature28(uint8_t , uint8_t *,int16_t *);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment