Skip to content

Commit

Permalink
Handle boards with 2 Serial (0 and 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Sep 6, 2024
1 parent 5e7d930 commit e78dde8
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 1 deletion.
7 changes: 7 additions & 0 deletions examples/Callback/Callback.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#include <ArduinoJson.h>
#include <MycilaJSY.h>

#ifndef SOC_UART_HP_NUM
#define SOC_UART_HP_NUM SOC_UART_NUM
#endif
#if SOC_UART_HP_NUM < 3
#define Serial2 Serial1
#endif

// Pin: RX (ESP32) -> TX (JSY)
#define JSY_TX_PIN 16

Expand Down
7 changes: 7 additions & 0 deletions examples/CallbackAsync/CallbackAsync.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
#include <ArduinoJson.h>
#include <MycilaJSY.h>

#ifndef SOC_UART_HP_NUM
#define SOC_UART_HP_NUM SOC_UART_NUM
#endif
#if SOC_UART_HP_NUM < 3
#define Serial2 Serial1
#endif

// Pin: Relay (ESP32)
#define RELAY_PIN 26
// #define RELAY_PIN 32
Expand Down
7 changes: 7 additions & 0 deletions examples/EnergyReset/EnergyReset.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
#include <HardwareSerial.h>
#include <MycilaJSY.h>

#ifndef SOC_UART_HP_NUM
#define SOC_UART_HP_NUM SOC_UART_NUM
#endif
#if SOC_UART_HP_NUM < 3
#define Serial2 Serial1
#endif

Mycila::JSY jsy;

void setup() {
Expand Down
7 changes: 7 additions & 0 deletions examples/EnergyResetAsync/EnergyResetAsync.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
#include <HardwareSerial.h>
#include <MycilaJSY.h>

#ifndef SOC_UART_HP_NUM
#define SOC_UART_HP_NUM SOC_UART_NUM
#endif
#if SOC_UART_HP_NUM < 3
#define Serial2 Serial1
#endif

Mycila::JSY jsy;

void setup() {
Expand Down
7 changes: 7 additions & 0 deletions examples/PerfTest1/PerfTest1.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#include <ArduinoJson.h>
#include <MycilaJSY.h>

#ifndef SOC_UART_HP_NUM
#define SOC_UART_HP_NUM SOC_UART_NUM
#endif
#if SOC_UART_HP_NUM < 3
#define Serial2 Serial1
#endif

// Pin: RX (ESP32) -> TX (JSY)
#define JSY_TX_PIN 16

Expand Down
7 changes: 7 additions & 0 deletions examples/PerfTest2/PerfTest2.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#include <ArduinoJson.h>
#include <MycilaJSY.h>

#ifndef SOC_UART_HP_NUM
#define SOC_UART_HP_NUM SOC_UART_NUM
#endif
#if SOC_UART_HP_NUM < 3
#define Serial2 Serial1
#endif

// Pin: RX (ESP32) -> TX (JSY)
#define JSY_TX_PIN 16

Expand Down
7 changes: 7 additions & 0 deletions examples/Read/Read.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
#include <ArduinoJson.h>
#include <MycilaJSY.h>

#ifndef SOC_UART_HP_NUM
#define SOC_UART_HP_NUM SOC_UART_NUM
#endif
#if SOC_UART_HP_NUM < 3
#define Serial2 Serial1
#endif

Mycila::JSY jsy;

void setup() {
Expand Down
7 changes: 7 additions & 0 deletions examples/ReadAsync/ReadAsync.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
#include <ArduinoJson.h>
#include <MycilaJSY.h>

#ifndef SOC_UART_HP_NUM
#define SOC_UART_HP_NUM SOC_UART_NUM
#endif
#if SOC_UART_HP_NUM < 3
#define Serial2 Serial1
#endif

Mycila::JSY jsy;

void setup() {
Expand Down
7 changes: 7 additions & 0 deletions examples/Repair/Repair.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
#include <HardwareSerial.h>
#include <MycilaJSY.h>

#ifndef SOC_UART_HP_NUM
#define SOC_UART_HP_NUM SOC_UART_NUM
#endif
#if SOC_UART_HP_NUM < 3
#define Serial2 Serial1
#endif

void setup() {
Serial.begin(115200);
while (!Serial)
Expand Down
7 changes: 7 additions & 0 deletions examples/SetSpeed/SetSpeed.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
#include <ArduinoJson.h>
#include <MycilaJSY.h>

#ifndef SOC_UART_HP_NUM
#define SOC_UART_HP_NUM SOC_UART_NUM
#endif
#if SOC_UART_HP_NUM < 3
#define Serial2 Serial1
#endif

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

Mycila::JSY jsy;
Expand Down
7 changes: 7 additions & 0 deletions examples/SetSpeed2/SetSpeed2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
#include <ArduinoJson.h>
#include <MycilaJSY.h>

#ifndef SOC_UART_HP_NUM
#define SOC_UART_HP_NUM SOC_UART_NUM
#endif
#if SOC_UART_HP_NUM < 3
#define Serial2 Serial1
#endif

Mycila::JSY jsy;

void setup() {
Expand Down
2 changes: 1 addition & 1 deletion src/MycilaJSY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ Mycila::JSY::ReadResult Mycila::JSY::_timedRead(uint8_t* buffer, const size_t ex

size_t count = 0;
while (count < expectedLength) {
size_t read = Serial2.readBytes(buffer + count, expectedLength - count);
size_t read = _serial->readBytes(buffer + count, expectedLength - count);
if (read) {
count += read;
} else {
Expand Down

0 comments on commit e78dde8

Please sign in to comment.