moccos mizuki / ATP3011F4
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ATP3011F4UART.h Source File

ATP3011F4UART.h

00001 #ifndef ATP3011F4UART_H
00002 #define ATP3011F4UART_H
00003 #include "ATP3011F4.h"
00004 
00005 /**
00006  * Control ATP3011F4 through UART.
00007  * @author moccos <tt.izawa, gmail>
00008  * Example:
00009  * @code
00010  * int main() {
00011  *     Serial ch(p9, p10);
00012  *     Serial pc(USBTX, USBRX);
00013  *     char cmd;
00014  * 
00015  *     ATP3011F4UART aq(&ch);
00016  *     aq.init();
00017  *     aq.waitCompletion();
00018  * 
00019  *     while (1) {
00020  *         if (pc.readable()) {
00021  *             cmd = pc.getc();
00022  *             if (cmd == '\r' || cmd == '\n') {
00023  *                 cmd = '\r';
00024  *             }
00025  *             // pc.putc(cmd);  // echo back
00026  *             aq.putc(cmd);
00027  *             if (cmd == '\r') {
00028  *                 aq.waitCompletion();
00029  *                 aq.chimeJ();
00030  *                 aq.waitCompletion();
00031  *             }
00032  *         }
00033  *     }
00034  * }
00035  * @endcode
00036  */
00037 class ATP3011F4UART : public ATP3011F4 {
00038 public:
00039     ATP3011F4UART(Serial *serial);
00040     virtual ~ATP3011F4UART(){};
00041     virtual bool init();
00042     virtual bool send(const char* str);
00043     virtual bool sendr(const char* str);
00044     virtual void waitCompletion();
00045     
00046     /** Puts one character */
00047     void putc(const char c) { ch->putc(c); };
00048 
00049 private:
00050     void flush();
00051     void receiveChar();
00052 
00053 private:
00054     Serial* ch;
00055 };
00056 
00057 #endif