Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
slav-at-attachix committed May 2, 2018
2 parents 201a74b + ff7fb1e commit 71c2857
Show file tree
Hide file tree
Showing 36 changed files with 1,333 additions and 219 deletions.
2 changes: 1 addition & 1 deletion Sming/Libraries/ArduCAM/ArduCAMStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ uint16_t ArduCAMStream::readMemoryBlock(char* data, int bufSize) {

}

int bytesread = min(len, bufSize);
int bytesread = min(len, (unsigned int)bufSize);

ACAM_DEBUG("ArduCAMStream::readMemoryBlock [%d] (%d bytes) remaining (%d bytes)\n", bcount++, bytesread, len);

Expand Down
2 changes: 1 addition & 1 deletion Sming/Libraries/I2Cdev/I2Cdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8
// I2C/TWI subsystem uses internal buffer that breaks with large data requests
// so if user requests more than BUFFER_LENGTH bytes, we have to do it in
// smaller chunks instead of all at once
for (uint8_t k = 0; k < length; k += min(length, BUFFER_LENGTH)) {
for (uint8_t k = 0; k < length; k += min((unsigned int)length, (unsigned int)BUFFER_LENGTH)) {
Wire.beginTransmission(devAddr);
Wire.write(regAddr);
Wire.endTransmission();
Expand Down
3 changes: 2 additions & 1 deletion Sming/Makefile-project.mk
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ else ifeq ($(ENABLE_CUSTOM_LWIP), 2)
endif

EXTRA_INCDIR += $(SMING_HOME)/include $(SMING_HOME)/ $(LWIP_INCDIR) $(SMING_HOME)/system/include \
$(SMING_HOME)/Wiring $(SMING_HOME)/Libraries $(SMING_HOME)/Libraries/Adafruit_GFX \
$(SMING_HOME)/Wiring $(SMING_HOME)/Libraries \
$(SMING_HOME)/Libraries/Adafruit_GFX $(SMING_HOME)/Libraries/Adafruit_Sensor \
$(SMING_HOME)/SmingCore $(SMING_HOME)/Services/SpifFS $(SDK_BASE)/../include \
$(THIRD_PARTY_DIR)/rboot $(THIRD_PARTY_DIR)/rboot/appcode $(THIRD_PARTY_DIR)/spiffs/src

Expand Down
3 changes: 2 additions & 1 deletion Sming/Makefile-rboot.mk
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ else ifeq ($(ENABLE_CUSTOM_LWIP), 2)
endif

EXTRA_INCDIR += $(SMING_HOME)/include $(SMING_HOME)/ $(LWIP_INCDIR) $(SMING_HOME)/system/include \
$(SMING_HOME)/Wiring $(SMING_HOME)/Libraries $(SMING_HOME)/Libraries/Adafruit_GFX \
$(SMING_HOME)/Wiring $(SMING_HOME)/Libraries \
$(SMING_HOME)/Libraries/Adafruit_GFX $(SMING_HOME)/Libraries/Adafruit_Sensor \
$(SMING_HOME)/SmingCore $(SMING_HOME)/Services/SpifFS $(SDK_BASE)/../include \
$(THIRD_PARTY_DIR)/rboot $(THIRD_PARTY_DIR)/rboot/appcode $(THIRD_PARTY_DIR)/spiffs/src

Expand Down
9 changes: 9 additions & 0 deletions Sming/SmingCore/ArduinoCompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
extern "C" {
#endif

#define abs(x) ((x)>0?(x):-(x))
#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#endif
#ifndef max
#define max(a,b) ((a)>(b)?(a):(b))
#endif
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))

void yield();

#ifdef __cplusplus
Expand Down
7 changes: 4 additions & 3 deletions Sming/SmingCore/DataSourceStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
****/

#include "../SmingCore/DataSourceStream.h"
#include <algorithm>

int IDataSourceStream::read()
{
Expand Down Expand Up @@ -91,7 +92,7 @@ size_t MemoryDataStream::write(const uint8_t* data, size_t len)

uint16_t MemoryDataStream::readMemoryBlock(char* data, int bufSize)
{
int available = min(size - (pos - buf), bufSize);
int available = std::min(size - (pos - buf), bufSize);
memcpy(data, pos, available);
return available;
}
Expand Down Expand Up @@ -154,7 +155,7 @@ FileStream::~FileStream()

uint16_t FileStream::readMemoryBlock(char* data, int bufSize)
{
int len = min(bufSize, size - pos);
int len = std::min(bufSize, size - pos);
int available = fileRead(handle, data, len);
fileSeek(handle, pos, eSO_FileStart); // Don't move cursor now (waiting seek)
if(available < 0) {
Expand Down Expand Up @@ -250,7 +251,7 @@ uint16_t TemplateFileStream::readMemoryBlock(char* data, int bufSize)
debug_d("var %s not found", varName.c_str());
state = eTES_Wait;
int len = FileStream::readMemoryBlock(data, bufSize);
return min(len, skipBlockSize);
return std::min(len, skipBlockSize);
}
}
else if (state == eTES_SendingVar)
Expand Down
2 changes: 1 addition & 1 deletion Sming/SmingCore/Interrupts.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void noInterrupts();
*/
void interrupts();

#define digitalPinToInterrupt(pin) ( (p) < ESP_MAX_INTERRUPTS ? (p) : -1 )
#define digitalPinToInterrupt(pin) ( (pin) < ESP_MAX_INTERRUPTS ? (pin) : -1 )

#define cli() noInterrupts()
#define sei() interrupts()
Expand Down
1 change: 1 addition & 0 deletions Sming/SmingCore/Network/Http/HttpConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ int HttpConnection::staticOnMessageComplete(http_parser* parser)
if(connection->incomingRequest->responseStream != NULL) {
connection->incomingRequest->responseStream->close();
delete connection->incomingRequest->responseStream;
connection->incomingRequest->responseStream = NULL;
}

delete connection->incomingRequest;
Expand Down
8 changes: 6 additions & 2 deletions Sming/SmingCore/Network/Http/HttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "HttpRequest.h"

#include <algorithm>

HttpRequest::HttpRequest(const URL& uri) {
this->uri = uri;
}
Expand Down Expand Up @@ -52,8 +54,10 @@ HttpRequest& HttpRequest::operator = (const HttpRequest& rhs) {
HttpRequest::~HttpRequest() {
delete queryParams;
delete stream;
delete responseStream;
queryParams = NULL;
stream = NULL;
responseStream = NULL;
}

HttpRequest* HttpRequest::setURL(const URL& uri) {
Expand Down Expand Up @@ -155,9 +159,9 @@ String HttpRequest::getBody()
if(stream->available() != -1 && stream->getStreamType() == eSST_Memory) {
MemoryDataStream *memory = (MemoryDataStream *)stream;
char buf[1024];
for(int i=0; i< stream->available(); i += 1024) {
while(stream->available() > 0) {
int available = memory->readMemoryBlock(buf, 1024);
memory->seek(max(available, 0));
memory->seek(std::max(available, 0));
ret += String(buf, available);
if(available < 1024) {
break;
Expand Down
9 changes: 6 additions & 3 deletions Sming/SmingCore/Network/Http/HttpServerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ int HttpServerConnection::staticOnMessageBegin(http_parser* parser)
return 0;
}

int HttpServerConnection::staticOnPath(http_parser *parser, const char *at, size_t length) {
int HttpServerConnection::staticOnPath(http_parser *parser, const char *at, size_t length)
{
HttpServerConnection *connection = (HttpServerConnection*)parser->data;
if(connection == NULL) {
// something went wrong
Expand Down Expand Up @@ -150,6 +151,7 @@ int HttpServerConnection::staticOnMessageComplete(http_parser* parser)
if(connection->request.responseStream != NULL) {
connection->request.responseStream->close();
delete connection->request.responseStream;
connection->request.responseStream = NULL;
}

return hasError;
Expand All @@ -175,7 +177,7 @@ int HttpServerConnection::staticOnHeadersComplete(http_parser* parser)
* chunked' headers that indicate the presence of a body.
*
* Returning `2` from on_headers_complete will tell parser that it should not
* expect neither a body nor any futher responses on this connection. This is
* expect neither a body nor any further responses on this connection. This is
* useful for handling responses to a CONNECT request which may not contain
* `Upgrade` or `Connection: upgrade` headers.
*/
Expand Down Expand Up @@ -509,7 +511,8 @@ bool HttpServerConnection::sendResponseBody(HttpResponse *response)

}

void HttpServerConnection::onError(err_t err) {
void HttpServerConnection::onError(err_t err)
{
TcpClient::onError(err);
}

Expand Down
4 changes: 3 additions & 1 deletion Sming/SmingCore/Network/Http/Stream/HttpChunkedStream.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "HttpChunkedStream.h"

#include <algorithm>

HttpChunkedStream::HttpChunkedStream(ReadWriteStream *stream)
{
this->stream = stream;
Expand Down Expand Up @@ -43,7 +45,7 @@ uint16_t HttpChunkedStream::readMemoryBlock(char* data, int bufSize)
int len = readSize;
char buffer[len];
len = stream->readMemoryBlock(buffer, len);
stream->seek(max(len, 0));
stream->seek(std::max(len, 0));
if(len < 1) {
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions Sming/SmingCore/Network/MqttClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void MqttClient::setPingRepeatTime(int seconds)
{
if (PingRepeatTime > keepAlive)
PingRepeatTime = keepAlive;
else
else
PingRepeatTime = seconds;
}

Expand Down Expand Up @@ -239,7 +239,7 @@ err_t MqttClient::onReceive(pbuf *buf)
continue;
}

int available = min(waitingSize, buf->tot_len - received);
int available = std::min(waitingSize, buf->tot_len - received);
waitingSize -= available;
if (current != NULL)
{
Expand Down
6 changes: 4 additions & 2 deletions Sming/SmingCore/Network/TcpConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "../Wiring/WString.h"
#include "../Wiring/IPAddress.h"

#include <algorithm>

TcpConnection::TcpConnection(bool autoDestruct) : autoSelfDestruct(autoDestruct), sleep(0), canSend(true), timeOut(70)
{

Expand Down Expand Up @@ -265,7 +267,7 @@ int TcpConnection::write(IDataSourceStream* stream)
do
{
pushCount++;
int read = min(NETWORK_SEND_BUFFER_SIZE, getAvailableWriteSize());
int read = std::min((uint16_t)NETWORK_SEND_BUFFER_SIZE, getAvailableWriteSize());
if (read > 0)
available = stream->readMemoryBlock(buffer, read);
else
Expand All @@ -275,7 +277,7 @@ int TcpConnection::write(IDataSourceStream* stream)
{
int written = write(buffer, available, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
total += written;
stream->seek(max(written, 0));
stream->seek(std::max(written, 0));
debug_d("Written: %d, Available: %d, isFinished: %d, PushCount: %d [TcpBuf: %d]", written, available, (stream->isFinished()?1:0), pushCount, tcp_sndbuf(tcp));
repeat = written == available && !stream->isFinished() && pushCount < 25;
}
Expand Down
4 changes: 2 additions & 2 deletions Sming/SmingCore/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void SPIClass::transfer(uint8 *buffer, size_t numberBytes) {
while (blocks--) {

// get full BLOCKSIZE or number of remaining bytes
bufLenght = min(numberBytes-bufIndx, BLOCKSIZE);
bufLenght = std::min(numberBytes-bufIndx, (unsigned int)BLOCKSIZE);

#ifdef SPI_DEBUG
debugf("Write/Read Block %d total %d bytes", total-blocks, bufLenght);
Expand Down Expand Up @@ -453,7 +453,7 @@ void SPIClass::setFrequency(int freq) {
return;
}

freq = min(freq, _CPU_freq/2);
freq = std::min(freq, _CPU_freq/2);
_SPISettings._speed = freq;


Expand Down
2 changes: 2 additions & 0 deletions Sming/SmingCore/SmingCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#define SMING_VERSION "3.5.1" // Major Minor Sub

#include <functional>

#include "../Wiring/WiringFrameworkIncludes.h"

#include "Delegate.h"
Expand Down
8 changes: 6 additions & 2 deletions Sming/Wiring/WConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@

#define sq(x) ((x)*(x))
//#define abs(x) ((x)>0?(x):-(x))
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
//#ifndef min
//#define min(a,b) ((a)<(b)?(a):(b))
//#endif
//#ifndef max
//#define max(a,b) ((a)>(b)?(a):(b))
//#endif
//#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
Expand Down
7 changes: 7 additions & 0 deletions Sming/appinit/user_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,10 @@ extern "C" uint32 ICACHE_FLASH_ATTR __attribute__((weak)) user_rf_cal_sector_se

return rf_cal_sec;
}

namespace std {
void __attribute__((weak)) __throw_bad_function_call()
{
while(1);
};
}
Loading

0 comments on commit 71c2857

Please sign in to comment.