-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
76 lines (60 loc) · 2.71 KB
/
main.cpp
File metadata and controls
76 lines (60 loc) · 2.71 KB
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
#include <iostream>
#include <algorithm>
#include <vector>
#include "spectrometer.hpp"
int main(void)
{
spectrometer::initializeUSBStack();
spectrometer::findDevices(true);
//libusb_device *dev = spectrometer::filterDevice(spectrometer::usb4kVID, spectrometer::usb4kPID, 0);
//spectrometer::usb4k spec(dev);
spectrometer::usb4k *spec = nullptr;
spec = new spectrometer::usb4k;
spec->setIntegration(3800);
spec->setTriggerMode(spectrometer::usb4k::NORMAL_TRIGGER);
try {
std::vector<std::array<uint16_t, spectrometer::usb4kPixelCount>> stack_spec(100);
std::array<float, spectrometer::usb4kPixelCount> dark_correct;
std::array<float, spectrometer::usb4kPixelCount> accumulator;
std::fill(std::begin(accumulator), std::end(accumulator), 0);
//accumulator.fill(0);
for (int i = 0; i < 100; ++i) {
//auto raw_data = spec->getRawSpectrum();
std::array<uint16_t, spectrometer::usb4kPixelCount> &raw_data = spec->getRawSpectrum();
// Optical Black Correction by electric dark pixels
uint32_t sum = 0;
for (int j : spectrometer::usb4kEdarkIndices) sum += raw_data[j];
float edarkness = (float)sum / spectrometer::usb4kEdarkIndices.size();
std::cout << "electric darkness: " << edarkness;
std::transform(std::begin(raw_data), std::end(raw_data), std::begin(dark_correct),
[edarkness](uint16_t v) -> float { return v - edarkness; });
// To see a value in peak of raw_data
float max_value = *std::max_element(std::begin(dark_correct) + spectrometer::usb4kActivePixelBegin,
std::begin(dark_correct) + spectrometer::usb4kActivePixelEnd);
std::cout << ", peak value: " << max_value;
// Accumulating raw_data
std::transform(std::begin(accumulator), std::end(accumulator),
std::begin(dark_correct), std::begin(accumulator),
std::plus<float>()); //[](float a, float b) -> float { return a + b; });
// To see a value in peak of accumulator
max_value = *std::max_element(std::begin(accumulator) + spectrometer::usb4kActivePixelBegin,
std::begin(accumulator) + spectrometer::usb4kActivePixelEnd);
std::cout << ", peak value in total: " << max_value;
/* Immutability check
stack_spec[i] = raw_data;
stack_spec[i][0] = 0;
std::cout << stack_spec[i][0] << "vs. " << raw_data[0] << std::endl;
*/
if (spectrometer::findDevice(spectrometer::usb4kVID, spectrometer::usb4kPID, 0)) {
std::cout << ", connection on" << std::endl;
} else {
std::cout << ", connection off" << std::endl;
}
}
} catch (std::runtime_error &e) {
std::cerr << e.what() << std::endl;
}
delete spec;
spectrometer::deinitializeUSBStack();
return 0;
}