Skip to content

Commit

Permalink
JSY Remote through UDP - Client side
Browse files Browse the repository at this point in the history
(cherry picked from commit 85ca5ebf2db38d352a125cdbb6eaac46fb14e323)
  • Loading branch information
mathieucarbou committed Jun 24, 2024
1 parent 07e24e6 commit b757b34
Show file tree
Hide file tree
Showing 7 changed files with 775 additions and 144 deletions.
22 changes: 22 additions & 0 deletions remote/JSYRemoteUDP/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Language: Cpp
BasedOnStyle: LLVM

AccessModifierOffset: -2
AlignConsecutiveMacros: true
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: Inline
BinPackArguments: false
ColumnLimit: 0
ContinuationIndentWidth: 2
FixNamespaceComments: false
IndentAccessModifiers: true
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
IndentWidth: 2
NamespaceIndentation: All
PointerAlignment: Left
ReferenceAlignment: Left
TabWidth: 2
UseTab: Never
12 changes: 7 additions & 5 deletions remote/JSYRemoteUDP/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
/.pio
/.vscode/.browse.c_cpp.db*
/.vscode/c_cpp_properties.json
/.vscode/launch.json
/.vscode/ipch
/*.cpp
/logs
31 changes: 16 additions & 15 deletions remote/JSYRemoteUDP/JSYRemoteUDP.ino
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
#include <Arduino.h>
#include <ArduinoJson.h>
#include <MycilaJSY.h>
#include <MycilaLogger.h>

Mycila::JSY jsy;
Mycila::Logger logger;

void setup() {
Serial.begin(115200);
while (!Serial)
continue;

logger.setLevel(ARDUHAL_LOG_LEVEL_DEBUG);
logger.forwardTo(&Serial);

// read JSY on pins 17 (JSY RX / Serial TX) and 16 (JSY TX / Serial RX)
jsy.begin(Serial2, 16, 17, true);
jsy.begin(Serial2, 16, 17);
if (jsy.isEnabled() && jsy.getBaudRate() != Mycila::JSYBaudRate::BAUD_38400)
jsy.setBaudRate(Mycila::JSYBaudRate::BAUD_38400);
}

Mycila::JSYBaudRate target = Mycila::JSYBaudRate::BAUD_38400;

void loop() {
if (!jsy.isEnabled()) {
delay(1000);
return;
}
jsy.read();

delay(1000);

JsonDocument doc;
jsy.toJson(doc.to<JsonObject>());
serializeJson(doc, Serial);
Serial.println();
if (jsy.isEnabled()) {
Serial.println((int)jsy.getBaudRate());

if (jsy.getBaudRate() != target) {
jsy.setBaudRate(target);
JsonDocument doc;
jsy.toJson(doc.to<JsonObject>());
serializeJson(doc, Serial);
Serial.println();
}
delay(1000);
}
Loading

0 comments on commit b757b34

Please sign in to comment.