54 lines
1.1 KiB
C
54 lines
1.1 KiB
C
#include "Python.h"
|
|
|
|
#ifndef _BPS_SAMPLE_H_
|
|
#define _BPS_SAMPLE_H_
|
|
|
|
#define SAMPLE_MODE_RAW 0
|
|
#define SAMPLE_MODE_FIRST 1
|
|
#define SAMPLE_MODE_AVG 2
|
|
|
|
typedef struct {
|
|
unsigned int time_step;
|
|
unsigned int count;
|
|
double value;
|
|
} ReSampleEntry;
|
|
|
|
void ReSampleEntry_add_value(unsigned int mode, ReSampleEntry *self, int value) {
|
|
switch (mode) {
|
|
case SAMPLE_MODE_RAW:
|
|
case SAMPLE_MODE_FIRST:
|
|
default:
|
|
if (self->count == 0) {
|
|
self->count = 1;
|
|
self->value = value;
|
|
}
|
|
break;
|
|
case SAMPLE_MODE_AVG:
|
|
// average value
|
|
self->count++;
|
|
self->value += value;
|
|
break;
|
|
}
|
|
}
|
|
|
|
int ReSampleEntry_value(unsigned int mode, ReSampleEntry *self, double *value) {
|
|
if (self->count == 0) {
|
|
return 0;
|
|
} else {
|
|
switch (mode) {
|
|
case SAMPLE_MODE_RAW:
|
|
case SAMPLE_MODE_FIRST:
|
|
default:
|
|
*value = self->value;
|
|
break;
|
|
case SAMPLE_MODE_AVG:
|
|
// average value
|
|
*value = self->value / self->count;
|
|
break;
|
|
}
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
#endif
|