mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-02 14:13:42 -04:00
271d4736a8
Add print_P and println_P implementations to give folks wedded to the vanilla Stream methods a way to print PROGMEM strings. git-svn-id: https://arducopter.googlecode.com/svn/trunk@715 f9c3cf11-9bcb-44bc-f272-b75c42450872
39 lines
1.2 KiB
C++
39 lines
1.2 KiB
C++
// -*- 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.
|
|
//
|
|
|
|
#include <Stream.h>
|
|
#include <avr/pgmspace.h>
|
|
|
|
class BetterStream : public Stream {
|
|
public:
|
|
BetterStream(void) {
|
|
// init stdio
|
|
fdev_setup_stream(&fd, &BetterStream::_putchar, &BetterStream::_getchar, _FDEV_SETUP_RW);
|
|
fdev_set_udata(&fd, this);
|
|
}
|
|
|
|
// Stream extensions
|
|
void print_P(const char *s);
|
|
void println_P(const char *s);
|
|
|
|
// stdio extensions
|
|
int printf(const char *fmt, ...);
|
|
int printf_P(const char *fmt, ...);
|
|
|
|
protected:
|
|
// subclasses can use this to e.g. set up stdin/stdout/stderr.
|
|
FILE fd;
|
|
|
|
private:
|
|
// stdio emulation
|
|
static int _putchar(char c, FILE *stream);
|
|
static int _getchar(FILE *stream);
|
|
};
|