-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayManager.ino
More file actions
213 lines (181 loc) · 4.33 KB
/
DisplayManager.ino
File metadata and controls
213 lines (181 loc) · 4.33 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* DisplayManager.ino
*
* OLED display management and user interface
*
* Displays:
* - Current state (idle, recording, playback)
* - Recording timer and audio level
* - Current filename and file navigation
* - Button controls and status
*/
#include "SongbirdRecorder.h"
void initializeDisplay()
{
Serial.println("Initializing display...");
// Initialize OLED display
if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDRESS))
{
Serial.println("Display initialization failed");
return;
}
display.setRotation(2); // Rotate display 180 degrees
resetDisplay();
// Show startup message
display.println("Songbird Recorder");
display.println("Initializing...");
display.display();
Serial.println("Display initialized");
}
void resetDisplay()
{
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
}
void updateDisplay()
{
resetDisplay();
// Line 1: Status and timing
if (currentState == STATE_RECORDING)
{
// Show recording status with timer
showRecordingStatus();
}
else if (currentState == STATE_PLAYBACK)
{
showPlaybackStatus();
}
else
{
showIdleStatus();
}
// DEBUG:
// display.setCursor(0, 24); // Bottom line
// display.print("USB Lvl: ");
// float level = getInputLevel();
// display.print(level, 2); // Show level with 2 decimal places
// if (level > 0.01)
// {
// display.print(" AUDIO");
// }
// else
// {
// display.print(" QUIET");
// }
display.display();
}
void showRecordingStatus()
{
// Line 1: Status and timing
// Show recording status with timer
unsigned long recordTime = (millis() - recordStartTime) / 1000;
display.print("REC ");
display.print(recordTime / 60);
display.print(":");
if (recordTime % 60 < 10) display.print("0");
display.print(recordTime % 60);
// Show audio level
float level = getInputLevel();
display.print(" L:");
drawProgressBar(80, 2, 40, 6, level);
// Line 2: Current filename or status
showFileStatus();
// Line 3: Button controls
display.setCursor(0, 24);
display.print("UP:Stop recording");
}
void showPlaybackStatus()
{
// Line 1: Status and timing
// Show playback status
display.print("PLAY");
if (playWav.isPlaying())
{
unsigned long playTime = playWav.positionMillis() / 1000;
display.print(" ");
display.print(playTime / 60);
display.print(":");
if (playTime % 60 < 10) display.print("0");
display.print(playTime % 60);
}
// Line 2: Current filename or status
showFileStatus();
// Line 3: Button controls
display.setCursor(0, 24);
display.print("UP/DN:Stop playback");
}
void showIdleStatus()
{
if (!sdCardReady)
{
// Show prominent SD card message
display.print("INSERT SD CARD");
// Line 2: instruction
display.setCursor(0, 12);
display.print("Please insert SD card");
// Line 3: Status
display.setCursor(0, 24);
display.print("Waiting for SD card...");
}
else
{
// Line 1: Status and timing
// Show idle status
display.print("IDLE");
if (totalFiles > 0)
{
display.print(" [");
display.print(currentFileIndex + 1);
display.print("/");
display.print(totalFiles);
display.print("]");
}
// Line 2: Current filename or status
showFileStatus();
// Line 3: Button controls
display.setCursor(0, 24);
if (totalFiles > 0)
{
display.print("UP:Rec DN:Play L/R:Nav");
}
else
{
display.print("UP:Record");
}
}
}
void showFileStatus()
{
display.setCursor(0, 12);
if (currentFilename.length() > 0)
{
String displayName = currentFilename;
// Truncate filename if too long
if (displayName.length() > 21)
{
displayName = displayName.substring(0, 18) + "...";
}
display.print(displayName);
}
else if (totalFiles == 0)
{
display.print("No recordings");
}
else if (!sdCardReady)
{
display.print("SD card not ready");
}
}
void drawProgressBar(int x, int y, int width, int height, float level)
{
// Draw progress bar border
display.drawRect(x, y, width, height, SSD1306_WHITE);
// Fill progress bar based on level (0.0 to 1.0)
int fillWidth = (int)(level * (width - 2));
if (fillWidth > 0)
{
display.fillRect(x + 1, y + 1, fillWidth, height - 2, SSD1306_WHITE);
}
}