mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-09-12 17:45:49 +00:00
* [addLib] Added SoftwareSerial library Added latest version from: https://github.com/plerup/espsoftwareserial * [renLib] Renamed files to avoid conflicts with existing code * [renLib] Changed include according to rename * [renLib] Renamed all occurences and includes and removed unused pins Renamed to make sure all plugins use the 'new' ESPeasySoftwareSerial. Also added pinToIndex function to reduce memory footprint with about 150 Bytes, as described in issue #630 * [unused pins] Adjust indices in object list Forgot to change the indices in the object list of SoftwareSerial * Simple patch for timeouts As mentioned in this issue: https://github.com/plerup/espsoftwareserial/issues/54 * [SoftSerial] Set ObjList static Set the object list static to share all SoftwareSerial iRAM used as described in #630 * [revertLib] Revert to old version lib, since new version uses more iram Just to test with old version, originally available in 2.3.0 library, to see if memory usage improves. * [test] Reduce number of ports to 1 and lower buffer size to 18 for MHZ19 Just as a test, to see what happens to the iRAM usage, lower the number of concurrent softserial ports to 1. Also the default buffer size = 64 Bytes. The MH-Z19 sensor can do with less, since a response will be up to 9 bytes, a 18-byte buffer allows for 2 messages to be stored. * Enable usage of up to 10 concurrent softserial and reduce variable sizes Re-enable use of up to 10 concurrent software serials. Also reduce the variable sizes to smaller ranges. (e.g. uint8 instead of int) * [test] Limit number of concurrent software serial devices Earlier tests show the amount of iRAM used is somewhat related to the maximum number of allowed software serial ports. In this test it is set to 3 and they are assigned through first come first served a slot.
79 lines
2.1 KiB
C++
79 lines
2.1 KiB
C++
/*
|
|
ESPeasySoftwareSerial.h
|
|
|
|
ESPeasySoftwareSerial.cpp - Implementation of the Arduino software serial for ESP8266.
|
|
Copyright (c) 2015-2016 Peter Lerup. All rights reserved.
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with this library; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
#ifndef ESPeasySoftwareSerial_h
|
|
#define ESPeasySoftwareSerial_h
|
|
|
|
#include <inttypes.h>
|
|
#include <Stream.h>
|
|
|
|
|
|
// This class is compatible with the corresponding AVR one,
|
|
// the constructor however has an optional rx buffer size.
|
|
// Speed up to 115200 can be used.
|
|
|
|
|
|
class ESPeasySoftwareSerial : public Stream
|
|
{
|
|
public:
|
|
ESPeasySoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false, uint16_t buffSize = 64);
|
|
virtual ~ESPeasySoftwareSerial();
|
|
|
|
void begin(long speed);
|
|
void setTransmitEnablePin(uint8_t transmitEnablePin);
|
|
|
|
int peek();
|
|
|
|
virtual size_t write(uint8_t byte);
|
|
virtual int read();
|
|
virtual int available();
|
|
virtual void flush();
|
|
operator bool() {return m_rxValid || m_txValid;}
|
|
|
|
// Disable or enable interrupts on the rx pin
|
|
void enableRx(bool on);
|
|
|
|
void rxRead();
|
|
|
|
using Print::write;
|
|
|
|
private:
|
|
bool isValidGPIOpin(uint8_t pin);
|
|
uint8_t pinToIndex(uint8_t pin);
|
|
|
|
// Member variables
|
|
uint8_t m_rxPin, m_txPin, m_txEnablePin;
|
|
bool m_rxValid, m_txValid, m_txEnableValid;
|
|
bool m_invert;
|
|
unsigned long m_bitTime;
|
|
uint16_t m_inPos, m_outPos;
|
|
uint16_t m_buffSize;
|
|
uint8_t *m_buffer;
|
|
|
|
};
|
|
|
|
// If only one tx or rx wanted then use this as parameter for the unused pin
|
|
#define SW_SERIAL_UNUSED_PIN -1
|
|
|
|
|
|
#endif
|