summaryrefslogtreecommitdiff
path: root/libsensors_iio/src/CircularBuffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'libsensors_iio/src/CircularBuffer.h')
-rw-r--r--libsensors_iio/src/CircularBuffer.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/libsensors_iio/src/CircularBuffer.h b/libsensors_iio/src/CircularBuffer.h
new file mode 100644
index 0000000..c07eb1f
--- /dev/null
+++ b/libsensors_iio/src/CircularBuffer.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2013-2015 STMicroelectronics
+ * Author: Denis Ciocca - <denis.ciocca@st.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ST_CIRCULAR_BUFFER_H
+#define ST_CIRCULAR_BUFFER_H
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <time.h>
+#include <pthread.h>
+#include <errno.h>
+
+typedef struct SensorBaseData {
+ float raw[4];
+ float offset[4];
+ float processed[4];
+ int64_t timestamp;
+} SensorBaseData;
+
+/*
+ * class CircularBuffer
+ */
+class CircularBuffer {
+private:
+ pthread_mutex_t data_mutex;
+ unsigned int lenght, elements_available;
+
+ SensorBaseData *data_sensor;
+ SensorBaseData *first_available_element;
+ SensorBaseData *first_free_element;
+
+public:
+ CircularBuffer(unsigned int num_elements);
+ ~CircularBuffer();
+
+ void writeElement(SensorBaseData *data);
+ int readElement(SensorBaseData *data);
+};
+
+#endif /* ST_CIRCULAR_BUFFER_H */