-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialManager.ino
More file actions
167 lines (151 loc) · 3.85 KB
/
SerialManager.ino
File metadata and controls
167 lines (151 loc) · 3.85 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* SerialManager.ino
*
* Serial command interface for manual file management
*
* Commands:
* - LIST: Show all recordings
* - DELETE filename.wav: Delete a specific recording
* - DELETEALL: Delete all WAV files in the CALLS directory
* - HELP: Show available commands
* - STATUS: Show system status
*/
#include "SongbirdRecorder.h"
void handleSerialCommands()
{
if (!Serial.available()) return;
// Read command for serial
String commandLine = Serial.readStringUntil('\n');
commandLine.trim();
Serial.print("Command received: ");
Serial.println(commandLine);
String command = "";
String arguments = "";
int spaceIndex = commandLine.indexOf(' ');
if (spaceIndex != -1)
{
// We've got arguments!
command = commandLine.substring(0, spaceIndex);
arguments = commandLine.substring(spaceIndex + 1);
arguments.trim();
}
else
{
command = commandLine;
}
command.toUpperCase();
// Process commands
if (command == "LIST")
{
listFiles();
}
else if (command == "DELETE")
{
if (arguments.length() == 0)
{
// No filename provided
Serial.println("ERROR: Please provide a filename to delete");
Serial.println("Usage: DELETE filename.wav");
Serial.println("Or use DELETEALL to delete all recordings");
}
else
{
deleteFile(arguments);
}
}
else if (command == "DELETEALL")
{
deleteAll();
}
else if (command == "HELP")
{
showHelp();
}
else if (command == "STATUS")
{
showStatus();
}
else if (command == "SCAN")
{
Serial.println("Rescanning SD card...");
scanForFiles();
}
else if (command == "INIT")
{
Serial.println("Reinitializing SD card...");
initializeSDCard();
}
else if (command == "")
{
// Ignore empty commands
}
else
{
Serial.print("Unknown command: ");
Serial.println(command);
Serial.println("Type HELP for available commands");
}
}
void showHelp()
{
Serial.println("=== Songbird Call Recorder Commands ===");
Serial.println("LIST - List all recordings");
Serial.println("DELETE filename.wav - Delete a recording");
Serial.println("DELETEALL - Delete all recordings");
Serial.println("STATUS - Show system status");
Serial.println("SCAN - Rescan SD card for files");
Serial.println("INIT - Reinitialize SD card");
Serial.println("HELP - Show this help");
Serial.println("");
Serial.println("Button Controls:");
Serial.println("UP - Start/Stop recording");
Serial.println("DOWN - Play/Pause current recording");
Serial.println("LEFT - Previous recording");
Serial.println("RIGHT - Next recording");
}
void showStatus()
{
Serial.println("=== System Status ===");
// Current state
Serial.print("State: ");
switch (currentState) {
case STATE_IDLE:
Serial.println("IDLE");
break;
case STATE_RECORDING:
Serial.print("RECORDING (");
Serial.print((millis() - recordStartTime) / 1000);
Serial.println(" seconds)");
break;
case STATE_PLAYBACK:
Serial.println("PLAYBACK");
break;
}
// SD card status
Serial.print("SD Card: ");
if (sdCardReady) {
Serial.println("Ready");
} else {
Serial.println("Not Ready");
}
// File information
Serial.print("Total Files: ");
Serial.println(totalFiles);
if (totalFiles > 0) {
Serial.print("Current File: [");
Serial.print(currentFileIndex + 1);
Serial.print("/");
Serial.print(totalFiles);
Serial.print("] ");
Serial.println(currentFilename);
}
// Audio level
Serial.print("Audio Level: ");
Serial.println(getInputLevel());
// Memory usage
Serial.print("Audio Memory: ");
Serial.print(AudioMemoryUsage());
Serial.print("/");
Serial.print(AudioMemoryUsageMax());
Serial.println(" blocks");
}