-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dad401/main
PR Test gemäß Thread
- Loading branch information
Showing
13 changed files
with
1,687 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
CircularBuffer - An Arduino circular buffering library for arbitrary types. | ||
Created by Ivo Pullens, Emmission, 2014 -- www.emmission.nl | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#ifndef CircularBuffer_h | ||
#define CircularBuffer_h | ||
|
||
#ifdef ESP8266 | ||
#define DISABLE_IRQ noInterrupts() | ||
#define RESTORE_IRQ interrupts() | ||
#else | ||
#define DISABLE_IRQ \ | ||
uint8_t sreg = SREG; \ | ||
cli(); | ||
|
||
#define RESTORE_IRQ \ | ||
SREG = sreg; | ||
#endif | ||
|
||
template <class T> class CircularBuffer | ||
{ | ||
public: | ||
/** Constructor | ||
* @param buffer Preallocated buffer of at least size records. | ||
* @param size Number of records available in the buffer. | ||
*/ | ||
CircularBuffer(T* buffer, const uint8_t size ) | ||
: m_size(size), m_buff(buffer) | ||
{ | ||
clear(); | ||
} | ||
|
||
/** Clear all entries in the circular buffer. */ | ||
void clear(void) | ||
{ | ||
m_front = 0; | ||
m_fill = 0; | ||
} | ||
|
||
/** Test if the circular buffer is empty */ | ||
inline bool empty(void) const | ||
{ | ||
return !m_fill; | ||
} | ||
|
||
/** Return the number of records stored in the buffer */ | ||
inline uint8_t available(void) const | ||
{ | ||
return m_fill; | ||
} | ||
|
||
/** Test if the circular buffer is full */ | ||
inline bool full(void) const | ||
{ | ||
return m_fill == m_size; | ||
} | ||
|
||
/** Aquire record on front of the buffer, for writing. | ||
* After filling the record, it has to be pushed to actually | ||
* add it to the buffer. | ||
* @return Pointer to record, or NULL when buffer is full. | ||
*/ | ||
T* getFront(void) const | ||
{ | ||
DISABLE_IRQ; | ||
T* f = NULL; | ||
if (!full()) | ||
f = get(m_front); | ||
RESTORE_IRQ; | ||
return f; | ||
} | ||
|
||
/** Push record to front of the buffer | ||
* @param record Record to push. If record was aquired previously (using getFront) its | ||
* data will not be copied as it is already present in the buffer. | ||
* @return True, when record was pushed successfully. | ||
*/ | ||
bool pushFront(T* record) | ||
{ | ||
bool ok = false; | ||
DISABLE_IRQ; | ||
if (!full()) | ||
{ | ||
T* f = get(m_front); | ||
if (f != record) | ||
*f = *record; | ||
m_front = (m_front+1) % m_size; | ||
m_fill++; | ||
ok = true; | ||
} | ||
RESTORE_IRQ; | ||
return ok; | ||
} | ||
|
||
/** Aquire record on back of the buffer, for reading. | ||
* After reading the record, it has to be pop'ed to actually | ||
* remove it from the buffer. | ||
* @return Pointer to record, or NULL when buffer is empty. | ||
*/ | ||
T* getBack(void) const | ||
{ | ||
T* b = NULL; | ||
DISABLE_IRQ; | ||
if (!empty()) | ||
b = get(back()); | ||
RESTORE_IRQ; | ||
return b; | ||
} | ||
|
||
/** Remove record from back of the buffer. | ||
* @return True, when record was pop'ed successfully. | ||
*/ | ||
bool popBack(void) | ||
{ | ||
bool ok = false; | ||
DISABLE_IRQ; | ||
if (!empty()) | ||
{ | ||
m_fill--; | ||
ok = true; | ||
} | ||
RESTORE_IRQ; | ||
return ok; | ||
} | ||
|
||
protected: | ||
inline T * get(const uint8_t idx) const | ||
{ | ||
return &(m_buff[idx]); | ||
} | ||
inline uint8_t back(void) const | ||
{ | ||
return (m_front - m_fill + m_size) % m_size; | ||
} | ||
|
||
const uint8_t m_size; // Total number of records that can be stored in the buffer. | ||
T* const m_buff; // Ptr to buffer holding all records. | ||
volatile uint8_t m_front; // Index of front element (not pushed yet). | ||
volatile uint8_t m_fill; // Amount of records currently pushed. | ||
}; | ||
|
||
#endif // CircularBuffer_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef __DEBUG_H | ||
|
||
#define __DEBUG_H | ||
|
||
#ifdef DEBUG | ||
#define DEBUG_OUT Serial | ||
#else | ||
//--- | ||
// disable Serial DEBUG output | ||
#define DEBUG_OUT DummySerial | ||
static class { | ||
public: | ||
void begin(...) {} | ||
void print(...) {} | ||
void println(...) {} | ||
void flush() {} | ||
bool available() { return false;} | ||
int readBytes(...) { return 0;} | ||
int printf (...) {return 0;} | ||
} DummySerial; | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// ################# WebServer ################# | ||
|
||
#ifndef __MODWEBSERVER_H | ||
#define __MODWEBSERVER_H | ||
#define MODWEBSERVER | ||
|
||
#include <ESP8266WebServer.h> | ||
#include "Debug.h" | ||
#include "Settings.h" | ||
|
||
ESP8266WebServer server (WEBSERVER_PORT); | ||
|
||
|
||
void returnOK () { | ||
//-------------- | ||
server.send(200, F("text/plain"), ""); | ||
} | ||
|
||
|
||
void returnFail(String msg) { | ||
//------------------------- | ||
server.send(500, F("text/plain"), msg + "\r\n"); | ||
} | ||
|
||
void handleHelp () { | ||
//----------------- | ||
String out = "<html>"; | ||
out += "<body><h2>Hilfe</h2>"; | ||
out += "<br><br><table>"; | ||
out += "<tr><td>/</td><td>zeigt alle Messwerte in einer Tabelle; refresh alle 10 Sekunden</td></tr>"; | ||
out += "<tr><td>/data</td><td>zum Abruf der Messwerte in der Form Name=wert</td></tr>"; | ||
out += "<tr><td>:{port+1}/update</td><td>OTA</td></tr>"; | ||
out += "<tr><td>/reboot</td><td>startet neu</td></tr>"; | ||
out += "</table></body></html>"; | ||
server.send (200, "text/html", out); | ||
} | ||
|
||
|
||
void handleReboot () { | ||
//------------------- | ||
returnOK (); | ||
ESP.reset(); | ||
} | ||
|
||
|
||
void handleRoot() { | ||
//---------------- | ||
String out = "<html><head><meta http-equiv=\"refresh\" content=\"10\":URL=\"" + server.uri() + "\"></head>"; | ||
out += "<body>"; | ||
out += "<h2>Hoymiles Micro-Inverter HM-600</h2>"; | ||
out += "<br><br><table border='1'>"; | ||
out += "<tr><th>Kanal</th><th>Wert</th></tr>"; | ||
for (byte i = 0; i < ANZAHL_VALUES; i++) { | ||
out += "<tr><td>" + String(getChannelName(i)) + "</td>"; | ||
out += "<td>" + String(VALUES[i]) + "</td></tr>"; | ||
} | ||
out += "</table>"; | ||
out += "</body></html>"; | ||
server.send (200, "text/html", out); | ||
//DEBUG_OUT.println (out); | ||
} | ||
|
||
|
||
void handleData () { | ||
//----------------- | ||
String out = ""; | ||
for (int i = 0; i < ANZAHL_VALUES; i++) { | ||
out += String(getChannelName(i)) + '=' + String (VALUES[i]) + '\n'; | ||
} | ||
server.send(200, "text/plain", out); | ||
} | ||
|
||
|
||
void handleNotFound() { | ||
//-------------------- | ||
String message = "URI: "; | ||
message += server.uri(); | ||
message += "\nMethod: "; | ||
message += (server.method() == HTTP_GET) ? "GET" : "POST"; | ||
message += "\nArguments: "; | ||
message += server.args(); | ||
message += "\n"; | ||
for (uint8_t i = 0; i < server.args(); i++) { | ||
message += " NAME:" + server.argName(i) + "\n VALUE:" + server.arg(i) + "\n"; | ||
} | ||
server.send(404, "text/plain", message); | ||
} | ||
|
||
|
||
void setupWebServer (void) { | ||
//------------------------- | ||
server.on("/", handleRoot); | ||
server.on("/reboot", handleReboot); | ||
server.on("/data", handleData); | ||
server.on("/help", handleHelp); | ||
//server.onNotFound(handleNotFound); wegen Spiffs-Dateimanager | ||
|
||
server.begin(); | ||
DEBUG_OUT.println ("[HTTP] installed"); | ||
} | ||
|
||
void webserverHandle() { | ||
//==================== | ||
server.handleClient(); | ||
} | ||
|
||
|
||
// ################# OTA ################# | ||
|
||
#ifdef WITH_OTA | ||
#include <ESP8266HTTPUpdateServer.h> | ||
|
||
ESP8266WebServer httpUpdateServer (UPDATESERVER_PORT); | ||
ESP8266HTTPUpdateServer httpUpdater; | ||
|
||
void setupUpdateByOTA () { | ||
//------------------------ | ||
httpUpdater.setup (&httpUpdateServer, UPDATESERVER_DIR, UPDATESERVER_USER, UPDATESERVER_PW); | ||
httpUpdateServer.begin(); | ||
DEBUG_OUT.println (F("[OTA] installed")); | ||
} | ||
|
||
void checkUpdateByOTA() { | ||
//--------------------- | ||
httpUpdateServer.handleClient(); | ||
} | ||
#endif | ||
|
||
#endif |
Oops, something went wrong.