Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrappers allowing to compile and run esp32-arduino basic examples #8845

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cores/esp8266/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class File : public Stream
operator bool() const;
const char* name() const;
const char* fullName() const; // Includes path
const char* path() const { return fullName(); } // esp32 compat
bool truncate(uint32_t size);

bool isFile() const;
Expand Down Expand Up @@ -225,6 +226,7 @@ class FS

File open(const char* path, const char* mode);
File open(const String& path, const char* mode);
File open(const String& path) { return open(path, "r"); } // esp32 compat

bool exists(const char* path);
bool exists(const String& path);
Expand Down
27 changes: 0 additions & 27 deletions libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,21 +479,6 @@ void ESP8266WebServerTemplate<ServerType>::_prepareHeader(String& response, int
_responseHeaders = "";
}

template <typename ServerType>
void ESP8266WebServerTemplate<ServerType>::send(int code, char* content_type, const String& content) {
return send(code, (const char*)content_type, content);
}

template <typename ServerType>
void ESP8266WebServerTemplate<ServerType>::send(int code, const char* content_type, const String& content) {
return send(code, content_type, content.c_str(), content.length());
}

template <typename ServerType>
void ESP8266WebServerTemplate<ServerType>::send(int code, const String& content_type, const String& content) {
return send(code, (const char*)content_type.c_str(), content);
}

template <typename ServerType>
void ESP8266WebServerTemplate<ServerType>::sendContent(const String& content) {
StreamConstPtr ref(content.c_str(), content.length());
Expand All @@ -513,18 +498,6 @@ void ESP8266WebServerTemplate<ServerType>::send(int code, const char* content_ty
return sendContent(stream, content_length);
}

template <typename ServerType>
void ESP8266WebServerTemplate<ServerType>::send_P(int code, PGM_P content_type, PGM_P content) {
StreamConstPtr ref(content, strlen_P(content));
return send(code, String(content_type).c_str(), &ref);
}

template <typename ServerType>
void ESP8266WebServerTemplate<ServerType>::send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength) {
StreamConstPtr ref(content, contentLength);
return send(code, String(content_type).c_str(), &ref);
}

template <typename ServerType>
void ESP8266WebServerTemplate<ServerType>::sendContent(Stream* content, ssize_t content_length /* = 0*/) {
if (_currentMethod == HTTP_HEAD)
Expand Down
70 changes: 59 additions & 11 deletions libraries/ESP8266WebServer/src/ESP8266WebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,73 @@ class ESP8266WebServerTemplate
// code - HTTP response code, can be 200 or 404
// content_type - HTTP content type, like "text/plain" or "image/png"
// content - actual content body
void send(int code, const char* content_type = NULL, const String& content = emptyString);
void send(int code, char* content_type, const String& content);
void send(int code, const String& content_type, const String& content);
void send(int code, const char *content_type, const char *content) {

#if 0

void send(int code) { send(code, nullptr, nullptr); }

template <CT content_type, CD content>
void send(int code, CT&& content_type, CD&& content)
{
String(std::forward<CT>(content_type)) content_type_forwarded;
StreamConstPtr(std::forward<CD>(content)) content_forwarded;
send(code, content_type_forwarded.c_str(), &content_forwarded);
}

template <CT content_type, C content>
void send(int code, CT&& content_type, C&& content, size_t content_length)
{
String(std::forward<CT>(content_type)) content_type_forwarded;
StreamConstPtr(std::forward<CD>(content), content_length) content_forwarded;
send(code, content_type_forwarded.c_str(), &content_forwarded);
}

template <CT content_type>
void send(int code, CT&& content_type, Stream* stream, size_t content_length = 0)
{
String(std::forward<CT>(content_type)) content_type_forwarded;
send(code, content_type_forwarded.c_str(), stream, content_length);
}

send_P


#else


void send(int code, const char* content_type = NULL, const String& content = emptyString) {
return send(code, content_type, content.c_str(), content.length());
}
void send(int code, char* content_type, const String& content) {
return send(code, (const char*)content_type, content);
}
void send(int code, const String& content_type, const String& content) {
return send(code, (const char*)content_type.c_str(), content);
}
void send(int code, const char* content_type, const char* content) {
send_P(code, content_type, content);
}
void send(int code, const char *content_type, const char *content, size_t content_length) {
void send(int code, const char* content_type, const char* content, size_t content_length) {
send_P(code, content_type, content, content_length);
}
void send(int code, const char *content_type, const uint8_t *content, size_t content_length) {
send_P(code, content_type, (const char *)content, content_length);
void send(int code, const char* content_type, const uint8_t* content, size_t content_length) {
send_P(code, content_type, (const char* )content, content_length);
}
void send_P(int code, PGM_P content_type, PGM_P content);
void send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength);

void send(int code, const char* content_type, Stream* stream, size_t content_length = 0);
void send(int code, const char* content_type, Stream& stream, size_t content_length = 0) {
send(code, content_type, &stream, content_length);
}
void send_P(int code, PGM_P content_type, PGM_P content) {
StreamConstPtr ref(content, strlen_P(content));
return send(code, String(content_type).c_str(), &ref);
}
void send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength) {
StreamConstPtr ref(content, contentLength);
return send(code, String(content_type).c_str(), &ref);
}

#endif

void send(int code, const char* content_type, Stream* stream, size_t content_length = 0);

void setContentLength(const size_t contentLength);
void sendHeader(const String& name, const String& value, bool first = false);
Expand Down
2 changes: 0 additions & 2 deletions libraries/ESP8266WiFi/src/WiFi.h

This file was deleted.

16 changes: 16 additions & 0 deletions libraries/WiFi/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#######################################
# Datatypes (KEYWORD1)
#######################################

ESPmDNS KEYWORD1
FFat KEYWORD1
WebServer KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

#######################################
# Constants (LITERAL1)
#######################################

6 changes: 6 additions & 0 deletions libraries/WiFi/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name=WiFi
version=1.0
author=esp8266-arduino
maintainer=esp8266-arduino
sentence=convergence headers for esp32-Arduino compatibility
architectures=esp8266
6 changes: 6 additions & 0 deletions libraries/WiFi/src/ESPmDNS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#pragma once

#include <ESP8266mDNS.h>

using ESPmDNS = MDNSResponder;
6 changes: 6 additions & 0 deletions libraries/WiFi/src/FFat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#pragma once

#include <LittleFS.h>

#define FFat LittleFS
4 changes: 4 additions & 0 deletions libraries/WiFi/src/SPIFFS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#pragma once

#include <FS.h>
6 changes: 6 additions & 0 deletions libraries/WiFi/src/WebServer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#pragma once

#include <ESP8266WebServer.h>

using WebServer = ESP8266WebServer;
6 changes: 6 additions & 0 deletions libraries/WiFi/src/WiFi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#pragma once

#include <ESP8266WiFi.h>

using WiFiClass = ESP8266WiFiClass;
Loading