1/* 2 Copyright (c) 2013 Arduino LLC. All right reserved. 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with this library; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17*/ 18 19#ifndef CONSOLE_H_ 20#define CONSOLE_H_ 21 22#include <Bridge.h> 23 24class ConsoleClass :public Stream { 25public: 26// Default constructor uses global Bridge instance 27ConsoleClass(); 28// Constructor with a user provided BridgeClass instance 29ConsoleClass(BridgeClass &_b); 30~ConsoleClass(); 31 32voidbegin(); 33voidend(); 34 35voidbuffer(uint8_t size); 36voidnoBuffer(); 37 38boolconnected(); 39 40// Stream methods 41// (read from console socket) 42intavailable(); 43intread(); 44intpeek(); 45// (write to console socket) 46size_twrite(uint8_t); 47size_twrite(const uint8_t*buffer,size_t size); 48voidflush(); 49 50operatorbool() { 51returnconnected(); 52} 53 54private: 55 BridgeClass &bridge; 56 57voiddoBuffer(); 58uint8_t inBuffered; 59uint8_t inReadPos; 60static const int BUFFER_SIZE =32; 61uint8_t*inBuffer; 62 63bool autoFlush; 64uint8_t outBuffered; 65uint8_t outBufferSize; 66uint8_t*outBuffer; 67}; 68 69extern ConsoleClass Console; 70 71#endif