11 #include "Printable.h"
18 #include "TextColors.h"
19 #include <realtimeapiset.h>
20 #include <processthreadsapi.h>
27 #define OSTREAM printStream
29 #define STREAM OSTREAM
36 static auto test(
const U* u) -> decltype(std::cout << *u);
38 static auto test(...)->std::false_type;
41 enum { value = !std::is_same_v<decltype(test((T*)0)), std::false_type> };
44 template<
typename T>
typename std::enable_if<std::is_floating_point<T>::value,
char*>::type ftoa(T f,
char * buf,
int precision) {
51 #define MAX_PRECISION (10)
52 static const double rounders[MAX_PRECISION + 1] =
68 if (precision > MAX_PRECISION)
69 precision = MAX_PRECISION;
80 if (f < 1.0) precision = 6;
81 else if (f < 10.0) precision = 5;
82 else if (f < 100.0) precision = 4;
83 else if (f < 1000.0) precision = 3;
84 else if (f < 10000.0) precision = 2;
85 else if (f < 100000.0) precision = 1;
91 f += rounders[precision];
107 *p++ =
'0' + intPart % 10;
183 size_t print(
char data);
185 size_t print(int32_t data, uint8_t base = DEC);
187 size_t print(uint32_t data, uint8_t base = DEC);
189 size_t print(
double data);
191 size_t print(std::string data);
193 size_t print(
const char* data);
195 template <
typename T>
size_t println(T data) {
196 size_t ret = print(data);
203 size_t write(
char val);
205 size_t write(uint8_t* val,
size_t count);
207 size_t write(
char* val,
size_t count);
211 printStream& operator<<(std::chrono::nanoseconds data);
213 template<
typename T> std::enable_if_t<is_streamable_cout<T>::value,
printStream&> operator<<(T data)
228 bool startsWith(
const char* txt);
230 bool startsWith(std::string txt);
232 int indexOf(
char c)
const;
234 int indexOf(
char ch,
unsigned int fromIndex)
const;
236 int indexOf(
const char* s2)
const {
237 return indexOf(
String(s2));
240 int indexOf(
const char* s2,
unsigned int fromIndex)
const {
241 return indexOf(
String(s2), fromIndex);
244 int indexOf(
const String& s2)
const;
246 int indexOf(
const String& s2,
unsigned int fromIndex)
const;
248 String substring(
size_t from,
size_t to);
250 String substring(
size_t from);
261 membuf(
char* p,
size_t size)
265 size_t written() {
return pptr() - pbase(); }
270 int32_t random(int32_t to);
272 int32_t random(int32_t from, int32_t to);
290 inline bool false_ret() {
294 #define __get_PRIMASK false_ret
295 #define __disable_irq()
296 #define __enable_irq()
301 template <
typename T>
304 template <
typename U>
305 static auto test(
const U* u) -> decltype(pout << *u);
307 static auto test(...)->std::false_type;
310 enum { value = !std::is_same_v<decltype(test((T*)0)), std::false_type> };