-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdc.h
79 lines (70 loc) · 1.9 KB
/
Adc.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
73
74
75
76
77
78
79
/*
* Adc.h
*
* Created on: Mar 5, 2015
* Author: mlaakso
*/
#ifndef ADC_H_
#define ADC_H_
#include <iterator>
#include <iio.h>
namespace PowerMonitor
{
class GalileoGen2Adc
{
public:
GalileoGen2Adc(unsigned int nChannels, unsigned int freq);
~GalileoGen2Adc();
void refill();
class const_iterator: public std::iterator<std::input_iterator_tag, float, ptrdiff_t, const float*, const float&>
{
public:
explicit const_iterator(char* first, ptrdiff_t step, struct iio_channel* chn) :
_ptr(first),
_step(step),
_chn(chn)
{
}
value_type operator*() const
{
uint16_t tmp;
iio_channel_convert(_chn, &tmp, _ptr);
// TODO: Dynamically set these.
return tmp * 5000.0 / 4096;
}
const_iterator& operator++()
{
_ptr += _step;
return *this;
}
const_iterator operator++(int)
{
const_iterator tmp = *this;
_ptr += _step;
return tmp;
}
bool operator==(const const_iterator& other) const
{
return _ptr == other._ptr;
}
bool operator!=(const const_iterator& other) const
{
return _ptr != other._ptr;
}
protected:
const char* _ptr;
ptrdiff_t _step;
private:
struct iio_channel* _chn;
};
const_iterator cbegin(unsigned int channel) const;
const_iterator cend(unsigned int channel) const;
private:
struct iio_context* _iioctx;
struct iio_device* _adc;
struct iio_device* _trigger;
struct iio_buffer* _adcbuf;
unsigned int _nChannels;
};
}
#endif /* ADC_H_ */