Skip to content

Commit 683270b

Browse files
authored
Merge pull request #11 from gelanchez/develop
BTprocess class creation and implementation of the receiver method
2 parents d5b75ee + 1f7be6d commit 683270b

File tree

5 files changed

+67
-25
lines changed

5 files changed

+67
-25
lines changed

src/BTprocess.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @file BTprocess.cpp
3+
* @author José Ángel Sánchez (https://github.com/gelanchez)
4+
* @brief Library for receiving and processing the data from the serial bluetooth.
5+
* @version 1.0.0
6+
* @date 2020-08-29
7+
* @copyright GPL-3.0
8+
*/
9+
10+
#include "BTprocess.h"
11+
12+
BTprocess::BTprocess()
13+
{
14+
}
15+
16+
BTprocess::~BTprocess()
17+
{
18+
}
19+
20+
String BTprocess::getBTData()
21+
{
22+
m_dataBT = "";
23+
while ((Serial.available() > 0) && (m_dataBT.endsWith("}") == false))
24+
{
25+
m_dataBT += static_cast<char>(Serial.read());
26+
delay(3);
27+
}
28+
if ((m_dataBT.length() > 0) && m_dataBT.endsWith("}"))
29+
return m_dataBT;
30+
else
31+
return "";
32+
}

src/BTprocess.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @file BTprocess.h
3+
* @author José Ángel Sánchez (https://github.com/gelanchez)
4+
* @brief Library for receiving and processing the data from the serial bluetooth.
5+
* @version 1.0.0
6+
* @date 2020-08-29
7+
* @copyright GPL-3.0
8+
*/
9+
10+
#ifndef BTPROCESS
11+
#define BTPROCESS
12+
13+
class BTprocess
14+
{
15+
private:
16+
String m_dataBT = "";
17+
18+
public:
19+
BTprocess();
20+
~BTprocess();
21+
String getBTData();
22+
};
23+
24+
#endif

src/main.ino

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
* @file main.ino
33
* @author José Ángel Sánchez (https://github.com/gelanchez)
44
* @brief Main program.
5-
* @version 1.0.0
6-
* @date 2020-08-22
5+
* @version 1.0.1
6+
* @date 2020-08-29
77
* @copyright GPL-3.0
88
*/
99

10+
#include "BTprocess.h"
1011
#include "constants.h"
1112
#include "robot.h"
1213
#include <ArduinoJson.h>
1314

1415
RobotControl Robot = RobotControl(); // Initialization of the RobotControl object
15-
String dataBT = "";
16+
BTprocess BTproc = BTprocess(); // Initialization of the BT processor object
1617

1718
/**
1819
* @brief Structure storing the JSON data received, which keeps the mode of the robot.
@@ -38,7 +39,7 @@ StaticJsonDocument<150> elegooDoc;
3839
* {"N":3,"D1":2} obstacle avoidance
3940
* {"N":2,"D1":1...5} joystick
4041
*/
41-
void decodeElegooJSON()
42+
void decodeElegooJSON(const String &dataBT)
4243
{
4344
DeserializationError error = deserializeJson(elegooDoc, dataBT);
4445
if (!error)
@@ -123,9 +124,9 @@ void setup()
123124

124125
void loop()
125126
{
126-
dataBT = Robot.getBTData();
127+
String dataBT = BTproc.getBTData();
127128
if (dataBT != "")
128-
decodeElegooJSON();
129+
decodeElegooJSON(dataBT);
129130

130131
switch (data.mode)
131132
{

src/robot.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* @file robot.cpp
33
* @author José Ángel Sánchez (https://github.com/gelanchez)
44
* @brief Library for controling the robot.
5-
* @version 1.0.2
6-
* @date 2020-08-28
5+
* @version 1.1.0
6+
* @date 2020-08-29
77
* @copyright GPL-3.0
88
*/
99

@@ -51,20 +51,6 @@ void RobotControl::begin()
5151
m_servo.begin(); // Servo initialization can not be done inside Robot constructor
5252
}
5353

54-
String RobotControl::getBTData()
55-
{
56-
String dataBT = "";
57-
while ((Serial.available() > 0) && (dataBT.endsWith("}") == false))
58-
{
59-
dataBT += static_cast<char>(Serial.read());
60-
delay(3);
61-
}
62-
if ((dataBT.length() > 0) && dataBT.endsWith("}"))
63-
return dataBT;
64-
else
65-
return "";
66-
}
67-
6854
void RobotControl::remoteControlMode(RemoteOrder order)
6955
{
7056
switch (order)

src/robot.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* @file robot.h
33
* @author José Ángel Sánchez (https://github.com/gelanchez)
44
* @brief Library for controling the robot.
5-
* @version 1.0.0
6-
* @date 2020-08-22
5+
* @version 1.1.0
6+
* @date 2020-08-29
77
* @copyright GPL-3.0
88
*/
99
#ifndef ROBOT_H
@@ -35,7 +35,6 @@ class RobotControl
3535
~RobotControl();
3636
void restartState();
3737
void begin();
38-
String getBTData();
3938

4039
void remoteControlMode(RemoteOrder order);
4140
void IRControlMode();

0 commit comments

Comments
 (0)