Skip to content

Commit cd7e239

Browse files
committed
#424 stdio serial plugin added
1 parent 15defd4 commit cd7e239

File tree

5 files changed

+128
-5
lines changed

5 files changed

+128
-5
lines changed

tcMenuGenerator/src/main/java/com/thecoderscorner/menu/editorui/generator/ui/GenerateCodeDialog.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public class GenerateCodeDialog {
9393
private TextField namespaceField;
9494
private ToggleButton useModuleButton;
9595
private TableView<TcMenuFormPersistenceWithOptionality> formTable;
96+
private VBox remotesPane;
9697

9798
public GenerateCodeDialog(CodePluginManager manager, CurrentProjectEditorUI editorUI,
9899
CurrentEditorProject project, CodeGeneratorRunner runner,
@@ -160,6 +161,8 @@ public void showCodeGenerator(Stage stage, boolean modal) {
160161
centerPane.getChildren().add(titleLbl);
161162

162163
List<String> remoteIds = genOptions.getLastRemoteCapabilitiesUuids();
164+
remotesPane = new VBox();
165+
centerPane.getChildren().add(remotesPane);
163166
if(remoteIds != null && !remoteIds.isEmpty()) {
164167
int count = 0;
165168
for(var remoteId : remoteIds) {
@@ -169,7 +172,7 @@ public void showCodeGenerator(Stage stage, boolean modal) {
169172
String pluginId = "remotePlugin" + count;
170173
var currentRemote = new UICodePluginItem(manager, itemRemote, CHANGE, this::onRemoteChange, editorUI, allItems, count, pluginId);
171174
currentRemote.getStyleClass().add("uiCodeGen");
172-
centerPane.getChildren().add(currentRemote);
175+
remotesPane.getChildren().add(currentRemote);
173176
count++;
174177
currentRemotes.add(currentRemote);
175178
}
@@ -180,7 +183,7 @@ public void showCodeGenerator(Stage stage, boolean modal) {
180183
String pluginId = "remotePlugin0";
181184
var currentRemote = new UICodePluginItem(manager, itemRemote, CHANGE, this::onRemoteChange, editorUI, allItems, 0, pluginId);
182185
currentRemote.getStyleClass().add("uiCodeGen");
183-
centerPane.getChildren().add(currentRemote);
186+
remotesPane.getChildren().add(currentRemote);
184187
}
185188

186189
Button addRemoteCapabilityButton = new Button(MenuEditorApp.getBundle().getString("code.gen.remote.add"));
@@ -284,7 +287,7 @@ private void produceAnotherRemoteCapability(ActionEvent actionEvent) {
284287
currentRemote.setId("currentRemoteUI-" + currentRemotes.size());
285288
currentRemote.getStyleClass().add("uiCodeGen");
286289
currentRemotes.add(currentRemote);
287-
centerPane.getChildren().add(currentRemote);
290+
remotesPane.getChildren().add(currentRemote);
288291
}
289292

290293
private Label addTitleLabel(Pane vbox, String text) {
@@ -608,7 +611,7 @@ private void onRemoteChange(UICodePluginItem uiPlugin, CodePluginItem item) {
608611
if(item == null) {
609612
logger.log(INFO, "Remove fired on remote");
610613
currentRemotes.remove(uiPlugin);
611-
centerPane.getChildren().remove(uiPlugin);
614+
remotesPane.getChildren().remove(uiPlugin);
612615
changeProperties();
613616

614617
for(int i=0; i<currentRemotes.size(); i++) {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<TcMenuPlugin name="EmbedControl/API using C++ stdio functions" id="DFE97583-1897-4F87-BEFA-10CB72C43F0E" subsystem="REMOTE" requiresDesigner="4.2"
2+
xmlns="https://www.thecoderscorner.com/libraries/tcmenuPluginItem" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="https://www.thecoderscorner.com/libraries/tcmenuPluginItem https://www.thecoderscorner.com/products/arduino-libraries/libraries/tcmenu-plugin-item.xsd">
4+
<SupportedPlatforms>
5+
<PlatformGroup>TrueCpp</PlatformGroup>
6+
</SupportedPlatforms>
7+
<Description>An EmbedControl/API connection using stdio functions such as printf() and gets(). This assumes you have stdio available and configured on your board.</Description>
8+
<Documentation link="https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/tcmenu-iot/serial-remote-plugin/"/>
9+
<RequiredLibraries/>
10+
<ImageFile>serial-connection.jpg</ImageFile>
11+
12+
<Properties/>
13+
14+
<ApplicabilityDefs/>
15+
16+
<SourceFiles>
17+
<SourceFile name="serialSrc/StdioTransport.cpp"/>
18+
<SourceFile name="serialSrc/StdioTransport.h"/>
19+
</SourceFiles>
20+
21+
<IncludeFiles>
22+
<Header name="RemoteConnector.h" inSource="false"/>
23+
<Header name="StdioTransport.h" inSource="true"/>
24+
</IncludeFiles>
25+
26+
<GlobalVariables>
27+
<Variable name="stdioInitializer" type="NoInitialisationNeeded"/>
28+
29+
<Variable name="stdioTransport" type="StdioTransport">
30+
<Param value="255"/>
31+
</Variable>
32+
33+
<Variable name="stdioConnection" type="TagValueRemoteServerConnection">
34+
<Param value="stdioTransport"/>
35+
<Param value="stdioInitializer"/>
36+
</Variable>
37+
</GlobalVariables>
38+
39+
<SetupFunctions>
40+
<Function name="addConnection" object="remoteServer">
41+
<Param ref="stdioConnection"/>
42+
</Function>
43+
</SetupFunctions>
44+
</TcMenuPlugin>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
#include "StdioTransport.h"
3+
4+
int StdioTransport::writeStr(const char *data) {
5+
auto dl = strlen(data);
6+
for(size_t i = 0; i<dl; ++i) {
7+
putchar_raw(data[i]);
8+
}
9+
return (int)dl;
10+
}
11+
12+
uint8_t StdioTransport::readByte() {
13+
if (inputBuffer.available()) {
14+
return inputBuffer.get();
15+
}
16+
return -1;
17+
}
18+
19+
void StdioTransport::close() {
20+
currentField.msgType = UNKNOWN_MSG_TYPE;
21+
currentField.fieldType = FVAL_PROCESSING_AWAITINGMSG;
22+
}
23+
24+
int StdioTransport::writeChar(char data) {
25+
putchar_raw(data);
26+
return 1;
27+
}
28+
29+
30+
bool StdioTransport::readAvailable() {
31+
int ch;
32+
while ((ch=getchar_timeout_us(0)) != PICO_ERROR_TIMEOUT) {
33+
inputBuffer.put(ch);
34+
}
35+
return inputBuffer.available();
36+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef STDIO_TRANSPORT_H
2+
#define STDIO_TRANSPORT_H
3+
4+
#include <PlatformDetermination.h>
5+
#include <RemoteConnector.h>
6+
#include <remote/BaseRemoteComponents.h>
7+
#include "SCCircularBuffer.h"
8+
9+
namespace tcremote {
10+
11+
class StdioTransport : public TagValueTransport {
12+
private:
13+
SCCircularBuffer inputBuffer;
14+
public:
15+
explicit StdioTransport(int readBufferSize) : inputBuffer(readBufferSize), TagValueTransport(TVAL_UNBUFFERED) {}
16+
17+
void flush() override { stdio_flush(); }
18+
19+
int writeChar(char data) override;
20+
21+
int writeStr(const char *data) override;
22+
23+
uint8_t readByte() override;
24+
25+
bool readAvailable() override;
26+
27+
bool available() override { return true; }
28+
29+
bool connected() override { return true; }
30+
31+
void close() override;
32+
};
33+
}
34+
35+
#ifndef TC_MANUAL_NAMESPACING
36+
using namespace tcremote;
37+
#endif // TC_MANUAL_NAMESPACING
38+
39+
#endif //STDIO_TRANSPORT_H

xmlPlugins/core-remote/tcmenu-plugin.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
<Plugin>remoteSerialESP.xml</Plugin>
2222
<Plugin>remoteWifiESP.xml</Plugin>
2323

24-
<!-- mbed specific -->
24+
<!-- true cpp specific -->
2525
<Plugin>remoteMbedEthernet.xml</Plugin>
26+
<Plugin>remoteStdio.xml</Plugin>
2627

2728
<!-- simhub connector -->
2829
<Plugin>simhubConnector.xml</Plugin>

0 commit comments

Comments
 (0)