mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
use Eclipse auto Format to get rip auf the tab, space and code style inconsistency
This commit is contained in:
parent
78ee754677
commit
f165a0afcd
@ -15,7 +15,7 @@
|
||||
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 Arduino_h
|
||||
#define Arduino_h
|
||||
@ -30,7 +30,7 @@
|
||||
#include "pgmspace.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void yield(void);
|
||||
@ -144,7 +144,6 @@ volatile uint32_t* portOutputRegister(uint32_t port);
|
||||
volatile uint32_t* portInputRegister(uint32_t port);
|
||||
volatile uint32_t* portModeRegister(uint32_t port);
|
||||
|
||||
|
||||
#define NOT_A_PIN 0
|
||||
#define NOT_A_PORT 0
|
||||
#define NOT_AN_INTERRUPT -1
|
||||
|
@ -15,7 +15,7 @@
|
||||
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 client_h
|
||||
#define client_h
|
||||
@ -23,9 +23,9 @@
|
||||
#include "Stream.h"
|
||||
#include "IPAddress.h"
|
||||
|
||||
class Client : public Stream {
|
||||
class Client: public Stream {
|
||||
|
||||
public:
|
||||
public:
|
||||
virtual int connect(IPAddress ip, uint16_t port) =0;
|
||||
virtual int connect(const char *host, uint16_t port) =0;
|
||||
virtual size_t write(uint8_t) =0;
|
||||
@ -38,8 +38,11 @@ public:
|
||||
virtual void stop() = 0;
|
||||
virtual uint8_t connected() = 0;
|
||||
virtual operator bool() = 0;
|
||||
protected:
|
||||
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
|
||||
protected:
|
||||
uint8_t* rawIPAddress(IPAddress& addr) {
|
||||
return addr.raw_address();
|
||||
}
|
||||
;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -61,11 +61,9 @@ extern "C" {
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// ####################################################################################################
|
||||
// ####################################################################################################
|
||||
// ####################################################################################################
|
||||
|
||||
HardwareSerial Serial(UART0);
|
||||
HardwareSerial Serial1(UART1);
|
||||
|
||||
@ -111,7 +109,8 @@ void ICACHE_FLASH_ATTR uart_interrupt_handler(uart_t* uart) {
|
||||
if(status & UART_RXFIFO_FULL_INT_ST) {
|
||||
while(true) {
|
||||
int rx_count = (READ_PERI_REG(UART_STATUS(0)) >> UART_RXFIFO_CNT_S) & UART_RXFIFO_CNT;
|
||||
if(!rx_count) break;
|
||||
if(!rx_count)
|
||||
break;
|
||||
|
||||
while(rx_count--) {
|
||||
char c = READ_PERI_REG(UART_FIFO(0)) & 0xFF;
|
||||
@ -135,7 +134,8 @@ void ICACHE_FLASH_ATTR uart_interrupt_handler(uart_t* uart) {
|
||||
if(status & UART_RXFIFO_FULL_INT_ST) {
|
||||
while(true) {
|
||||
int rx_count = (READ_PERI_REG(UART_STATUS(1)) >> UART_RXFIFO_CNT_S) & UART_RXFIFO_CNT;
|
||||
if(!rx_count) break;
|
||||
if(!rx_count)
|
||||
break;
|
||||
|
||||
while(rx_count--) {
|
||||
char c = READ_PERI_REG(UART_FIFO(1)) & 0xFF;
|
||||
@ -160,7 +160,8 @@ void ICACHE_FLASH_ATTR uart_wait_for_tx_fifo(uart_t* uart, size_t size_needed) {
|
||||
if(uart->txEnabled) {
|
||||
while(true) {
|
||||
size_t tx_count = (READ_PERI_REG(UART_STATUS(uart->uart_nr)) >> UART_TXFIFO_CNT_S) & UART_TXFIFO_CNT;
|
||||
if(tx_count <= (UART_TX_FIFO_SIZE - size_needed)) break;
|
||||
if(tx_count <= (UART_TX_FIFO_SIZE - size_needed))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -327,9 +328,8 @@ void ICACHE_FLASH_ATTR uart_uninit(uart_t* uart) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
pinMode(uart->rxPin , INPUT);
|
||||
pinMode(uart->txPin , INPUT);
|
||||
pinMode(uart->rxPin, INPUT);
|
||||
pinMode(uart->txPin, INPUT);
|
||||
|
||||
os_free(uart);
|
||||
}
|
||||
@ -351,7 +351,6 @@ void ICACHE_FLASH_ATTR uart_swap(uart_t* uart) {
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_GPIO3);
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_GPIO1);
|
||||
|
||||
|
||||
pinMode(uart->rxPin, INPUT);
|
||||
pinMode(uart->txPin, INPUT);
|
||||
|
||||
@ -370,7 +369,6 @@ void ICACHE_FLASH_ATTR uart_swap(uart_t* uart) {
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13);
|
||||
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_GPIO15);
|
||||
|
||||
|
||||
pinMode(uart->rxPin, INPUT);
|
||||
pinMode(uart->txPin, INPUT);
|
||||
uart->rxPin = 3;
|
||||
@ -498,12 +496,14 @@ void ICACHE_FLASH_ATTR HardwareSerial::setDebugOutput(bool en) {
|
||||
}
|
||||
|
||||
bool ICACHE_FLASH_ATTR HardwareSerial::isTxEnabled(void) {
|
||||
if(_uart == 0) return false;
|
||||
if(_uart == 0)
|
||||
return false;
|
||||
return _uart->txEnabled;
|
||||
}
|
||||
|
||||
bool ICACHE_FLASH_ATTR HardwareSerial::isRxEnabled(void) {
|
||||
if(_uart == 0) return false;
|
||||
if(_uart == 0)
|
||||
return false;
|
||||
return _uart->rxEnabled;
|
||||
}
|
||||
|
||||
@ -540,8 +540,10 @@ int ICACHE_FLASH_ATTR HardwareSerial::availableForWrite(void) {
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR HardwareSerial::flush() {
|
||||
if(!_uart->txEnabled) return;
|
||||
if(!_written) return;
|
||||
if(!_uart->txEnabled)
|
||||
return;
|
||||
if(!_written)
|
||||
return;
|
||||
|
||||
while(_tx_buffer->getSize() || uart_get_tx_fifo_room(_uart) < UART_TX_FIFO_SIZE)
|
||||
yield();
|
||||
@ -550,7 +552,8 @@ void ICACHE_FLASH_ATTR HardwareSerial::flush() {
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR HardwareSerial::write(uint8_t c) {
|
||||
if(!_uart->txEnabled) return 0;
|
||||
if(!_uart->txEnabled)
|
||||
return 0;
|
||||
_written = true;
|
||||
size_t room = uart_get_tx_fifo_room(_uart);
|
||||
if(room > 0 && _tx_buffer->empty()) {
|
||||
|
@ -62,9 +62,7 @@
|
||||
class cbuf;
|
||||
|
||||
typedef enum {
|
||||
UART0 = 0,
|
||||
UART1 = 1,
|
||||
UART_NO = 0xFF
|
||||
UART0 = 0, UART1 = 1, UART_NO = 0xFF
|
||||
} UARTnr_t;
|
||||
|
||||
typedef struct {
|
||||
|
@ -15,57 +15,48 @@
|
||||
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
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <IPAddress.h>
|
||||
#include <Print.h>
|
||||
|
||||
IPAddress::IPAddress()
|
||||
{
|
||||
IPAddress::IPAddress() {
|
||||
_address.dword = 0;
|
||||
}
|
||||
|
||||
IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet)
|
||||
{
|
||||
IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) {
|
||||
_address.bytes[0] = first_octet;
|
||||
_address.bytes[1] = second_octet;
|
||||
_address.bytes[2] = third_octet;
|
||||
_address.bytes[3] = fourth_octet;
|
||||
}
|
||||
|
||||
IPAddress::IPAddress(uint32_t address)
|
||||
{
|
||||
IPAddress::IPAddress(uint32_t address) {
|
||||
_address.dword = address;
|
||||
}
|
||||
|
||||
IPAddress::IPAddress(const uint8_t *address)
|
||||
{
|
||||
IPAddress::IPAddress(const uint8_t *address) {
|
||||
memcpy(_address.bytes, address, sizeof(_address.bytes));
|
||||
}
|
||||
|
||||
IPAddress& IPAddress::operator=(const uint8_t *address)
|
||||
{
|
||||
IPAddress& IPAddress::operator=(const uint8_t *address) {
|
||||
memcpy(_address.bytes, address, sizeof(_address.bytes));
|
||||
return *this;
|
||||
}
|
||||
|
||||
IPAddress& IPAddress::operator=(uint32_t address)
|
||||
{
|
||||
IPAddress& IPAddress::operator=(uint32_t address) {
|
||||
_address.dword = address;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool IPAddress::operator==(const uint8_t* addr) const
|
||||
{
|
||||
bool IPAddress::operator==(const uint8_t* addr) const {
|
||||
return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0;
|
||||
}
|
||||
|
||||
size_t IPAddress::printTo(Print& p) const
|
||||
{
|
||||
size_t IPAddress::printTo(Print& p) const {
|
||||
size_t n = 0;
|
||||
for (int i =0; i < 3; i++)
|
||||
{
|
||||
for(int i = 0; i < 3; i++) {
|
||||
n += p.print(_address.bytes[i], DEC);
|
||||
n += p.print('.');
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
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 IPAddress_h
|
||||
#define IPAddress_h
|
||||
@ -25,8 +25,8 @@
|
||||
|
||||
// A class to make it easier to handle and pass around IP addresses
|
||||
|
||||
class IPAddress : public Printable {
|
||||
private:
|
||||
class IPAddress: public Printable {
|
||||
private:
|
||||
union {
|
||||
uint8_t bytes[4]; // IPv4 address
|
||||
uint32_t dword;
|
||||
@ -36,9 +36,11 @@ private:
|
||||
// to the internal structure rather than a copy of the address this function should only
|
||||
// be used when you know that the usage of the returned uint8_t* will be transient and not
|
||||
// stored.
|
||||
uint8_t* raw_address() { return _address.bytes; };
|
||||
uint8_t* raw_address() {
|
||||
return _address.bytes;
|
||||
}
|
||||
|
||||
public:
|
||||
public:
|
||||
// Constructors
|
||||
IPAddress();
|
||||
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
|
||||
@ -47,13 +49,21 @@ public:
|
||||
|
||||
// Overloaded cast operator to allow IPAddress objects to be used where a pointer
|
||||
// to a four-byte uint8_t array is expected
|
||||
operator uint32_t() const { return _address.dword; };
|
||||
bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; };
|
||||
operator uint32_t() const {
|
||||
return _address.dword;
|
||||
}
|
||||
bool operator==(const IPAddress& addr) const {
|
||||
return _address.dword == addr._address.dword;
|
||||
}
|
||||
bool operator==(const uint8_t* addr) const;
|
||||
|
||||
// Overloaded index operator to allow getting and setting individual octets of the address
|
||||
uint8_t operator[](int index) const { return _address.bytes[index]; };
|
||||
uint8_t& operator[](int index) { return _address.bytes[index]; };
|
||||
uint8_t operator[](int index) const {
|
||||
return _address.bytes[index];
|
||||
}
|
||||
uint8_t& operator[](int index) {
|
||||
return _address.bytes[index];
|
||||
}
|
||||
|
||||
// Overloaded copy operators to allow initialisation of IPAddress objects from other types
|
||||
IPAddress& operator=(const uint8_t *address);
|
||||
@ -69,7 +79,6 @@ public:
|
||||
friend class DNSClient;
|
||||
};
|
||||
|
||||
const IPAddress INADDR_NONE(0,0,0,0);
|
||||
|
||||
const IPAddress INADDR_NONE(0, 0, 0, 0);
|
||||
|
||||
#endif
|
||||
|
@ -34,51 +34,43 @@ extern "C" {
|
||||
// Public Methods //////////////////////////////////////////////////////////////
|
||||
|
||||
/* default implementation: may be overridden */
|
||||
size_t ICACHE_FLASH_ATTR Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::write(const uint8_t *buffer, size_t size) {
|
||||
size_t n = 0;
|
||||
while (size--) {
|
||||
while(size--) {
|
||||
n += write(*buffer++);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::print(const String &s)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::print(const String &s) {
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::print(const char str[])
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::print(const char str[]) {
|
||||
return write(str);
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::print(char c)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::print(char c) {
|
||||
return write(c);
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::print(unsigned char b, int base)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::print(unsigned char b, int base) {
|
||||
return print((unsigned long) b, base);
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::print(int n, int base)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::print(int n, int base) {
|
||||
return print((long) n, base);
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::print(unsigned int n, int base)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::print(unsigned int n, int base) {
|
||||
return print((unsigned long) n, base);
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0) {
|
||||
size_t ICACHE_FLASH_ATTR Print::print(long n, int base) {
|
||||
if(base == 0) {
|
||||
return write(n);
|
||||
} else if (base == 10) {
|
||||
if (n < 0) {
|
||||
} else if(base == 10) {
|
||||
if(n < 0) {
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
@ -89,93 +81,81 @@ size_t ICACHE_FLASH_ATTR Print::print(long n, int base)
|
||||
}
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0) return write(n);
|
||||
else return printNumber(n, base);
|
||||
size_t ICACHE_FLASH_ATTR Print::print(unsigned long n, int base) {
|
||||
if(base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::print(double n, int digits)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::print(double n, int digits) {
|
||||
return printFloat(n, digits);
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::print(const Printable& x)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::print(const Printable& x) {
|
||||
return x.printTo(*this);
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::println(void)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::println(void) {
|
||||
size_t n = print("\r\n");
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::println(const String &s)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::println(const String &s) {
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::println(const char c[])
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::println(const char c[]) {
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::println(char c)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::println(char c) {
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::println(unsigned char b, int base)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::println(unsigned char b, int base) {
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::println(int num, int base)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::println(int num, int base) {
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::println(unsigned int num, int base)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::println(unsigned int num, int base) {
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::println(long num, int base)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::println(long num, int base) {
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::println(unsigned long num, int base)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::println(unsigned long num, int base) {
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::println(double num, int digits)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::println(double num, int digits) {
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::println(const Printable& x)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::println(const Printable& x) {
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
@ -190,7 +170,8 @@ size_t ICACHE_FLASH_ATTR Print::printNumber(unsigned long n, uint8_t base) {
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2) base = 10;
|
||||
if(base < 2)
|
||||
base = 10;
|
||||
|
||||
do {
|
||||
unsigned long m = n;
|
||||
@ -202,42 +183,43 @@ size_t ICACHE_FLASH_ATTR Print::printNumber(unsigned long n, uint8_t base) {
|
||||
return write(str);
|
||||
}
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Print::printFloat(double number, uint8_t digits)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Print::printFloat(double number, uint8_t digits) {
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number)) return print("nan");
|
||||
if (isinf(number)) return print("inf");
|
||||
if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
if(isnan(number))
|
||||
return print("nan");
|
||||
if(isinf(number))
|
||||
return print("inf");
|
||||
if(number > 4294967040.0)
|
||||
return print("ovf"); // constant determined empirically
|
||||
if(number < -4294967040.0)
|
||||
return print("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
if(number < 0.0) {
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
for (uint8_t i=0; i<digits; ++i)
|
||||
for(uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
unsigned long int_part = (unsigned long) number;
|
||||
double remainder = number - (double) int_part;
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0) {
|
||||
if(digits > 0) {
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
while(digits-- > 0) {
|
||||
remainder *= 10.0;
|
||||
int toPrint = int(remainder);
|
||||
n += print(toPrint);
|
||||
|
@ -15,7 +15,7 @@
|
||||
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 Print_h
|
||||
#define Print_h
|
||||
@ -31,28 +31,36 @@
|
||||
#define OCT 8
|
||||
#define BIN 2
|
||||
|
||||
class Print
|
||||
{
|
||||
class Print {
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printFloat(double, uint8_t);
|
||||
protected:
|
||||
void setWriteError(int err = 1) { write_error = err; }
|
||||
void setWriteError(int err = 1) {
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
Print() :
|
||||
write_error(0) {
|
||||
}
|
||||
|
||||
int getWriteError() { return write_error; }
|
||||
void clearWriteError() { setWriteError(0); }
|
||||
int getWriteError() {
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError() {
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str) {
|
||||
if (str == NULL) return 0;
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
if(str == NULL)
|
||||
return 0;
|
||||
return write((const uint8_t *) str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
return write((const uint8_t *)buffer, size);
|
||||
return write((const uint8_t *) buffer, size);
|
||||
}
|
||||
|
||||
size_t print(const String &);
|
||||
|
@ -15,7 +15,7 @@
|
||||
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 Printable_h
|
||||
#define Printable_h
|
||||
@ -28,10 +28,9 @@ class Print;
|
||||
By deriving from Printable and implementing the printTo method, it will then be possible
|
||||
for users to print out instances of this class by passing them into the usual
|
||||
Print::print and Print::println methods.
|
||||
*/
|
||||
*/
|
||||
|
||||
class Printable
|
||||
{
|
||||
class Printable {
|
||||
public:
|
||||
virtual size_t printTo(Print& p) const = 0;
|
||||
};
|
||||
|
@ -15,15 +15,15 @@
|
||||
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 server_h
|
||||
#define server_h
|
||||
|
||||
#include "Print.h"
|
||||
|
||||
class Server : public Print {
|
||||
public:
|
||||
class Server: public Print {
|
||||
public:
|
||||
virtual void begin() =0;
|
||||
};
|
||||
|
||||
|
@ -22,33 +22,33 @@
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Stream.h"
|
||||
extern "C"{
|
||||
#include "c_types.h"
|
||||
extern "C" {
|
||||
#include "c_types.h"
|
||||
}
|
||||
#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait
|
||||
#define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field
|
||||
|
||||
// private method to read stream with timeout
|
||||
int ICACHE_FLASH_ATTR Stream::timedRead()
|
||||
{
|
||||
int ICACHE_FLASH_ATTR Stream::timedRead() {
|
||||
int c;
|
||||
_startMillis = millis();
|
||||
do {
|
||||
c = read();
|
||||
if (c >= 0) return c;
|
||||
if(c >= 0)
|
||||
return c;
|
||||
yield();
|
||||
} while(millis() - _startMillis < _timeout);
|
||||
return -1; // -1 indicates timeout
|
||||
}
|
||||
|
||||
// private method to peek stream with timeout
|
||||
int ICACHE_FLASH_ATTR Stream::timedPeek()
|
||||
{
|
||||
int ICACHE_FLASH_ATTR Stream::timedPeek() {
|
||||
int c;
|
||||
_startMillis = millis();
|
||||
do {
|
||||
c = peek();
|
||||
if (c >= 0) return c;
|
||||
if(c >= 0)
|
||||
return c;
|
||||
yield();
|
||||
} while(millis() - _startMillis < _timeout);
|
||||
return -1; // -1 indicates timeout
|
||||
@ -56,14 +56,16 @@ int ICACHE_FLASH_ATTR Stream::timedPeek()
|
||||
|
||||
// returns peek of the next digit in the stream or -1 if timeout
|
||||
// discards non-numeric characters
|
||||
int ICACHE_FLASH_ATTR Stream::peekNextDigit()
|
||||
{
|
||||
int ICACHE_FLASH_ATTR Stream::peekNextDigit() {
|
||||
int c;
|
||||
while (1) {
|
||||
while(1) {
|
||||
c = timedPeek();
|
||||
if (c < 0) return c; // timeout
|
||||
if (c == '-') return c;
|
||||
if (c >= '0' && c <= '9') return c;
|
||||
if(c < 0)
|
||||
return c; // timeout
|
||||
if(c == '-')
|
||||
return c;
|
||||
if(c >= '0' && c <= '9')
|
||||
return c;
|
||||
read(); // discard non-numeric
|
||||
}
|
||||
}
|
||||
@ -76,71 +78,63 @@ void ICACHE_FLASH_ATTR Stream::setTimeout(unsigned long timeout) // sets the ma
|
||||
_timeout = timeout;
|
||||
}
|
||||
|
||||
// find returns true if the target string is found
|
||||
bool ICACHE_FLASH_ATTR Stream::find(const char *target)
|
||||
{
|
||||
return findUntil(target, (char*)"");
|
||||
// find returns true if the target string is found
|
||||
bool ICACHE_FLASH_ATTR Stream::find(const char *target) {
|
||||
return findUntil(target, (char*) "");
|
||||
}
|
||||
|
||||
// reads data from the stream until the target string of given length is found
|
||||
// returns true if target string is found, false if timed out
|
||||
bool ICACHE_FLASH_ATTR Stream::find(const char *target, size_t length)
|
||||
{
|
||||
bool ICACHE_FLASH_ATTR Stream::find(const char *target, size_t length) {
|
||||
return findUntil(target, length, NULL, 0);
|
||||
}
|
||||
|
||||
// as find but search ends if the terminator string is found
|
||||
bool ICACHE_FLASH_ATTR Stream::findUntil(const char *target, const char *terminator)
|
||||
{
|
||||
bool ICACHE_FLASH_ATTR Stream::findUntil(const char *target, const char *terminator) {
|
||||
return findUntil(target, strlen(target), terminator, strlen(terminator));
|
||||
}
|
||||
|
||||
// reads data from the stream until the target string of the given length is found
|
||||
// search terminated if the terminator string is found
|
||||
// returns true if target string is found, false if terminated or timed out
|
||||
bool ICACHE_FLASH_ATTR Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen)
|
||||
{
|
||||
bool ICACHE_FLASH_ATTR Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen) {
|
||||
size_t index = 0; // maximum target string length is 64k bytes!
|
||||
size_t termIndex = 0;
|
||||
int c;
|
||||
|
||||
if( *target == 0)
|
||||
if(*target == 0)
|
||||
return true; // return true if target is a null string
|
||||
while( (c = timedRead()) > 0){
|
||||
while((c = timedRead()) > 0) {
|
||||
|
||||
if(c != target[index])
|
||||
index = 0; // reset index if any char does not match
|
||||
|
||||
if( c == target[index]){
|
||||
if(c == target[index]) {
|
||||
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
|
||||
if(++index >= targetLen){ // return true if all chars in the target match
|
||||
if(++index >= targetLen) { // return true if all chars in the target match
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(termLen > 0 && c == terminator[termIndex]){
|
||||
if(termLen > 0 && c == terminator[termIndex]) {
|
||||
if(++termIndex >= termLen)
|
||||
return false; // return false if terminate string found before target string
|
||||
}
|
||||
else
|
||||
} else
|
||||
termIndex = 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// returns the first valid (long) integer value from the current position.
|
||||
// initial characters that are not digits (or the minus sign) are skipped
|
||||
// function is terminated by the first character that is not a digit.
|
||||
long ICACHE_FLASH_ATTR Stream::parseInt()
|
||||
{
|
||||
long ICACHE_FLASH_ATTR Stream::parseInt() {
|
||||
return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
|
||||
}
|
||||
|
||||
// as above but a given skipChar is ignored
|
||||
// this allows format characters (typically commas) in values to be ignored
|
||||
long ICACHE_FLASH_ATTR Stream::parseInt(char skipChar)
|
||||
{
|
||||
long ICACHE_FLASH_ATTR Stream::parseInt(char skipChar) {
|
||||
boolean isNegative = false;
|
||||
long value = 0;
|
||||
int c;
|
||||
@ -150,7 +144,7 @@ long ICACHE_FLASH_ATTR Stream::parseInt(char skipChar)
|
||||
if(c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
|
||||
do{
|
||||
do {
|
||||
if(c == skipChar)
|
||||
; // ignore this charactor
|
||||
else if(c == '-')
|
||||
@ -159,24 +153,21 @@ long ICACHE_FLASH_ATTR Stream::parseInt(char skipChar)
|
||||
value = value * 10 + c - '0';
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
}
|
||||
while( (c >= '0' && c <= '9') || c == skipChar );
|
||||
} while((c >= '0' && c <= '9') || c == skipChar);
|
||||
|
||||
if(isNegative)
|
||||
value = -value;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
// as parseInt but returns a floating point value
|
||||
float ICACHE_FLASH_ATTR Stream::parseFloat()
|
||||
{
|
||||
float ICACHE_FLASH_ATTR Stream::parseFloat() {
|
||||
return parseFloat(NO_SKIP_CHAR);
|
||||
}
|
||||
|
||||
// as above but the given skipChar is ignored
|
||||
// this allows format characters (typically commas) in values to be ignored
|
||||
float ICACHE_FLASH_ATTR Stream::parseFloat(char skipChar){
|
||||
float ICACHE_FLASH_ATTR Stream::parseFloat(char skipChar) {
|
||||
boolean isNegative = false;
|
||||
boolean isFraction = false;
|
||||
long value = 0;
|
||||
@ -188,12 +179,12 @@ float ICACHE_FLASH_ATTR Stream::parseFloat(char skipChar){
|
||||
if(c < 0)
|
||||
return 0; // zero returned if timeout
|
||||
|
||||
do{
|
||||
do {
|
||||
if(c == skipChar)
|
||||
; // ignore
|
||||
else if(c == '-')
|
||||
isNegative = true;
|
||||
else if (c == '.')
|
||||
else if(c == '.')
|
||||
isFraction = true;
|
||||
else if(c >= '0' && c <= '9') { // is c a digit?
|
||||
value = value * 10 + c - '0';
|
||||
@ -202,8 +193,7 @@ float ICACHE_FLASH_ATTR Stream::parseFloat(char skipChar){
|
||||
}
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
}
|
||||
while( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||
} while((c >= '0' && c <= '9') || c == '.' || c == skipChar);
|
||||
|
||||
if(isNegative)
|
||||
value = -value;
|
||||
@ -218,55 +208,51 @@ float ICACHE_FLASH_ATTR Stream::parseFloat(char skipChar){
|
||||
// returns the number of characters placed in the buffer
|
||||
// the buffer is NOT null terminated.
|
||||
//
|
||||
size_t ICACHE_FLASH_ATTR Stream::readBytes(char *buffer, size_t length)
|
||||
{
|
||||
size_t ICACHE_FLASH_ATTR Stream::readBytes(char *buffer, size_t length) {
|
||||
size_t count = 0;
|
||||
while (count < length) {
|
||||
while(count < length) {
|
||||
int c = timedRead();
|
||||
if (c < 0) break;
|
||||
*buffer++ = (char)c;
|
||||
if(c < 0)
|
||||
break;
|
||||
*buffer++ = (char) c;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
// as readBytes with terminator character
|
||||
// terminates if length characters have been read, timeout, or if the terminator character detected
|
||||
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||
|
||||
size_t ICACHE_FLASH_ATTR Stream::readBytesUntil(char terminator, char *buffer, size_t length)
|
||||
{
|
||||
if (length < 1) return 0;
|
||||
size_t ICACHE_FLASH_ATTR Stream::readBytesUntil(char terminator, char *buffer, size_t length) {
|
||||
if(length < 1)
|
||||
return 0;
|
||||
size_t index = 0;
|
||||
while (index < length) {
|
||||
while(index < length) {
|
||||
int c = timedRead();
|
||||
if (c < 0 || c == terminator) break;
|
||||
*buffer++ = (char)c;
|
||||
if(c < 0 || c == terminator)
|
||||
break;
|
||||
*buffer++ = (char) c;
|
||||
index++;
|
||||
}
|
||||
return index; // return number of characters, not including null terminator
|
||||
}
|
||||
|
||||
String ICACHE_FLASH_ATTR Stream::readString()
|
||||
{
|
||||
String ICACHE_FLASH_ATTR Stream::readString() {
|
||||
String ret;
|
||||
int c = timedRead();
|
||||
while (c >= 0)
|
||||
{
|
||||
ret += (char)c;
|
||||
while(c >= 0) {
|
||||
ret += (char) c;
|
||||
c = timedRead();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
String ICACHE_FLASH_ATTR Stream::readStringUntil(char terminator)
|
||||
{
|
||||
String ICACHE_FLASH_ATTR Stream::readStringUntil(char terminator) {
|
||||
String ret;
|
||||
int c = timedRead();
|
||||
while (c >= 0 && c != terminator)
|
||||
{
|
||||
ret += (char)c;
|
||||
while(c >= 0 && c != terminator) {
|
||||
ret += (char) c;
|
||||
c = timedRead();
|
||||
}
|
||||
return ret;
|
||||
|
@ -17,7 +17,7 @@
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
parsing functions based on TextFinder library by Michael Margolis
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef Stream_h
|
||||
#define Stream_h
|
||||
@ -27,16 +27,15 @@
|
||||
|
||||
// compatability macros for testing
|
||||
/*
|
||||
#define getInt() parseInt()
|
||||
#define getInt(skipChar) parseInt(skipchar)
|
||||
#define getFloat() parseFloat()
|
||||
#define getFloat(skipChar) parseFloat(skipChar)
|
||||
#define getString( pre_string, post_string, buffer, length)
|
||||
readBytesBetween( pre_string, terminator, buffer, length)
|
||||
*/
|
||||
#define getInt() parseInt()
|
||||
#define getInt(skipChar) parseInt(skipchar)
|
||||
#define getFloat() parseFloat()
|
||||
#define getFloat(skipChar) parseFloat(skipChar)
|
||||
#define getString( pre_string, post_string, buffer, length)
|
||||
readBytesBetween( pre_string, terminator, buffer, length)
|
||||
*/
|
||||
|
||||
class Stream : public Print
|
||||
{
|
||||
class Stream: public Print {
|
||||
protected:
|
||||
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
|
||||
unsigned long _startMillis; // used for timeout measurement
|
||||
@ -50,26 +49,35 @@ class Stream : public Print
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0;
|
||||
|
||||
Stream() {_timeout=1000;}
|
||||
Stream() {
|
||||
_timeout = 1000;
|
||||
}
|
||||
|
||||
// parsing methods
|
||||
|
||||
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
||||
|
||||
bool find(const char *target); // reads data from the stream until the target string is found
|
||||
bool find(uint8_t *target) { return find ((char *)target); }
|
||||
bool find(uint8_t *target) {
|
||||
return find((char *) target);
|
||||
}
|
||||
// returns true if target string is found, false if timed out (see setTimeout)
|
||||
|
||||
bool find(const char *target, size_t length); // reads data from the stream until the target string of given length is found
|
||||
bool find(const uint8_t *target, size_t length) { return find ((char *)target, length); }
|
||||
bool find(const uint8_t *target, size_t length) {
|
||||
return find((char *) target, length);
|
||||
}
|
||||
// returns true if target string is found, false if timed out
|
||||
|
||||
bool findUntil(const char *target, const char *terminator); // as find but search ends if the terminator string is found
|
||||
bool findUntil(const uint8_t *target, const char *terminator) { return findUntil((char *)target, terminator); }
|
||||
bool findUntil(const uint8_t *target, const char *terminator) {
|
||||
return findUntil((char *) target, terminator);
|
||||
}
|
||||
|
||||
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen); // as above but search ends if the terminate string is found
|
||||
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) {return findUntil((char *)target, targetLen, terminate, termLen); }
|
||||
|
||||
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) {
|
||||
return findUntil((char *) target, targetLen, terminate, termLen);
|
||||
}
|
||||
|
||||
long parseInt(); // returns the first valid (long) integer value from the current position.
|
||||
// initial characters that are not digits (or the minus sign) are skipped
|
||||
@ -77,13 +85,17 @@ class Stream : public Print
|
||||
|
||||
float parseFloat(); // float version of parseInt
|
||||
|
||||
size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
|
||||
size_t readBytes( uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
|
||||
size_t readBytes(char *buffer, size_t length); // read chars from stream into buffer
|
||||
size_t readBytes(uint8_t *buffer, size_t length) {
|
||||
return readBytes((char *) buffer, length);
|
||||
}
|
||||
// terminates if length characters have been read or timeout (see setTimeout)
|
||||
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||
|
||||
size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character
|
||||
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); }
|
||||
size_t readBytesUntil(char terminator, char *buffer, size_t length); // as readBytes with terminator character
|
||||
size_t readBytesUntil(char terminator, uint8_t *buffer, size_t length) {
|
||||
return readBytesUntil(terminator, (char *) buffer, length);
|
||||
}
|
||||
// terminates if length characters have been read, timeout, or if the terminator character detected
|
||||
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||
|
||||
|
@ -18,32 +18,32 @@
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Version Modified By Date Comments
|
||||
------- ----------- -------- --------
|
||||
0001 B Hagman 09/08/02 Initial coding
|
||||
0002 B Hagman 09/08/18 Multiple pins
|
||||
0003 B Hagman 09/08/18 Moved initialization from constructor to begin()
|
||||
0004 B Hagman 09/09/26 Fixed problems with ATmega8
|
||||
0005 B Hagman 09/11/23 Scanned prescalars for best fit on 8 bit timers
|
||||
Version Modified By Date Comments
|
||||
------- ----------- -------- --------
|
||||
0001 B Hagman 09/08/02 Initial coding
|
||||
0002 B Hagman 09/08/18 Multiple pins
|
||||
0003 B Hagman 09/08/18 Moved initialization from constructor to begin()
|
||||
0004 B Hagman 09/09/26 Fixed problems with ATmega8
|
||||
0005 B Hagman 09/11/23 Scanned prescalars for best fit on 8 bit timers
|
||||
09/11/25 Changed pin toggle method to XOR
|
||||
09/11/25 Fixed timer0 from being excluded
|
||||
0006 D Mellis 09/12/29 Replaced objects with functions
|
||||
0007 M Sproul 10/08/29 Changed #ifdefs from cpu to register
|
||||
0008 S Kanemoto 12/06/22 Fixed for Leonardo by @maris_HY
|
||||
*************************************************/
|
||||
0006 D Mellis 09/12/29 Replaced objects with functions
|
||||
0007 M Sproul 10/08/29 Changed #ifdefs from cpu to register
|
||||
0008 S Kanemoto 12/06/22 Fixed for Leonardo by @maris_HY
|
||||
*************************************************/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "pins_arduino.h"
|
||||
|
||||
|
||||
static int8_t toneBegin(uint8_t _pin)
|
||||
{
|
||||
static int8_t toneBegin(uint8_t _pin) {
|
||||
//TODO implement tone
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
|
||||
{
|
||||
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration) {
|
||||
//TODO implement tone
|
||||
}
|
||||
|
||||
void noTone(uint8_t _pin)
|
||||
{
|
||||
void noTone(uint8_t _pin) {
|
||||
//TODO implement tone
|
||||
}
|
||||
|
@ -38,9 +38,9 @@
|
||||
#include <Stream.h>
|
||||
#include <IPAddress.h>
|
||||
|
||||
class UDP : public Stream {
|
||||
class UDP: public Stream {
|
||||
|
||||
public:
|
||||
public:
|
||||
virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
|
||||
virtual void stop() =0; // Finish with the UDP socket
|
||||
|
||||
@ -81,8 +81,10 @@ public:
|
||||
virtual IPAddress remoteIP() =0;
|
||||
// Return the port of the host who sent the current incoming packet
|
||||
virtual uint16_t remotePort() =0;
|
||||
protected:
|
||||
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
|
||||
protected:
|
||||
uint8_t* rawIPAddress(IPAddress& addr) {
|
||||
return addr.raw_address();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -24,7 +24,6 @@
|
||||
#define isascii(__c) ((unsigned)(__c)<=0177)
|
||||
#define toascii(__c) ((__c)&0177)
|
||||
|
||||
|
||||
// WCharacter.h prototypes
|
||||
inline boolean isAlphaNumeric(int c) __attribute__((always_inline));
|
||||
inline boolean isAlpha(int c) __attribute__((always_inline));
|
||||
@ -41,131 +40,99 @@ inline boolean isUpperCase(int c) __attribute__((always_inline));
|
||||
inline boolean isHexadecimalDigit(int c) __attribute__((always_inline));
|
||||
inline int toAscii(int c) __attribute__((always_inline));
|
||||
inline int toLowerCase(int c) __attribute__((always_inline));
|
||||
inline int toUpperCase(int c)__attribute__((always_inline));
|
||||
|
||||
inline int toUpperCase(int c) __attribute__((always_inline));
|
||||
|
||||
// Checks for an alphanumeric character.
|
||||
// It is equivalent to (isalpha(c) || isdigit(c)).
|
||||
inline boolean isAlphaNumeric(int c)
|
||||
{
|
||||
return ( isalnum(c) == 0 ? false : true);
|
||||
inline boolean isAlphaNumeric(int c) {
|
||||
return (isalnum(c) == 0 ? false : true);
|
||||
}
|
||||
|
||||
|
||||
// Checks for an alphabetic character.
|
||||
// It is equivalent to (isupper(c) || islower(c)).
|
||||
inline boolean isAlpha(int c)
|
||||
{
|
||||
return ( isalpha(c) == 0 ? false : true);
|
||||
inline boolean isAlpha(int c) {
|
||||
return (isalpha(c) == 0 ? false : true);
|
||||
}
|
||||
|
||||
|
||||
// Checks whether c is a 7-bit unsigned char value
|
||||
// that fits into the ASCII character set.
|
||||
inline boolean isAscii(int c)
|
||||
{
|
||||
inline boolean isAscii(int c) {
|
||||
return ( isascii (c) == 0 ? false : true);
|
||||
}
|
||||
|
||||
|
||||
// Checks for a blank character, that is, a space or a tab.
|
||||
inline boolean isWhitespace(int c)
|
||||
{
|
||||
return ( isblank (c) == 0 ? false : true);
|
||||
inline boolean isWhitespace(int c) {
|
||||
return (isblank(c) == 0 ? false : true);
|
||||
}
|
||||
|
||||
|
||||
// Checks for a control character.
|
||||
inline boolean isControl(int c)
|
||||
{
|
||||
return ( iscntrl (c) == 0 ? false : true);
|
||||
inline boolean isControl(int c) {
|
||||
return (iscntrl(c) == 0 ? false : true);
|
||||
}
|
||||
|
||||
|
||||
// Checks for a digit (0 through 9).
|
||||
inline boolean isDigit(int c)
|
||||
{
|
||||
return ( isdigit (c) == 0 ? false : true);
|
||||
inline boolean isDigit(int c) {
|
||||
return (isdigit(c) == 0 ? false : true);
|
||||
}
|
||||
|
||||
|
||||
// Checks for any printable character except space.
|
||||
inline boolean isGraph(int c)
|
||||
{
|
||||
return ( isgraph (c) == 0 ? false : true);
|
||||
inline boolean isGraph(int c) {
|
||||
return (isgraph(c) == 0 ? false : true);
|
||||
}
|
||||
|
||||
|
||||
// Checks for a lower-case character.
|
||||
inline boolean isLowerCase(int c)
|
||||
{
|
||||
return (islower (c) == 0 ? false : true);
|
||||
inline boolean isLowerCase(int c) {
|
||||
return (islower(c) == 0 ? false : true);
|
||||
}
|
||||
|
||||
|
||||
// Checks for any printable character including space.
|
||||
inline boolean isPrintable(int c)
|
||||
{
|
||||
return ( isprint (c) == 0 ? false : true);
|
||||
inline boolean isPrintable(int c) {
|
||||
return (isprint(c) == 0 ? false : true);
|
||||
}
|
||||
|
||||
|
||||
// Checks for any printable character which is not a space
|
||||
// or an alphanumeric character.
|
||||
inline boolean isPunct(int c)
|
||||
{
|
||||
return ( ispunct (c) == 0 ? false : true);
|
||||
inline boolean isPunct(int c) {
|
||||
return (ispunct(c) == 0 ? false : true);
|
||||
}
|
||||
|
||||
|
||||
// Checks for white-space characters. For the avr-libc library,
|
||||
// these are: space, formfeed ('\f'), newline ('\n'), carriage
|
||||
// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
|
||||
inline boolean isSpace(int c)
|
||||
{
|
||||
return ( isspace (c) == 0 ? false : true);
|
||||
inline boolean isSpace(int c) {
|
||||
return (isspace(c) == 0 ? false : true);
|
||||
}
|
||||
|
||||
|
||||
// Checks for an uppercase letter.
|
||||
inline boolean isUpperCase(int c)
|
||||
{
|
||||
return ( isupper (c) == 0 ? false : true);
|
||||
inline boolean isUpperCase(int c) {
|
||||
return (isupper(c) == 0 ? false : true);
|
||||
}
|
||||
|
||||
|
||||
// Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7
|
||||
// 8 9 a b c d e f A B C D E F.
|
||||
inline boolean isHexadecimalDigit(int c)
|
||||
{
|
||||
return ( isxdigit (c) == 0 ? false : true);
|
||||
inline boolean isHexadecimalDigit(int c) {
|
||||
return (isxdigit(c) == 0 ? false : true);
|
||||
}
|
||||
|
||||
|
||||
// Converts c to a 7-bit unsigned char value that fits into the
|
||||
// ASCII character set, by clearing the high-order bits.
|
||||
inline int toAscii(int c)
|
||||
{
|
||||
return toascii (c);
|
||||
inline int toAscii(int c) {
|
||||
return toascii(c);
|
||||
}
|
||||
|
||||
|
||||
// Warning:
|
||||
// Many people will be unhappy if you use this function.
|
||||
// This function will convert accented letters into random
|
||||
// characters.
|
||||
|
||||
// Converts the letter c to lower case, if possible.
|
||||
inline int toLowerCase(int c)
|
||||
{
|
||||
return tolower (c);
|
||||
inline int toLowerCase(int c) {
|
||||
return tolower(c);
|
||||
}
|
||||
|
||||
|
||||
// Converts the letter c to upper case, if possible.
|
||||
inline int toUpperCase(int c)
|
||||
{
|
||||
return toupper (c);
|
||||
inline int toUpperCase(int c) {
|
||||
return toupper(c);
|
||||
}
|
||||
|
||||
#endif
|
@ -21,40 +21,41 @@
|
||||
Boston, MA 02111-1307 USA
|
||||
|
||||
$Id$
|
||||
*/
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h>
|
||||
}
|
||||
|
||||
void randomSeed(unsigned int seed)
|
||||
{
|
||||
if (seed != 0) {
|
||||
void randomSeed(unsigned int seed) {
|
||||
if(seed != 0) {
|
||||
srand(seed);
|
||||
}
|
||||
}
|
||||
|
||||
long random(long howbig)
|
||||
{
|
||||
if (howbig == 0) {
|
||||
long random(long howbig) {
|
||||
if(howbig == 0) {
|
||||
return 0;
|
||||
}
|
||||
return rand() % howbig;
|
||||
}
|
||||
|
||||
long random(long howsmall, long howbig)
|
||||
{
|
||||
if (howsmall >= howbig) {
|
||||
long random(long howsmall, long howbig) {
|
||||
if(howsmall >= howbig) {
|
||||
return howsmall;
|
||||
}
|
||||
long diff = howbig - howsmall;
|
||||
return random(diff) + howsmall;
|
||||
}
|
||||
|
||||
long map(long x, long in_min, long in_max, long out_min, long out_max)
|
||||
{
|
||||
long map(long x, long in_min, long in_max, long out_min, long out_max) {
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
|
||||
unsigned int makeWord(unsigned int w) { return w; }
|
||||
unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; }
|
||||
unsigned int makeWord(unsigned int w) {
|
||||
return w;
|
||||
}
|
||||
|
||||
unsigned int makeWord(unsigned char h, unsigned char l) {
|
||||
return (h << 8) | l;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
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
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "WString.h"
|
||||
#include "stdlib_noniso.h"
|
||||
@ -33,33 +33,30 @@ extern "C" {
|
||||
/* Constructors */
|
||||
/*********************************************/
|
||||
|
||||
ICACHE_FLASH_ATTR String::String(const char *cstr)
|
||||
{
|
||||
ICACHE_FLASH_ATTR String::String(const char *cstr) {
|
||||
init();
|
||||
if (cstr) copy(cstr, strlen(cstr));
|
||||
if(cstr)
|
||||
copy(cstr, strlen(cstr));
|
||||
}
|
||||
|
||||
ICACHE_FLASH_ATTR String::String(const String &value)
|
||||
{
|
||||
ICACHE_FLASH_ATTR String::String(const String &value) {
|
||||
init();
|
||||
*this = value;
|
||||
}
|
||||
|
||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||
ICACHE_FLASH_ATTR String::String(String &&rval)
|
||||
{
|
||||
ICACHE_FLASH_ATTR String::String(String &&rval) {
|
||||
init();
|
||||
move(rval);
|
||||
}
|
||||
ICACHE_FLASH_ATTR String::String(StringSumHelper &&rval)
|
||||
{
|
||||
|
||||
ICACHE_FLASH_ATTR String::String(StringSumHelper &&rval) {
|
||||
init();
|
||||
move(rval);
|
||||
}
|
||||
#endif
|
||||
|
||||
ICACHE_FLASH_ATTR String::String(char c)
|
||||
{
|
||||
ICACHE_FLASH_ATTR String::String(char c) {
|
||||
init();
|
||||
char buf[2];
|
||||
buf[0] = c;
|
||||
@ -67,62 +64,54 @@ ICACHE_FLASH_ATTR String::String(char c)
|
||||
*this = buf;
|
||||
}
|
||||
|
||||
ICACHE_FLASH_ATTR String::String(unsigned char value, unsigned char base)
|
||||
{
|
||||
ICACHE_FLASH_ATTR String::String(unsigned char value, unsigned char base) {
|
||||
init();
|
||||
char buf[1 + 8 * sizeof(unsigned char)];
|
||||
utoa(value, buf, base);
|
||||
*this = buf;
|
||||
}
|
||||
|
||||
ICACHE_FLASH_ATTR String::String(int value, unsigned char base)
|
||||
{
|
||||
ICACHE_FLASH_ATTR String::String(int value, unsigned char base) {
|
||||
init();
|
||||
char buf[2 + 8 * sizeof(int)];
|
||||
itoa(value, buf, base);
|
||||
*this = buf;
|
||||
}
|
||||
|
||||
ICACHE_FLASH_ATTR String::String(unsigned int value, unsigned char base)
|
||||
{
|
||||
ICACHE_FLASH_ATTR String::String(unsigned int value, unsigned char base) {
|
||||
init();
|
||||
char buf[1 + 8 * sizeof(unsigned int)];
|
||||
utoa(value, buf, base);
|
||||
*this = buf;
|
||||
}
|
||||
|
||||
ICACHE_FLASH_ATTR String::String(long value, unsigned char base)
|
||||
{
|
||||
ICACHE_FLASH_ATTR String::String(long value, unsigned char base) {
|
||||
init();
|
||||
char buf[2 + 8 * sizeof(long)];
|
||||
ltoa(value, buf, base);
|
||||
*this = buf;
|
||||
}
|
||||
|
||||
ICACHE_FLASH_ATTR String::String(unsigned long value, unsigned char base)
|
||||
{
|
||||
ICACHE_FLASH_ATTR String::String(unsigned long value, unsigned char base) {
|
||||
init();
|
||||
char buf[1 + 8 * sizeof(unsigned long)];
|
||||
ultoa(value, buf, base);
|
||||
*this = buf;
|
||||
}
|
||||
|
||||
ICACHE_FLASH_ATTR String::String(float value, unsigned char decimalPlaces)
|
||||
{
|
||||
ICACHE_FLASH_ATTR String::String(float value, unsigned char decimalPlaces) {
|
||||
init();
|
||||
char buf[33];
|
||||
*this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
|
||||
}
|
||||
|
||||
ICACHE_FLASH_ATTR String::String(double value, unsigned char decimalPlaces)
|
||||
{
|
||||
ICACHE_FLASH_ATTR String::String(double value, unsigned char decimalPlaces) {
|
||||
init();
|
||||
char buf[33];
|
||||
*this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
|
||||
}
|
||||
|
||||
ICACHE_FLASH_ATTR String::~String()
|
||||
{
|
||||
ICACHE_FLASH_ATTR String::~String() {
|
||||
os_free(buffer);
|
||||
}
|
||||
|
||||
@ -130,34 +119,33 @@ ICACHE_FLASH_ATTR String::~String()
|
||||
// /* Memory Management */
|
||||
// /*********************************************/
|
||||
|
||||
inline void String::init(void)
|
||||
{
|
||||
inline void String::init(void) {
|
||||
buffer = NULL;
|
||||
capacity = 0;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR String::invalidate(void)
|
||||
{
|
||||
if (buffer) os_free(buffer);
|
||||
void ICACHE_FLASH_ATTR String::invalidate(void) {
|
||||
if(buffer)
|
||||
os_free(buffer);
|
||||
buffer = NULL;
|
||||
capacity = len = 0;
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::reserve(unsigned int size)
|
||||
{
|
||||
if (buffer && capacity >= size) return 1;
|
||||
if (changeBuffer(size)) {
|
||||
if (len == 0) buffer[0] = 0;
|
||||
unsigned char ICACHE_FLASH_ATTR String::reserve(unsigned int size) {
|
||||
if(buffer && capacity >= size)
|
||||
return 1;
|
||||
if(changeBuffer(size)) {
|
||||
if(len == 0)
|
||||
buffer[0] = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::changeBuffer(unsigned int maxStrLen)
|
||||
{
|
||||
char *newbuffer = (char *)os_realloc(buffer, maxStrLen + 1);
|
||||
if (newbuffer) {
|
||||
unsigned char ICACHE_FLASH_ATTR String::changeBuffer(unsigned int maxStrLen) {
|
||||
char *newbuffer = (char *) os_realloc(buffer, maxStrLen + 1);
|
||||
if(newbuffer) {
|
||||
buffer = newbuffer;
|
||||
capacity = maxStrLen;
|
||||
return 1;
|
||||
@ -169,9 +157,8 @@ unsigned char ICACHE_FLASH_ATTR String::changeBuffer(unsigned int maxStrLen)
|
||||
// /* Copy and Move */
|
||||
// /*********************************************/
|
||||
|
||||
String & ICACHE_FLASH_ATTR String::copy(const char *cstr, unsigned int length)
|
||||
{
|
||||
if (!reserve(length)) {
|
||||
String & ICACHE_FLASH_ATTR String::copy(const char *cstr, unsigned int length) {
|
||||
if(!reserve(length)) {
|
||||
invalidate();
|
||||
return *this;
|
||||
}
|
||||
@ -180,12 +167,10 @@ String & ICACHE_FLASH_ATTR String::copy(const char *cstr, unsigned int length)
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||
void ICACHE_FLASH_ATTR String::move(String &rhs)
|
||||
{
|
||||
if (buffer) {
|
||||
if (capacity >= rhs.len) {
|
||||
void ICACHE_FLASH_ATTR String::move(String &rhs) {
|
||||
if(buffer) {
|
||||
if(capacity >= rhs.len) {
|
||||
strcpy(buffer, rhs.buffer);
|
||||
len = rhs.len;
|
||||
rhs.len = 0;
|
||||
@ -203,117 +188,112 @@ void ICACHE_FLASH_ATTR String::move(String &rhs)
|
||||
}
|
||||
#endif
|
||||
|
||||
String & ICACHE_FLASH_ATTR String::operator = (const String &rhs)
|
||||
{
|
||||
if (this == &rhs) return *this;
|
||||
String & ICACHE_FLASH_ATTR String::operator =(const String &rhs) {
|
||||
if(this == &rhs)
|
||||
return *this;
|
||||
|
||||
if (rhs.buffer) copy(rhs.buffer, rhs.len);
|
||||
else invalidate();
|
||||
if(rhs.buffer)
|
||||
copy(rhs.buffer, rhs.len);
|
||||
else
|
||||
invalidate();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||
String & ICACHE_FLASH_ATTR String::operator = (String &&rval)
|
||||
{
|
||||
if (this != &rval) move(rval);
|
||||
String & ICACHE_FLASH_ATTR String::operator =(String &&rval) {
|
||||
if(this != &rval)
|
||||
move(rval);
|
||||
return *this;
|
||||
}
|
||||
|
||||
String & ICACHE_FLASH_ATTR String::operator = (StringSumHelper &&rval)
|
||||
{
|
||||
if (this != &rval) move(rval);
|
||||
String & ICACHE_FLASH_ATTR String::operator =(StringSumHelper &&rval) {
|
||||
if(this != &rval)
|
||||
move(rval);
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
String & ICACHE_FLASH_ATTR String::operator = (const char *cstr)
|
||||
{
|
||||
if (cstr) copy(cstr, strlen(cstr));
|
||||
else invalidate();
|
||||
String & ICACHE_FLASH_ATTR String::operator =(const char *cstr) {
|
||||
if(cstr)
|
||||
copy(cstr, strlen(cstr));
|
||||
else
|
||||
invalidate();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// /*********************************************/
|
||||
// /* concat */
|
||||
// /*********************************************/
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(const String &s)
|
||||
{
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(const String &s) {
|
||||
return concat(s.buffer, s.len);
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(const char *cstr, unsigned int length)
|
||||
{
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(const char *cstr, unsigned int length) {
|
||||
unsigned int newlen = len + length;
|
||||
if (!cstr) return 0;
|
||||
if (length == 0) return 1;
|
||||
if (!reserve(newlen)) return 0;
|
||||
if(!cstr)
|
||||
return 0;
|
||||
if(length == 0)
|
||||
return 1;
|
||||
if(!reserve(newlen))
|
||||
return 0;
|
||||
strcpy(buffer + len, cstr);
|
||||
len = newlen;
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(const char *cstr)
|
||||
{
|
||||
if (!cstr) return 0;
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(const char *cstr) {
|
||||
if(!cstr)
|
||||
return 0;
|
||||
return concat(cstr, strlen(cstr));
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(char c)
|
||||
{
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(char c) {
|
||||
char buf[2];
|
||||
buf[0] = c;
|
||||
buf[1] = 0;
|
||||
return concat(buf, 1);
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(unsigned char num)
|
||||
{
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(unsigned char num) {
|
||||
char buf[1 + 3 * sizeof(unsigned char)];
|
||||
itoa(num, buf, 10);
|
||||
return concat(buf, strlen(buf));
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(int num)
|
||||
{
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(int num) {
|
||||
char buf[2 + 3 * sizeof(int)];
|
||||
itoa(num, buf, 10);
|
||||
return concat(buf, strlen(buf));
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(unsigned int num)
|
||||
{
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(unsigned int num) {
|
||||
char buf[1 + 3 * sizeof(unsigned int)];
|
||||
utoa(num, buf, 10);
|
||||
return concat(buf, strlen(buf));
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(long num)
|
||||
{
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(long num) {
|
||||
char buf[2 + 3 * sizeof(long)];
|
||||
ltoa(num, buf, 10);
|
||||
return concat(buf, strlen(buf));
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(unsigned long num)
|
||||
{
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(unsigned long num) {
|
||||
char buf[1 + 3 * sizeof(unsigned long)];
|
||||
ultoa(num, buf, 10);
|
||||
return concat(buf, strlen(buf));
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(float num)
|
||||
{
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(float num) {
|
||||
char buf[20];
|
||||
char* string = dtostrf(num, 4, 2, buf);
|
||||
return concat(string, strlen(string));
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(double num)
|
||||
{
|
||||
unsigned char ICACHE_FLASH_ATTR String::concat(double num) {
|
||||
char buf[20];
|
||||
char* string = dtostrf(num, 4, 2, buf);
|
||||
return concat(string, strlen(string));
|
||||
@ -323,151 +303,150 @@ unsigned char ICACHE_FLASH_ATTR String::concat(double num)
|
||||
/* Concatenate */
|
||||
/*********************************************/
|
||||
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, const String &rhs)
|
||||
{
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator +(const StringSumHelper &lhs, const String &rhs) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||
if (!a.concat(rhs.buffer, rhs.len)) a.invalidate();
|
||||
if(!a.concat(rhs.buffer, rhs.len))
|
||||
a.invalidate();
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, const char *cstr)
|
||||
{
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator +(const StringSumHelper &lhs, const char *cstr) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||
if (!cstr || !a.concat(cstr, strlen(cstr))) a.invalidate();
|
||||
if(!cstr || !a.concat(cstr, strlen(cstr)))
|
||||
a.invalidate();
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, char c)
|
||||
{
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator +(const StringSumHelper &lhs, char c) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||
if (!a.concat(c)) a.invalidate();
|
||||
if(!a.concat(c))
|
||||
a.invalidate();
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, unsigned char num)
|
||||
{
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator +(const StringSumHelper &lhs, unsigned char num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||
if (!a.concat(num)) a.invalidate();
|
||||
if(!a.concat(num))
|
||||
a.invalidate();
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, int num)
|
||||
{
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator +(const StringSumHelper &lhs, int num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||
if (!a.concat(num)) a.invalidate();
|
||||
if(!a.concat(num))
|
||||
a.invalidate();
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, unsigned int num)
|
||||
{
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator +(const StringSumHelper &lhs, unsigned int num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||
if (!a.concat(num)) a.invalidate();
|
||||
if(!a.concat(num))
|
||||
a.invalidate();
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, long num)
|
||||
{
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator +(const StringSumHelper &lhs, long num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||
if (!a.concat(num)) a.invalidate();
|
||||
if(!a.concat(num))
|
||||
a.invalidate();
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, unsigned long num)
|
||||
{
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator +(const StringSumHelper &lhs, unsigned long num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||
if (!a.concat(num)) a.invalidate();
|
||||
if(!a.concat(num))
|
||||
a.invalidate();
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, float num)
|
||||
{
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator +(const StringSumHelper &lhs, float num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||
if (!a.concat(num)) a.invalidate();
|
||||
if(!a.concat(num))
|
||||
a.invalidate();
|
||||
return a;
|
||||
}
|
||||
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator + (const StringSumHelper &lhs, double num)
|
||||
{
|
||||
StringSumHelper & ICACHE_FLASH_ATTR operator +(const StringSumHelper &lhs, double num) {
|
||||
StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
|
||||
if (!a.concat(num)) a.invalidate();
|
||||
if(!a.concat(num))
|
||||
a.invalidate();
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
// /*********************************************/
|
||||
// /* Comparison */
|
||||
// /*********************************************/
|
||||
|
||||
int ICACHE_FLASH_ATTR String::compareTo(const String &s) const
|
||||
{
|
||||
if (!buffer || !s.buffer) {
|
||||
if (s.buffer && s.len > 0) return 0 - *(unsigned char *)s.buffer;
|
||||
if (buffer && len > 0) return *(unsigned char *)buffer;
|
||||
int ICACHE_FLASH_ATTR String::compareTo(const String &s) const {
|
||||
if(!buffer || !s.buffer) {
|
||||
if(s.buffer && s.len > 0)
|
||||
return 0 - *(unsigned char *) s.buffer;
|
||||
if(buffer && len > 0)
|
||||
return *(unsigned char *) buffer;
|
||||
return 0;
|
||||
}
|
||||
return strcmp(buffer, s.buffer);
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::equals(const String &s2) const
|
||||
{
|
||||
unsigned char ICACHE_FLASH_ATTR String::equals(const String &s2) const {
|
||||
return (len == s2.len && compareTo(s2) == 0);
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::equals(const char *cstr) const
|
||||
{
|
||||
if (len == 0) return (cstr == NULL || *cstr == 0);
|
||||
if (cstr == NULL) return buffer[0] == 0;
|
||||
unsigned char ICACHE_FLASH_ATTR String::equals(const char *cstr) const {
|
||||
if(len == 0)
|
||||
return (cstr == NULL || *cstr == 0);
|
||||
if(cstr == NULL)
|
||||
return buffer[0] == 0;
|
||||
return strcmp(buffer, cstr) == 0;
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::operator<(const String &rhs) const
|
||||
{
|
||||
unsigned char ICACHE_FLASH_ATTR String::operator<(const String &rhs) const {
|
||||
return compareTo(rhs) < 0;
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::operator>(const String &rhs) const
|
||||
{
|
||||
unsigned char ICACHE_FLASH_ATTR String::operator>(const String &rhs) const {
|
||||
return compareTo(rhs) > 0;
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::operator<=(const String &rhs) const
|
||||
{
|
||||
unsigned char ICACHE_FLASH_ATTR String::operator<=(const String &rhs) const {
|
||||
return compareTo(rhs) <= 0;
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::operator>=(const String &rhs) const
|
||||
{
|
||||
unsigned char ICACHE_FLASH_ATTR String::operator>=(const String &rhs) const {
|
||||
return compareTo(rhs) >= 0;
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::equalsIgnoreCase( const String &s2 ) const
|
||||
{
|
||||
if (this == &s2) return 1;
|
||||
if (len != s2.len) return 0;
|
||||
if (len == 0) return 1;
|
||||
unsigned char ICACHE_FLASH_ATTR String::equalsIgnoreCase(const String &s2) const {
|
||||
if(this == &s2)
|
||||
return 1;
|
||||
if(len != s2.len)
|
||||
return 0;
|
||||
if(len == 0)
|
||||
return 1;
|
||||
const char *p1 = buffer;
|
||||
const char *p2 = s2.buffer;
|
||||
while (*p1) {
|
||||
if (tolower(*p1++) != tolower(*p2++)) return 0;
|
||||
while(*p1) {
|
||||
if(tolower(*p1++) != tolower(*p2++))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::startsWith( const String &s2 ) const
|
||||
{
|
||||
if (len < s2.len) return 0;
|
||||
unsigned char ICACHE_FLASH_ATTR String::startsWith(const String &s2) const {
|
||||
if(len < s2.len)
|
||||
return 0;
|
||||
return startsWith(s2, 0);
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::startsWith( const String &s2, unsigned int offset ) const
|
||||
{
|
||||
if (offset > len - s2.len || !buffer || !s2.buffer) return 0;
|
||||
return strncmp( &buffer[offset], s2.buffer, s2.len ) == 0;
|
||||
unsigned char ICACHE_FLASH_ATTR String::startsWith(const String &s2, unsigned int offset) const {
|
||||
if(offset > len - s2.len || !buffer || !s2.buffer)
|
||||
return 0;
|
||||
return strncmp(&buffer[offset], s2.buffer, s2.len) == 0;
|
||||
}
|
||||
|
||||
unsigned char ICACHE_FLASH_ATTR String::endsWith( const String &s2 ) const
|
||||
{
|
||||
if ( len < s2.len || !buffer || !s2.buffer) return 0;
|
||||
unsigned char ICACHE_FLASH_ATTR String::endsWith(const String &s2) const {
|
||||
if(len < s2.len || !buffer || !s2.buffer)
|
||||
return 0;
|
||||
return strcmp(&buffer[len - s2.len], s2.buffer) == 0;
|
||||
}
|
||||
|
||||
@ -475,42 +454,41 @@ unsigned char ICACHE_FLASH_ATTR String::endsWith( const String &s2 ) const
|
||||
// /* Character Access */
|
||||
// /*********************************************/
|
||||
|
||||
char ICACHE_FLASH_ATTR String::charAt(unsigned int loc) const
|
||||
{
|
||||
char ICACHE_FLASH_ATTR String::charAt(unsigned int loc) const {
|
||||
return operator[](loc);
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR String::setCharAt(unsigned int loc, char c)
|
||||
{
|
||||
if (loc < len) buffer[loc] = c;
|
||||
void ICACHE_FLASH_ATTR String::setCharAt(unsigned int loc, char c) {
|
||||
if(loc < len)
|
||||
buffer[loc] = c;
|
||||
}
|
||||
|
||||
char & ICACHE_FLASH_ATTR String::operator[](unsigned int index)
|
||||
{
|
||||
char & ICACHE_FLASH_ATTR String::operator[](unsigned int index) {
|
||||
static char dummy_writable_char;
|
||||
if (index >= len || !buffer) {
|
||||
if(index >= len || !buffer) {
|
||||
dummy_writable_char = 0;
|
||||
return dummy_writable_char;
|
||||
}
|
||||
return buffer[index];
|
||||
}
|
||||
|
||||
char ICACHE_FLASH_ATTR String::operator[]( unsigned int index ) const
|
||||
{
|
||||
if (index >= len || !buffer) return 0;
|
||||
char ICACHE_FLASH_ATTR String::operator[](unsigned int index) const {
|
||||
if(index >= len || !buffer)
|
||||
return 0;
|
||||
return buffer[index];
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index) const
|
||||
{
|
||||
if (!bufsize || !buf) return;
|
||||
if (index >= len) {
|
||||
void ICACHE_FLASH_ATTR String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index) const {
|
||||
if(!bufsize || !buf)
|
||||
return;
|
||||
if(index >= len) {
|
||||
buf[0] = 0;
|
||||
return;
|
||||
}
|
||||
unsigned int n = bufsize - 1;
|
||||
if (n > len - index) n = len - index;
|
||||
strncpy((char *)buf, buffer + index, n);
|
||||
if(n > len - index)
|
||||
n = len - index;
|
||||
strncpy((char *) buf, buffer + index, n);
|
||||
buf[n] = 0;
|
||||
}
|
||||
|
||||
@ -519,76 +497,79 @@ void ICACHE_FLASH_ATTR String::getBytes(unsigned char *buf, unsigned int bufsize
|
||||
// /*********************************************/
|
||||
ICACHE_FLASH_ATTR ICACHE_FLASH_ATTR
|
||||
|
||||
int ICACHE_FLASH_ATTR String::indexOf(char c) const
|
||||
{
|
||||
int ICACHE_FLASH_ATTR String::indexOf(char c) const {
|
||||
return indexOf(c, 0);
|
||||
}
|
||||
|
||||
int ICACHE_FLASH_ATTR String::indexOf( char ch, unsigned int fromIndex ) const
|
||||
{
|
||||
if (fromIndex >= len) return -1;
|
||||
int ICACHE_FLASH_ATTR String::indexOf(char ch, unsigned int fromIndex) const {
|
||||
if(fromIndex >= len)
|
||||
return -1;
|
||||
const char* temp = strchr(buffer + fromIndex, ch);
|
||||
if (temp == NULL) return -1;
|
||||
if(temp == NULL)
|
||||
return -1;
|
||||
return temp - buffer;
|
||||
}
|
||||
|
||||
int ICACHE_FLASH_ATTR String::indexOf(const String &s2) const
|
||||
{
|
||||
int ICACHE_FLASH_ATTR String::indexOf(const String &s2) const {
|
||||
return indexOf(s2, 0);
|
||||
}
|
||||
|
||||
int ICACHE_FLASH_ATTR String::indexOf(const String &s2, unsigned int fromIndex) const
|
||||
{
|
||||
if (fromIndex >= len) return -1;
|
||||
int ICACHE_FLASH_ATTR String::indexOf(const String &s2, unsigned int fromIndex) const {
|
||||
if(fromIndex >= len)
|
||||
return -1;
|
||||
const char *found = strstr(buffer + fromIndex, s2.buffer);
|
||||
if (found == NULL) return -1;
|
||||
if(found == NULL)
|
||||
return -1;
|
||||
return found - buffer;
|
||||
}
|
||||
|
||||
int ICACHE_FLASH_ATTR String::lastIndexOf( char theChar ) const
|
||||
{
|
||||
int ICACHE_FLASH_ATTR String::lastIndexOf(char theChar) const {
|
||||
return lastIndexOf(theChar, len - 1);
|
||||
}
|
||||
|
||||
int ICACHE_FLASH_ATTR String::lastIndexOf(char ch, unsigned int fromIndex) const
|
||||
{
|
||||
if (fromIndex >= len) return -1;
|
||||
int ICACHE_FLASH_ATTR String::lastIndexOf(char ch, unsigned int fromIndex) const {
|
||||
if(fromIndex >= len)
|
||||
return -1;
|
||||
char tempchar = buffer[fromIndex + 1];
|
||||
buffer[fromIndex + 1] = '\0';
|
||||
char* temp = strrchr( buffer, ch );
|
||||
char* temp = strrchr(buffer, ch);
|
||||
buffer[fromIndex + 1] = tempchar;
|
||||
if (temp == NULL) return -1;
|
||||
if(temp == NULL)
|
||||
return -1;
|
||||
return temp - buffer;
|
||||
}
|
||||
|
||||
int ICACHE_FLASH_ATTR String::lastIndexOf(const String &s2) const
|
||||
{
|
||||
int ICACHE_FLASH_ATTR String::lastIndexOf(const String &s2) const {
|
||||
return lastIndexOf(s2, len - s2.len);
|
||||
}
|
||||
|
||||
int ICACHE_FLASH_ATTR String::lastIndexOf(const String &s2, unsigned int fromIndex) const
|
||||
{
|
||||
if (s2.len == 0 || len == 0 || s2.len > len) return -1;
|
||||
if (fromIndex >= len) fromIndex = len - 1;
|
||||
int ICACHE_FLASH_ATTR String::lastIndexOf(const String &s2, unsigned int fromIndex) const {
|
||||
if(s2.len == 0 || len == 0 || s2.len > len)
|
||||
return -1;
|
||||
if(fromIndex >= len)
|
||||
fromIndex = len - 1;
|
||||
int found = -1;
|
||||
for (char *p = buffer; p <= buffer + fromIndex; p++) {
|
||||
for(char *p = buffer; p <= buffer + fromIndex; p++) {
|
||||
p = strstr(p, s2.buffer);
|
||||
if (!p) break;
|
||||
if ((unsigned int)(p - buffer) <= fromIndex) found = p - buffer;
|
||||
if(!p)
|
||||
break;
|
||||
if((unsigned int) (p - buffer) <= fromIndex)
|
||||
found = p - buffer;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
String ICACHE_FLASH_ATTR String::substring(unsigned int left, unsigned int right) const
|
||||
{
|
||||
if (left > right) {
|
||||
String ICACHE_FLASH_ATTR String::substring(unsigned int left, unsigned int right) const {
|
||||
if(left > right) {
|
||||
unsigned int temp = right;
|
||||
right = left;
|
||||
left = temp;
|
||||
}
|
||||
String out;
|
||||
if (left >= len) return out;
|
||||
if (right > len) right = len;
|
||||
if(left >= len)
|
||||
return out;
|
||||
if(right > len)
|
||||
right = len;
|
||||
char temp = buffer[right]; // save the replaced character
|
||||
buffer[right] = '\0';
|
||||
out = buffer + left; // pointer arithmetic
|
||||
@ -600,28 +581,29 @@ String ICACHE_FLASH_ATTR String::substring(unsigned int left, unsigned int right
|
||||
// /* Modification */
|
||||
// /*********************************************/
|
||||
|
||||
void ICACHE_FLASH_ATTR String::replace(char find, char replace)
|
||||
{
|
||||
if (!buffer) return;
|
||||
for (char *p = buffer; *p; p++) {
|
||||
if (*p == find) *p = replace;
|
||||
void ICACHE_FLASH_ATTR String::replace(char find, char replace) {
|
||||
if(!buffer)
|
||||
return;
|
||||
for(char *p = buffer; *p; p++) {
|
||||
if(*p == find)
|
||||
*p = replace;
|
||||
}
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR String::replace(const String& find, const String& replace)
|
||||
{
|
||||
if (len == 0 || find.len == 0) return;
|
||||
void ICACHE_FLASH_ATTR String::replace(const String& find, const String& replace) {
|
||||
if(len == 0 || find.len == 0)
|
||||
return;
|
||||
int diff = replace.len - find.len;
|
||||
char *readFrom = buffer;
|
||||
char *foundAt;
|
||||
if (diff == 0) {
|
||||
while ((foundAt = strstr(readFrom, find.buffer)) != NULL) {
|
||||
if(diff == 0) {
|
||||
while((foundAt = strstr(readFrom, find.buffer)) != NULL) {
|
||||
memcpy(foundAt, replace.buffer, replace.len);
|
||||
readFrom = foundAt + replace.len;
|
||||
}
|
||||
} else if (diff < 0) {
|
||||
} else if(diff < 0) {
|
||||
char *writeTo = buffer;
|
||||
while ((foundAt = strstr(readFrom, find.buffer)) != NULL) {
|
||||
while((foundAt = strstr(readFrom, find.buffer)) != NULL) {
|
||||
unsigned int n = foundAt - readFrom;
|
||||
memcpy(writeTo, readFrom, n);
|
||||
writeTo += n;
|
||||
@ -633,14 +615,16 @@ void ICACHE_FLASH_ATTR String::replace(const String& find, const String& replace
|
||||
strcpy(writeTo, readFrom);
|
||||
} else {
|
||||
unsigned int size = len; // compute size needed for result
|
||||
while ((foundAt = strstr(readFrom, find.buffer)) != NULL) {
|
||||
while((foundAt = strstr(readFrom, find.buffer)) != NULL) {
|
||||
readFrom = foundAt + find.len;
|
||||
size += diff;
|
||||
}
|
||||
if (size == len) return;
|
||||
if (size > capacity && !changeBuffer(size)) return; // XXX: tell user!
|
||||
if(size == len)
|
||||
return;
|
||||
if(size > capacity && !changeBuffer(size))
|
||||
return; // XXX: tell user!
|
||||
int index = len - 1;
|
||||
while (index >= 0 && (index = lastIndexOf(find, index)) >= 0) {
|
||||
while(index >= 0 && (index = lastIndexOf(find, index)) >= 0) {
|
||||
readFrom = buffer + index + find.len;
|
||||
memmove(readFrom + diff, readFrom, len - (readFrom - buffer));
|
||||
len += diff;
|
||||
@ -651,48 +635,57 @@ void ICACHE_FLASH_ATTR String::replace(const String& find, const String& replace
|
||||
}
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR String::remove(unsigned int index){
|
||||
void ICACHE_FLASH_ATTR String::remove(unsigned int index) {
|
||||
// Pass the biggest integer as the count. The remove method
|
||||
// below will take care of truncating it at the end of the
|
||||
// string.
|
||||
remove(index, (unsigned int)-1);
|
||||
remove(index, (unsigned int) -1);
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR String::remove(unsigned int index, unsigned int count){
|
||||
if (index >= len) { return; }
|
||||
if (count <= 0) { return; }
|
||||
if (count > len - index) { count = len - index; }
|
||||
void ICACHE_FLASH_ATTR String::remove(unsigned int index, unsigned int count) {
|
||||
if(index >= len) {
|
||||
return;
|
||||
}
|
||||
if(count <= 0) {
|
||||
return;
|
||||
}
|
||||
if(count > len - index) {
|
||||
count = len - index;
|
||||
}
|
||||
char *writeTo = buffer + index;
|
||||
len = len - count;
|
||||
strncpy(writeTo, buffer + index + count,len - index);
|
||||
strncpy(writeTo, buffer + index + count, len - index);
|
||||
buffer[len] = 0;
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR String::toLowerCase(void)
|
||||
{
|
||||
if (!buffer) return;
|
||||
for (char *p = buffer; *p; p++) {
|
||||
void ICACHE_FLASH_ATTR String::toLowerCase(void) {
|
||||
if(!buffer)
|
||||
return;
|
||||
for(char *p = buffer; *p; p++) {
|
||||
*p = tolower(*p);
|
||||
}
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR String::toUpperCase(void)
|
||||
{
|
||||
if (!buffer) return;
|
||||
for (char *p = buffer; *p; p++) {
|
||||
void ICACHE_FLASH_ATTR String::toUpperCase(void) {
|
||||
if(!buffer)
|
||||
return;
|
||||
for(char *p = buffer; *p; p++) {
|
||||
*p = toupper(*p);
|
||||
}
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR String::trim(void)
|
||||
{
|
||||
if (!buffer || len == 0) return;
|
||||
void ICACHE_FLASH_ATTR String::trim(void) {
|
||||
if(!buffer || len == 0)
|
||||
return;
|
||||
char *begin = buffer;
|
||||
while (isspace(*begin)) begin++;
|
||||
while(isspace(*begin))
|
||||
begin++;
|
||||
char *end = buffer + len - 1;
|
||||
while (isspace(*end) && end >= begin) end--;
|
||||
while(isspace(*end) && end >= begin)
|
||||
end--;
|
||||
len = end + 1 - begin;
|
||||
if (begin > buffer) memcpy(buffer, begin, len);
|
||||
if(begin > buffer)
|
||||
memcpy(buffer, begin, len);
|
||||
buffer[len] = 0;
|
||||
}
|
||||
|
||||
@ -700,14 +693,14 @@ void ICACHE_FLASH_ATTR String::trim(void)
|
||||
// /* Parsing / Conversion */
|
||||
// /*********************************************/
|
||||
|
||||
long ICACHE_FLASH_ATTR String::toInt(void) const
|
||||
{
|
||||
if (buffer) return atol(buffer);
|
||||
long ICACHE_FLASH_ATTR String::toInt(void) const {
|
||||
if(buffer)
|
||||
return atol(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
float ICACHE_FLASH_ATTR String::toFloat(void) const
|
||||
{
|
||||
if (buffer) return atof(buffer);
|
||||
float ICACHE_FLASH_ATTR String::toFloat(void) const {
|
||||
if(buffer)
|
||||
return atof(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
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 String_class_h
|
||||
#define String_class_h
|
||||
@ -37,15 +37,15 @@ typedef char* __FlashStringHelper;
|
||||
#define F(str) str
|
||||
|
||||
// The string class
|
||||
class String
|
||||
{
|
||||
class String {
|
||||
// use a function pointer to allow for "if (s)" without the
|
||||
// complications of an operator bool(). for more information, see:
|
||||
// http://www.artima.com/cppsource/safebool.html
|
||||
typedef void (String::*StringIfHelperType)() const;
|
||||
void StringIfHelper() const {}
|
||||
void StringIfHelper() const {
|
||||
}
|
||||
|
||||
public:
|
||||
public:
|
||||
// constructors
|
||||
// creates a copy of the initial value.
|
||||
// if the initial value is null or invalid, or if memory allocation
|
||||
@ -53,18 +53,18 @@ public:
|
||||
// be false).
|
||||
String(const char *cstr = "");
|
||||
String(const String &str);
|
||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||
String(String &&rval);
|
||||
String(StringSumHelper &&rval);
|
||||
#endif
|
||||
#endif
|
||||
explicit String(char c);
|
||||
explicit String(unsigned char, unsigned char base=10);
|
||||
explicit String(int, unsigned char base=10);
|
||||
explicit String(unsigned int, unsigned char base=10);
|
||||
explicit String(long, unsigned char base=10);
|
||||
explicit String(unsigned long, unsigned char base=10);
|
||||
explicit String(float, unsigned char decimalPlaces=2);
|
||||
explicit String(double, unsigned char decimalPlaces=2);
|
||||
explicit String(unsigned char, unsigned char base = 10);
|
||||
explicit String(int, unsigned char base = 10);
|
||||
explicit String(unsigned int, unsigned char base = 10);
|
||||
explicit String(long, unsigned char base = 10);
|
||||
explicit String(unsigned long, unsigned char base = 10);
|
||||
explicit String(float, unsigned char decimalPlaces = 2);
|
||||
explicit String(double, unsigned char decimalPlaces = 2);
|
||||
~String(void);
|
||||
|
||||
// memory management
|
||||
@ -72,17 +72,19 @@ public:
|
||||
// is left unchanged). reserve(0), if successful, will validate an
|
||||
// invalid string (i.e., "if (s)" will be true afterwards)
|
||||
unsigned char reserve(unsigned int size);
|
||||
inline unsigned int length(void) const {return len;}
|
||||
inline unsigned int length(void) const {
|
||||
return len;
|
||||
}
|
||||
|
||||
// creates a copy of the assigned value. if the value is null or
|
||||
// invalid, or if the memory allocation fails, the string will be
|
||||
// marked as invalid ("if (s)" will be false).
|
||||
String & operator = (const String &rhs);
|
||||
String & operator = (const char *cstr);
|
||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||
String & operator = (String &&rval);
|
||||
String & operator = (StringSumHelper &&rval);
|
||||
#endif
|
||||
String & operator =(const String &rhs);
|
||||
String & operator =(const char *cstr);
|
||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||
String & operator =(String &&rval);
|
||||
String & operator =(StringSumHelper &&rval);
|
||||
#endif
|
||||
|
||||
// concatenate (works w/ built-in types)
|
||||
|
||||
@ -102,67 +104,113 @@ public:
|
||||
|
||||
// if there's not enough memory for the concatenated value, the string
|
||||
// will be left unchanged (but this isn't signalled in any way)
|
||||
String & operator += (const String &rhs) {concat(rhs); return (*this);}
|
||||
String & operator += (const char *cstr) {concat(cstr); return (*this);}
|
||||
String & operator += (char c) {concat(c); return (*this);}
|
||||
String & operator += (unsigned char num) {concat(num); return (*this);}
|
||||
String & operator += (int num) {concat(num); return (*this);}
|
||||
String & operator += (unsigned int num) {concat(num); return (*this);}
|
||||
String & operator += (long num) {concat(num); return (*this);}
|
||||
String & operator += (unsigned long num) {concat(num); return (*this);}
|
||||
String & operator += (float num) {concat(num); return (*this);}
|
||||
String & operator += (double num) {concat(num); return (*this);}
|
||||
String & operator +=(const String &rhs) {
|
||||
concat(rhs);
|
||||
return (*this);
|
||||
}
|
||||
String & operator +=(const char *cstr) {
|
||||
concat(cstr);
|
||||
return (*this);
|
||||
}
|
||||
String & operator +=(char c) {
|
||||
concat(c);
|
||||
return (*this);
|
||||
}
|
||||
String & operator +=(unsigned char num) {
|
||||
concat(num);
|
||||
return (*this);
|
||||
}
|
||||
String & operator +=(int num) {
|
||||
concat(num);
|
||||
return (*this);
|
||||
}
|
||||
String & operator +=(unsigned int num) {
|
||||
concat(num);
|
||||
return (*this);
|
||||
}
|
||||
String & operator +=(long num) {
|
||||
concat(num);
|
||||
return (*this);
|
||||
}
|
||||
String & operator +=(unsigned long num) {
|
||||
concat(num);
|
||||
return (*this);
|
||||
}
|
||||
String & operator +=(float num) {
|
||||
concat(num);
|
||||
return (*this);
|
||||
}
|
||||
String & operator +=(double num) {
|
||||
concat(num);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, char c);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, int num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, long num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, float num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, double num);
|
||||
friend StringSumHelper & operator +(const StringSumHelper &lhs, const String &rhs);
|
||||
friend StringSumHelper & operator +(const StringSumHelper &lhs, const char *cstr);
|
||||
friend StringSumHelper & operator +(const StringSumHelper &lhs, char c);
|
||||
friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned char num);
|
||||
friend StringSumHelper & operator +(const StringSumHelper &lhs, int num);
|
||||
friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned int num);
|
||||
friend StringSumHelper & operator +(const StringSumHelper &lhs, long num);
|
||||
friend StringSumHelper & operator +(const StringSumHelper &lhs, unsigned long num);
|
||||
friend StringSumHelper & operator +(const StringSumHelper &lhs, float num);
|
||||
friend StringSumHelper & operator +(const StringSumHelper &lhs, double num);
|
||||
|
||||
// comparison (only works w/ Strings and "strings")
|
||||
operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; }
|
||||
operator StringIfHelperType() const {
|
||||
return buffer ? &String::StringIfHelper : 0;
|
||||
}
|
||||
int compareTo(const String &s) const;
|
||||
unsigned char equals(const String &s) const;
|
||||
unsigned char equals(const char *cstr) const;
|
||||
unsigned char operator == (const String &rhs) const {return equals(rhs);}
|
||||
unsigned char operator == (const char *cstr) const {return equals(cstr);}
|
||||
unsigned char operator != (const String &rhs) const {return !equals(rhs);}
|
||||
unsigned char operator != (const char *cstr) const {return !equals(cstr);}
|
||||
unsigned char operator < (const String &rhs) const;
|
||||
unsigned char operator > (const String &rhs) const;
|
||||
unsigned char operator <= (const String &rhs) const;
|
||||
unsigned char operator >= (const String &rhs) const;
|
||||
unsigned char operator ==(const String &rhs) const {
|
||||
return equals(rhs);
|
||||
}
|
||||
unsigned char operator ==(const char *cstr) const {
|
||||
return equals(cstr);
|
||||
}
|
||||
unsigned char operator !=(const String &rhs) const {
|
||||
return !equals(rhs);
|
||||
}
|
||||
unsigned char operator !=(const char *cstr) const {
|
||||
return !equals(cstr);
|
||||
}
|
||||
unsigned char operator <(const String &rhs) const;
|
||||
unsigned char operator >(const String &rhs) const;
|
||||
unsigned char operator <=(const String &rhs) const;
|
||||
unsigned char operator >=(const String &rhs) const;
|
||||
unsigned char equalsIgnoreCase(const String &s) const;
|
||||
unsigned char startsWith( const String &prefix) const;
|
||||
unsigned char startsWith(const String &prefix) const;
|
||||
unsigned char startsWith(const String &prefix, unsigned int offset) const;
|
||||
unsigned char endsWith(const String &suffix) const;
|
||||
|
||||
// character acccess
|
||||
char charAt(unsigned int index) const;
|
||||
void setCharAt(unsigned int index, char c);
|
||||
char operator [] (unsigned int index) const;
|
||||
char& operator [] (unsigned int index);
|
||||
void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const;
|
||||
void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const
|
||||
{getBytes((unsigned char *)buf, bufsize, index);}
|
||||
const char * c_str() const { return buffer; }
|
||||
char operator [](unsigned int index) const;
|
||||
char& operator [](unsigned int index);
|
||||
void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index = 0) const;
|
||||
void toCharArray(char *buf, unsigned int bufsize, unsigned int index = 0) const {
|
||||
getBytes((unsigned char *) buf, bufsize, index);
|
||||
}
|
||||
const char * c_str() const {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// search
|
||||
int indexOf( char ch ) const;
|
||||
int indexOf( char ch, unsigned int fromIndex ) const;
|
||||
int indexOf( const String &str ) const;
|
||||
int indexOf( const String &str, unsigned int fromIndex ) const;
|
||||
int lastIndexOf( char ch ) const;
|
||||
int lastIndexOf( char ch, unsigned int fromIndex ) const;
|
||||
int lastIndexOf( const String &str ) const;
|
||||
int lastIndexOf( const String &str, unsigned int fromIndex ) const;
|
||||
String substring( unsigned int beginIndex ) const { return substring(beginIndex, len); };
|
||||
String substring( unsigned int beginIndex, unsigned int endIndex ) const;
|
||||
int indexOf(char ch) const;
|
||||
int indexOf(char ch, unsigned int fromIndex) const;
|
||||
int indexOf(const String &str) const;
|
||||
int indexOf(const String &str, unsigned int fromIndex) const;
|
||||
int lastIndexOf(char ch) const;
|
||||
int lastIndexOf(char ch, unsigned int fromIndex) const;
|
||||
int lastIndexOf(const String &str) const;
|
||||
int lastIndexOf(const String &str, unsigned int fromIndex) const;
|
||||
String substring(unsigned int beginIndex) const {
|
||||
return substring(beginIndex, len);
|
||||
}
|
||||
;
|
||||
String substring(unsigned int beginIndex, unsigned int endIndex) const;
|
||||
|
||||
// modification
|
||||
void replace(char find, char replace);
|
||||
@ -177,11 +225,11 @@ public:
|
||||
long toInt(void) const;
|
||||
float toFloat(void) const;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
char *buffer; // the actual char array
|
||||
unsigned int capacity; // the array length minus one (for the '\0')
|
||||
unsigned int len; // the String length (not counting the '\0')
|
||||
protected:
|
||||
protected:
|
||||
void init(void);
|
||||
void invalidate(void);
|
||||
unsigned char changeBuffer(unsigned int maxStrLen);
|
||||
@ -189,24 +237,43 @@ protected:
|
||||
|
||||
// copy and move
|
||||
String & copy(const char *cstr, unsigned int length);
|
||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||
#ifdef __GXX_EXPERIMENTAL_CXX0X__
|
||||
void move(String &rhs);
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
class StringSumHelper : public String
|
||||
{
|
||||
public:
|
||||
StringSumHelper(const String &s) : String(s) {}
|
||||
StringSumHelper(const char *p) : String(p) {}
|
||||
StringSumHelper(char c) : String(c) {}
|
||||
StringSumHelper(unsigned char num) : String(num) {}
|
||||
StringSumHelper(int num) : String(num) {}
|
||||
StringSumHelper(unsigned int num) : String(num) {}
|
||||
StringSumHelper(long num) : String(num) {}
|
||||
StringSumHelper(unsigned long num) : String(num) {}
|
||||
StringSumHelper(float num) : String(num) {}
|
||||
StringSumHelper(double num) : String(num) {}
|
||||
class StringSumHelper: public String {
|
||||
public:
|
||||
StringSumHelper(const String &s) :
|
||||
String(s) {
|
||||
}
|
||||
StringSumHelper(const char *p) :
|
||||
String(p) {
|
||||
}
|
||||
StringSumHelper(char c) :
|
||||
String(c) {
|
||||
}
|
||||
StringSumHelper(unsigned char num) :
|
||||
String(num) {
|
||||
}
|
||||
StringSumHelper(int num) :
|
||||
String(num) {
|
||||
}
|
||||
StringSumHelper(unsigned int num) :
|
||||
String(num) {
|
||||
}
|
||||
StringSumHelper(long num) :
|
||||
String(num) {
|
||||
}
|
||||
StringSumHelper(unsigned long num) :
|
||||
String(num) {
|
||||
}
|
||||
StringSumHelper(float num) :
|
||||
String(num) {
|
||||
}
|
||||
StringSumHelper(double num) :
|
||||
String(num) {
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __cplusplus
|
||||
|
@ -14,7 +14,7 @@
|
||||
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
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
extern "C" {
|
||||
@ -53,9 +53,9 @@ void __cxa_deleted_virtual(void) {
|
||||
}
|
||||
|
||||
namespace std {
|
||||
void __throw_bad_function_call() {
|
||||
void __throw_bad_function_call() {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: rebuild windows toolchain to make this unnecessary:
|
||||
|
@ -15,7 +15,7 @@
|
||||
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 Binary_h
|
||||
#define Binary_h
|
||||
|
@ -16,76 +16,57 @@
|
||||
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 __cbuf_h
|
||||
#define __cbuf_h
|
||||
|
||||
#include <stdint.h>
|
||||
class cbuf
|
||||
{
|
||||
public:
|
||||
cbuf(size_t size)
|
||||
: _size(size)
|
||||
, _buf(new char[size])
|
||||
, _bufend(_buf + size)
|
||||
, _begin(_buf)
|
||||
, _end(_begin)
|
||||
{
|
||||
class cbuf {
|
||||
public:
|
||||
cbuf(size_t size) :
|
||||
_size(size), _buf(new char[size]), _bufend(_buf + size), _begin(_buf), _end(_begin) {
|
||||
}
|
||||
|
||||
~cbuf()
|
||||
{
|
||||
~cbuf() {
|
||||
delete[] _buf;
|
||||
}
|
||||
|
||||
size_t getSize() const
|
||||
{
|
||||
if (_end >= _begin)
|
||||
return _end - _begin;
|
||||
size_t getSize() const {
|
||||
if(_end >= _begin) return _end - _begin;
|
||||
|
||||
return _size - (_begin - _end);
|
||||
}
|
||||
|
||||
size_t room() const
|
||||
{
|
||||
if (_end >= _begin)
|
||||
return _size - (_end - _begin) - 1;
|
||||
size_t room() const {
|
||||
if(_end >= _begin) return _size - (_end - _begin) - 1;
|
||||
|
||||
return _begin - _end - 1;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
bool empty() const {
|
||||
return _begin == _end;
|
||||
}
|
||||
|
||||
int peek()
|
||||
{
|
||||
if (_end == _begin)
|
||||
return -1;
|
||||
int peek() {
|
||||
if(_end == _begin) return -1;
|
||||
|
||||
return static_cast<int>(*_begin);
|
||||
}
|
||||
|
||||
int read()
|
||||
{
|
||||
if (getSize() == 0)
|
||||
return -1;
|
||||
int read() {
|
||||
if(getSize() == 0) return -1;
|
||||
|
||||
char result = *_begin;
|
||||
if (++_begin == _bufend)
|
||||
_begin = _buf;
|
||||
if(++_begin == _bufend) _begin = _buf;
|
||||
return static_cast<int>(result);
|
||||
}
|
||||
|
||||
size_t read(char* dst, size_t size)
|
||||
{
|
||||
size_t read(char* dst, size_t size) {
|
||||
size_t bytes_available = getSize();
|
||||
size_t size_to_read = (size < bytes_available) ? size : bytes_available;
|
||||
size_t size_read = size_to_read;
|
||||
if (_end < _begin && size_to_read > _bufend - _begin)
|
||||
{
|
||||
if(_end < _begin && size_to_read > _bufend - _begin) {
|
||||
size_t top_size = _bufend - _begin;
|
||||
memcpy(dst, _begin, top_size);
|
||||
_begin = _buf;
|
||||
@ -94,29 +75,23 @@ public:
|
||||
}
|
||||
memcpy(dst, _begin, size_to_read);
|
||||
_begin += size_to_read;
|
||||
if (_begin == _bufend)
|
||||
_begin = _buf;
|
||||
if(_begin == _bufend) _begin = _buf;
|
||||
return size_read;
|
||||
}
|
||||
|
||||
size_t write(char c)
|
||||
{
|
||||
if (room() == 0)
|
||||
return 0;
|
||||
size_t write(char c) {
|
||||
if(room() == 0) return 0;
|
||||
|
||||
*_end = c;
|
||||
if (++_end == _bufend)
|
||||
_end = _buf;
|
||||
if(++_end == _bufend) _end = _buf;
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t write(const char* src, size_t size)
|
||||
{
|
||||
size_t write(const char* src, size_t size) {
|
||||
size_t bytes_available = room();
|
||||
size_t size_to_write = (size < bytes_available) ? size : bytes_available;
|
||||
size_t size_written = size_to_write;
|
||||
if (_end > _begin && size_to_write > _bufend - _end)
|
||||
{
|
||||
if(_end > _begin && size_to_write > _bufend - _end) {
|
||||
size_t top_size = _bufend - _end;
|
||||
memcpy(_end, src, top_size);
|
||||
_end = _buf;
|
||||
@ -125,18 +100,16 @@ public:
|
||||
}
|
||||
memcpy(_end, src, size_to_write);
|
||||
_end += size_to_write;
|
||||
if (_end == _bufend)
|
||||
_end = _buf;
|
||||
if(_end == _bufend) _end = _buf;
|
||||
return size_written;
|
||||
}
|
||||
|
||||
void flush()
|
||||
{
|
||||
void flush() {
|
||||
_begin = _buf;
|
||||
_end = _buf;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
size_t _size;
|
||||
char* _buf;
|
||||
char* _bufend;
|
||||
@ -144,5 +117,4 @@ private:
|
||||
char* _end;
|
||||
};
|
||||
|
||||
|
||||
#endif//__cbuf_h
|
||||
|
@ -16,8 +16,7 @@
|
||||
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 CONT_H_
|
||||
#define CONT_H_
|
||||
@ -26,8 +25,7 @@
|
||||
#define CONT_STACKSIZE 4096
|
||||
#endif
|
||||
|
||||
typedef struct cont_
|
||||
{
|
||||
typedef struct cont_ {
|
||||
void (*pc_ret)(void);
|
||||
unsigned* sp_ret;
|
||||
|
||||
@ -44,11 +42,11 @@ typedef struct cont_
|
||||
} cont_t;
|
||||
|
||||
// Initialize the cont_t structure before calling cont_run
|
||||
void cont_init (cont_t*);
|
||||
void cont_init(cont_t*);
|
||||
|
||||
// Run function pfn in a separate stack, or continue execution
|
||||
// at the point where cont_yield was called
|
||||
void cont_run(cont_t*, void(*pfn)(void));
|
||||
void cont_run(cont_t*, void (*pfn)(void));
|
||||
|
||||
// Return to the point where cont_run was called, saving the
|
||||
// execution state (registers and stack)
|
||||
|
@ -16,25 +16,21 @@
|
||||
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
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "cont.h"
|
||||
|
||||
#define CONT_STACKGUARD 0xfeefeffe
|
||||
|
||||
void cont_init(cont_t* cont)
|
||||
{
|
||||
void cont_init(cont_t* cont) {
|
||||
cont->stack_guard1 = CONT_STACKGUARD;
|
||||
cont->stack_guard2 = CONT_STACKGUARD;
|
||||
cont->stack_end = cont->stack + (sizeof(cont->stack) / 4 - 1);
|
||||
cont->struct_start = (unsigned*) cont;
|
||||
}
|
||||
|
||||
int cont_check(cont_t* cont)
|
||||
{
|
||||
if (cont->stack_guard1 != CONT_STACKGUARD ||
|
||||
cont->stack_guard2 != CONT_STACKGUARD )
|
||||
return 1;
|
||||
int cont_check(cont_t* cont) {
|
||||
if(cont->stack_guard1 != CONT_STACKGUARD || cont->stack_guard2 != CONT_STACKGUARD) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -18,11 +18,10 @@
|
||||
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
|
||||
*/
|
||||
*/
|
||||
|
||||
//This may be used to change user task stack size:
|
||||
//#define CONT_STACKSIZE 4096
|
||||
|
||||
#include <Arduino.h>
|
||||
extern "C" {
|
||||
#include "ets_sys.h"
|
||||
@ -35,26 +34,26 @@ extern "C" {
|
||||
#define LOOP_TASK_PRIORITY 0
|
||||
#define LOOP_QUEUE_SIZE 1
|
||||
|
||||
int atexit(void (*func)()) { return 0; }
|
||||
int atexit(void (*func)()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" void ets_update_cpu_frequency(int freqmhz);
|
||||
void initVariant() __attribute__((weak));
|
||||
void initVariant() { }
|
||||
void initVariant() {
|
||||
}
|
||||
|
||||
extern void loop();
|
||||
extern void setup();
|
||||
|
||||
void preloop_update_frequency() __attribute__((weak));
|
||||
void preloop_update_frequency()
|
||||
{
|
||||
void preloop_update_frequency() {
|
||||
#if defined(F_CPU) && (F_CPU == 16000000L)
|
||||
REG_SET_BIT(0x3ff00014, BIT(0));
|
||||
ets_update_cpu_frequency(160);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern void (*__init_array_start)(void);
|
||||
extern void (*__init_array_end)(void);
|
||||
|
||||
@ -63,39 +62,32 @@ static os_event_t g_loop_queue[LOOP_QUEUE_SIZE];
|
||||
|
||||
static uint32_t g_micros_at_task_start;
|
||||
|
||||
extern "C" uint32_t esp_micros_at_task_start()
|
||||
{
|
||||
extern "C" uint32_t esp_micros_at_task_start() {
|
||||
return g_micros_at_task_start;
|
||||
}
|
||||
|
||||
extern "C" void abort()
|
||||
{
|
||||
while(1){}
|
||||
extern "C" void abort() {
|
||||
while(1) {
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void esp_yield()
|
||||
{
|
||||
extern "C" void esp_yield() {
|
||||
cont_yield(&g_cont);
|
||||
}
|
||||
|
||||
extern "C" void esp_schedule()
|
||||
{
|
||||
extern "C" void esp_schedule() {
|
||||
system_os_post(LOOP_TASK_PRIORITY, 0, 0);
|
||||
}
|
||||
|
||||
extern "C" void __yield()
|
||||
{
|
||||
extern "C" void __yield() {
|
||||
esp_schedule();
|
||||
esp_yield();
|
||||
}
|
||||
extern "C" void yield(void) __attribute__ ((weak, alias("__yield")));
|
||||
|
||||
|
||||
static void loop_wrapper()
|
||||
{
|
||||
static void loop_wrapper() {
|
||||
static bool setup_done = false;
|
||||
if (!setup_done)
|
||||
{
|
||||
if(!setup_done) {
|
||||
setup();
|
||||
setup_done = true;
|
||||
}
|
||||
@ -104,33 +96,28 @@ static void loop_wrapper()
|
||||
esp_schedule();
|
||||
}
|
||||
|
||||
static void loop_task(os_event_t *events)
|
||||
{
|
||||
static void loop_task(os_event_t *events) {
|
||||
g_micros_at_task_start = system_get_time();
|
||||
cont_run(&g_cont, &loop_wrapper);
|
||||
if (cont_check(&g_cont) != 0)
|
||||
{
|
||||
if(cont_check(&g_cont) != 0) {
|
||||
ets_printf("\r\nheap collided with sketch stack\r\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
static void do_global_ctors(void)
|
||||
{
|
||||
static void do_global_ctors(void) {
|
||||
void (**p)(void);
|
||||
for (p = &__init_array_start; p != &__init_array_end; ++p)
|
||||
for(p = &__init_array_start; p != &__init_array_end; ++p)
|
||||
(*p)();
|
||||
}
|
||||
|
||||
void init_done()
|
||||
{
|
||||
void init_done() {
|
||||
do_global_ctors();
|
||||
esp_schedule();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void user_init(void)
|
||||
{
|
||||
void user_init(void) {
|
||||
uart_div_modify(0, UART_CLK_FREQ / (115200));
|
||||
|
||||
init();
|
||||
@ -139,9 +126,8 @@ void user_init(void)
|
||||
|
||||
cont_init(&g_cont);
|
||||
|
||||
system_os_task( loop_task,
|
||||
LOOP_TASK_PRIORITY,
|
||||
g_loop_queue,
|
||||
system_os_task(loop_task,
|
||||
LOOP_TASK_PRIORITY, g_loop_queue,
|
||||
LOOP_QUEUE_SIZE);
|
||||
|
||||
system_init_done_cb(&init_done);
|
||||
|
@ -72,7 +72,8 @@ char* itoa(int value, char* result, int base) {
|
||||
} while(quotient);
|
||||
|
||||
// Apply negative sign
|
||||
if(value < 0) *out++ = '-';
|
||||
if(value < 0)
|
||||
*out++ = '-';
|
||||
|
||||
reverse(result, out);
|
||||
*out = 0;
|
||||
@ -96,7 +97,8 @@ char* ltoa(long value, char* result, int base) {
|
||||
} while(quotient);
|
||||
|
||||
// Apply negative sign
|
||||
if(value < 0) *out++ = '-';
|
||||
if(value < 0)
|
||||
*out++ = '-';
|
||||
|
||||
reverse(result, out);
|
||||
*out = 0;
|
||||
@ -194,3 +196,4 @@ char * dtostrf(double number, signed char width, unsigned char prec, char *s) {
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,7 @@
|
||||
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
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
#include "wiring_private.h"
|
||||
#include "ets_sys.h"
|
||||
@ -36,57 +35,45 @@ static uint32_t micros_overflow_count = 0;
|
||||
#define ONCE 0
|
||||
#define REPEAT 1
|
||||
|
||||
|
||||
void delay_end(void* arg)
|
||||
{
|
||||
void delay_end(void* arg) {
|
||||
esp_schedule();
|
||||
}
|
||||
|
||||
void delay(unsigned long ms)
|
||||
{
|
||||
if (ms)
|
||||
{
|
||||
void delay(unsigned long ms) {
|
||||
if(ms) {
|
||||
os_timer_setfn(&delay_timer, (os_timer_func_t*) &delay_end, 0);
|
||||
os_timer_arm(&delay_timer, ms, ONCE);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
esp_schedule();
|
||||
}
|
||||
esp_yield();
|
||||
if (ms)
|
||||
{
|
||||
if(ms) {
|
||||
os_timer_disarm(&delay_timer);
|
||||
}
|
||||
}
|
||||
|
||||
void micros_overflow_tick(void* arg)
|
||||
{
|
||||
void micros_overflow_tick(void* arg) {
|
||||
uint32_t m = system_get_time();
|
||||
if (m < micros_at_last_overflow_tick)
|
||||
if(m < micros_at_last_overflow_tick)
|
||||
++micros_overflow_count;
|
||||
micros_at_last_overflow_tick = m;
|
||||
}
|
||||
|
||||
unsigned long millis()
|
||||
{
|
||||
unsigned long millis() {
|
||||
uint32_t m = system_get_time();
|
||||
uint32_t c = micros_overflow_count + ((m < micros_at_last_overflow_tick) ? 1 : 0);
|
||||
return c * 4294967 + m / 1000;
|
||||
}
|
||||
|
||||
unsigned long micros()
|
||||
{
|
||||
unsigned long micros() {
|
||||
return system_get_time();
|
||||
}
|
||||
|
||||
void delayMicroseconds(unsigned int us)
|
||||
{
|
||||
void delayMicroseconds(unsigned int us) {
|
||||
os_delay_us(us);
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
void init() {
|
||||
initPins();
|
||||
os_timer_setfn(µs_overflow_timer, (os_timer_func_t*) µs_overflow_tick, 0);
|
||||
os_timer_arm(µs_overflow_timer, 60000, REPEAT);
|
||||
|
@ -17,23 +17,19 @@
|
||||
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
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "wiring_private.h"
|
||||
#include "pins_arduino.h"
|
||||
|
||||
|
||||
void analogReference(uint8_t mode)
|
||||
{
|
||||
void analogReference(uint8_t mode) {
|
||||
}
|
||||
|
||||
extern int __analogRead(uint8_t pin)
|
||||
{
|
||||
if (pin == 0)
|
||||
extern int __analogRead(uint8_t pin) {
|
||||
if(pin == 0)
|
||||
return system_adc_read();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
extern int analogRead(uint8_t pin) __attribute__ ((weak, alias("__analogRead")));
|
||||
|
@ -17,7 +17,7 @@
|
||||
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
|
||||
*/
|
||||
*/
|
||||
|
||||
#define ARDUINO_MAIN
|
||||
#include "wiring_private.h"
|
||||
@ -31,77 +31,42 @@
|
||||
|
||||
#define PINCOUNT 16
|
||||
|
||||
static const uint32_t g_pin_muxes[PINCOUNT] = {
|
||||
[0] = PERIPHS_IO_MUX_GPIO0_U,
|
||||
[1] = PERIPHS_IO_MUX_U0TXD_U,
|
||||
[2] = PERIPHS_IO_MUX_GPIO2_U,
|
||||
[3] = PERIPHS_IO_MUX_U0RXD_U,
|
||||
[4] = PERIPHS_IO_MUX_GPIO4_U,
|
||||
[5] = PERIPHS_IO_MUX_GPIO5_U,
|
||||
static const uint32_t g_pin_muxes[PINCOUNT] = { [0] = PERIPHS_IO_MUX_GPIO0_U, [1] = PERIPHS_IO_MUX_U0TXD_U, [2] = PERIPHS_IO_MUX_GPIO2_U, [3] = PERIPHS_IO_MUX_U0RXD_U, [4] = PERIPHS_IO_MUX_GPIO4_U, [5] = PERIPHS_IO_MUX_GPIO5_U,
|
||||
|
||||
// These 6 pins are used for SPI flash interface
|
||||
[6] = 0,
|
||||
[7] = 0,
|
||||
[8] = 0,
|
||||
[9] = 0,
|
||||
[10] = 0,
|
||||
[11] = 0,
|
||||
// These 6 pins are used for SPI flash interface
|
||||
[6] = 0, [7] = 0, [8] = 0, [9] = 0, [10] = 0, [11] = 0,
|
||||
|
||||
[12] = PERIPHS_IO_MUX_MTDI_U,
|
||||
[13] = PERIPHS_IO_MUX_MTCK_U,
|
||||
[14] = PERIPHS_IO_MUX_MTMS_U,
|
||||
[15] = PERIPHS_IO_MUX_MTDO_U,
|
||||
};
|
||||
[12] = PERIPHS_IO_MUX_MTDI_U, [13] = PERIPHS_IO_MUX_MTCK_U, [14] = PERIPHS_IO_MUX_MTMS_U, [15] = PERIPHS_IO_MUX_MTDO_U, };
|
||||
|
||||
static const uint32_t g_pin_funcs[PINCOUNT] = {
|
||||
[0] = FUNC_GPIO0,
|
||||
[1] = FUNC_GPIO1,
|
||||
[2] = FUNC_GPIO2,
|
||||
[3] = FUNC_GPIO3,
|
||||
[4] = FUNC_GPIO4,
|
||||
[5] = FUNC_GPIO5,
|
||||
[12] = FUNC_GPIO12,
|
||||
[13] = FUNC_GPIO13,
|
||||
[14] = FUNC_GPIO14,
|
||||
[15] = FUNC_GPIO15,
|
||||
};
|
||||
static const uint32_t g_pin_funcs[PINCOUNT] = { [0] = FUNC_GPIO0, [1] = FUNC_GPIO1, [2] = FUNC_GPIO2, [3] = FUNC_GPIO3, [4] = FUNC_GPIO4, [5] = FUNC_GPIO5, [12] = FUNC_GPIO12, [13] = FUNC_GPIO13, [14] = FUNC_GPIO14, [15] = FUNC_GPIO15, };
|
||||
|
||||
|
||||
uint32_t digitalPinToPort(uint32_t pin)
|
||||
{
|
||||
uint32_t digitalPinToPort(uint32_t pin) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t digitalPinToBitMask(uint32_t pin)
|
||||
{
|
||||
uint32_t digitalPinToBitMask(uint32_t pin) {
|
||||
return 1 << pin;
|
||||
}
|
||||
|
||||
volatile uint32_t* portOutputRegister(uint32_t port)
|
||||
{
|
||||
volatile uint32_t* portOutputRegister(uint32_t port) {
|
||||
return (volatile uint32_t*) (PERIPHS_GPIO_BASEADDR + GPIO_OUT_ADDRESS);
|
||||
}
|
||||
|
||||
volatile uint32_t* portInputRegister(uint32_t port)
|
||||
{
|
||||
volatile uint32_t* portInputRegister(uint32_t port) {
|
||||
return (volatile uint32_t*) (PERIPHS_GPIO_BASEADDR + GPIO_IN_ADDRESS);
|
||||
}
|
||||
|
||||
volatile uint32_t* portModeRegister(uint32_t port)
|
||||
{
|
||||
volatile uint32_t* portModeRegister(uint32_t port) {
|
||||
return (volatile uint32_t*) (PERIPHS_GPIO_BASEADDR + GPIO_ENABLE_ADDRESS);
|
||||
}
|
||||
|
||||
|
||||
enum PinFunction { GPIO, PWM };
|
||||
static uint32_t g_gpio_function[PINCOUNT] = {
|
||||
GPIO
|
||||
enum PinFunction {
|
||||
GPIO, PWM
|
||||
};
|
||||
static uint32_t g_gpio_function[PINCOUNT] = { GPIO };
|
||||
|
||||
extern void __pinMode(uint8_t pin, uint8_t mode)
|
||||
{
|
||||
if (pin == 16)
|
||||
{
|
||||
extern void __pinMode(uint8_t pin, uint8_t mode) {
|
||||
if(pin == 16) {
|
||||
uint32_t val = (mode == OUTPUT) ? 1 : 0;
|
||||
|
||||
MODIFY_PERI_REG(PAD_XPD_DCDC_CONF, 0x43, 1);
|
||||
@ -111,115 +76,84 @@ extern void __pinMode(uint8_t pin, uint8_t mode)
|
||||
}
|
||||
|
||||
uint32_t mux = g_pin_muxes[pin];
|
||||
if (mode == INPUT)
|
||||
{
|
||||
if(mode == INPUT) {
|
||||
gpio_output_set(0, 0, 0, 1 << pin);
|
||||
PIN_PULLUP_DIS(mux);
|
||||
}
|
||||
else if (mode == INPUT_PULLUP)
|
||||
{
|
||||
} else if(mode == INPUT_PULLUP) {
|
||||
gpio_output_set(0, 0, 0, 1 << pin);
|
||||
PIN_PULLUP_EN(mux);
|
||||
}
|
||||
else if (mode == OUTPUT)
|
||||
{
|
||||
} else if(mode == OUTPUT) {
|
||||
gpio_output_set(0, 0, 1 << pin, 0);
|
||||
}
|
||||
else if (mode == OUTPUT_OPEN_DRAIN)
|
||||
{
|
||||
GPIO_REG_WRITE(
|
||||
GPIO_PIN_ADDR(GPIO_ID_PIN(pin)),
|
||||
GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin))) |
|
||||
GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)
|
||||
);
|
||||
} else if(mode == OUTPUT_OPEN_DRAIN) {
|
||||
GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE));
|
||||
|
||||
GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << pin));
|
||||
}
|
||||
}
|
||||
|
||||
extern void __digitalWrite(uint8_t pin, uint8_t val)
|
||||
{
|
||||
if (pin == 16)
|
||||
{
|
||||
extern void __digitalWrite(uint8_t pin, uint8_t val) {
|
||||
if(pin == 16) {
|
||||
MODIFY_PERI_REG(RTC_GPIO_OUT, 1, (val & 1));
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t mask = 1 << pin;
|
||||
if (val)
|
||||
if(val)
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, mask);
|
||||
else
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, mask);
|
||||
}
|
||||
|
||||
extern int __digitalRead(uint8_t pin)
|
||||
{
|
||||
if (pin == 16)
|
||||
extern int __digitalRead(uint8_t pin) {
|
||||
if(pin == 16)
|
||||
return (READ_PERI_REG(RTC_GPIO_IN_DATA) & 1);
|
||||
else
|
||||
return ((gpio_input_get() >> pin) & 1);
|
||||
}
|
||||
|
||||
extern void __analogWrite(uint8_t pin, int val)
|
||||
{
|
||||
extern void __analogWrite(uint8_t pin, int val) {
|
||||
}
|
||||
|
||||
typedef void (*voidFuncPtr)(void);
|
||||
static voidFuncPtr g_handlers[PINCOUNT] = { 0 };
|
||||
|
||||
|
||||
void interrupt_handler(void *arg)
|
||||
{
|
||||
void interrupt_handler(void *arg) {
|
||||
uint32_t intr_mask = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
|
||||
for (int pin = 0; intr_mask; intr_mask >>= 1, ++pin)
|
||||
{
|
||||
if ((intr_mask & 1) && g_handlers[pin])
|
||||
{
|
||||
for(int pin = 0; intr_mask; intr_mask >>= 1, ++pin) {
|
||||
if((intr_mask & 1) && g_handlers[pin]) {
|
||||
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, 1 << pin);
|
||||
(*g_handlers[pin])();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern void __attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode)
|
||||
{
|
||||
if (pin < 0 || pin > PINCOUNT)
|
||||
extern void __attachInterrupt(uint8_t pin, voidFuncPtr handler, int mode) {
|
||||
if(pin < 0 || pin > PINCOUNT)
|
||||
return;
|
||||
|
||||
g_handlers[pin] = handler;
|
||||
|
||||
if (mode == RISING)
|
||||
{
|
||||
if(mode == RISING) {
|
||||
gpio_pin_intr_state_set(pin, GPIO_PIN_INTR_POSEDGE);
|
||||
}
|
||||
else if (mode == FALLING)
|
||||
{
|
||||
} else if(mode == FALLING) {
|
||||
gpio_pin_intr_state_set(pin, GPIO_PIN_INTR_NEGEDGE);
|
||||
}
|
||||
else if (mode == CHANGE)
|
||||
{
|
||||
} else if(mode == CHANGE) {
|
||||
gpio_pin_intr_state_set(pin, GPIO_PIN_INTR_ANYEDGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
gpio_pin_intr_state_set(pin, GPIO_PIN_INTR_DISABLE);
|
||||
}
|
||||
}
|
||||
|
||||
extern void __detachInterrupt(uint8_t pin)
|
||||
{
|
||||
extern void __detachInterrupt(uint8_t pin) {
|
||||
g_handlers[pin] = 0;
|
||||
gpio_pin_intr_state_set(pin, GPIO_PIN_INTR_DISABLE);
|
||||
}
|
||||
|
||||
void initPins()
|
||||
{
|
||||
void initPins() {
|
||||
gpio_init();
|
||||
for (int i = 0; i < PINCOUNT; ++i)
|
||||
{
|
||||
for(int i = 0; i < PINCOUNT; ++i) {
|
||||
uint32_t mux = g_pin_muxes[i];
|
||||
if (mux)
|
||||
{
|
||||
if(mux) {
|
||||
uint32_t func = g_pin_funcs[i];
|
||||
PIN_FUNC_SELECT(mux, func);
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
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
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "wiring_private.h"
|
||||
#include "pins_arduino.h"
|
||||
@ -26,7 +26,6 @@
|
||||
* or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds
|
||||
* to 3 minutes in length, but must be called at least a few dozen microseconds
|
||||
* before the start of the pulse. */
|
||||
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
|
||||
{
|
||||
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "wiring_private.h"
|
||||
|
||||
@ -31,9 +31,9 @@ uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
|
||||
uint8_t value = 0;
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < 8; ++i) {
|
||||
for(i = 0; i < 8; ++i) {
|
||||
digitalWrite(clockPin, HIGH);
|
||||
if (bitOrder == LSBFIRST)
|
||||
if(bitOrder == LSBFIRST)
|
||||
value |= digitalRead(dataPin) << i;
|
||||
else
|
||||
value |= digitalRead(dataPin) << (7 - i);
|
||||
@ -42,12 +42,11 @@ uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
|
||||
return value;
|
||||
}
|
||||
|
||||
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
|
||||
{
|
||||
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) {
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (bitOrder == LSBFIRST)
|
||||
for(i = 0; i < 8; i++) {
|
||||
if(bitOrder == LSBFIRST)
|
||||
digitalWrite(dataPin, !!(val & (1 << i)));
|
||||
else
|
||||
digitalWrite(dataPin, !!(val & (1 << (7 - i))));
|
||||
|
@ -17,7 +17,7 @@
|
||||
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
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "i2c.h"
|
||||
@ -33,56 +33,46 @@ static uint8_t s_sda_pin = 0;
|
||||
static uint8_t s_scl_pin = 2;
|
||||
static uint32_t s_i2c_delay = 5;
|
||||
|
||||
static inline void i2c_digital_write(int pin, int val)
|
||||
{
|
||||
static inline void i2c_digital_write(int pin, int val) {
|
||||
uint32_t mask = 1 << pin;
|
||||
if (val)
|
||||
if(val)
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, mask);
|
||||
else
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, mask);
|
||||
}
|
||||
|
||||
static inline void i2c_set(int sda, int scl)
|
||||
{
|
||||
static inline void i2c_set(int sda, int scl) {
|
||||
i2c_digital_write(s_sda_pin, sda);
|
||||
i2c_digital_write(s_scl_pin, scl);
|
||||
}
|
||||
|
||||
static inline void i2c_set_sda(int sda)
|
||||
{
|
||||
static inline void i2c_set_sda(int sda) {
|
||||
i2c_digital_write(s_sda_pin, sda);
|
||||
}
|
||||
|
||||
static inline void i2c_set_scl(int scl)
|
||||
{
|
||||
static inline void i2c_set_scl(int scl) {
|
||||
i2c_digital_write(s_scl_pin, scl);
|
||||
}
|
||||
|
||||
static inline uint8_t i2c_get_sda()
|
||||
{
|
||||
static inline uint8_t i2c_get_sda() {
|
||||
return GPIO_INPUT_GET(GPIO_ID_PIN(s_sda_pin));
|
||||
}
|
||||
|
||||
static inline uint8_t i2c_get_scl()
|
||||
{
|
||||
static inline uint8_t i2c_get_scl() {
|
||||
return GPIO_INPUT_GET(GPIO_ID_PIN(s_scl_pin));
|
||||
}
|
||||
|
||||
|
||||
static inline void i2c_wait()
|
||||
{
|
||||
static inline void i2c_wait() {
|
||||
delayMicroseconds(s_i2c_delay);
|
||||
}
|
||||
|
||||
void i2c_freq(int freq_hz)
|
||||
{
|
||||
void i2c_freq(int freq_hz) {
|
||||
s_i2c_delay = 1000000 / freq_hz / 4 - 1;
|
||||
if (s_i2c_delay < 0)
|
||||
if(s_i2c_delay < 0)
|
||||
s_i2c_delay = 0;
|
||||
}
|
||||
|
||||
void i2c_init(int sda_pin, int scl_pin)
|
||||
{
|
||||
void i2c_init(int sda_pin, int scl_pin) {
|
||||
s_sda_pin = sda_pin;
|
||||
s_scl_pin = scl_pin;
|
||||
pinMode(ESP_PINS_OFFSET + sda_pin, OUTPUT_OPEN_DRAIN);
|
||||
@ -91,15 +81,12 @@ void i2c_init(int sda_pin, int scl_pin)
|
||||
i2c_wait();
|
||||
}
|
||||
|
||||
|
||||
void i2c_release()
|
||||
{
|
||||
void i2c_release() {
|
||||
pinMode(ESP_PINS_OFFSET + s_sda_pin, INPUT);
|
||||
pinMode(ESP_PINS_OFFSET + s_scl_pin, INPUT);
|
||||
}
|
||||
|
||||
void i2c_start()
|
||||
{
|
||||
void i2c_start() {
|
||||
i2c_set(1, 1);
|
||||
i2c_wait();
|
||||
i2c_set_sda(0);
|
||||
@ -109,8 +96,7 @@ void i2c_start()
|
||||
i2c_wait();
|
||||
}
|
||||
|
||||
void i2c_stop()
|
||||
{
|
||||
void i2c_stop() {
|
||||
i2c_wait();
|
||||
i2c_set_scl(1);
|
||||
i2c_wait();
|
||||
@ -118,8 +104,7 @@ void i2c_stop()
|
||||
i2c_wait();
|
||||
}
|
||||
|
||||
void i2c_set_ack(int ack)
|
||||
{
|
||||
void i2c_set_ack(int ack) {
|
||||
i2c_set_sda(!ack);
|
||||
i2c_wait();
|
||||
i2c_set_scl(1);
|
||||
@ -130,8 +115,7 @@ void i2c_set_ack(int ack)
|
||||
i2c_wait();
|
||||
}
|
||||
|
||||
int i2c_get_ack()
|
||||
{
|
||||
int i2c_get_ack() {
|
||||
i2c_set_scl(1);
|
||||
i2c_wait();
|
||||
int result = i2c_get_sda();
|
||||
@ -142,11 +126,9 @@ int i2c_get_ack()
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t i2c_read(void)
|
||||
{
|
||||
uint8_t i2c_read(void) {
|
||||
uint8_t result = 0;
|
||||
for (int i = 7; i >= 0; --i)
|
||||
{
|
||||
for(int i = 7; i >= 0; --i) {
|
||||
i2c_wait();
|
||||
i2c_set_scl(1);
|
||||
i2c_wait();
|
||||
@ -157,11 +139,8 @@ uint8_t i2c_read(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void i2c_write(uint8_t val)
|
||||
{
|
||||
for (int i = 7; i >= 0; --i)
|
||||
{
|
||||
void i2c_write(uint8_t val) {
|
||||
for(int i = 7; i >= 0; --i) {
|
||||
i2c_set_sda((val >> i) & 1);
|
||||
i2c_wait();
|
||||
i2c_set_scl(1);
|
||||
@ -172,78 +151,72 @@ void i2c_write(uint8_t val)
|
||||
i2c_set_sda(1);
|
||||
}
|
||||
|
||||
size_t i2c_master_read_from(int address, uint8_t* data, size_t size, bool sendStop)
|
||||
{
|
||||
size_t i2c_master_read_from(int address, uint8_t* data, size_t size, bool sendStop) {
|
||||
i2c_start();
|
||||
i2c_write(address << 1 | 1);
|
||||
int ack = i2c_get_ack();
|
||||
uint8_t* end = data + size;
|
||||
for (;data != end; ++data )
|
||||
{
|
||||
for(; data != end; ++data) {
|
||||
i2c_set_sda(1);
|
||||
pinMode(ESP_PINS_OFFSET + s_sda_pin, INPUT);
|
||||
*data = i2c_read();
|
||||
pinMode(ESP_PINS_OFFSET + s_sda_pin, OUTPUT_OPEN_DRAIN);
|
||||
if (data == end - 1)
|
||||
if(data == end - 1)
|
||||
i2c_set_ack(0);
|
||||
else
|
||||
i2c_set_ack(1);
|
||||
}
|
||||
if (sendStop)
|
||||
if(sendStop)
|
||||
i2c_stop();
|
||||
return size;
|
||||
}
|
||||
|
||||
size_t i2c_master_write_to(int address, const uint8_t* data, size_t size, bool sendStop)
|
||||
{
|
||||
size_t i2c_master_write_to(int address, const uint8_t* data, size_t size, bool sendStop) {
|
||||
i2c_start();
|
||||
i2c_write(address << 1);
|
||||
int ack = i2c_get_ack();
|
||||
const uint8_t* end = data + size;
|
||||
for (;data != end; ++data )
|
||||
{
|
||||
for(; data != end; ++data) {
|
||||
i2c_write(*data);
|
||||
ack = i2c_get_ack();
|
||||
}
|
||||
if (sendStop)
|
||||
if(sendStop)
|
||||
i2c_stop();
|
||||
return size;
|
||||
}
|
||||
|
||||
// some stubs for libraries that use private twi.h interface
|
||||
extern "C"
|
||||
{
|
||||
void twi_init(void) { }
|
||||
|
||||
void twi_setAddress(uint8_t) { }
|
||||
|
||||
uint8_t twi_readFrom(uint8_t addr, uint8_t* data, uint8_t size, uint8_t sendStop)
|
||||
{
|
||||
return i2c_master_read_from(addr, data, size, sendStop);
|
||||
}
|
||||
|
||||
uint8_t twi_writeTo(uint8_t addr, uint8_t* data, uint8_t size, uint8_t wait, uint8_t sendStop)
|
||||
{
|
||||
return i2c_master_write_to(addr, data, size, sendStop);
|
||||
}
|
||||
|
||||
uint8_t twi_transmit(const uint8_t* data, uint8_t length)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void twi_attachSlaveRxEvent( void (*)(uint8_t*, int) ) { }
|
||||
void twi_attachSlaveTxEvent( void (*)(void) ) { }
|
||||
void twi_reply(uint8_t) { }
|
||||
void twi_stop(void)
|
||||
{
|
||||
i2c_stop();
|
||||
}
|
||||
|
||||
void twi_releaseBus(void)
|
||||
{
|
||||
i2c_set(1, 1);
|
||||
}
|
||||
extern "C" {
|
||||
void twi_init(void) {
|
||||
}
|
||||
|
||||
void twi_setAddress(uint8_t) {
|
||||
}
|
||||
|
||||
uint8_t twi_readFrom(uint8_t addr, uint8_t* data, uint8_t size, uint8_t sendStop) {
|
||||
return i2c_master_read_from(addr, data, size, sendStop);
|
||||
}
|
||||
|
||||
uint8_t twi_writeTo(uint8_t addr, uint8_t* data, uint8_t size, uint8_t wait, uint8_t sendStop) {
|
||||
return i2c_master_write_to(addr, data, size, sendStop);
|
||||
}
|
||||
|
||||
uint8_t twi_transmit(const uint8_t* data, uint8_t length) {
|
||||
|
||||
}
|
||||
|
||||
void twi_attachSlaveRxEvent(void (*)(uint8_t*, int)) {
|
||||
}
|
||||
void twi_attachSlaveTxEvent(void (*)(void)) {
|
||||
}
|
||||
void twi_reply(uint8_t) {
|
||||
}
|
||||
void twi_stop(void) {
|
||||
i2c_stop();
|
||||
}
|
||||
|
||||
void twi_releaseBus(void) {
|
||||
i2c_set(1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
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 I2C_H
|
||||
#define I2C_H
|
||||
@ -34,7 +34,6 @@ int i2c_get_ack();
|
||||
uint8_t i2c_read(void);
|
||||
void i2c_write(uint8_t val);
|
||||
|
||||
|
||||
size_t i2c_master_read_from(int address, uint8_t* data, size_t size, bool sendStop);
|
||||
size_t i2c_master_write_to(int address, const uint8_t* data, size_t size, bool sendStop);
|
||||
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include "mem.h"
|
||||
#include "user_interface.h"
|
||||
|
||||
|
||||
void* malloc(size_t size) {
|
||||
return os_malloc(size);
|
||||
}
|
||||
@ -49,7 +48,7 @@ void* realloc(void* ptr, size_t size) {
|
||||
return os_realloc(ptr, size);
|
||||
}
|
||||
|
||||
int puts(const char * str){
|
||||
int puts(const char * str) {
|
||||
return os_printf("%s", str);
|
||||
}
|
||||
|
||||
@ -223,7 +222,6 @@ char * strdup(const char *str) {
|
||||
return cstr;
|
||||
}
|
||||
|
||||
|
||||
long int ICACHE_FLASH_ATTR strtol(const char* str, char** endptr, int base) {
|
||||
long int result = 0;
|
||||
int sign = 1;
|
||||
@ -275,7 +273,6 @@ long int ICACHE_FLASH_ATTR strtol(const char* str, char** endptr, int base) {
|
||||
return sign * result;
|
||||
}
|
||||
|
||||
|
||||
// based on Source:
|
||||
// https://github.com/anakod/Sming/blob/master/Sming/system/stringconversion.cpp#L93
|
||||
double ICACHE_FLASH_ATTR strtod(const char* str, char** endptr) {
|
||||
|
@ -6,7 +6,6 @@
|
||||
#define PROGMEM
|
||||
#define PGM_P const char *
|
||||
#define PSTR(str) (str)
|
||||
#define F(str) (str)
|
||||
|
||||
#define vsnprintf_P(...) vsnprintf( __VA_ARGS__ )
|
||||
#define snprintf_P(...) snprintf( __VA_ARGS__ )
|
||||
|
@ -17,7 +17,7 @@
|
||||
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 SIGMA_DELTA_H
|
||||
#define SIGMA_DELTA_H
|
||||
|
@ -20,7 +20,7 @@
|
||||
Boston, MA 02111-1307 USA
|
||||
|
||||
$Id: wiring.h 239 2007-01-12 17:58:39Z mellis $
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef WiringPrivate_h
|
||||
#define WiringPrivate_h
|
||||
@ -31,7 +31,7 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*voidFuncPtr)(void);
|
||||
|
@ -17,33 +17,22 @@
|
||||
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 CLIENTCONTEXT_H
|
||||
#define CLIENTCONTEXT_H
|
||||
|
||||
class ClientContext;
|
||||
class WiFiClient;
|
||||
|
||||
typedef void(*discard_cb_t)(void*, ClientContext*);
|
||||
typedef void (*discard_cb_t)(void*, ClientContext*);
|
||||
|
||||
extern "C" void esp_yield();
|
||||
extern "C" void esp_schedule();
|
||||
|
||||
|
||||
class ClientContext
|
||||
{
|
||||
public:
|
||||
ClientContext(tcp_pcb* pcb,
|
||||
discard_cb_t discard_cb, void* discard_cb_arg)
|
||||
: _pcb(pcb)
|
||||
, _rx_buf(0)
|
||||
, _rx_buf_offset(0)
|
||||
, _discard_cb(discard_cb)
|
||||
, _discard_cb_arg(discard_cb_arg)
|
||||
, _refcnt(0)
|
||||
, _next(0)
|
||||
, _send_waiting(false)
|
||||
{
|
||||
class ClientContext {
|
||||
public:
|
||||
ClientContext(tcp_pcb* pcb, discard_cb_t discard_cb, void* discard_cb_arg) :
|
||||
_pcb(pcb), _rx_buf(0), _rx_buf_offset(0), _discard_cb(discard_cb), _discard_cb_arg(discard_cb_arg), _refcnt(0), _next(0), _send_waiting(false) {
|
||||
tcp_setprio(pcb, TCP_PRIO_MIN);
|
||||
tcp_arg(pcb, this);
|
||||
tcp_recv(pcb, &_s_recv);
|
||||
@ -51,35 +40,28 @@ public:
|
||||
tcp_err(pcb, &_s_error);
|
||||
}
|
||||
|
||||
~ClientContext()
|
||||
{
|
||||
~ClientContext() {
|
||||
}
|
||||
|
||||
ClientContext* next() const
|
||||
{
|
||||
ClientContext* next() const {
|
||||
return _next;
|
||||
}
|
||||
|
||||
ClientContext* next(ClientContext* new_next)
|
||||
{
|
||||
ClientContext* next(ClientContext* new_next) {
|
||||
_next = new_next;
|
||||
}
|
||||
|
||||
void ref()
|
||||
{
|
||||
void ref() {
|
||||
++_refcnt;
|
||||
DEBUGV(":ref %d\r\n", _refcnt);
|
||||
}
|
||||
|
||||
void unref()
|
||||
{
|
||||
void unref() {
|
||||
err_t err;
|
||||
DEBUGV(":ur %d\r\n", _refcnt);
|
||||
if (--_refcnt == 0)
|
||||
{
|
||||
if(--_refcnt == 0) {
|
||||
flush();
|
||||
if (_pcb)
|
||||
{
|
||||
if(_pcb) {
|
||||
tcp_arg(_pcb, NULL);
|
||||
tcp_sent(_pcb, NULL);
|
||||
tcp_recv(_pcb, NULL);
|
||||
@ -95,52 +77,41 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getRemoteAddress()
|
||||
{
|
||||
if (!_pcb)
|
||||
return 0;
|
||||
uint32_t getRemoteAddress() {
|
||||
if(!_pcb) return 0;
|
||||
|
||||
return _pcb->remote_ip.addr;
|
||||
}
|
||||
|
||||
uint16_t getRemotePort()
|
||||
{
|
||||
if (!_pcb)
|
||||
return 0;
|
||||
uint16_t getRemotePort() {
|
||||
if(!_pcb) return 0;
|
||||
|
||||
return _pcb->remote_port;
|
||||
}
|
||||
|
||||
size_t getSize() const
|
||||
{
|
||||
if (!_rx_buf)
|
||||
return 0;
|
||||
size_t getSize() const {
|
||||
if(!_rx_buf) return 0;
|
||||
|
||||
return _rx_buf->tot_len - _rx_buf_offset;
|
||||
}
|
||||
|
||||
char read()
|
||||
{
|
||||
if (!_rx_buf)
|
||||
return 0;
|
||||
char read() {
|
||||
if(!_rx_buf) return 0;
|
||||
|
||||
char c = reinterpret_cast<char*>(_rx_buf->payload)[_rx_buf_offset];
|
||||
_consume(1);
|
||||
return c;
|
||||
}
|
||||
|
||||
size_t read(char* dst, size_t size)
|
||||
{
|
||||
if (!_rx_buf)
|
||||
return 0;
|
||||
size_t read(char* dst, size_t size) {
|
||||
if(!_rx_buf) return 0;
|
||||
|
||||
size_t max_size = _rx_buf->tot_len - _rx_buf_offset;
|
||||
size = (size < max_size) ? size : max_size;
|
||||
|
||||
DEBUGV(":rd %d, %d, %d\r\n", size, _rx_buf->tot_len, _rx_buf_offset);
|
||||
size_t size_read = 0;
|
||||
while(size)
|
||||
{
|
||||
while(size) {
|
||||
size_t buf_size = _rx_buf->len - _rx_buf_offset;
|
||||
size_t copy_size = (size < buf_size) ? size : buf_size;
|
||||
DEBUGV(":rdi %d, %d\r\n", buf_size, copy_size);
|
||||
@ -153,16 +124,13 @@ public:
|
||||
return size_read;
|
||||
}
|
||||
|
||||
char peek()
|
||||
{
|
||||
if (!_rx_buf)
|
||||
return 0;
|
||||
char peek() {
|
||||
if(!_rx_buf) return 0;
|
||||
|
||||
return reinterpret_cast<char*>(_rx_buf->payload)[_rx_buf_offset];
|
||||
}
|
||||
|
||||
void flush()
|
||||
{
|
||||
void flush() {
|
||||
if(!_rx_buf) {
|
||||
return;
|
||||
}
|
||||
@ -174,17 +142,14 @@ public:
|
||||
_rx_buf_offset = 0;
|
||||
}
|
||||
|
||||
uint8_t state() const
|
||||
{
|
||||
if (!_pcb)
|
||||
return CLOSED;
|
||||
uint8_t state() const {
|
||||
if(!_pcb) return CLOSED;
|
||||
|
||||
return _pcb->state;
|
||||
}
|
||||
|
||||
size_t write(const char* data, size_t size)
|
||||
{
|
||||
if (!_pcb) {
|
||||
size_t write(const char* data, size_t size) {
|
||||
if(!_pcb) {
|
||||
DEBUGV(":wr !_pcb\r\n");
|
||||
return 0;
|
||||
}
|
||||
@ -196,7 +161,7 @@ public:
|
||||
size_t room = tcp_sndbuf(_pcb);
|
||||
size_t will_send = (room < size) ? room : size;
|
||||
err_t err = tcp_write(_pcb, data, will_send, 0);
|
||||
if (err != ERR_OK) {
|
||||
if(err != ERR_OK) {
|
||||
DEBUGV(":wr !ERR_OK\r\n");
|
||||
return 0;
|
||||
}
|
||||
@ -210,42 +175,32 @@ public:
|
||||
return will_send - _size_sent;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
private:
|
||||
|
||||
void _consume(size_t size)
|
||||
{
|
||||
void _consume(size_t size) {
|
||||
ptrdiff_t left = _rx_buf->len - _rx_buf_offset - size;
|
||||
if (left > 0)
|
||||
{
|
||||
if(left > 0) {
|
||||
_rx_buf_offset += size;
|
||||
}
|
||||
else if (!_rx_buf->next)
|
||||
{
|
||||
} else if(!_rx_buf->next) {
|
||||
DEBUGV(":c0 %d, %d\r\n", size, _rx_buf->tot_len);
|
||||
if (_pcb)
|
||||
tcp_recved(_pcb, _rx_buf->len);
|
||||
if(_pcb) tcp_recved(_pcb, _rx_buf->len);
|
||||
pbuf_free(_rx_buf);
|
||||
_rx_buf = 0;
|
||||
_rx_buf_offset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
DEBUGV(":c %d, %d, %d\r\n", size, _rx_buf->len, _rx_buf->tot_len);
|
||||
auto head = _rx_buf;
|
||||
_rx_buf = _rx_buf->next;
|
||||
_rx_buf_offset = 0;
|
||||
pbuf_ref(_rx_buf);
|
||||
if (_pcb)
|
||||
tcp_recved(_pcb, head->len);
|
||||
if(_pcb) tcp_recved(_pcb, head->len);
|
||||
pbuf_free(head);
|
||||
}
|
||||
}
|
||||
|
||||
err_t _recv(tcp_pcb* pcb, pbuf* pb, err_t err)
|
||||
{
|
||||
err_t _recv(tcp_pcb* pcb, pbuf* pb, err_t err) {
|
||||
|
||||
if (pb == 0) // connection closed
|
||||
if(pb == 0) // connection closed
|
||||
{
|
||||
DEBUGV(":rcl\r\n");
|
||||
tcp_arg(pcb, NULL);
|
||||
@ -264,15 +219,12 @@ private:
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
if (_rx_buf)
|
||||
{
|
||||
if(_rx_buf) {
|
||||
// there is some unread data
|
||||
// chain the new pbuf to the existing one
|
||||
DEBUGV(":rch %d, %d\r\n", _rx_buf->tot_len, pb->tot_len);
|
||||
pbuf_cat(_rx_buf, pb);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
DEBUGV(":rn %d\r\n", pb->tot_len);
|
||||
_rx_buf = pb;
|
||||
_rx_buf_offset = 0;
|
||||
@ -282,8 +234,7 @@ private:
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void _error(err_t err)
|
||||
{
|
||||
void _error(err_t err) {
|
||||
DEBUGV(":er %d\r\n", err);
|
||||
|
||||
if(_pcb) {
|
||||
@ -304,42 +255,34 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
err_t _poll(tcp_pcb* pcb)
|
||||
{
|
||||
err_t _poll(tcp_pcb* pcb) {
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
err_t _sent(tcp_pcb* pcb, uint16_t len)
|
||||
{
|
||||
err_t _sent(tcp_pcb* pcb, uint16_t len) {
|
||||
DEBUGV(":sent %d\r\n", len);
|
||||
_size_sent -= len;
|
||||
if (_size_sent == 0 && _send_waiting)
|
||||
esp_schedule();
|
||||
if(_size_sent == 0 && _send_waiting) esp_schedule();
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
||||
static err_t _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, err_t err)
|
||||
{
|
||||
static err_t _s_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *pb, err_t err) {
|
||||
return reinterpret_cast<ClientContext*>(arg)->_recv(tpcb, pb, err);
|
||||
}
|
||||
|
||||
static void _s_error(void *arg, err_t err)
|
||||
{
|
||||
static void _s_error(void *arg, err_t err) {
|
||||
reinterpret_cast<ClientContext*>(arg)->_error(err);
|
||||
}
|
||||
|
||||
static err_t _s_poll(void *arg, struct tcp_pcb *tpcb)
|
||||
{
|
||||
static err_t _s_poll(void *arg, struct tcp_pcb *tpcb) {
|
||||
return reinterpret_cast<ClientContext*>(arg)->_poll(tpcb);
|
||||
}
|
||||
|
||||
static err_t _s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len)
|
||||
{
|
||||
static err_t _s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len) {
|
||||
return reinterpret_cast<ClientContext*>(arg)->_sent(tpcb, len);
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
ClientContext* _next;
|
||||
int _refcnt;
|
||||
|
||||
@ -355,6 +298,4 @@ private:
|
||||
bool _send_waiting;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif//CLIENTCONTEXT_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user