@@ -16,6 +16,13 @@ bool onPowerState(const String &deviceId, bool &state) {
1616}
1717// ! [onPowerState]
1818
19+ // ! [onToggleState]
20+ bool onToggleState (const String &deviceId, const String &instance, bool &state) {
21+ Serial.printf (" Device %s state \" %s\" turned %s\r\n " , deviceId.c_str (), instance.c_str (), state ? " on" : " off" );
22+ return true ; // request handled properly
23+ }
24+ // ! [onToggleState]
25+
1926// ! [onPowerLevel]
2027bool onPowerLevel (const String &deviceId, int &powerLevel) {
2128 Serial.printf (" Device %s powerlevel %d\r\n " , deviceId.c_str (), powerLevel);
@@ -91,22 +98,40 @@ bool onDecreaseColorTemperature(const String &deviceId, int &colorTemperature) {
9198
9299// ! [onRangeValue]
93100bool onRangeValue (const String &deviceId, int &rangeValue) {
94- Serial.printf (" Device %s range value has been set to %d\r\n " , rangeValue);
101+ Serial.printf (" Device %s range value has been set to %d\r\n " , deviceId. c_str (), rangeValue);
95102 return true ; // request handled properly
96103}
97104// ! [onRangeValue]
98105
106+ // ! [onRangeValueGeneric]
107+ bool onRangeValue (const String &deviceId, const String &instance, int &rangeValue) {
108+ Serial.printf (" Device %s range value for %s has been set to %d\r\n " , deviceId.c_str (), instance.c_str (), rangeValue);
109+ return true ; // request handled properly
110+ }
111+ // ! [onRangeValueGeneric]
112+
99113// ! [onAdjustRangeValue]
100114int globalRangeValue;
101115
102116bool onAdjustRangeValue (const String &deviceId, int &rangeValueDelta) {
103117 globalRangeValue += rangeValue; // calculate absolute rangeValue
104- Serial.printf (" Device %s range value has been changed about %i to %d\r\n " , rangeValueDelta, globalRangeValue);
118+ Serial.printf (" Device %s range value has been changed about %i to %d\r\n " , deviceId. c_str (), rangeValueDelta, globalRangeValue);
105119 rangeValueDelta = globalRangeValue; // return absolute rangeValue
106120 return true ; // request handled properly
107121}
108122// ! [onAdjustRangeValue]
109123
124+ // ! [onAdjustRangeValueGeneric]
125+ int globalRangeValue;
126+
127+ bool onAdjustRangeValue (const String &deviceId, const String& instance, int &rangeValueDelta) {
128+ globalRangeValue += rangeValueDelta; // calculate absolute rangeValue
129+ Serial.printf (" Device %s range value for %s has been changed about %i to %d\r\n " , deviceId.c_str (), instance.c_str (), rangeValueDelta, globalRangeValue);
130+ rangeValueDelta = globalRangeValue; // return absolute rangeValue
131+ return true ; // request handled properly
132+ }
133+ // ! [onAdjustRangeValueGeneric]
134+
110135// ! [onTargetTemperature]
111136bool onTargetTemperature (const String &deviceId, float &targetTemp) {
112137 Serial.printf (" Device %s target temperature set to %f\r\n " , deviceId.c_str (), targetTemp);
@@ -160,61 +185,39 @@ bool onMute(const String &deviceId, bool &mute) {
160185
161186// ! [onMediaControl]
162187bool onMediaControl (const String &deviceId, String &control) {
163- Serial.printf (" Device %s: %s\r\n " , deviceId.c_str (), control);
188+ Serial.printf (" Device %s: %s\r\n " , deviceId.c_str (), control. c_str () );
164189 return true ; // request handled properly
165190}
166191// ! [onMediaControl]
167192
168193// ! [onSetBands]
194+ std::map<String, int > equalizerBands;
195+
169196bool onSetBands (const String &deviceId, String &bands, int &level) {
170197 Serial.printf (" Device %s bands %s set to %d\r\n " , deviceId.c_str (), bands.c_str (), level);
198+ equalizerBands[bands] = level;
171199 return true ; // request handled properly
172200}
173201// ! [onSetBands]
174202
175203// ! [onAdjustBands]
176- int globalBass;
177- int globalMidrange;
178- int globalTrebble;
204+ std::map<String, int > equalizerBands;
179205
180206bool onAdjustBands (const String &deviceId, String &bands, int &levelDelta) {
181- if (bands == " BASS" ) {
182- globalBass += levelDelta; // calculate absolute bass level
183- levelDelta = globalBass; // return absolute bass level
184- }
185- if (bands == " MIDRANGE" ) {
186- globalMidrange += levelDelta; // calculate absolute midrange level
187- levelDelta = globalMidrange; // return absolute midrange level
188- }
189- if (bands == " TREBBLE" ) {
190- globalMidrange += levelDelta; // calculate absolute trebble level
191- levelDelta = globalMidrange; // return absolute trebble level
192- }
193- 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);
207+ equalizerBands[bands] += levelDelta; // calculate absolute bands level
208+ Serial.printf (" Device %s bands %s changed about %d to %d\r\n " , deviceId.c_str (), bands.c_str (), levelDelta, equalizerBands[bands]);
209+ levelDelta = equalizerBands[bands]; // return absolute bands level
194210 return true ; // request handled properly
195211}
196212// ! [onAdjustBands]
197213
198214
199215// ! [onResetBands]
200- int globalBass;
201- int globalMidrange;
202- int globalTrebble;
203-
204- bool onAdjustBands (const String &deviceId, String &bands, int &level) {
205- if (bands == " BASS" ) {
206- globalBass = 0 ; // reset bass level to 0
207- level = globalBass; // return bass level
208- }
209- if (bands == " MIDRANGE" ) {
210- globalMidrange = 0 ; // reset midrange level to 0
211- level = globalMidrange; // return midrange level
212- }
213- if (bands == " TREBBLE" ) {
214- globalMidrange = 0 ; // reset trebble level to 0
215- level = globalMidrange; // return trebble level
216- }
217- 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);
216+ std::map<String, int > equalizerBands;
217+
218+ bool onResetBands (const String &deviceId, String &bands, int &level) {
219+ equalizerBands[bands] = 0 ; // reset bands level to 0
220+ Serial.printf (" Device %s bands %s reset to %d\r\n " , deviceId.c_str (), bands.c_str (), equalizerBands[bands]);
218221 return true ; // request handled properly
219222}
220223// ! [onResetBands]
@@ -227,6 +230,13 @@ bool onSetMode(const String &deviceId, String &mode) {
227230}
228231// ! [onSetMode]
229232
233+ // ! [onSetModeGeneric]
234+ bool onSetMode (const String &deviceId, const String &instance, String &mode) {
235+ Serial.printf (" Device %s mode %s set to %s\r\n " , deviceId.c_str (), instance.c_str (), mode);
236+ return true ; // request handled properly
237+ }
238+ // ! [onSetModeGeneric]
239+
230240// ! [onChangeChannel]
231241// channelNames used to convert channelNumber into channelName
232242// please put in your TV channel names
@@ -402,3 +412,27 @@ bool onDoorState(const String &deviceId, bool &doorState) {
402412}
403413// ! [onDoorState]
404414
415+ // ! [onKeystroke]
416+ bool onKeystroke (const String& deviceId, String &keystroke) {
417+ Serial.printf (" Device %s, key %s pressed\r\n " , deviceId.c_str (), keystroke.c_str ());
418+ return true ;
419+ }
420+ // ! [onKeystroke]
421+
422+ // ! [onSetPercentage]
423+ bool onSetPercentage (const String &deviceId, int &percentage) {
424+ Serial.printf (" Device %s percentage %d\r\n " , deviceId.c_str (), percentage);
425+ return true ; // request handled properly
426+ }
427+ // ! [onSetPercentage]
428+
429+ // ! [onAdjustPercentage]
430+ int absolutePercentage;
431+
432+ bool onAdjustPercentage (const String &deviceId, int &percentageDelta) {
433+ absolutePercentage += percentageDelta; // calculate absolute percentage
434+ Serial.printf (" Device %s percentage changed about %i to %d\r\n " , deviceId.c_str (), percentageDelta, absolutePercentage);
435+ percentageDelta = absolutePercentage; // return absolute percentage
436+ return true ; // request handled properly
437+ }
438+ // ! [onAdjustPercentage]
0 commit comments