forked from orangkucing/MewPro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha_Queue.ino
More file actions
58 lines (52 loc) · 1.67 KB
/
Copy patha_Queue.ino
File metadata and controls
58 lines (52 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#define MEWPRO_BUFFER_LENGTH 64
byte queue[MEWPRO_BUFFER_LENGTH];
volatile int queueb = 0, queuee = 0;
boolean waiting = false;
// "waiting" flag is used to prevent reading the next command from the
// queue until a response has been received to previous command (processed
// in d_BacpacCommands, checkBacpacCommands())
void emptyQueue()
{
queueb = queuee = 0;
waiting = false;
}
boolean inputAvailable()
{ // Test if any messages exist, either in the queue or on the serial line
if (!waiting && (queueb != queuee || Serial.available())) {
return true;
}
return false;
}
byte myRead()
{ // This reads Serial messages. First from the queue, then from the
// Serial monitor line
if (queueb != queuee) {
byte c = queue[queueb];
queueb = (queueb + 1) % MEWPRO_BUFFER_LENGTH;
return c;
}
return Serial.read();
}
// Utility functions
void queueIn(const __FlashStringHelper *p)
{ // queueIn allows MewPro to "fake" a serial message from user. MewPro
// processes this message as though it had come from the Serial monitor
int i;
char c;
for (i = 0; (c = pgm_read_byte((char PROGMEM *)p + i)) != 0; i++) {
queue[(queuee + i) % MEWPRO_BUFFER_LENGTH] = c;
}
queue[(queuee + i) % MEWPRO_BUFFER_LENGTH] = '\n';
queuee = (queuee + i + 1) % MEWPRO_BUFFER_LENGTH;
}
void queueIn(const char *p)
{ // queueIn allows MewPro to "fake" a serial message from user. MewPro
// processes this message as though it had come from the Serial monitor
int i;
char c;
for (i = 0; (c = *(p + i)) != 0; i++) {
queue[(queuee + i) % MEWPRO_BUFFER_LENGTH] = c;
}
queue[(queuee + i) % MEWPRO_BUFFER_LENGTH] = '\n';
queuee = (queuee + i + 1) % MEWPRO_BUFFER_LENGTH;
}