Arduino Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
uart.hpp
Go to the documentation of this file.
1 // Author: Mario S. Könz <mskoenz@gmx.net>
2 // Date: 14.06.2013 23:08:37 EDT
3 // File: prototype_uart.hpp
4 
5 /* This program is free software. It comes without any warranty, to
6  * the extent permitted by applicable law. You can redistribute it
7  * and/or modify it under the terms of the Do What The Fuck You Want
8  * To Public License, Version 2, as published by Sam Hocevar. See
9  * http://www.wtfpl.net/ or COPYING for more details. */
10 
11 #ifndef __PROTOTYPE_UART_HEADER
12 #define __PROTOTYPE_UART_HEADER
13 
14 #include "serializer.hpp"
15 
16 namespace com {
17  //------------------- of class -------------------
18  template<typename D>
19  class osw_class {
20  public:
22 
23  osw_class(D & data): data(data) {
24  }
25  template<typename T>
26  osw_class & operator&(T & t) {
27  serialize(*this, t);
28  return (*this);
29  }
30  void write(uint8_t const & in) {
31  data.write(in);
32  }
33  private:
34  D & data;
35  };
36 
37  //------------------- if class -------------------
38  template<typename D>
39  class isw_class {
40  public:
42 
43  isw_class(D & data): data(data) {
44  }
45  template<typename T>
46  isw_class & operator&(T & t) {
47  serialize(*this, t);
48  return (*this);
49  }
50  uint8_t read() {
51  while(!data.available());
52  return data.read();
53  }
54  private:
55  D & data;
56  };
57  //------------------- combined class -------------------
58  template<typename D>
60  typedef uint16_t size_type;
61  public:
62  uart_class_template(D & data): data_(data), osw_(data), isw_(data) {
63  }
64  operator bool() {
65  return available() > 0;
66  }
67 
68  size_type available() const {
69  return data_.available();
70  }
71 
72  template<typename T>
74  osw_ & t;
75  return (*this);
76  }
77  template<typename T>
79  isw_ & t;
80  return (*this);
81  }
82  void wait() {
83  while(!available()) {};
84  }
85  //~ void reflect() {
86  //~ osw_.write(isw_.read());
87  //~ }
88  private:
89  D & data_;
90  osw_class<D> osw_;
91  isw_class<D> isw_;
92  };
93 
94  #ifdef Arduino_h
95  uart_class_template<HardwareSerial> uart(Serial);
96  #endif //Arduino_h
97 }//end namespace com
98 #endif //__PROTOTYPE_UART_HEADER
void serialize(Archive &ar, T &t)
Definition: serializer.hpp:95
static archive_enum const type
Definition: uart.hpp:21
Definition: uart.hpp:39
Definition: uart.hpp:19
uint8_t read()
Definition: uart.hpp:50
osw_class(D &data)
Definition: uart.hpp:23
void write(uint8_t const &in)
Definition: uart.hpp:30
size_type available() const
Definition: uart.hpp:68
isw_class & operator&(T &t)
Definition: uart.hpp:46
uart_class_template & operator<<(T &t)
Definition: uart.hpp:73
void wait()
Definition: uart.hpp:82
osw_class & operator&(T &t)
Definition: uart.hpp:26
archive_enum
Definition: archive_enum.hpp:14
serial_class Serial
uart_class_template & operator>>(T &t)
Definition: uart.hpp:78
uart_class_template(D &data)
Definition: uart.hpp:62
static archive_enum const type
Definition: uart.hpp:41
Definition: uart.hpp:59
isw_class(D &data)
Definition: uart.hpp:43