SinricPro Library
SinricProTV

Device to control a TV. More...

Inheritance diagram for SinricProTV:
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 &, String &)> ChangeChannelCallback
 Callback definition for onChangeChannel function. More...
 
typedef std::function< bool(const String &, int, String &)> ChangeChannelNumberCallback
 Callback definition for onChangeChannelNumber function. More...
 
typedef std::function< bool(const String &, int, String &)> SkipChannelsCallback
 Callback definition for onSkipChannels 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 onChangeChannel (ChangeChannelCallback cb)
 Set callback function for changeChannel request. More...
 
void onChangeChannelNumber (ChangeChannelNumberCallback cb)
 Set callback function for changeChannel request. More...
 
void onSkipChannels (SkipChannelsCallback cb)
 Set callback function for skipChannels 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 sendChangeChannelEvent (String channelName, String cause="PHYSICAL_INTERACTION")
 Send changeChannel event to SinricPro Server to report selected channel. 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 TV.

Supporting:

  • setVolume / adjustVolume
  • mute / unmute
  • media controls:
    • FastForward, Next, Pause, Play, Previous, Rewind, StartOver, Stop
  • select input
    • 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
  • Change channel by number
  • Change channel by name
  • Skip channels

Member Typedef Documentation

◆ 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
}

◆ ChangeChannelCallback

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

Callback definition for onChangeChannel function.

Gets called when device receive a changeChannel request by using channel name

Parameters
[in]deviceIdString which contains the ID of device
[in]channelString with channel name device is requested to switch to
[out]channelString with channel name device has switchted to
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

// channelNames used to convert channelNumber into channelName
// please put in your TV channel names
// channel numbers starts counting from 0!
// so "ZDF" is channel 2
const char* channelNames[] = {
"A/V",
"ard",
"ZDF",
"n. d. r.",
"kabel eins",
"VOX",
"Sat.1",
"ProSieben",
"rtl",
"RTL II",
"SUPER RTL",
"KiKA"
};
int tvChannel; // current channel selected
#define MAX_CHANNELS sizeof(channelNames) / sizeof(channelNames[0]) // just to determine how many channels are in channelNames array
// map channelNumbers used to convert channelName into channelNumber
// This map is initialized in "setupChannelNumbers()" function by using the "channelNames" array
std::map<String, unsigned int> channelNumbers;
void setupChannelNumbers() {
for (unsigned int i=0; i < MAX_CHANNELS; i++) {
channelNumbers[channelNames[i]] = i;
}
}
bool onChangeChannel(const String &deviceId, String &channel) {
tvChannel = channelNumbers[channel]; // save new channelNumber in tvChannel variable
Serial.printf("Change channel to \"%s\" (channel number %d)\r\n", channel.c_str(), tvChannel);
return true;
}

◆ ChangeChannelNumberCallback

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

Callback definition for onChangeChannelNumber function.

Gets called when device receive a changeChannel request by using channel number

Parameters
[in]deviceIdString which contains the ID of device
[in]channelNumberInteger with channel number device is requested to switch to
[out]channelNameString with channel name device has switchted to
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

// channelNames used to convert channelNumber into channelName
// please put in your TV channel names
// channel numbers starts counting from 0!
// so "ZDF" is channel 2
const char* channelNames[] = {
"A/V",
"ard",
"ZDF",
"n. d. r.",
"kabel eins",
"VOX",
"Sat.1",
"ProSieben",
"rtl",
"RTL II",
"SUPER RTL",
"KiKA"
};
int tvChannel; // current channel selected
#define MAX_CHANNELS sizeof(channelNames) / sizeof(channelNames[0]) // just to determine how many channels are in channelNames array
// map channelNumbers used to convert channelName into channelNumber
// This map is initialized in "setupChannelNumbers()" function by using the "channelNames" array
std::map<String, unsigned int> channelNumbers;
void setupChannelNumbers() {
for (unsigned int i=0; i < MAX_CHANNELS; i++) {
channelNumbers[channelNames[i]] = i;
}
}
bool onChangeChannelNumber(const String& deviceId, int channelNumber, String& channelName) {
tvChannel = channelNumber; // update tvChannel to new channel number
if (tvChannel < 0) tvChannel = 0;
if (tvChannel > MAX_CHANNELS-1) tvChannel = MAX_CHANNELS-1;
channelName = channelNames[tvChannel]; // return the channelName
Serial.printf("Change to channel to %d (channel name \"%s\")\r\n", tvChannel, channelName.c_str());
return true;
}

◆ 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
}

◆ 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
}

◆ 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;
}

◆ 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
}

◆ SkipChannelsCallback

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

Callback definition for onSkipChannels function.

Gets called when device receive a changeChannel request by using channel number

Parameters
[in]deviceIdString which contains the ID of device
[in]channelCountInteger with channels device is requested to skip -n..+n
[out]channelNameString with channel name device has switchted to
Returns
the success of the request
Return values
truerequest handled properly
falserequest was not handled properly because of some error

Example-Code

// channelNames used to convert channelNumber into channelName
// please put in your TV channel names
// channel numbers starts counting from 0!
// so "ZDF" is channel 2
const char* channelNames[] = {
"A/V",
"ard",
"ZDF",
"n. d. r.",
"kabel eins",
"VOX",
"Sat.1",
"ProSieben",
"rtl",
"RTL II",
"SUPER RTL",
"KiKA"
};
int tvChannel; // current channel selected
#define MAX_CHANNELS sizeof(channelNames) / sizeof(channelNames[0]) // just to determine how many channels are in channelNames array
// map channelNumbers used to convert channelName into channelNumber
// This map is initialized in "setupChannelNumbers()" function by using the "channelNames" array
std::map<String, unsigned int> channelNumbers;
void setupChannelNumbers() {
for (unsigned int i=0; i < MAX_CHANNELS; i++) {
channelNumbers[channelNames[i]] = i;
}
}
bool onSkipChannels(const String &deviceId, const int channelCount, String &channelName) {
tvChannel += channelCount; // calculate new channel number
if (tvChannel < 0) tvChannel = 0;
if (tvChannel > MAX_CHANNELS-1) tvChannel = MAX_CHANNELS-1;
channelName = String(channelNames[tvChannel]); // return channel name
Serial.printf("Skip channel: %i (number: %i / name: \"%s\")\r\n", channelCount, tvChannel, channelName.c_str());
return true;
}

Member Function Documentation

◆ onAdjustVolume()

void onAdjustVolume ( AdjustVolumeCallback  cb)

Set callback function for adjustVolume request.

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

◆ onChangeChannel()

void onChangeChannel ( ChangeChannelCallback  cb)

Set callback function for changeChannel request.

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

◆ onChangeChannelNumber()

void onChangeChannelNumber ( ChangeChannelNumberCallback  cb)

Set callback function for changeChannel request.

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

◆ 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

◆ onSelectInput()

void onSelectInput ( SelectInputCallback  cb)

Set callback function for selectInput request.

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

◆ onSetVolume()

void onSetVolume ( SetVolumeCallback  cb)

Set callback function for setVolume request.

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

◆ onSkipChannels()

void onSkipChannels ( SkipChannelsCallback  cb)

Set callback function for skipChannels request.

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

◆ sendChangeChannelEvent()

bool sendChangeChannelEvent ( String  channelName,
String  cause = "PHYSICAL_INTERACTION" 
)

Send changeChannel event to SinricPro Server to report selected channel.

Parameters
channelNameString with actual channel
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

◆ 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
SinricProTV::onMediaControl
void onMediaControl(MediaControlCallback cb)
Set callback function for mediaControl request.
Definition: SinricProTV.h:308
SinricProTV::onMute
void onMute(MuteCallback cb)
Set callback function for setMute request.
Definition: SinricProTV.h:299
SinricProTV::onChangeChannelNumber
void onChangeChannelNumber(ChangeChannelNumberCallback cb)
Set callback function for changeChannel request.
Definition: SinricProTV.h:335
SinricProTV::onSetVolume
void onSetVolume(SetVolumeCallback cb)
Set callback function for setVolume request.
Definition: SinricProTV.h:281
SinricProTV::onSelectInput
void onSelectInput(SelectInputCallback cb)
Set callback function for selectInput request.
Definition: SinricProTV.h:317
SinricProTV::onChangeChannel
void onChangeChannel(ChangeChannelCallback cb)
Set callback function for changeChannel request.
Definition: SinricProTV.h:326
SinricProTV::onSkipChannels
void onSkipChannels(SkipChannelsCallback cb)
Set callback function for skipChannels request.
Definition: SinricProTV.h:344
SinricProTV::onAdjustVolume
void onAdjustVolume(AdjustVolumeCallback cb)
Set callback function for adjustVolume request.
Definition: SinricProTV.h:290
SinricProDevice::onPowerState
virtual void onPowerState(PowerStateCallback cb)
Set callback function for powerState request.
Definition: SinricProDevice.h:157