Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_IKS01A1-f255a2c75ecb mbed-rtos mbed
Diff: sensor.cpp
- Revision:
- 31:8bbdfea60151
- Parent:
- 29:464097268aaf
- Child:
- 32:e4cd87b7064c
diff -r 464097268aaf -r 8bbdfea60151 sensor.cpp
--- a/sensor.cpp Wed May 18 00:38:55 2016 +0000
+++ b/sensor.cpp Wed May 18 01:11:13 2016 +0000
@@ -4,27 +4,36 @@
#include "sensor.h"
#include "userMethods.h"
-// Mail box
+// Queue
Queue<log_data, QUEUESIZE> ExpansionBoard::queue;
-vector<log_data> * ExpansionBoard::v;
+std::vector<log_data> ExpansionBoard::v;
int * ExpansionBoard::n;
bool ExpansionBoard::flag;
-
-
//This is the producer
void ExpansionBoard::sampleData()
{
if(flag) printf("\nAbout to alloc\n");
- log_data* log_d = (log_data*)mail_box.alloc(5000);
-
+ log_data *log_d;
+/*
if (log_d == NULL) {
mail_box.get(5000);
if(flag) printf("Out of memory, last sample deleted\n");
log_data* log_d = (log_data*)mail_box.alloc(5000);
if(flag) printf("Allocated after out of memory\n");
}
+*/
+
+ if(v.size() >= 4){
+ osEvent evt = queue.get();
+ if(evt.status == osEventMessage){
+ log_data *message = (log_data*)evt.value.p;
+ printf("Pressure: %f", message->pressure);
+ printf("Temperature: %f", message->tempCelsius);
+ }
+ }
+
if(flag) printf("Not null, reading values\n");
//Store read data in a sample
@@ -38,8 +47,11 @@
log_d->pressure = value;
if(flag) printf("All values STORED\n");
//Send pointer to sample to the queue
- osStatus stat = mail_box.put(log_d);
-
+ queue.put(log_d);
+
+ v.push_back(*log_d);
+
+ /*
if(flag) printf("Log added to maibox\n");
// Check for resource error
if (stat == osErrorResource) {
@@ -47,6 +59,7 @@
//Error, free up memory block taken
mail_box.free(log_d);
}
+ */
}
// This is the consumer
@@ -94,9 +107,8 @@
}
// Constructor for the class
-ExpansionBoard::ExpansionBoard(vector<log_data> vector, int num, bool lFlag): T(15.0f)
+ExpansionBoard::ExpansionBoard(int num, bool lFlag): T(15.0f)
{
- v = &vector;
n = #
flag = &lFlag;
