-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLineInput.ino
123 lines (100 loc) · 2.68 KB
/
LineInput.ino
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*---------------------------------------------------------------------------*/
/*
Line Input routine.
By Allen C. Huffman
www.subethasoftware.com
Simple line input routine, modified to call the sequencerHandler() inside
the "waiting for a character" routine. This allows the Music Sequencer to
play music while the user is entering input. :)
REFERENCES:
CONFIGURATION:
VERSION HISTORY:
2017-03-01 0.0 allenh - In the beginning...
2017-03-06 0.1 allenh - Comments.
TODO:
TOFIX:
*/
/*---------------------------------------------------------------------------*/
// Read string up to len bytes. This code comes from my Hayes AT Command
// parser, so the variables are named differently.
/*---------------------------------------------------------------------------*/
// DEFINES
/*---------------------------------------------------------------------------*/
#define CR 13
#define BEL 7
#define BS 8
//#define CAN 24
/*---------------------------------------------------------------------------*/
// FUNCTIONS
/*---------------------------------------------------------------------------*/
/*
* Line Input routine.
*
* *cmdLine - pointer to buffer to hold the input.
*
* len - length of the input buffer.
*/
byte lineinput(char *cmdLine, byte len)
{
int ch;
byte cmdLen = 0;
bool done;
done = false;
while(!done)
{
//ledBlink();
// Call handler so notes can fade, etc. in the "background".
playHandler();
ch = -1; // -1 is no data available
if (Serial.available()>0)
{
ch = Serial.read();
}
else
{
continue; // No data. Go back to the while()...
}
switch(ch)
{
case -1: // No data available.
break;
case CR:
Serial.println();
cmdLine[cmdLen] = '\0';
done = true;
break;
/*case CAN:
print(F("[CAN]"));
cmdLen = 0;
break;*/
case BS:
if (cmdLen>0)
{
Serial.print((char)BS);
//printSemi(F(" "));
//printCharSemi(BS);
cmdLen--;
}
break;
default:
// If there is room, store any printable characters in the cmdline.
if (cmdLen<len)
{
if ((ch>31) && (ch<127)) // isprint(ch) does not work.
{
Serial.print((char)ch);
cmdLine[cmdLen] = ch; // toupper(ch);
cmdLen++;
}
}
else
{
Serial.print((char)BEL); // Overflow. Ring 'dat bell.
}
break;
} // end of switch(ch)
} // end of while(!done)
return cmdLen;
} // end of lineinput()
/*---------------------------------------------------------------------------*/
// End of LineInput