forked from bristlemouth/bm_protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_mic.c
More file actions
96 lines (74 loc) · 2.27 KB
/
debug_mic.c
File metadata and controls
96 lines (74 loc) · 2.27 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
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
/* FreeRTOS+CLI includes. */
#include "FreeRTOS_CLI.h"
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include "debug.h"
#include "mic.h"
#include "bsp.h"
#include "debug_mic.h"
static BaseType_t debugMicCommand( char *writeBuffer,
size_t writeBufferLen,
const char *commandString);
static const CLI_Command_Definition_t cmdMic = {
// Command string
"mic",
// Help string
"mic:\n"
" * db <duration seconds> - print dB level for n seconds\n",
// Command function
debugMicCommand,
// Number of parameters (variable)
-1
};
static SAI_HandleTypeDef *_sai;
void debugMicInit(SAI_HandleTypeDef *saiHandle) {
_sai = saiHandle;
FreeRTOS_CLIRegisterCommand( &cmdMic );
}
static bool processSamplesRMS(const uint32_t *samples, uint32_t numSamples, void *args) {
(void)args;
printf("%0.1f dB\n", micGetDB(samples, numSamples));
return true;
}
static BaseType_t debugMicCommand(char *writeBuffer,
size_t writeBufferLen,
const char *commandString) {
const char *parameter;
BaseType_t parameterStringLength;
( void ) writeBuffer;
( void ) writeBufferLen;
do {
parameter = FreeRTOS_CLIGetParameter(
commandString,
1, // Get the first parameter (command)
¶meterStringLength);
if(parameter == NULL) {
printf("ERR Invalid paramters\n");
break;
}
if (strncmp("db", parameter, parameterStringLength) == 0) {
if(!micInit(_sai, NULL)) {
printf("ERR Microphone not detected. Aborting\n");
break;
}
const char *duration = FreeRTOS_CLIGetParameter(
commandString,
2, // Get the second parameter (duration)
¶meterStringLength);
if(parameterStringLength == 0) {
printf("ERR duration required\n");
break;
}
uint32_t durationSec = strtoul(duration, NULL, 10);
micSample(durationSec, processSamplesRMS, NULL);
} else {
printf("ERR Invalid paramters\n");
break;
}
} while(0);
return pdFALSE;
}