2010-10-23 02:59:40 -03:00
|
|
|
// -*- Mode: C++; c-basic-offset: 8; indent-tabs-mode: nil -*-
|
|
|
|
//
|
|
|
|
// Copyright (c) 2010 Michael Smith. All rights reserved.
|
|
|
|
//
|
|
|
|
// This 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.
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Enhancements to the Arduino Stream class.
|
|
|
|
//
|
|
|
|
|
2011-06-12 19:26:39 -03:00
|
|
|
#include <limits.h>
|
2010-10-23 02:59:40 -03:00
|
|
|
#include "BetterStream.h"
|
|
|
|
|
|
|
|
// Stream extensions////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void
|
2011-03-21 04:25:48 -03:00
|
|
|
BetterStream::print_P(const prog_char_t *s)
|
2010-10-23 02:59:40 -03:00
|
|
|
{
|
|
|
|
char c;
|
|
|
|
|
2011-03-21 04:25:48 -03:00
|
|
|
while ('\0' != (c = pgm_read_byte((const prog_char *)s++)))
|
2010-10-23 02:59:40 -03:00
|
|
|
write(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-03-21 04:25:48 -03:00
|
|
|
BetterStream::println_P(const prog_char_t *s)
|
2010-10-23 02:59:40 -03:00
|
|
|
{
|
|
|
|
print_P(s);
|
|
|
|
println();
|
|
|
|
}
|
|
|
|
|
2010-11-22 20:38:16 -04:00
|
|
|
void
|
2010-10-23 02:59:40 -03:00
|
|
|
BetterStream::printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2010-11-22 20:38:16 -04:00
|
|
|
_vprintf(0, fmt, ap);
|
2010-10-23 02:59:40 -03:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2010-11-22 20:38:16 -04:00
|
|
|
void
|
2012-11-21 01:17:50 -04:00
|
|
|
BetterStream::_printf_P(const prog_char_t *fmt, ...)
|
2010-10-23 02:59:40 -03:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2012-11-21 01:17:50 -04:00
|
|
|
_vprintf(1, (const char *)fmt, ap);
|
2010-10-23 02:59:40 -03:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2012-11-21 01:17:50 -04:00
|
|
|
void
|
|
|
|
BetterStream::vprintf_P(const prog_char_t *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
_vprintf(1, (const char *)fmt, ap);
|
|
|
|
}
|
|
|
|
|
2011-06-12 19:26:39 -03:00
|
|
|
int
|
2011-09-04 19:52:11 -03:00
|
|
|
BetterStream::txspace(void)
|
2011-06-12 19:26:39 -03:00
|
|
|
{
|
2011-09-04 19:52:11 -03:00
|
|
|
// by default claim that there is always space in transmit buffer
|
2011-06-12 19:26:39 -03:00
|
|
|
return(INT_MAX);
|
|
|
|
}
|