Skip to content

Commit

Permalink
Use double precision to get measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
zsand committed Apr 19, 2020
1 parent c01b65e commit 83a700a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions ext/co2mon/co2mon.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ decode_temperature(uint16_t w)
return (double)w * 0.0625 - 273.15;
}

static int *device_loop(co2mon_device dev)
static double *device_loop(co2mon_device dev)
{
co2mon_data_t magic_table = { 0 };
co2mon_data_t result;
int temp = 0;
int co = 0;
static int array [2];
double temp = 0;
double co = 0;
static double array [2];

if (!co2mon_send_magic_table(dev, magic_table))
{
Expand Down Expand Up @@ -171,7 +171,7 @@ static int *device_loop(co2mon_device dev)
switch (r0)
{
case CODE_TAMB:
temp = (int)decode_temperature(w);
temp = decode_temperature(w);

break;
case CODE_CNTR:
Expand All @@ -180,7 +180,7 @@ static int *device_loop(co2mon_device dev)
break;
}

co = (int)w;
co = (double)w;

break;
}
Expand All @@ -192,9 +192,9 @@ static int *device_loop(co2mon_device dev)
return array;
}

static int *main_loop()
static double *main_loop()
{
static int empty_result[2] = {0};
static double empty_result[2] = {0};

co2mon_device dev = co2mon_open_device();

Expand All @@ -203,18 +203,18 @@ static int *main_loop()
return empty_result;
}

int *result = device_loop(dev);
double *result = device_loop(dev);

hid_close(dev);

return result;
}

int *get()
double *get()
{
hid_init();

int *result = main_loop();
double *result = main_loop();

hid_exit();

Expand Down
2 changes: 1 addition & 1 deletion lib/co2mon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Co2mon
attach_function :get, [], :pointer

def self.get_data
data = get.get_array_of_int32(0, 2)
data = get.read_array_of_double(2)

{
:co2 => data[0],
Expand Down

0 comments on commit 83a700a

Please sign in to comment.