mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-29 15:42:20 +03:00
first
This commit is contained in:
18
lib/ArduinoStreamUtils/extras/test/cores/esp32/Arduino.h
Normal file
18
lib/ArduinoStreamUtils/extras/test/cores/esp32/Arduino.h
Normal file
@@ -0,0 +1,18 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Client.h>
|
||||
#include <Print.h>
|
||||
#include <Stream.h>
|
||||
#include <WString.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
inline unsigned long millis() {
|
||||
return static_cast<unsigned long>(time(NULL));
|
||||
}
|
||||
|
||||
inline void yield() {}
|
||||
@@ -0,0 +1,22 @@
|
||||
# StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
# Copyright Benoit Blanchon 2019-2021
|
||||
# MIT License
|
||||
|
||||
add_library(Esp32Core
|
||||
Client.h
|
||||
EEPROM.cpp
|
||||
EEPROM.h
|
||||
Print.h
|
||||
Stream.h
|
||||
WString.h
|
||||
)
|
||||
|
||||
target_include_directories(Esp32Core
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(Esp32Core
|
||||
PUBLIC
|
||||
ARDUINO_ARCH_ESP32
|
||||
)
|
||||
26
lib/ArduinoStreamUtils/extras/test/cores/esp32/Client.h
Normal file
26
lib/ArduinoStreamUtils/extras/test/cores/esp32/Client.h
Normal file
@@ -0,0 +1,26 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Stream.h"
|
||||
#include "WString.h"
|
||||
|
||||
using IPAddress = String;
|
||||
|
||||
class Client : public Stream {
|
||||
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;
|
||||
virtual size_t write(const uint8_t *buf, size_t size) = 0;
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int read(uint8_t *buf, size_t size) = 0;
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual uint8_t connected() = 0;
|
||||
virtual operator bool() = 0;
|
||||
};
|
||||
20
lib/ArduinoStreamUtils/extras/test/cores/esp32/EEPROM.cpp
Normal file
20
lib/ArduinoStreamUtils/extras/test/cores/esp32/EEPROM.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "EEPROM.h"
|
||||
|
||||
#include <string.h> // memcpy
|
||||
|
||||
EEPROMClass EEPROM;
|
||||
static uint8_t commitedData[512];
|
||||
static uint8_t pendingData[512];
|
||||
|
||||
uint8_t EEPROMClass::read(int address) {
|
||||
return commitedData[address];
|
||||
}
|
||||
|
||||
void EEPROMClass::write(int address, uint8_t value) {
|
||||
pendingData[address] = value;
|
||||
}
|
||||
|
||||
bool EEPROMClass::commit() {
|
||||
memcpy(commitedData, pendingData, 512);
|
||||
return true;
|
||||
}
|
||||
12
lib/ArduinoStreamUtils/extras/test/cores/esp32/EEPROM.h
Normal file
12
lib/ArduinoStreamUtils/extras/test/cores/esp32/EEPROM.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class EEPROMClass {
|
||||
public:
|
||||
uint8_t read(int);
|
||||
void write(int, uint8_t);
|
||||
bool commit();
|
||||
};
|
||||
|
||||
extern EEPROMClass EEPROM;
|
||||
42
lib/ArduinoStreamUtils/extras/test/cores/esp32/Print.h
Normal file
42
lib/ArduinoStreamUtils/extras/test/cores/esp32/Print.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <WString.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstring>
|
||||
|
||||
struct Print {
|
||||
virtual ~Print() {}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
virtual size_t write(uint8_t data) = 0;
|
||||
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
size_t print(const String &s) {
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t print(const char *s) {
|
||||
return write(s, std::strlen(s));
|
||||
}
|
||||
|
||||
size_t println() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t print(const T &value) {
|
||||
return print(String(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
size_t println(const T &value) {
|
||||
return print(value);
|
||||
}
|
||||
};
|
||||
48
lib/ArduinoStreamUtils/extras/test/cores/esp32/Stream.h
Normal file
48
lib/ArduinoStreamUtils/extras/test/cores/esp32/Stream.h
Normal file
@@ -0,0 +1,48 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Print.h"
|
||||
|
||||
struct Stream : Print {
|
||||
virtual ~Stream() {}
|
||||
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0;
|
||||
|
||||
virtual size_t readBytes(char *buffer, size_t length) {
|
||||
size_t count = 0;
|
||||
while (count < length) {
|
||||
int c = timedRead();
|
||||
if (c < 0)
|
||||
break;
|
||||
*buffer++ = (char)c;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
virtual size_t readBytes(uint8_t *buffer, size_t length) {
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
|
||||
virtual String readString() {
|
||||
String result;
|
||||
int c;
|
||||
while ((c = timedRead()) >= 0) {
|
||||
result += c;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void setTimeout(unsigned long) {}
|
||||
|
||||
protected:
|
||||
int timedRead() {
|
||||
return read();
|
||||
}
|
||||
};
|
||||
5
lib/ArduinoStreamUtils/extras/test/cores/esp32/WString.h
Normal file
5
lib/ArduinoStreamUtils/extras/test/cores/esp32/WString.h
Normal file
@@ -0,0 +1,5 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#include "../avr/WString.h"
|
||||
Reference in New Issue
Block a user