Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Method to take temperature reading
This is the first step in separating the various things happening in the
main loop. Like the original, this method reads up to three times
looking for a non-zero value and returns immediately if one is read.

Unlike the original, this one uses errno to indicate no successful
reads.
  • Loading branch information
bertoldia committed Jan 20, 2015
commit b51c92fa3444bd1a78799cae78f2ecb0b3c1ad30
23 changes: 23 additions & 0 deletions temper.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include <stdio.h>
#include <errno.h>
#include <time.h>
#include "pcsensor.h"

Expand All @@ -12,6 +13,28 @@
static float scale = 1.0287;
static float offset = -0.85;

float read_temp() {
int i;
float tempc = 0.0000;

for (i = 0; i < 4; i++) {
usb_dev_handle* lvr_winusb = pcsensor_open();
if (!lvr_winusb) {
sleep(3);
continue;
}
tempc = pcsensor_get_temperature(lvr_winusb);
pcsensor_close(lvr_winusb);

/* Read can fail silently with a 0.0 return; repeat until we get a not zero
* value or until we have read a zero value 3 times (just in case the
* temperature really is zero */
if (tempc < -0.0001 || tempc > 0.0001) { return tempc; }
}
errno = ENOENT;
return tempc;
}

int main(){
int passes = 0;
float tempc = 0.0000;
Expand Down