From f6fc3d174ca0e79de2bd6030191910c56f28ee04 Mon Sep 17 00:00:00 2001 From: Robert Gustafsson Date: Thu, 5 Oct 2017 18:58:12 +0200 Subject: Change: user responsible for memory allocation * Add function to request only one sensor value. --- broccoli/src/midbropasad.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'broccoli/src/midbropasad.c') diff --git a/broccoli/src/midbropasad.c b/broccoli/src/midbropasad.c index d3c6829..04da7a0 100644 --- a/broccoli/src/midbropasad.c +++ b/broccoli/src/midbropasad.c @@ -8,20 +8,28 @@ Fifo_q * q; - int * -request_sensor_data(int number) + void +request_n_values(int number, int arrayOfValues[]) { int i; - int * arrayOfValues; Sensor_t * sensor; - arrayOfValues = (int *) malloc(number*sizeof(int)); for(i=0; ivalue; free(sensor); } printf("Release %d sensor data values\n", number); - return arrayOfValues; +} + int +request_value() +{ + int value; + Sensor_t * sensor; + sensor = pop_from_queue(q); + value = sensor->value; + free(sensor); + printf("Release 1 sensor data value\n"); + return value; } void @@ -44,7 +52,7 @@ main(int argc, char **argv) sleep(10); while(true){ print_queue(q); - free(request_sensor_data(5)); + request_value(); } free(q); return 0; -- cgit v1.2.3