-
Notifications
You must be signed in to change notification settings - Fork 0
/
BluetoothReceiver.cpp
36 lines (27 loc) · 1.21 KB
/
BluetoothReceiver.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
#include <Arduino.h>
#include "BluetoothReceiver.h"
#include "Logger.h"
#include "BluetoothA2DPSink.h"
BluetoothA2DPSink& BluetoothReceiver::a2dp_sink() { // add definition of the free function
static BluetoothA2DPSink instance;
return instance;
}
BluetoothReceiver::BluetoothReceiver() {}
BluetoothReceiver::BluetoothReceiver(MomentaryButton &seekBack, MomentaryButton &playPause, MomentaryButton &seekForward, Print *logger, void(*avrc_metadata_callback)(uint8_t, const uint8_t*))
: _seekBack(seekBack), _playPause(playPause), _seekForward(seekForward), _logger(logger), avrc_metadata_callback(avrc_metadata_callback) {
a2dp_sink().set_avrc_metadata_callback(avrc_metadata_callback);
a2dp_sink().start("Grandpa Johnson's Radio");
}
void BluetoothReceiver::checkButtons() {
_seekBack.checkButton();
_playPause.checkButton();
_seekForward.checkButton();
}
void BluetoothReceiver::volumeUp(int amount) {
_logger->print("Current volume: ");
_logger->println(a2dp_sink().get_volume());
a2dp_sink().set_volume(std::min(128, a2dp_sink().get_volume() + (amount*5)));
}
void BluetoothReceiver::volumeDown(int amount) {
a2dp_sink().set_volume(std::max(0, a2dp_sink().get_volume() - (amount*5)));
}