mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Add config request functionality.
This commit is contained in:
parent
6bc3157759
commit
2daa15b317
2 changed files with 54 additions and 3 deletions
31
MiniDSP.cpp
31
MiniDSP.cpp
|
@ -72,6 +72,25 @@ void MiniDSP::ParseHIDData(USBHID *hid __attribute__ ((unused)), bool is_rpt_id
|
||||||
pFuncOnInputSourceChange(inputSource);
|
pFuncOnInputSourceChange(inputSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if this is an Config update.
|
||||||
|
if(buf[3] == 0xD8){
|
||||||
|
// Parse data.
|
||||||
|
// Response is of format [ length ] [ 0x05 0xFF 0xD8 ] [ config ].
|
||||||
|
const auto newConfig = buf[4];
|
||||||
|
|
||||||
|
// Ensure we only interpret valid inputs.
|
||||||
|
if(newConfig >= 0x00 && newConfig <= 0x03){
|
||||||
|
const auto configChanged = newConfig != (char) config;
|
||||||
|
|
||||||
|
// Update values.
|
||||||
|
config = (Config) newConfig;
|
||||||
|
|
||||||
|
// Call callbacks.
|
||||||
|
if(pFuncOnConfigChange != nullptr && configChanged)
|
||||||
|
pFuncOnConfigChange(config);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t MiniDSP::OnInitSuccessful() {
|
uint8_t MiniDSP::OnInitSuccessful() {
|
||||||
|
@ -82,6 +101,7 @@ uint8_t MiniDSP::OnInitSuccessful() {
|
||||||
// Request current information so we can initialize the values.
|
// Request current information so we can initialize the values.
|
||||||
RequestStatus();
|
RequestStatus();
|
||||||
RequestInputSource();
|
RequestInputSource();
|
||||||
|
RequestConfig();
|
||||||
|
|
||||||
if(pFuncOnInit != nullptr)
|
if(pFuncOnInit != nullptr)
|
||||||
pFuncOnInit();
|
pFuncOnInit();
|
||||||
|
@ -131,9 +151,14 @@ void MiniDSP::RequestStatus() const {
|
||||||
SendCommand(RequestStatusOutputCommand, sizeof (RequestStatusOutputCommand));
|
SendCommand(RequestStatusOutputCommand, sizeof (RequestStatusOutputCommand));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MiniDSP::RequestInputSource() const {
|
void MiniDSP::RequestInputSource() const {
|
||||||
uint8_t RequestInputSourceCommand[] = {0x05, 0xFF, 0xD9, 0x01};
|
uint8_t RequestInputSourceCommand[] = {0x05, 0xFF, 0xD9, 0x01};
|
||||||
|
|
||||||
SendCommand(RequestInputSourceCommand, sizeof(RequestInputSourceCommand));
|
SendCommand(RequestInputSourceCommand, sizeof(RequestInputSourceCommand));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MiniDSP::RequestConfig() const {
|
||||||
|
uint8_t RequestConfigCommand[] = {0x05, 0xFF, 0xD8, 0x01};
|
||||||
|
|
||||||
|
SendCommand(RequestConfigCommand, sizeof(RequestConfigCommand));
|
||||||
|
}
|
26
MiniDSP.h
26
MiniDSP.h
|
@ -46,6 +46,14 @@ public:
|
||||||
Unknown = 0x03
|
Unknown = 0x03
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class Config : uint8_t {
|
||||||
|
Config_1 = 0x00,
|
||||||
|
Config_2 = 0x01,
|
||||||
|
Config_3 = 0x02,
|
||||||
|
Config_4 = 0x03,
|
||||||
|
Unknown = 0x04
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the MiniDSP class.
|
* Constructor for the MiniDSP class.
|
||||||
* @param p Pointer to the USB class instance.
|
* @param p Pointer to the USB class instance.
|
||||||
|
@ -98,6 +106,14 @@ public:
|
||||||
pFuncOnInputSourceChange = funcOnInputSourceChange;
|
pFuncOnInputSourceChange = funcOnInputSourceChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to call your own function when the config has changed.
|
||||||
|
* @param funcOnConfigChange Function to call.
|
||||||
|
*/
|
||||||
|
void attachOnConfigChange(void (*funcOnConfigChange)(Config)) {
|
||||||
|
pFuncOnConfigChange = funcOnConfigChange;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the current volume of the MiniDSP.
|
* Retrieve the current volume of the MiniDSP.
|
||||||
* The volume is passed as an unsigned integer that represents twice the
|
* The volume is passed as an unsigned integer that represents twice the
|
||||||
|
@ -188,6 +204,12 @@ private:
|
||||||
void
|
void
|
||||||
RequestInputSource() const;
|
RequestInputSource() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the "Request config" command to the MiniDSP.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
RequestConfig() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the given MiniDSP command. This function will create a buffer
|
* Send the given MiniDSP command. This function will create a buffer
|
||||||
* with the expected header and checksum and send it to the MiniDSP.
|
* with the expected header and checksum and send it to the MiniDSP.
|
||||||
|
@ -211,6 +233,9 @@ private:
|
||||||
// Pointer to function called when input source changes.
|
// Pointer to function called when input source changes.
|
||||||
void (*pFuncOnInputSourceChange)(InputSource) = nullptr;
|
void (*pFuncOnInputSourceChange)(InputSource) = nullptr;
|
||||||
|
|
||||||
|
// Pointer to function called when config changes.
|
||||||
|
void (*pFuncOnConfigChange)(Config) = nullptr;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
// MiniDSP state. Currently only volume and muted status are
|
// MiniDSP state. Currently only volume and muted status are
|
||||||
|
@ -221,4 +246,5 @@ private:
|
||||||
uint8_t volume = 0;
|
uint8_t volume = 0;
|
||||||
bool muted = false;
|
bool muted = false;
|
||||||
InputSource inputSource = InputSource::Unknown;
|
InputSource inputSource = InputSource::Unknown;
|
||||||
|
Config config = Config::Unknown;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue