forked from DustinWatts/FreeTouchDeck
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAudio.cpp
58 lines (56 loc) · 1.33 KB
/
Audio.cpp
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
#include "globals.hpp"
#include "ConfigLoad.h"
#include "Audio.h"
namespace FreeTouchDeck
{
void ChipTune(double freq, uint16_t duration)
{
if (generalconfig.beep)
{
ledcAttachPin(speakerPin, 2);
ledcWriteTone(2, freq);
delay(duration);
ledcDetachPin(speakerPin);
ledcWrite(2, 0);
}
}
void AudioChipTune(Sounds sound)
{
switch (sound)
{
case Sounds::GOING_TO_SLEEP:
ChipTune(1200,150);
ChipTune(800,150);
ChipTune(600,150);
break;
case Sounds::BEEP:
ChipTune(600,50);
break;
case Sounds::STARTUP:
ChipTune(600,150);
ChipTune(800,150);
ChipTune(1200,150);
break;
case Sounds::ERROR:
ChipTune(500,50);
ChipTune(300,250);
default:
break;
}
}
void HandleAudio(Sounds sound)
{
if (speakerPin >= 0)
{
static bool isInit = false;
if (!isInit)
{
// Setup PWM channel for Piezo speaker
ledcSetup(2, 500, 8);
isInit = true;
}
AudioChipTune(sound);
}
// todo: add support for i2s audio
}
}