cgnuino
cgnuino.h
Go to the documentation of this file.
1 
7 #ifndef INCLUDED_CGNUINO
8 #define INCLUDED_CGNUINO
9 
10 #include "Arduino.h"
11 
16 #define countof(array) (sizeof(array) / sizeof(array[0]))
17 
18 extern const uint32_t ULONG_MAX;
19 extern const byte BYTE_MAX;
20 constexpr byte N_CGNDI = 10;
21 constexpr byte N_CGNDO = 10;
22 constexpr byte N_CGNVALTIEL = 20;
23 
27 class CgnDI {
28  public:
29  CgnDI(byte, byte = 1, byte = NULL, byte = 2);
30  void update();
31  bool on(byte = 0);
32  bool off(byte = 0);
33  bool turnon(byte = 0);
34  bool turnoff(byte = 0);
35  bool change(byte = 0);
36  bool keep(byte = 0);
37 
38  private:
39  byte first;
40  byte n;
41  byte relay;
42  bool relaid;
43  bool cur[N_CGNDI];
44  bool pre[N_CGNDI];
45  byte r;
46  byte rest[N_CGNDI];
47  uint32_t last;
48 };
49 
53 class CgnDO {
54  public:
55  CgnDO(byte, byte = 1, char = 'd');
56  void update();
57  void out(byte, uint32_t, uint16_t = 440);
58 
59  private:
60  byte first;
61  byte n;
62  char type;
63  uint32_t limit[N_CGNDO];
64 };
65 
69 class CgnLogger {
70  public:
71  CgnLogger(bool = false, byte = NULL, byte = 0);
72  void update(bool);
73  bool on();
74  bool off();
75  bool turnon();
76  bool turnoff();
77  bool change();
78  bool keep();
79 
80  private:
81  bool cur;
82  bool pre;
83  byte relay;
84  bool relaid;
85  byte r;
86  byte rest;
87  uint32_t last;
88 };
89 
93 class CgnPause {
94  public:
95  CgnPause(byte, bool = LOW, uint16_t = 100);
96  void check();
97 
98  private:
99  byte pin;
100  bool stopwhen;
101  uint16_t cycle;
102 };
103 
107 class CgnPeriod {
108  public:
109  CgnPeriod();
110  void set(String, uint32_t = 0);
111  bool is(String);
112  bool expire();
113  String get();
114  uint32_t until();
115 
116  private:
117  String period;
118  uint32_t limit;
119 };
120 
124 class CgnSerial {
125  public:
126  CgnSerial(char = 10, char = 9);
127  String update(bool = true);
128  int getCode();
129  String getValue();
130  void append(String);
131  void out();
132  void clear();
133 
134  private:
135  int c;
136  String v;
137  char eol;
138  char sep;
139  String data;
140 };
141 
146  public:
147  CgnStopwatch();
148  uint32_t lap();
149  uint32_t get();
150 
151  private:
152  uint32_t from;
153 };
154 
158 class CgnStrobe {
159  public:
160  CgnStrobe(byte, uint32_t = 5);
161  uint32_t out(String);
162 
163  private:
164  void wait();
165  byte first;
166  uint32_t len;
167  bool us;
168 };
169 
173 class CgnValtiel {
174  public:
175  CgnValtiel();
176  float update();
177 
178  private:
179  uint32_t from;
180  uint32_t n;
181  byte l[N_CGNVALTIEL];
182 };
183 
184 #endif
185 
Remembers current task period and its time constraint.
Definition: cgnuino.h:107
Offers convenient digital-in buffering.
Definition: cgnuino.h:27
void update()
Updates DI buffer by current pin voltages.
Definition: CgnDI.cpp:47
bool turnoff(byte=0)
Checks whether i-th DI pin was turned off in current loop.
Definition: CgnDI.cpp:100
bool on(byte=0)
Checks whether i-th DI pin is on (active).
Definition: CgnDI.cpp:76
Logs arbitorary bit change similar to CgnDI class.
Definition: cgnuino.h:69
bool change(byte=0)
Checks whether i-th DI pin was changed from previous loop.
Definition: CgnDI.cpp:108
constexpr byte N_CGNVALTIEL
Number of buffers CgnValtiel, speed checker for main loop, can holds.
Definition: cgnuino.h:22
Temporally pauses task progression by digital-in pin state.
Definition: cgnuino.h:93
Emits asynchroneous digital-out.
Definition: cgnuino.h:53
bool turnon(byte=0)
Checks whether i-th DI pin was turned on in current loop.
Definition: CgnDI.cpp:92
bool off(byte=0)
Checks whether i-th DI pin is off (inactive).
Definition: CgnDI.cpp:84
const uint32_t ULONG_MAX
Maximal value for unsigned long.
Definition: Cgn.cpp:4
bool keep(byte=0)
Checks whether i-th DI pin kept unchanged from previous loop.
Definition: CgnDI.cpp:116
Monitors average length of executed loops on Arduino.
Definition: cgnuino.h:173
constexpr byte N_CGNDO
Number of pins that can be simultaneously set for a CgnDO instance.
Definition: cgnuino.h:21
CgnDI(byte, byte=1, byte=NULL, byte=2)
Constructor.
Definition: CgnDI.cpp:17
const byte BYTE_MAX
Maximal value for byte.
Definition: Cgn.cpp:5
Communicates with external control apprication running on the PC.
Definition: cgnuino.h:124
Emits a text as one-by-one characters using (8 + 1)-bit digital-out.
Definition: cgnuino.h:158
Measures time difference in milliseconds.
Definition: cgnuino.h:145
constexpr byte N_CGNDI
Number of pins that can be simultaneously set for a CgnDI instance.
Definition: cgnuino.h:20