-
Notifications
You must be signed in to change notification settings - Fork 0
/
samplebuffer.h
72 lines (62 loc) · 1.88 KB
/
samplebuffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Written by Icewire Technologies
*/
#ifndef _SAMPLEBUFFER_H
#define _SAMPLEBUFFER_H
#include <stdint.h>
#include <stdbool.h>
/* Hold the logger's sample axes */
struct LoggerSample {
uint8_t x_axis[2];
uint8_t y_axis[2];
uint8_t z_axis[2];
};
/* Hold the loggers' sample data */
struct Sample {
uint8_t delta_time[3];
struct LoggerSample accel;
struct LoggerSample gyro;
};
/* Circular buffer that holds the samples */
struct SampleBuffer {
volatile struct Sample *samples;
uint16_t size;
uint16_t start;
uint16_t end;
volatile uint16_t count;
};
/*
* Set up a new sample buffer using the provided samples.
*
* sample_buffer: the buffer for holding the specified samples.
*
* samples: the samples to insert into the specified sample_buffer.
*
* size: the number of samples to be inserted.
*/
void construct_sample_buffer(struct SampleBuffer *sample_buffer, volatile struct Sample *samples, uint16_t size);
/*
* Set all samples in the buffer to default values.
*
* sample_buffer: the buffer for which the samples inside will be cleared
*/
void clear_sample_buffer(struct SampleBuffer *sample_buffer);
/*
* Insert a new sample into the buffer.
*
* PARAMS TODO
*
* Return true if the insertion was successful, false if not
*/
bool add_sample(struct SampleBuffer *sample_buffer, uint8_t delta_time_h, uint8_t delta_time_m, uint8_t delta_time_l,
uint8_t accel_x_axis_h, uint8_t accel_x_axis_l, uint8_t accel_y_axis_h, uint8_t accel_y_axis_l, uint8_t accel_z_axis_h, uint8_t accel_z_axis_l,
uint8_t gyro_x_axis_h, uint8_t gyro_x_axis_l, uint8_t gyro_y_axis_h, uint8_t gyro_y_axis_l, uint8_t gyro_z_axis_h, uint8_t gyro_z_axis_l);
/*
* Retrieve and removes the oldest sample from the buffer.
*
* PARAMS TODO
*
* Return true if the retrieval was successful, false if not
*/
bool remove_sample(struct SampleBuffer *sample_buffer, struct Sample *sample_ret);
#endif