aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Gustafsson <robg@student.chalmers.se>2017-10-05 18:58:12 +0200
committerAndreas Lindhé <andreas@lindhe.io>2017-10-09 12:14:35 +0200
commitf6fc3d174ca0e79de2bd6030191910c56f28ee04 (patch)
treed0f476714f9132f816d9c57a18eacd13df36e36f
parenta0095ef4c4ef74d3726e58dea5f04cb55f2a6a20 (diff)
downloadmidbro-f6fc3d174ca0e79de2bd6030191910c56f28ee04.tar.gz
midbro-f6fc3d174ca0e79de2bd6030191910c56f28ee04.tar.bz2
Change: user responsible for memory allocation
* Add function to request only one sensor value.
-rw-r--r--broccoli/src/midbropasad.c20
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;