SinricPro Library
SinricProSpeaker

Device to control a smart speaker. More...

Inheritance diagram for SinricProSpeaker:
SinricProDevice

Public Types

typedef std::function< bool(const String &, int &)> SetVolumeCallback
 Callback definition for onSetVolume function. More...
 
typedef std::function< bool(const String &, int &, bool)> AdjustVolumeCallback
 Callback definition for onAdjustVolume function. More...
 
typedef std::function< bool(const String &, bool &)> MuteCallback
 Callback definition for onMute function. More...
 
typedef std::function< bool(const String &, String &)> MediaControlCallback
 Callback definition for onMediaControl function. More...
 
typedef std::function< bool(const String &, String &)> SelectInputCallback
 Callback definition for onSelectInput function. More...
 
typedef std::function< bool(const String &, const String &, int &)> SetBandsCallback
 Callback definition for onSetBands function. More...
 
typedef std::function< bool(const String &, const String &, int &)> AdjustBandsCallback
 Callback definition for onAdjustBands function. More...
 
typedef std::function< bool(const String &, const String &, int &)> ResetBandsCallback
 Callback definition for onResetBands function. More...
 
typedef std::function< bool(const String &, String &)> ModeCallback
 Callback definition for onSetMode function. More...
 
typedef std::function< bool(const String &, bool &)> PowerStateCallback
 Callback definition for onPowerState function. More...
 

Public Member Functions

void onSetVolume (SetVolumeCallback cb)
 Set callback function for setVolume request. More...
 
void onAdjustVolume (AdjustVolumeCallback cb)
 Set callback function for adjustVolume request. More...
 
void onMute (MuteCallback cb)
 Set callback function for setMute request. More...
 
void onMediaControl (MediaControlCallback cb)
 Set callback function for mediaControl request. More...
 
void onSelectInput (SelectInputCallback cb)
 Set callback function for selectInput request. More...
 
void onSetBands (SetBandsCallback cb)
 Set callback function for setBands request. More...
 
void onAdjustBands (AdjustBandsCallback cb)
 Set callback function for adjustBands request. More...
 
void onResetBands (ResetBandsCallback cb)
 Set callback function for resetBands request. More...
 
void onSetMode (ModeCallback cb)
 Set callback function for setMode request. More...
 
bool sendVolumeEvent (int volume, String cause="PHYSICAL_INTERACTION")
 Send setVolume event to SinricPro Server indicating actual volume has changed. More...
 
bool sendMuteEvent (bool mute, String cause="PHYSICAL_INTERACTION")
 Send setMute event to SinricPro Server indicating actual mute state. More...
 
bool sendMediaControlEvent (String mediaControl, String cause="PHYSICAL_INTERACTION")
 Send mediaControl event to SinricPro Server indicating devices media control state. More...
 
bool sendSelectInputEvent (String intput, String cause="PHYSICAL_INTERACTION")
 Send selectInput event to SinricPro Server to report selected input. More...
 
bool sendBandsEvent (String bands, int level, String cause="PHYSICAL_INTERACTION")
 Send setBands event to SinricPro Server indicating bands level has changed. More...
 
bool sendModeEvent (String mode, String cause="PHYSICAL_INTERACTION")
 Send setMode event to SinricPro Server indicating the mode has changed. More...
 
virtual void onPowerState (PowerStateCallback cb)
 Set callback function for powerState request. More...
 
bool sendPowerStateEvent (bool state, String cause="PHYSICAL_INTERACTION")
 Send setPowerState event to SinricPro Server indicating actual power state. More...
 

Detailed Description

Device to control a smart speaker.

Supporting:

  • setVolume / adjustVolume
  • set / adjust / reset bands (BASS, MIDRANGE, TREBBLE)
  • mute / unmute
  • media controls:
    • FastForward
    • Next
    • Pause
    • Play
    • Previous
    • Rewind
    • StartOver
    • Stop
  • set mode (TV, MOVIE, ...)

Member Typedef Documentation

◆ AdjustBandsCallback

typedef std::function<bool(const String&, const String&, int&)> AdjustBandsCallback

Callback definition for onAdjustBands function.

Gets called when device receive a adjustBands request

Parameters
[in]deviceIdString which contains the ID of device
[in]bandsString with requested bands to change
BASS, MIDRANGE, TREBBLE
[in]levelDeltaInteger with relative level value device should change bands about
[out]bandsString with changed bands
BASS, MIDRANGE, TREBBLE
[out]levelDeltaInteger value with level bands changed to
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

int globalBass;
int globalMidrange;
int globalTrebble;
bool onAdjustBands(const String &deviceId, String &bands, int &levelDelta) {
if (bands == "BASS") {
globalBass += levelDelta; // calculate absolute bass level
levelDelta = globalBass; // return absolute bass level
}
if (bands == "MIDRANGE") {
globalMidrange += levelDelta; // calculate absolute midrange level
levelDelta = globalMidrange; // return absolute midrange level
}
if (bands == "TREBBLE") {
globalMidrange += levelDelta; // calculate absolute trebble level
levelDelta = globalMidrange; // return absolute trebble level
}
Serial.printf("Device %s bands set to\r\n - BASS: %d\r\n - MIDRANGE: %d\r\n - TREBBLE: %d\r\n", deviceId.c_str(), globalBass, globalMidrange, globalTrebble);
return true; // request handled properly
}

◆ AdjustVolumeCallback

typedef std::function<bool(const String&, int&, bool)> AdjustVolumeCallback

Callback definition for onAdjustVolume function.

Gets called when device receive a adjustVolume request

Parameters
[in]deviceIdString which contains the ID of device
[in]volumeDeltaInteger with relative volume the device should change about (-100..100)
[out]volumeDeltaInteger with absolute volume device has been set to
[in]volumeDefaultBool false if the user specified the amount by which to change the volume; otherwise true
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

int absoluteVolume;
bool onAdjustVolume(const String &deviceId, int &volumeDelta, bool volumeDefault) {
absoluteVolume += volumeDelta; // calculate absolute volume
Serial.printf("Device %s volume changed about %i to %d (default: %s)\r\n", deviceId.c_str(), volumeDelta, absoluteVolume, volumeDefault);
volumeDelta = absoluteVolume; // return absolute volume
return true; // request handled properly
}

◆ MediaControlCallback

typedef std::function<bool(const String&, String&)> MediaControlCallback

Callback definition for onMediaControl function.

Gets called when device receive a mediaControl request

Parameters
[in]deviceIdString which contains the ID of device
[in]controlString with requested control
FastForward, Next, Pause, Play, Previous, Rewind, StartOver, Stop
[out]controlString with control
FastForward, Next, Pause, Play, Previous, Rewind, StartOver, Stop
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

bool onMediaControl(const String &deviceId, String &control) {
Serial.printf("Device %s: %s\r\n", deviceId.c_str(), control);
return true; // request handled properly
}

◆ ModeCallback

typedef std::function<bool(const String&, String&)> ModeCallback

Callback definition for onSetMode function.

Gets called when device receive a setBands request

Parameters
[in]deviceIdString which contains the ID of device
[in]modeString device mode should set to
MOVIE, MUSIC, NIGHT, SPORT, TV
[out]modeString devices mode is set to
MOVIE, MUSIC, NIGHT, SPORT, TV
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

bool onSetMode(const String &deviceId, String &mode) {
Serial.printf("Device %s is set to mode %s\r\n", deviceId.c_str(), mode);
return true; // request handled properly
}

◆ MuteCallback

typedef std::function<bool(const String&, bool&)> MuteCallback

Callback definition for onMute function.

Gets called when device receive a setMute request

Parameters
[in]deviceIdString which contains the ID of device
[in]mutetrue mute device
false unmute device
[out]mutetrue device is muted
false device is unmuted
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

bool onMute(const String &deviceId, bool &mute) {
Serial.printf("Device %s is %s\r\n", deviceId.c_str(), mute?"muted":"unmuted");
return true; // request handled properly
}

◆ PowerStateCallback

typedef std::function<bool(const String&, bool&)> PowerStateCallback
inherited

Callback definition for onPowerState function.

Gets called when device receive a setPowerState reuqest

Parameters
[in]deviceIdString which contains the ID of device
[in]statetrue = device is requested to turn on
false = device is requested to turn off
[out]statetrue = device has been turned on
false = device has been turned off
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

bool onPowerState(const String &deviceId, bool &state) {
Serial.printf("Device %s turned %s\r\n", deviceId.c_str(), state?"on":"off");
return true; // request handled properly
}

◆ ResetBandsCallback

typedef std::function<bool(const String&, const String&, int&)> ResetBandsCallback

Callback definition for onResetBands function.

Gets called when device receive a onResetBands request

Parameters
[in]deviceIdString which contains the ID of device
[in]bandsString with requested bands to reset
BASS, MIDRANGE, TREBBLE
[out]bandsString with changed bands
BASS, MIDRANGE, TREBBLE
[out]levelInteger value with level bands changed to
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

int globalBass;
int globalMidrange;
int globalTrebble;
bool onAdjustBands(const String &deviceId, String &bands, int &level) {
if (bands == "BASS") {
globalBass = 0; // reset bass level to 0
level = globalBass; // return bass level
}
if (bands == "MIDRANGE") {
globalMidrange = 0; // reset midrange level to 0
level = globalMidrange; // return midrange level
}
if (bands == "TREBBLE") {
globalMidrange = 0; // reset trebble level to 0
level = globalMidrange; // return trebble level
}
Serial.printf("Device %s bands reset to\r\n - BASS: %d\r\n - MIDRANGE: %d\r\n - TREBBLE: %d\r\n", deviceId.c_str(), globalBass, globalMidrange, globalTrebble);
return true; // request handled properly
}

◆ SelectInputCallback

typedef std::function<bool(const String&, String&)> SelectInputCallback

Callback definition for onSelectInput function.

Gets called when device receive a selectInput request

Parameters
[in]deviceIdString which contains the ID of device
[in]inputString with input name device is requested to switch to
AUX 1..AUX 7, BLURAY, CABLE, CD, COAX 1,COAX 2, COMPOSITE 1, DVD, GAME, HD RADIO, HDMI 1.. HDMI 10, HDMI ARC, INPUT 1..INPUT 10, IPOD, LINE 1..LINE 7, MEDIA PLAYER, OPTICAL 1, OPTICAL 2, PHONO, PLAYSTATION, PLAYSTATION 3, PLAYSTATION 4, SATELLITE, SMARTCAST, TUNER, TV, USB DAC, VIDEO 1..VIDEO 3, XBOX
[out]inputString with input name device has switchted to
AUX 1..AUX 7, BLURAY, CABLE, CD, COAX 1,COAX 2, COMPOSITE 1, DVD, GAME, HD RADIO, HDMI 1.. HDMI 10, HDMI ARC, INPUT 1..INPUT 10, IPOD, LINE 1..LINE 7, MEDIA PLAYER, OPTICAL 1, OPTICAL 2, PHONO, PLAYSTATION, PLAYSTATION 3, PLAYSTATION 4, SATELLITE, SMARTCAST, TUNER, TV, USB DAC, VIDEO 1..VIDEO 3, XBOX
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

bool onSelectInput(const String &deviceId, String &input) {
Serial.printf("Device %s input changed to %s\r\n", deviceId.c_str(), input.c_str());
return true;
}

◆ SetBandsCallback

typedef std::function<bool(const String&, const String&, int&)> SetBandsCallback

Callback definition for onSetBands function.

Gets called when device receive a setBands request

Parameters
[in]deviceIdString which contains the ID of device
[in]bandsString with requested bands to change
BASS, MIDRANGE, TREBBLE
[in]levelInteger value with level bands should set to
[out]bandsString with changed bands
BASS, MIDRANGE, TREBBLE
[out]levelInteger value with level bands changed to
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

bool onSetBands(const String &deviceId, String &bands, int &level) {
Serial.printf("Device %s bands %s set to %d\r\n", deviceId.c_str(), bands.c_str(), level);
return true; // request handled properly
}

◆ SetVolumeCallback

typedef std::function<bool(const String&, int&)> SetVolumeCallback

Callback definition for onSetVolume function.

Gets called when device receive a setVolume request

Parameters
[in]deviceIdString which contains the ID of device
[in]volumeInteger with volume device should set to
[out]volumeInteger with volume device has been set to
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

bool onSetVolume(const String &deviceId, int &volume) {
Serial.printf("Device %s volume set to %d\r\n", deviceId.c_str(), volume);
return true; // request handled properly
}

Member Function Documentation

◆ onAdjustBands()

void onAdjustBands ( AdjustBandsCallback  cb)

Set callback function for adjustBands request.

Parameters
cbFunction pointer to a AdjustBandsCallback function
Returns
void
See also
AdjustBandsCallback

◆ onAdjustVolume()

void onAdjustVolume ( AdjustVolumeCallback  cb)

Set callback function for adjustVolume request.

Parameters
cbFunction pointer to a AdjustVolumeCallback function
Returns
void
See also
AdjustVolumeCallback

◆ onMediaControl()

void onMediaControl ( MediaControlCallback  cb)

Set callback function for mediaControl request.

Parameters
cbFunction pointer to a MediaControlCallback function
Returns
void
See also
MediaControlCallback

◆ onMute()

void onMute ( MuteCallback  cb)

Set callback function for setMute request.

Parameters
cbFunction pointer to a MuteCallback function
Returns
void
See also
MuteCallback

◆ onPowerState()

void onPowerState ( PowerStateCallback  cb)
virtualinherited

Set callback function for powerState request.

Parameters
cbFunction pointer to a PowerStateCallback function
Returns
void
See also
PowerStateCallback

◆ onResetBands()

void onResetBands ( ResetBandsCallback  cb)

Set callback function for resetBands request.

Parameters
cbFunction pointer to a ResetBandsCallback function
Returns
void
See also
ResetBandsCallback

◆ onSelectInput()

void onSelectInput ( SelectInputCallback  cb)

Set callback function for selectInput request.

Parameters
cbFunction pointer to a SelectInputCallback function
Returns
void
See also
SelectInputCallback

◆ onSetBands()

void onSetBands ( SetBandsCallback  cb)

Set callback function for setBands request.

Parameters
cbFunction pointer to a SetBandsCallback function
Returns
void
See also
SetBandsCallback

◆ onSetMode()

void onSetMode ( ModeCallback  cb)

Set callback function for setMode request.

Parameters
cbFunction pointer to a ModeCallback function
Returns
void
See also
ModeCallback

◆ onSetVolume()

void onSetVolume ( SetVolumeCallback  cb)

Set callback function for setVolume request.

Parameters
cbFunction pointer to a SetVolumeCallback function
Returns
void
See also
SetVolumeCallback

◆ sendBandsEvent()

bool sendBandsEvent ( String  bands,
int  level,
String  cause = "PHYSICAL_INTERACTION" 
)

Send setBands event to SinricPro Server indicating bands level has changed.

Parameters
bandsString which bands has changed
BASS, MIDRANGE, TREBBLE
levelInteger with changed bands level
cause(optional) String reason why event is sent (default = "PHYSICAL_INTERACTION")
Returns
the success of sending the even
Return values
trueevent has been sent successfully
falseevent has not been sent, maybe you sent to much events in a short distance of time

◆ sendMediaControlEvent()

bool sendMediaControlEvent ( String  mediaControl,
String  cause = "PHYSICAL_INTERACTION" 
)

Send mediaControl event to SinricPro Server indicating devices media control state.

Parameters
mediaControlString with actual media control
FastForward, Next, Pause, Play, Previous, Rewind, StartOver, Stop
cause(optional) String reason why event is sent (default = "PHYSICAL_INTERACTION")
Returns
the success of sending the even
Return values
trueevent has been sent successfully
falseevent has not been sent, maybe you sent to much events in a short distance of time

◆ sendModeEvent()

bool sendModeEvent ( String  mode,
String  cause = "PHYSICAL_INTERACTION" 
)

Send setMode event to SinricPro Server indicating the mode has changed.

Parameters
modeString with actual mode device is set to
MOVIE, MUSIC, NIGHT, SPORT, TV
cause(optional) String reason why event is sent (default = "PHYSICAL_INTERACTION")
Returns
the success of sending the even
Return values
trueevent has been sent successfully
falseevent has not been sent, maybe you sent to much events in a short distance of time

◆ sendMuteEvent()

bool sendMuteEvent ( bool  mute,
String  cause = "PHYSICAL_INTERACTION" 
)

Send setMute event to SinricPro Server indicating actual mute state.

Parameters
mutetrue = device is muted on
false = device is unmuted
cause(optional) String reason why event is sent (default = "PHYSICAL_INTERACTION")
Returns
the success of sending the even
Return values
trueevent has been sent successfully
falseevent has not been sent, maybe you sent to much events in a short distance of time

◆ sendPowerStateEvent()

bool sendPowerStateEvent ( bool  state,
String  cause = "PHYSICAL_INTERACTION" 
)
inherited

Send setPowerState event to SinricPro Server indicating actual power state.

Parameters
statetrue = device turned on
false = device turned off
cause(optional) String reason why event is sent (default = "PHYSICAL_INTERACTION")
Returns
the success of sending the even
Return values
trueevent has been sent successfully
falseevent has not been sent, maybe you sent to much events in a short distance of time

◆ sendSelectInputEvent()

bool sendSelectInputEvent ( String  input,
String  cause = "PHYSICAL_INTERACTION" 
)

Send selectInput event to SinricPro Server to report selected input.

Parameters
inputString with actual media control
AUX 1..AUX 7, BLURAY, CABLE, CD, COAX 1,COAX 2, COMPOSITE 1, DVD, GAME, HD RADIO, HDMI 1.. HDMI 10, HDMI ARC, INPUT 1..INPUT 10, IPOD, LINE 1..LINE 7, MEDIA PLAYER, OPTICAL 1, OPTICAL 2, PHONO, PLAYSTATION, PLAYSTATION 3, PLAYSTATION 4, SATELLITE, SMARTCAST, TUNER, TV, USB DAC, VIDEO 1..VIDEO 3, XBOX
cause(optional) String reason why event is sent (default = "PHYSICAL_INTERACTION")
Returns
the success of sending the even
Return values
trueevent has been sent successfully
falseevent has not been sent, maybe you sent to much events in a short distance of time

◆ sendVolumeEvent()

bool sendVolumeEvent ( int  volume,
String  cause = "PHYSICAL_INTERACTION" 
)

Send setVolume event to SinricPro Server indicating actual volume has changed.

Parameters
volumeInteger reporting the volume that the device have been set to
cause(optional) Reason why event is sent (default = "PHYSICAL_INTERACTION")
Returns
the success of sending the event
Return values
trueevent has been sent successfully
falseevent has not been sent, maybe you sent to much events in a short distance of time
SinricProSpeaker::onSetBands
void onSetBands(SetBandsCallback cb)
Set callback function for setBands request.
Definition: SinricProSpeaker.h:382
SinricProSpeaker::onAdjustBands
void onAdjustBands(AdjustBandsCallback cb)
Set callback function for adjustBands request.
Definition: SinricProSpeaker.h:391
SinricProSpeaker::onAdjustVolume
void onAdjustVolume(AdjustVolumeCallback cb)
Set callback function for adjustVolume request.
Definition: SinricProSpeaker.h:346
SinricProSpeaker::onSetMode
void onSetMode(ModeCallback cb)
Set callback function for setMode request.
Definition: SinricProSpeaker.h:409
SinricProSpeaker::onSelectInput
void onSelectInput(SelectInputCallback cb)
Set callback function for selectInput request.
Definition: SinricProSpeaker.h:373
SinricProSpeaker::onSetVolume
void onSetVolume(SetVolumeCallback cb)
Set callback function for setVolume request.
Definition: SinricProSpeaker.h:337
SinricProSpeaker::onMute
void onMute(MuteCallback cb)
Set callback function for setMute request.
Definition: SinricProSpeaker.h:355
SinricProSpeaker::onMediaControl
void onMediaControl(MediaControlCallback cb)
Set callback function for mediaControl request.
Definition: SinricProSpeaker.h:364
SinricProDevice::onPowerState
virtual void onPowerState(PowerStateCallback cb)
Set callback function for powerState request.
Definition: SinricProDevice.h:157