mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 03:49:13 +03:00
compiling
This commit is contained in:
18
lib/ArduinoStreamUtils/extras/test/cores/teensy/Arduino.h
Normal file
18
lib/ArduinoStreamUtils/extras/test/cores/teensy/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(TeensyCore
|
||||
Client.h
|
||||
EEPROM.cpp
|
||||
EEPROM.h
|
||||
Print.h
|
||||
Stream.h
|
||||
WString.h
|
||||
)
|
||||
|
||||
target_include_directories(TeensyCore
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(TeensyCore
|
||||
PUBLIC
|
||||
CORE_TEENSY
|
||||
)
|
||||
31
lib/ArduinoStreamUtils/extras/test/cores/teensy/Client.h
Normal file
31
lib/ArduinoStreamUtils/extras/test/cores/teensy/Client.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Stream.h"
|
||||
#include "WString.h"
|
||||
|
||||
using IPAddress = String;
|
||||
|
||||
struct Client : Stream {
|
||||
virtual int connect(IPAddress ip, uint16_t port) = 0;
|
||||
virtual int connect(const char *host, uint16_t port) = 0;
|
||||
virtual uint8_t connected() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual operator bool() = 0;
|
||||
|
||||
// Already in Print
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
virtual size_t write(const uint8_t *buf, size_t size) = 0;
|
||||
virtual void flush() = 0;
|
||||
|
||||
// Already in Stream
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
|
||||
// Curiously not in Stream
|
||||
virtual int read(uint8_t *buf, size_t size) = 0;
|
||||
};
|
||||
12
lib/ArduinoStreamUtils/extras/test/cores/teensy/EEPROM.cpp
Normal file
12
lib/ArduinoStreamUtils/extras/test/cores/teensy/EEPROM.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "EEPROM.h"
|
||||
|
||||
EEPROMClass EEPROM;
|
||||
static uint8_t data[512];
|
||||
|
||||
uint8_t EEPROMClass::read(int address) {
|
||||
return data[address];
|
||||
}
|
||||
|
||||
void EEPROMClass::update(int address, uint8_t value) {
|
||||
data[address] = value;
|
||||
}
|
||||
12
lib/ArduinoStreamUtils/extras/test/cores/teensy/EEPROM.h
Normal file
12
lib/ArduinoStreamUtils/extras/test/cores/teensy/EEPROM.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class EEPROMClass {
|
||||
public:
|
||||
uint8_t read(int);
|
||||
void update(int, uint8_t);
|
||||
// void write(int, uint8_t); <- it exists but we want to use update() instead
|
||||
};
|
||||
|
||||
extern EEPROMClass EEPROM;
|
||||
46
lib/ArduinoStreamUtils/extras/test/cores/teensy/Print.h
Normal file
46
lib/ArduinoStreamUtils/extras/test/cores/teensy/Print.h
Normal file
@@ -0,0 +1,46 @@
|
||||
// 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 size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
virtual size_t write(uint8_t data) = 0;
|
||||
virtual void flush() {}
|
||||
|
||||
virtual int availableForWrite() {
|
||||
return 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);
|
||||
}
|
||||
};
|
||||
42
lib/ArduinoStreamUtils/extras/test/cores/teensy/Stream.h
Normal file
42
lib/ArduinoStreamUtils/extras/test/cores/teensy/Stream.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Print.h"
|
||||
|
||||
struct Stream : Print {
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
String readString() {
|
||||
String result;
|
||||
int c;
|
||||
while ((c = timedRead()) >= 0) {
|
||||
result += static_cast<char>(c);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void setTimeout(unsigned long) {}
|
||||
|
||||
private:
|
||||
int timedRead() {
|
||||
return read();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
// StreamUtils - github.com/bblanchon/ArduinoStreamUtils
|
||||
// Copyright Benoit Blanchon 2019-2021
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../avr/WString.h"
|
||||
Reference in New Issue
Block a user