-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTestingInterface.cpp
More file actions
109 lines (90 loc) · 2.32 KB
/
TestingInterface.cpp
File metadata and controls
109 lines (90 loc) · 2.32 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "config.h"
#include <spdlog/spdlog.h>
#if TESTING == 1
#include "TestingInterface.h"
TestingInterface::TestingInterface()
{
logger = spdlog::default_logger();
}
TestingInterface::~TestingInterface() = default;
void TestingInterface::initialize()
{
SPDLOG_LOGGER_INFO(logger, "Initializing TESTING...");
testingSensors.initialize();
initializeOutputs();
}
void TestingInterface::initializeOutputs()
{
#if USE_LOGGER == 1
SPDLOG_LOGGER_INFO(logger, "Initializing LOGGER...");
sensorLogger.initialize();
#endif
#if USE_RADIO == 1
SPDLOG_LOGGER_INFO(logger, "Initializing RADIO...");
radio.initialize();
#endif
}
bool TestingInterface::updateInputs()
{
latestState = std::make_shared<StateData>(testingSensors.getLatest());
return true;
}
bool TestingInterface::updateOutputs(std::shared_ptr<StateData> data)
{
#if USE_LOGGER == 1
if (latestState->outOfData)
{
if (!sensorLogger.queueEmpty())
{
// Wait for logger to finish
return false;
}
exit(EXIT_SUCCESS);
}
sensorLogger.enqueueSensorData(*data);
#endif
#if USE_RADIO == 1
radio.enqueueSensorData(*data);
#endif
return true;
}
#if USE_GPIO == 1
void TestingInterface::createNewGpioOutput(std::string name, int pinNbr)
{
return; // don't do anything for now
}
void TestingInterface::createNewGpioPwmOutput(std::string name, int pinNbr, int safePosition, bool softpwm)
{
return; // don't do anything for now
}
void TestingInterface::createNewGpioDCMotorOutput(std::string name, int pinForward, int pinReverse, int motorPower,
int limitSwitchMinPin, int limitSwitchMaxPin, int potentiometerPin)
{
return; // don't do anything for now
}
#endif
void TestingInterface::calibrateTelemetry()
{
}
std::shared_ptr<StateData> TestingInterface::getLatest()
{
return latestState;
}
time_point TestingInterface::getCurrentTime()
{
if (latestState != nullptr)
{
return time_point(std::chrono::duration_cast<time_point::duration>(duration_ns(latestState->timeStamp)));
}
else
{
return time_point(std::chrono::duration_cast<time_point::duration>(duration_ns(0)));
}
}
#if USE_LOGGER == 1
void TestingInterface::restartLogger()
{
return; // don't do anything for now
}
#endif
#endif