mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Add setters for volume / muted + extend example.
This commit is contained in:
parent
2daa15b317
commit
db36383aab
3 changed files with 73 additions and 3 deletions
39
MiniDSP.cpp
39
MiniDSP.cpp
|
@ -22,13 +22,28 @@
|
|||
#include "MiniDSP.h"
|
||||
|
||||
void MiniDSP::ParseHIDData(USBHID *hid __attribute__ ((unused)), bool is_rpt_id __attribute__ ((unused)), uint8_t len, uint8_t *buf) {
|
||||
constexpr uint8_t InputCommand[] = {0x05, 0xFF};
|
||||
|
||||
// Only care about valid data for the MiniDSP 2x4HD.
|
||||
if(HIDUniversal::VID != MINIDSP_VID || HIDUniversal::PID != MINIDSP_PID || len <= 4 || buf == nullptr)
|
||||
return;
|
||||
|
||||
// Only deal with valid inputs.
|
||||
// Check if this is a requested mute change.
|
||||
if(buf[1] == 0x17){
|
||||
// Response is of format [ length ] [ 0x17 ] [ muted ]
|
||||
muted = (bool)buf[2];
|
||||
Serial.println("Muted was set to: " + String(muted));
|
||||
}
|
||||
|
||||
// Check if this is a requested volume change.
|
||||
if(buf[1] == 0x42){
|
||||
// Response is of format [ length ] [ 0x42 ] [ volume ]
|
||||
volume = buf[2];
|
||||
Serial.println("Volume was set to: " + String(volume));
|
||||
|
||||
}
|
||||
|
||||
constexpr uint8_t InputCommand[] = {0x05, 0xFF};
|
||||
|
||||
// Only deal with status updates from now on.
|
||||
if(memcmp(buf + 1, InputCommand, sizeof (InputCommand)) != 0)
|
||||
return;
|
||||
|
||||
|
@ -162,3 +177,21 @@ void MiniDSP::RequestConfig() const {
|
|||
|
||||
SendCommand(RequestConfigCommand, sizeof(RequestConfigCommand));
|
||||
}
|
||||
|
||||
void MiniDSP::setVolumeDB(float volumeDB) const {
|
||||
// Only accept values between 0dB and -127.5dB.
|
||||
// Don't do error handling.
|
||||
if(volume > 0 || volume < -127.5){
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t SetVolumeCommand[] = {0x42, (int)-2*volumedB};
|
||||
|
||||
SendCommand(SetVolumeCommand, sizeof(SetVolumeCommand));
|
||||
}
|
||||
|
||||
void MiniDSP::setMuted(bool muted) const {
|
||||
uint8_t SetMutedommand[] = {0x17, muted ? 0x01 : 0x00};
|
||||
|
||||
SendCommand(SetMutedommand, sizeof(SetMutedommand));
|
||||
}
|
21
MiniDSP.h
21
MiniDSP.h
|
@ -148,6 +148,27 @@ public:
|
|||
return inputSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set volume of the MiniDSP in dB. Values between 0 and -127.5 are
|
||||
* accepted. If any values outside if this range are passed, this
|
||||
* function does nothing.
|
||||
*
|
||||
* Calling this function will not trigger the volume change callback.
|
||||
*
|
||||
* @param volumeDB New volume to set.
|
||||
*/
|
||||
void setVolumeDB(float volumeDB) const;
|
||||
|
||||
|
||||
/**
|
||||
* Mute or unmute the MiniDSP.
|
||||
*
|
||||
* Calling this function will not trigger the mute change callback.
|
||||
*
|
||||
* @param muted Muted status.
|
||||
*/
|
||||
void setMuted(bool muted) const;
|
||||
|
||||
protected:
|
||||
/** @name HIDUniversal implementation */
|
||||
/**
|
||||
|
|
|
@ -39,6 +39,21 @@ void OnInputSourceChange(MiniDSP::InputSource inputSource) {
|
|||
Serial.println("Input source: " + inputSourceStr);
|
||||
}
|
||||
|
||||
void OnConfigChange(MiniDSP::Config config) {
|
||||
String configStr = "Unknown";
|
||||
|
||||
if (config == MiniDSP::Config::Config_1) {
|
||||
configStr = "Config 1";
|
||||
} else if (config == MiniDSP::Config::Config_2) {
|
||||
configStr = "Config 2";
|
||||
} else if (config == MiniDSP::Config::Config_3) {
|
||||
configStr = "Config 3";
|
||||
} else if (config == MiniDSP::Config::Config_4) {
|
||||
configStr = "Config 4";
|
||||
}
|
||||
Serial.println("Config: " + configStr);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
#if !defined(__MIPSEL__)
|
||||
|
@ -55,6 +70,7 @@ void setup() {
|
|||
MiniDSP.attachOnVolumeChange(&OnVolumeChange);
|
||||
MiniDSP.attachOnMutedChange(&OnMutedChange);
|
||||
MiniDSP.attachOnInputSourceChange(&OnInputSourceChange);
|
||||
MiniDSP.attachOnConfigChange(&OnConfigChange);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
|
Loading…
Reference in a new issue