diff options
author | Robert Gustafsson <robg@student.chalmers.se> | 2017-10-05 18:58:12 +0200 |
---|---|---|
committer | Robert Gustafsson <robg@student.chalmers.se> | 2017-10-05 18:58:12 +0200 |
commit | 6ad51a4acde9e6a03c48c3a483cd47eb802f2ed0 (patch) | |
tree | 230454a5139ef06d0df2af8e0972cc56a2a0281b /broccoli | |
parent | 27b430b23d397b44a3b3d634254de7fa01f9d23e (diff) | |
download | midbro-broccoli-test.tar.gz midbro-broccoli-test.tar.bz2 |
Change: user responsible for memory allocationbroccoli-test
* Add function to request only one sensor value.
Diffstat (limited to 'broccoli')
-rw-r--r-- | broccoli/src/midbropasad.c | 20 |
1 files changed, 14 insertions, 6 deletions
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; i<number; ++i){ sensor = pop_from_queue(q); arrayOfValues[i] = sensor->value; 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; |