char_dev.hpp
Go to the documentation of this file.
1 /*
2  * SocialLedge.com - Copyright (C) 2013
3  *
4  * This file is part of free software framework for embedded processors.
5  * You can use it and/or distribute it as long as this copyright header
6  * remains unmodified. The code is free for personal use and requires
7  * permission to use in a commercial product.
8  *
9  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
10  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
12  * I SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
13  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
14  *
15  * You can reach the author of this software at :
16  * p r e e t . w i k i @ g m a i l . c o m
17  */
18 
26 #ifndef CHAR_DEV_HPP_
27 #define CHAR_DEV_HPP_
28 
29 #include <stdint.h>
30 
31 #include "FreeRTOS.h"
32 #include "queue.h"
33 #include "semphr.h"
34 
35 
36 
43 class CharDev
44 {
45  public:
53  virtual bool getChar(char* pInputChar, unsigned int timeout=portMAX_DELAY) = 0;
54 
62  virtual bool putChar(char out, unsigned int timeout=portMAX_DELAY) = 0;
63 
67  virtual bool flush(void) { return true; }
68 
73  bool put (const char* pString, unsigned int timeout=0xffffffff);
74  void putline(const char* pBuff, unsigned int timeout=0xffffffff);
83  bool gets(char* pBuff, int maxLen, unsigned int timeout=0xffffffff);
84 
89  int printf(const char *format, ...);
90 
96  int scanf(const char *format, ...);
97 
101  inline uint16_t getPrintfMemSize(void) const { return mPrintfMemSize; }
102 
107  bool isReady(void) { return mReady; }
108  void setReady(bool r) { mReady = r; }
111  protected:
112  CharDev();
113  virtual ~CharDev();
114 
115  private:
116  char *mpPrintfMem;
117  uint16_t mPrintfMemSize;
118  SemaphoreHandle_t mPrintfSemaphore;
119  bool mReady;
120 };
121 
122 
123 
124 #endif /* CHAR_DEV_HPP_ */
virtual bool putChar(char out, unsigned int timeout=portMAX_DELAY)=0
#define portMAX_DELAY
Definition: portmacro.h:106
uint16_t getPrintfMemSize(void) const
Definition: char_dev.hpp:101
void setReady(bool r)
Definition: char_dev.hpp:108
bool gets(char *pBuff, int maxLen, unsigned int timeout=0xffffffff)
Definition: char_dev.cpp:54
int scanf(const char *format,...)
Definition: char_dev.cpp:130
CharDev()
Definition: char_dev.cpp:145
int printf(const char *format,...)
Definition: char_dev.cpp:81
virtual bool getChar(char *pInputChar, unsigned int timeout=portMAX_DELAY)=0
virtual ~CharDev()
Definition: char_dev.cpp:151
bool isReady(void)
Definition: char_dev.hpp:107
bool put(const char *pString, unsigned int timeout=0xffffffff)
Definition: char_dev.cpp:33
Definition: char_dev.hpp:43
virtual bool flush(void)
Definition: char_dev.hpp:67
void putline(const char *pBuff, unsigned int timeout=0xffffffff)
Definition: char_dev.cpp:48
QueueHandle_t SemaphoreHandle_t
Definition: semphr.h:79