File tree Expand file tree Collapse file tree 5 files changed +67
-25
lines changed Expand file tree Collapse file tree 5 files changed +67
-25
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
1415RobotControl 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
124125void 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 {
Original file line number Diff line number Diff line change 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-
6854void RobotControl::remoteControlMode (RemoteOrder order)
6955{
7056 switch (order)
Original file line number Diff line number Diff line change 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 ();
You can’t perform that action at this time.
0 commit comments