9#include "platforms/io.h"
46static print_handler_t& get_print_handler() {
47 static print_handler_t handler;
51static println_handler_t& get_println_handler() {
52 static println_handler_t handler;
56static available_handler_t& get_available_handler() {
57 static available_handler_t handler;
61static read_handler_t& get_read_handler() {
62 static read_handler_t handler;
66static flush_handler_t& get_flush_handler() {
67 static flush_handler_t handler;
71static write_bytes_handler_t& get_write_bytes_handler() {
72 static write_bytes_handler_t handler;
84 if (get_print_handler()) {
85 get_print_handler()(str);
91 platforms::print(str);
101 if (get_println_handler()) {
102 get_println_handler()(str);
108 platforms::println(str);
112#ifdef FASTLED_TESTING
114 if (get_available_handler()) {
115 return get_available_handler()();
120 return platforms::available();
124 return platforms::peek();
128#ifdef FASTLED_TESTING
130 if (get_read_handler()) {
131 return get_read_handler()();
136 return platforms::read();
168 if (c == delimiter) {
178 out << static_cast<char>(c);
191 int nativeLen = platforms::readLineNative(delimiter, nativeBuf,
sizeof(nativeBuf));
192 if (nativeLen >= 0) {
209#ifdef FASTLED_TESTING
210 if (get_flush_handler()) {
211 return get_flush_handler()(timeoutMs);
214 return platforms::flush(timeoutMs);
218 if (!buffer || size == 0)
return 0;
219#ifdef FASTLED_TESTING
220 if (get_write_bytes_handler()) {
221 return get_write_bytes_handler()(buffer, size);
224 return platforms::write_bytes(buffer, size);
228 platforms::begin(baudRate);
232 return platforms::serial_ready();
241#ifdef FASTLED_TESTING
244void inject_print_handler(
const print_handler_t& handler) {
245 get_print_handler() = handler;
248void inject_println_handler(
const println_handler_t& handler) {
249 get_println_handler() = handler;
252void inject_available_handler(
const available_handler_t& handler) {
253 get_available_handler() = handler;
256void inject_read_handler(
const read_handler_t& handler) {
257 get_read_handler() = handler;
260void inject_flush_handler(
const flush_handler_t& handler) {
261 get_flush_handler() = handler;
264void inject_write_bytes_handler(
const write_bytes_handler_t& handler) {
265 get_write_bytes_handler() = handler;
269void clear_io_handlers() {
270 get_print_handler() = print_handler_t{};
271 get_println_handler() = println_handler_t{};
272 get_available_handler() = available_handler_t{};
273 get_read_handler() = read_handler_t{};
274 get_flush_handler() = flush_handler_t{};
275 get_write_bytes_handler() = write_bytes_handler_t{};
279void clear_print_handler() {
280 get_print_handler() = print_handler_t{};
283void clear_println_handler() {
284 get_println_handler() = println_handler_t{};
287void clear_available_handler() {
288 get_available_handler() = available_handler_t{};
291void clear_read_handler() {
292 get_read_handler() = read_handler_t{};
295void clear_flush_handler() {
296 get_flush_handler() = flush_handler_t{};
299void clear_write_bytes_handler() {
300 get_write_bytes_handler() = write_bytes_handler_t{};
307namespace cstdio_init {
308 void init_io_handlers() {
310 (void)get_print_handler();
311 (void)get_println_handler();
312 (void)get_available_handler();
313 (void)get_read_handler();
314 (void)get_flush_handler();
315 (void)get_write_bytes_handler();
319FL_INIT(cstdio_init_wrapper, cstdio_init::init_io_handlers)
bool has_value() const FL_NOEXCEPT
string str() const FL_NOEXCEPT
void delay_impl(u32 ms, bool run_async)
Internal delay implementation used by the public fl::delay wrapper.
Compile-time linker keep-alive hook for a single fl::Bus.
void print(const char *str)
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
void serial_begin(u32 baudRate)
@ FL_LOG_LEVEL_DEBUG
All logging including debug (default)
@ FL_LOG_LEVEL_NONE
No logging (completely silent)
expected< T, E > result
Alias for expected (Rust-style naming)
constexpr nullopt_t nullopt
bool readStringUntil(sstream &out, char delimiter, char skipChar, fl::optional< u32 > timeoutMs)
size_t write_bytes(const u8 *buffer, size_t size)
u8 getLogLevel()
Get the current global log level.
void println(const char *str) FL_NOEXCEPT
void delayMicroseconds(u32 us)
Delay for a given number of microseconds.
bool flush(u32 timeoutMs)
void setLogLevel(u8 level)
Set the global log level.
fl::optional< fl::string > readLine(char delimiter, char skipChar, fl::optional< u32 > timeoutMs)
Base definition for an LED controller.