using the externals for USBSerial and Serial1
This commit is contained in:
parent
ac91aeb491
commit
dc2f353893
|
@ -63,8 +63,8 @@ void GwChannelList::begin(bool fallbackSerial){
|
|||
GwChannel *channel=NULL;
|
||||
//usb
|
||||
if (! fallbackSerial){
|
||||
GwSerial *usb=new GwSerial(NULL,0,USB_CHANNEL_ID);
|
||||
usb->setup(config->getInt(config->usbBaud),3,1);
|
||||
GwSerial *usb=new GwSerial(NULL,&USBSerial,USB_CHANNEL_ID);
|
||||
USBSerial.begin(config->getInt(config->usbBaud));
|
||||
logger->setWriter(new GwSerialLog(usb,config->getBool(config->usbActisense)));
|
||||
logger->prefix="GWSERIAL:";
|
||||
channel=new GwChannel(logger,"USB",USB_CHANNEL_ID);
|
||||
|
@ -133,9 +133,9 @@ void GwChannelList::begin(bool fallbackSerial){
|
|||
);
|
||||
if (serialtx != -1 || serialrx != -1 ){
|
||||
LOG_DEBUG(GwLog::LOG,"creating serial interface rx=%d, tx=%d",serialrx,serialtx);
|
||||
GwSerial *serial=new GwSerial(logger,1,SERIAL1_CHANNEL_ID,serCanRead);
|
||||
int rt=serial->setup(config->getInt(config->serialBaud,115200),serialrx,serialtx);
|
||||
LOG_DEBUG(GwLog::LOG,"starting serial returns %d",rt);
|
||||
Serial1.begin(config->getInt(config->serialBaud,115200),SERIAL_8N1,serialrx,serialtx);
|
||||
GwSerial *serial=new GwSerial(logger,&Serial1,SERIAL1_CHANNEL_ID,serCanRead);
|
||||
LOG_DEBUG(GwLog::LOG,"starting serial1 ");
|
||||
channel=new GwChannel(logger,"SER",SERIAL1_CHANNEL_ID);
|
||||
channel->setImpl(serial);
|
||||
channel->begin(
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
*/
|
||||
#ifndef _GWHARDWARE_H
|
||||
#define _GWHARDWARE_H
|
||||
#include <HardwareSerial.h>
|
||||
#include "GwUserTasks.h"
|
||||
|
||||
//general definitions for M5AtomLite
|
||||
|
@ -30,6 +31,7 @@
|
|||
#define GWBUTTON_PULLUPDOWN
|
||||
#define BOARD_LEFT1 GPIO_NUM_22
|
||||
#define BOARD_LEFT2 GPIO_NUM_19
|
||||
#define USBSerial Serial
|
||||
#endif
|
||||
//general definitiones for M5AtomS3
|
||||
#ifdef PLATFORM_BOARD_M5STACK_ATOMS3
|
||||
|
@ -52,6 +54,12 @@
|
|||
#ifdef PLATFORM_BOARD_M5STICK_C
|
||||
#define GROOVE_PIN_1 GPIO_NUM_32
|
||||
#define GROOVE_PIN_2 GPIO_NUM_31
|
||||
#define USBSerial Serial
|
||||
#endif
|
||||
|
||||
//NodeMCU 32 S
|
||||
#ifdef PLATFORM_BOARD_NODEMCU_32S
|
||||
#define USBSerial Serial
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_M5ATOM
|
||||
|
@ -157,4 +165,5 @@
|
|||
#define ESP32_CAN_RX_PIN GROOVE_PIN_2
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,12 +40,11 @@ class GwSerialStream: public Stream{
|
|||
|
||||
|
||||
|
||||
GwSerial::GwSerial(GwLog *logger, int num, int id,bool allowRead)
|
||||
GwSerial::GwSerial(GwLog *logger, Stream *s, int id,bool allowRead):serial(s)
|
||||
{
|
||||
LOG_DEBUG(GwLog::DEBUG,"creating GwSerial %p port %d for %d",this,(int)num,id);
|
||||
LOG_DEBUG(GwLog::DEBUG,"creating GwSerial %p id %d",this,id);
|
||||
this->id=id;
|
||||
this->logger = logger;
|
||||
this->num = num;
|
||||
String bufName="Ser(";
|
||||
bufName+=String(id);
|
||||
bufName+=")";
|
||||
|
@ -54,21 +53,15 @@ GwSerial::GwSerial(GwLog *logger, int num, int id,bool allowRead)
|
|||
if (allowRead){
|
||||
this->readBuffer=new GwBuffer(logger, GwBuffer::RX_BUFFER_SIZE,bufName+"rd");
|
||||
}
|
||||
this->serial=new HardwareSerial(num);
|
||||
buffer->reset("init");
|
||||
initialized=true;
|
||||
}
|
||||
GwSerial::~GwSerial()
|
||||
{
|
||||
delete buffer;
|
||||
if (readBuffer) delete readBuffer;
|
||||
delete serial;
|
||||
}
|
||||
int GwSerial::setup(int baud, int rxpin, int txpin)
|
||||
{
|
||||
serial->begin(baud,SERIAL_8N1,rxpin,txpin);
|
||||
buffer->reset(F("init"));
|
||||
initialized = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool GwSerial::isInitialized() { return initialized; }
|
||||
size_t GwSerial::enqueue(const uint8_t *data, size_t len, bool partial)
|
||||
{
|
||||
|
|
|
@ -10,19 +10,17 @@ class GwSerial : public GwChannelInterface{
|
|||
GwBuffer *buffer;
|
||||
GwBuffer *readBuffer=NULL;
|
||||
GwLog *logger;
|
||||
int num;
|
||||
bool initialized=false;
|
||||
bool allowRead=true;
|
||||
GwBuffer::WriteStatus write();
|
||||
int id=-1;
|
||||
int overflows=0;
|
||||
size_t enqueue(const uint8_t *data, size_t len,bool partial=false);
|
||||
HardwareSerial *serial;
|
||||
Stream *serial;
|
||||
public:
|
||||
static const int bufferSize=200;
|
||||
GwSerial(GwLog *logger,int num,int id,bool allowRead=true);
|
||||
GwSerial(GwLog *logger,Stream *stream,int id,bool allowRead=true);
|
||||
~GwSerial();
|
||||
int setup(int baud,int rxpin,int txpin);
|
||||
bool isInitialized();
|
||||
virtual size_t sendToClients(const char *buf,int sourceId,bool partial=false);
|
||||
virtual void loop(bool handleRead=true,bool handleWrite=true);
|
||||
|
|
Loading…
Reference in New Issue