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
30
31
35
36
37
43
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
79
80
81
82
83
84
85
86
87
92
99
100
105
109
110
115
119
120
125
129
130
135
136
137
141
145
149
153
157
158
159
164
175
176
181
192
193
198
209
210
215
226
231
232
233
234
235
236
237
238
239
245
246
247
248
249
250
251
255
256
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
303
305
306
307
308
313
314
315
316
317
318
319
320
321
322
323
324
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
362
364
365
366
367
372
373
374
375
376
377
384
385
389
390
397
398
399
400
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
472
473
477
478
479
480
481
482
483
484
485
486
487
488
493
494
499
500
504
505
506
507
508
509
510
511
512
513
514
515
516
517
523
524
530
531
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
574
575
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
603
604
605
606
613
618
619
622
623
/* ... */
#include "main.h"
#include "audio_recorder_res.c"
#include "../Common/audio_if.h"
#include "audio_recorder_app.h"
/* ... */
/* ... */
Includes
static void Startup(WM_HWIN hWin, uint16_t xpos, uint16_t ypos);
extern FATFS mSDDISK_FatFs;
extern char mSDDISK_Drive[4];
Private function prototypes
K_ModuleItem_Typedef audio_recorder_board =
{
3,
(uint8_t*)"",
&bmrecorder5,
Startup,
...}
;
Private typedef
#define ID_MAIN_FRAME (GUI_ID_USER + 0x00)
#define ID_BUTTON_EXIT (GUI_ID_USER + 0x02)
#define ID_IMAGE_0 (GUI_ID_USER + 0x03)
#define ID_RECORD_CANCEL (GUI_ID_USER + 0x04)
#define ID_RECORD_REC_CANCEL_PLAY (GUI_ID_USER + 0x05)
#define ID_RECORD_SAVE (GUI_ID_USER + 0x06)
#define ID_ELAPSED_TIME (GUI_ID_USER + 0x07)
#define ID_PROCESS_TIMER (GUI_ID_USER + 0x0E)
#define RECORDER_MODE_REC_DISABLED 0x00
#define RECORDER_MODE_REC_IDLE 0x01
#define RECORDER_MODE_RECORDING 0x02
#define RECORDER_MODE_PLAY_IDLE 0x03
#define RECORDER_MODE_PLAYING 0x04
13 defines
Private defines
static const GUI_WIDGET_CREATE_INFO _aDialog[] =
{
{ WINDOW_CreateIndirect, "", ID_MAIN_FRAME, 0, 0, 240, 240, 0, 0x64, 0 },
{ TEXT_CreateIndirect, "00:00", ID_ELAPSED_TIME, 85, 180, 80, 32, 0, 0x0, 0 },
...};
static WM_HWIN hMainWin;
extern K_ModuleItem_Typedef audio_player_board;
static uint8_t RecorderMode;
static char FileName[256];
RNG_HandleTypeDef hRNG;
Private variables
/* ... */
static void _BuildFileName(void) {
hRNG.Instance = RNG;
__HAL_RCC_RNG_CLK_ENABLE();
HAL_RNG_Init(&hRNG);
sprintf(FileName, "record-%04lu.wav", HAL_RNG_GetRandomNumber(&hRNG) % 10000);
}{ ... }
/* ... */
static void _OnPaint_exit(BUTTON_Handle hObj)
{
GUI_DrawBitmap(&bmexit, 20, 0);
}{ ... }
/* ... */
static void _OnPaint_cancel(BUTTON_Handle hObj)
{
GUI_DrawBitmap(&bmrecord_cancel, 0, 0);
}{ ... }
/* ... */
static void _OnPaint_save(BUTTON_Handle hObj)
{
GUI_DrawBitmap(&bmsave, 0, 0);
}{ ... }
/* ... */
static void _OnPaint_record(BUTTON_Handle hObj) {
if(RecorderMode == RECORDER_MODE_REC_DISABLED)
{
GUI_DrawBitmap(&bmrecord_des, 0, 0);
}if (RecorderMode == RECORDER_MODE_REC_DISABLED) { ... }
else if(RecorderMode == RECORDER_MODE_PLAYING)
{
GUI_DrawBitmap(&bmrecord_play, 0, 0);
}else if (RecorderMode == RECORDER_MODE_PLAYING) { ... }
else if(RecorderMode == RECORDER_MODE_REC_IDLE)
{
GUI_DrawBitmap(&bmrecord, 0, 0);
}else if (RecorderMode == RECORDER_MODE_REC_IDLE) { ... }
else if(RecorderMode == RECORDER_MODE_PLAY_IDLE)
{
GUI_DrawBitmap(&bmrecord_play, 0, 0);
}else if (RecorderMode == RECORDER_MODE_PLAY_IDLE) { ... }
else if(RecorderMode == RECORDER_MODE_RECORDING)
{
GUI_DrawBitmap(&bmrecord_pause, 0, 0);
}else if (RecorderMode == RECORDER_MODE_RECORDING) { ... }
}{ ... }
/* ... */
static void _cbButton_record(WM_MESSAGE * pMsg) {
switch (pMsg->MsgId) {
case WM_PAINT:
_OnPaint_record(pMsg->hWin);
break;case WM_PAINT:
default:
BUTTON_Callback(pMsg);
break;default
}switch (pMsg->MsgId) { ... }
}{ ... }
/* ... */
static void _cbButton_exit(WM_MESSAGE * pMsg) {
switch (pMsg->MsgId) {
case WM_PAINT:
_OnPaint_exit(pMsg->hWin);
break;case WM_PAINT:
default:
BUTTON_Callback(pMsg);
break;default
}switch (pMsg->MsgId) { ... }
}{ ... }
/* ... */
static void _cbButton_cancel(WM_MESSAGE * pMsg) {
switch (pMsg->MsgId) {
case WM_PAINT:
_OnPaint_cancel(pMsg->hWin);
break;case WM_PAINT:
default:
BUTTON_Callback(pMsg);
break;default
}switch (pMsg->MsgId) { ... }
}{ ... }
/* ... */
static void _cbButton_save(WM_MESSAGE * pMsg) {
switch (pMsg->MsgId) {
case WM_PAINT:
_OnPaint_save(pMsg->hWin);
break;case WM_PAINT:
default:
BUTTON_Callback(pMsg);
break;default
}switch (pMsg->MsgId) { ... }
}{ ... }
/* ... */
static void _cbMediaConnection(WM_MESSAGE * pMsg)
{
WM_HWIN hItem;
static WM_HTIMER hStatusTimer;
static uint8_t prev_msd_status = 0;
switch (pMsg->MsgId)
{
case WM_CREATE:
prev_msd_status = k_StorageGetStatus(MSD_DISK_UNIT);
hStatusTimer = WM_CreateTimer(pMsg->hWin, 0, 500, 0);
break;
case WM_CREATE:
case WM_TIMER:
if(prev_msd_status != k_StorageGetStatus(MSD_DISK_UNIT))
{
prev_msd_status = k_StorageGetStatus(MSD_DISK_UNIT);
if(prev_msd_status == 0)
{
if( RecorderMode == RECORDER_MODE_RECORDING)
{
AUDIO_RECORDER_StopRec();
}if (RecorderMode == RECORDER_MODE_RECORDING) { ... }
else if( RecorderMode == RECORDER_MODE_PLAYING)
{
AUDIO_RECORDER_StopPlayer();
}else if (RecorderMode == RECORDER_MODE_PLAYING) { ... }
RecorderMode = RECORDER_MODE_REC_DISABLED;
hItem = WM_GetDialogItem(hMainWin, ID_RECORD_CANCEL);
WM_DisableWindow(hItem);
WM_Update(hItem);
hItem = WM_GetDialogItem(hMainWin, ID_RECORD_REC_CANCEL_PLAY);
WM_DisableWindow(hItem);
WM_Update(hItem);
hItem = WM_GetDialogItem(hMainWin, ID_RECORD_SAVE);
WM_DisableWindow(hItem);
WM_Update(hItem);
}if (prev_msd_status == 0) { ... }
else
{
RecorderMode = RECORDER_MODE_REC_IDLE;
hItem = WM_GetDialogItem(hMainWin, ID_RECORD_CANCEL);
WM_EnableWindow(hItem);
WM_Update(hItem);
hItem = WM_GetDialogItem(hMainWin, ID_RECORD_REC_CANCEL_PLAY);
WM_EnableWindow(hItem);
WM_Update(hItem);
hItem = WM_GetDialogItem(hMainWin, ID_RECORD_SAVE);
WM_EnableWindow(hItem);
WM_Update(hItem);
}else { ... }
}if (prev_msd_status != k_StorageGetStatus(MSD_DISK_UNIT)) { ... }
WM_RestartTimer(pMsg->Data.v, 500);
break;
case WM_TIMER:
case WM_DELETE:
if(hStatusTimer != 0)
{
WM_DeleteTimer(hStatusTimer);
hStatusTimer = 0;
}if (hStatusTimer != 0) { ... }
break;
case WM_DELETE:
default:
WM_DefaultProc(pMsg);default
}switch (pMsg->MsgId) { ... }
}{ ... }
/* ... */
static void _cbAudioProcess(WM_MESSAGE * pMsg) {
uint32_t Id;
static WM_HTIMER hProcessTimer;
WM_HWIN hItem;
char tmp[] = "00:00/00:00";
uint32_t duration;
switch (pMsg->MsgId)
{
case WM_CREATE:
hProcessTimer = WM_CreateTimer(pMsg->hWin, ID_PROCESS_TIMER, 1000, 0);
break;
case WM_CREATE:
case WM_TIMER:
Id = WM_GetTimerId(pMsg->Data.v);
if(Id == ID_PROCESS_TIMER)
{
if(AUDIO_RECORDER_GetState() == AUDIO_RECORDER_RECORDING)
{
duration = AUDIO_RECORDER_GetElapsedTime();
sprintf((char *)tmp , "%02lu:%02lu", duration/60, duration%60 );
hItem = WM_GetDialogItem(hMainWin, ID_ELAPSED_TIME);
TEXT_SetText(hItem, tmp);
}if (AUDIO_RECORDER_GetState() == AUDIO_RECORDER_RECORDING) { ... }
if(AUDIO_RECORDER_GetState() == AUDIO_RECORDER_PLAYING)
{
duration = AUDIO_RECORDER_GetTotalTime() - AUDIO_RECORDER_GetPlayedTime();
sprintf((char *)tmp , "%02lu:%02lu", duration/60, duration%60);
hItem = WM_GetDialogItem(hMainWin, ID_ELAPSED_TIME);
TEXT_SetText(hItem, tmp);
}if (AUDIO_RECORDER_GetState() == AUDIO_RECORDER_PLAYING) { ... }
WM_RestartTimer(pMsg->Data.v, 1000);
}if (Id == ID_PROCESS_TIMER) { ... }
break;
case WM_TIMER:
case WM_DELETE:
WM_DeleteTimer(hProcessTimer);
break;
case WM_DELETE:
default:
WM_DefaultProc(pMsg);default
}switch (pMsg->MsgId) { ... }
}{ ... }
/* ... */
void _cbNotifyStateChange (void)
{
WM_HWIN hItem;
if(AUDIO_RECORDER_GetState() == AUDIO_RECORDER_SUSPENDED)
{
if(RecorderMode == RECORDER_MODE_PLAYING)
{
RecorderMode = RECORDER_MODE_PLAY_IDLE;
hItem = WM_GetDialogItem(hMainWin, ID_RECORD_REC_CANCEL_PLAY);
WM_InvalidateWindow(hItem);
WM_Update(hItem);
}if (RecorderMode == RECORDER_MODE_PLAYING) { ... }
if(RecorderMode == RECORDER_MODE_RECORDING)
{
RecorderMode = RECORDER_MODE_REC_IDLE;
}if (RecorderMode == RECORDER_MODE_RECORDING) { ... }
if(hMainWin != 0)
{
hItem = WM_GetDialogItem(hMainWin, ID_ELAPSED_TIME);
TEXT_SetText(hItem, "00:00");
WM_Update(hItem);
}if (hMainWin != 0) { ... }
}if (AUDIO_RECORDER_GetState() == AUDIO_RECORDER_SUSPENDED) { ... }
}{ ... }
/* ... */
static void _cbDialog(WM_MESSAGE * pMsg) {
WM_HWIN hItem;
int Id, NCode;
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
hItem = BUTTON_CreateEx(80, 90, 80, 80, pMsg->hWin, WM_CF_SHOW, 0, ID_RECORD_REC_CANCEL_PLAY);
WM_SetCallback(hItem, _cbButton_record);
hItem = BUTTON_CreateEx(186, 3, 50, 30, pMsg->hWin, WM_CF_SHOW, 0, ID_BUTTON_EXIT);
WM_SetCallback(hItem, _cbButton_exit);
hItem = BUTTON_CreateEx(175, 110, 40, 40, pMsg->hWin, WM_CF_SHOW, 0, ID_RECORD_SAVE);
WM_SetCallback(hItem, _cbButton_save);
hItem = BUTTON_CreateEx(25, 110, 40, 40, pMsg->hWin, WM_CF_SHOW, 0, ID_RECORD_CANCEL);
WM_SetCallback(hItem, _cbButton_cancel);
hItem = WM_GetDialogItem(pMsg->hWin, ID_ELAPSED_TIME);
TEXT_SetFont(hItem, &GUI_FontLubalGraph32);
TEXT_SetTextColor(hItem, GUI_WHITE);
RecorderMode = RECORDER_MODE_REC_IDLE;
WM_CreateWindowAsChild(0,
100,
10,
10,
pMsg->hWin,
WM_CF_SHOW | WM_CF_HASTRANS,
_cbAudioProcess,
0);
WM_CreateWindowAsChild(239, 239, 1, 1, pMsg->hWin, WM_CF_SHOW | WM_CF_HASTRANS, _cbMediaConnection , 0);
break;
case WM_INIT_DIALOG:
case WM_PAINT:
GUI_SetBkColor(0xFF000000);
GUI_Clear();
GUI_SetColor(0x00D0FE);
GUI_FillRect(0, 0, 240, 40);
GUI_SetColor(0x2223D3);
GUI_AA_FillCircle(120, 140, 100);
break;
case WM_PAINT:
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch (Id) {
case ID_BUTTON_EXIT:
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
if( RecorderMode == RECORDER_MODE_RECORDING)
{
AUDIO_RECORDER_StopRec();
}if (RecorderMode == RECORDER_MODE_RECORDING) { ... }
else if( RecorderMode == RECORDER_MODE_PLAYING)
{
AUDIO_RECORDER_StopPlayer();
}else if (RecorderMode == RECORDER_MODE_PLAYING) { ... }
AUDIO_RECORDER_DeInit();
GUI_EndDialog(pMsg->hWin, 0);
break;case WM_NOTIFICATION_CLICKED:
}switch (NCode) { ... }
break;
case ID_BUTTON_EXIT:
case ID_RECORD_SAVE:
switch(NCode) {
case WM_NOTIFICATION_RELEASED:
if( RecorderMode == RECORDER_MODE_RECORDING)
{
AUDIO_RECORDER_StopRec();
RecorderMode = RECORDER_MODE_PLAY_IDLE;
}if (RecorderMode == RECORDER_MODE_RECORDING) { ... }
else if( RecorderMode == RECORDER_MODE_PLAYING)
{
AUDIO_RECORDER_StopPlayer();
RecorderMode = RECORDER_MODE_PLAY_IDLE;
}else if (RecorderMode == RECORDER_MODE_PLAYING) { ... }
else if( RecorderMode == RECORDER_MODE_PLAY_IDLE)
{
RecorderMode = RECORDER_MODE_REC_IDLE;
}else if (RecorderMode == RECORDER_MODE_PLAY_IDLE) { ... }
hItem = WM_GetDialogItem(pMsg->hWin, ID_RECORD_REC_CANCEL_PLAY);
WM_InvalidateWindow(hItem);
WM_Update(hItem);
break;case WM_NOTIFICATION_RELEASED:
}switch (NCode) { ... }
break;
case ID_RECORD_SAVE:
case ID_RECORD_CANCEL:
switch(NCode) {
case WM_NOTIFICATION_RELEASED:
if( RecorderMode == RECORDER_MODE_RECORDING)
{
AUDIO_RECORDER_StopRec();
RecorderMode = RECORDER_MODE_REC_IDLE;
AUDIO_RECORDER_RemoveAudioFile(FileName);
}if (RecorderMode == RECORDER_MODE_RECORDING) { ... }
else if( RecorderMode == RECORDER_MODE_PLAYING)
{
AUDIO_RECORDER_StopPlayer();
RecorderMode = RECORDER_MODE_PLAY_IDLE;
AUDIO_RECORDER_RemoveAudioFile(FileName);
}else if (RecorderMode == RECORDER_MODE_PLAYING) { ... }
else if( RecorderMode == RECORDER_MODE_PLAY_IDLE)
{
RecorderMode = RECORDER_MODE_REC_IDLE;
}else if (RecorderMode == RECORDER_MODE_PLAY_IDLE) { ... }
hItem = WM_GetDialogItem(pMsg->hWin, ID_RECORD_REC_CANCEL_PLAY);
WM_InvalidateWindow(hItem);
WM_Update(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_RECORD_CANCEL);
WM_InvalidateWindow(hItem);
WM_Update(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_RECORD_SAVE);
WM_InvalidateWindow(hItem);
WM_Update(hItem);
break;case WM_NOTIFICATION_RELEASED:
}switch (NCode) { ... }
break;
case ID_RECORD_CANCEL:
case ID_RECORD_REC_CANCEL_PLAY:
switch(NCode) {
case WM_NOTIFICATION_RELEASED:
if( RecorderMode == RECORDER_MODE_REC_IDLE)
{
_BuildFileName();
AUDIO_RECORDER_SelectFile(FileName, FA_CREATE_ALWAYS | FA_WRITE);
AUDIO_RECORDER_StartRec(DEFAULT_AUDIO_IN_FREQ);
RecorderMode = RECORDER_MODE_RECORDING;
}if (RecorderMode == RECORDER_MODE_REC_IDLE) { ... }
else if( RecorderMode == RECORDER_MODE_RECORDING)
{
AUDIO_RECORDER_StopRec();
RecorderMode = RECORDER_MODE_REC_IDLE;
AUDIO_RECORDER_RemoveAudioFile(FileName);
}else if (RecorderMode == RECORDER_MODE_RECORDING) { ... }
else if( RecorderMode == RECORDER_MODE_PLAY_IDLE)
{
RecorderMode = RECORDER_MODE_PLAYING;
AUDIO_RECORDER_SelectFile(FileName, FA_OPEN_EXISTING | FA_READ);
AUDIO_RECORDER_Play(DEFAULT_AUDIO_IN_FREQ);
}else if (RecorderMode == RECORDER_MODE_PLAY_IDLE) { ... }
hItem = WM_GetDialogItem(pMsg->hWin, ID_RECORD_REC_CANCEL_PLAY);
WM_InvalidateWindow(hItem);
WM_Update(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_RECORD_CANCEL);
WM_InvalidateWindow(hItem);
WM_Update(hItem);
hItem = WM_GetDialogItem(pMsg->hWin, ID_RECORD_SAVE);
WM_InvalidateWindow(hItem);
WM_Update(hItem);
break;case WM_NOTIFICATION_RELEASED:
}switch (NCode) { ... }
break; case ID_RECORD_REC_CANCEL_PLAY:
}switch (Id) { ... }
break;
case WM_NOTIFY_PARENT:
default:
WM_DefaultProc(pMsg);
break;default
}switch (pMsg->MsgId) { ... }
}{ ... }
/* ... */
static void Startup(WM_HWIN hWin, uint16_t xpos, uint16_t ypos)
{
AUDIO_RECORDER_Init(50);
hMainWin = GUI_CreateDialogBox(_aDialog, GUI_COUNTOF(_aDialog), _cbDialog, hWin, xpos, ypos);
}{ ... }
/* ... */
/* ... */