-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduinomicro.cpp
55 lines (49 loc) · 1.69 KB
/
arduinomicro.cpp
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
/*
* arduinomicro.cpp
*
* MSU STARX Exosuit
* Software Version 2.3
* Created on: September 30, 2018
* All rights reserved
*/
#include "arduinomicro.h"
std::string ArduinoMicro::createPacket(std::string command, std::vector<std::string> parameters = {}){
std::string message = "";
message.reserve(message.capacity() * 10); // Increase message capacity for appending parameters
message.append(command);
if(!parameters.empty()) {
for(int i = 0; i < parameters.size(); i++) {
message.append(PacketDelimiterString);
message.append(parameters[i]);
}
}
message.append(PacketTerminatorString);
return message;
}
std::string ArduinoMicro::getADC(void){
packet = this->createPacket(GetADCValuesString).c_str();
arduinoPort.writePort(packet);
usleep(waitTime * 1000); // Delay before reading buffer
data = arduinoPort.readPort();
return std::string(data);
}
std::string ArduinoMicro::getGPIO(void){
packet = this->createPacket(GetGPIOValuesString).c_str();
arduinoPort.writePort(packet);
usleep(waitTime * 1000); // Delay before reading buffer
data = arduinoPort.readPort();
return std::string(data);
}
std::string ArduinoMicro::setPWM(std::vector<std::string> dutyCycles){
packet = this->createPacket(SetPWMDutyCycleString, dutyCycles).c_str();
arduinoPort.writePort(packet);
usleep(waitTime * 1000); // Delay before reading buffer
data = arduinoPort.readPort();
return std::string(data);
}
void ArduinoMicro::setupSerial(std::string portName, int baudRate){
arduinoPort.portName = portName.c_str();
arduinoPort.baudRate = baudRate;
arduinoPort.openPort();
arduinoPort.setPort();
}