Skip to content

Commit 4f74e49

Browse files
committed
Fix bug with documentation
1 parent 56edc63 commit 4f74e49

File tree

5 files changed

+274
-4
lines changed

5 files changed

+274
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ MESSAGE(STATUS "Using CMake ${CMAKE_VERSION}")
33

44
SET(RLENVSCPP_VERSION_MAJOR 1)
55
SET(RLENVSCPP_VERSION_MINOR 16)
6-
SET(RLENVSCPP_VERSION_PATCH 0)
6+
SET(RLENVSCPP_VERSION_PATCH 1)
77

88

99
SET(RLENVSCPP_VERSION "${RLENVSCPP_VERSION_MAJOR}.${RLENVSCPP_VERSION_MINOR}.${RLENVSCPP_VERSION_PATCH}")

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
author = 'Alexandros Giavaras'
2424

2525
# The full version, including alpha/beta/rc tags
26-
release = 'v1.11.6'
26+
release = 'v1.16.1'
2727

2828

2929
# -- General configuration ---------------------------------------------------
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
Connecting with Arduino over USB
2+
========================================
3+
4+
.. code-block::
5+
6+
Arduino Code
7+
String incomingMessage = "";
8+
9+
void setup() {
10+
pinMode(LED_BUILTIN, OUTPUT);
11+
Serial.begin(9600);
12+
}
13+
14+
void loop() {
15+
if (Serial.available()) {
16+
incomingMessage = Serial.readStringUntil('\n');
17+
incomingMessage.trim(); // Remove whitespace and newline
18+
19+
if (incomingMessage == "ON") {
20+
digitalWrite(LED_BUILTIN, HIGH);
21+
Serial.println("LED is ON");
22+
} else if (incomingMessage == "OFF") {
23+
digitalWrite(LED_BUILTIN, LOW);
24+
Serial.println("LED is OFF");
25+
} else {
26+
Serial.println("Unknown command");
27+
}
28+
}
29+
}
30+
31+
.. code-block::
32+
33+
#include "rlenvs/boards/arduino/arduino_connector_usb_base.h"
34+
35+
#include <iostream>
36+
#include <string>
37+
#include <chrono>
38+
#include <thread>
39+
40+
namespace example
41+
{
42+
using rlenvscpp::boards::arduino::ArduinoCMDBase;
43+
using rlenvscpp::boards::arduino::ArduinoConnectorUSBBase;
44+
45+
struct ArduinoONCMD: public ArduinoCMDBase
46+
{
47+
virtual std::string get_cmd()const final;
48+
};
49+
50+
std::string ArduinoONCMD::get_cmd() const
51+
{
52+
return "ON";
53+
}
54+
55+
struct ArduinoOFFCMD: public ArduinoCMDBase
56+
{
57+
virtual std::string get_cmd()const final;
58+
};
59+
60+
std::string ArduinoOFFCMD::get_cmd() const
61+
{
62+
return "OFF";
63+
}
64+
}
65+
66+
67+
int main() {
68+
69+
using namespace example;
70+
71+
ArduinoConnectorUSBBase connector("/dev/ttyACM0");
72+
connector.connect();
73+
74+
ArduinoONCMD on_cmd;
75+
ArduinoOFFCMD off_cmd;
76+
77+
std::string user_input;
78+
while (true) {
79+
std::cout << "Enter command ON/OFF or e (to exit): ";
80+
std::getline(std::cin, user_input);
81+
82+
if (user_input == "e") {
83+
connector.send_cmd(off_cmd);
84+
break;
85+
}
86+
87+
if (user_input == "ON")
88+
{
89+
connector.send_cmd(on_cmd);
90+
}
91+
92+
if (user_input == "OFF")
93+
{
94+
connector.send_cmd(off_cmd);
95+
}
96+
97+
std::this_thread::sleep_for(std::chrono::seconds(1));
98+
}
99+
100+
connector.close_connection();
101+
return 0;
102+
}
103+
104+
105+
References
106+
----------
107+
108+
109+
110+
111+
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
Connecting with Arduino over WiFi
2+
========================================
3+
4+
.. code-block::
5+
6+
#include <WiFiS3.h>
7+
8+
char ssid[] = "YOU-SSID";
9+
char password[] = "YOUR-PASSWORD";
10+
11+
int status = WL_IDLE_STATUS;
12+
WiFiServer server(8005);
13+
14+
15+
void setup() {
16+
17+
pinMode(LED_BUILTIN, OUTPUT);
18+
19+
Serial.begin(9600);
20+
delay(1000);
21+
if (Serial.available()) {
22+
Serial.println("Connecting to WiFi...");
23+
}
24+
25+
while (status != WL_CONNECTED) {
26+
Serial.print("Connecting to ");
27+
Serial.println(ssid);
28+
status = WiFi.begin(ssid, password);
29+
delay(5000);
30+
}
31+
32+
Serial.println("\nWiFi connected.");
33+
Serial.print("IP address: ");
34+
Serial.println(WiFi.localIP());
35+
36+
server.begin();
37+
Serial.println("HTTP server started");
38+
39+
}
40+
41+
void loop() {
42+
43+
WiFiClient client = server.available();
44+
45+
if (client) {
46+
//client.flush();
47+
Serial.println("Client connected.");
48+
String request = "";
49+
while (client.connected()) {
50+
if (client.available()) {
51+
char c = client.read();
52+
request += c;
53+
if (c == '\n' && request.endsWith("\r\n\r\n")) {
54+
break; // End of HTTP headers
55+
}
56+
}
57+
}
58+
59+
String body = "";
60+
while (client.available()) {
61+
body += (char)client.read();
62+
}
63+
64+
if(body == "ON"){
65+
digitalWrite(LED_BUILTIN, HIGH);
66+
String response = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nLED is ON\n";
67+
client.print(response);
68+
}
69+
else if(body == "OFF"){
70+
digitalWrite(LED_BUILTIN, LOW);
71+
String response = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nLED is OFF\n";
72+
client.print(response);
73+
74+
}
75+
76+
delay(1);
77+
client.stop();
78+
Serial.println("Client disconnected.");
79+
}
80+
}
81+
82+
.. code-block::
83+
84+
#include "rlenvs/boards/arduino/arduino_connector_wifi_base.h"
85+
#include <iostream>
86+
87+
namespace example
88+
{
89+
using rlenvscpp::boards::arduino::ArduinoCMDBase;
90+
using rlenvscpp::boards::arduino::ArduinoConnectorWIFIBase;
91+
92+
struct ArduinoONCMD: public ArduinoCMDBase
93+
{
94+
virtual std::string get_cmd()const final;
95+
};
96+
97+
std::string ArduinoONCMD::get_cmd() const
98+
{
99+
return "ON";
100+
}
101+
102+
struct ArduinoOFFCMD: public ArduinoCMDBase
103+
{
104+
virtual std::string get_cmd()const final;
105+
};
106+
107+
std::string ArduinoOFFCMD::get_cmd() const
108+
{
109+
return "OFF";
110+
}
111+
}
112+
113+
int main() {
114+
115+
116+
using namespace example;
117+
118+
ArduinoConnectorWIFIBase connector("http://192.168.0.70:8005");
119+
ArduinoONCMD on_cmd;
120+
ArduinoOFFCMD off_cmd;
121+
122+
std::string user_input;
123+
while (true)
124+
{
125+
std::cout << "Enter command ON/OFF or e (to exit): ";
126+
std::getline(std::cin, user_input);
127+
128+
if (user_input == "e") {
129+
connector.send_cmd(off_cmd);
130+
break;
131+
}
132+
133+
if (user_input == "ON")
134+
{
135+
auto response = connector.send_cmd(on_cmd);
136+
std::cout<<"Arduino response: "<<response<<std::endl;
137+
}
138+
139+
if (user_input == "OFF")
140+
{
141+
auto response = connector.send_cmd(off_cmd);
142+
std::cout<<"Arduino response: "<<response<<std::endl;
143+
}
144+
145+
std::this_thread::sleep_for(std::chrono::seconds(1));
146+
}
147+
148+
return 0;
149+
}
150+
151+
152+
153+
References
154+
----------
155+
156+
157+
158+
159+

src/rlenvs/rlenvscpp_version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define GYMFCPP_VERSION_H
33

44
#define RLENVSCPP_VERSION_MAJOR 1
5-
#define RLENVSCPP_VERSION_MINOR 14
5+
#define RLENVSCPP_VERSION_MINOR 16
66
#define RLENVSCPP_VERSION_PATCH 0
7-
#define RLENVSCPP_VERSION "1.14.0"
7+
#define RLENVSCPP_VERSION "1.16.0"
88
#endif

0 commit comments

Comments
 (0)