CANSAT_CAMERA
Dependents: CANSAT_COMBINED CANSAT_CAMERA_servo CANSAT_CAMERA2
Fork of Camera_LS_Y201 by
SerialBuffered.h
00001 /** 00002 * ============================================================================= 00003 * LS-Y201 device driver class (Version 0.0.1) 00004 * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface 00005 * January 2010 00006 * ============================================================================= 00007 * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems) 00008 * 00009 * Permission is hereby granted, free of charge, to any person obtaining a copy 00010 * of this software and associated documentation files (the "Software"), to deal 00011 * in the Software without restriction, including without limitation the rights 00012 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 * copies of the Software, and to permit persons to whom the Software is 00014 * furnished to do so, subject to the following conditions: 00015 * 00016 * The above copyright notice and this permission notice shall be included in 00017 * all copies or substantial portions of the Software. 00018 * 00019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 * THE SOFTWARE. 00026 * ============================================================================= 00027 */ 00028 00029 #ifndef _SERIAL_BUFFERED_H_ 00030 #define _SERIAL_BUFFERED_H_ 00031 00032 /** 00033 * Buffered serial class. 00034 */ 00035 class SerialBuffered : public Serial { 00036 public: 00037 /** 00038 * Create a buffered serial class. 00039 * 00040 * @param tx A pin for transmit. 00041 * @param rx A pin for receive. 00042 */ 00043 SerialBuffered(PinName tx, PinName rx); 00044 00045 /** 00046 * Destroy. 00047 */ 00048 virtual ~SerialBuffered(); 00049 00050 /** 00051 * Get a character. 00052 * 00053 * @return A character. (-1:timeout) 00054 */ 00055 int getc(); 00056 00057 /** 00058 * Returns 1 if there is a character available to read, 0 otherwise. 00059 */ 00060 int readable(); 00061 00062 /** 00063 * Set timeout for getc(). 00064 * 00065 * @param ms milliseconds. (-1:Disable timeout) 00066 */ 00067 void setTimeout(int ms); 00068 00069 /** 00070 * Read requested bytes. 00071 * 00072 * @param bytes A pointer to a buffer. 00073 * @param requested Length. 00074 * 00075 * @return Readed byte length. 00076 */ 00077 size_t readBytes(uint8_t *bytes, size_t requested); 00078 00079 private: 00080 void handleInterrupt(); 00081 static const int BUFFERSIZE = 4096; 00082 uint8_t buffer[BUFFERSIZE]; // points at a circular buffer, containing data from m_contentStart, for m_contentSize bytes, wrapping when you get to the end 00083 uint16_t indexContentStart; // index of first bytes of content 00084 uint16_t indexContentEnd; // index of bytes after last byte of content 00085 int timeout; 00086 Timer timer; 00087 }; 00088 00089 #endif
Generated on Tue Jul 12 2022 13:49:23 by 1.7.2