MCPcopy Create free account
hub / github.com/BlueAndi/Pixelix / execButtonAction

Function execButtonAction

src/Topics/Topics.cpp:240–279  ·  view source on GitHub ↗

* Execute a button action. * * @param[in] topic Topic * @param[in] value Value * * @return If successful, it will return true otherwise false. */

Source from the content-addressed store, hash-verified

238 * @return If successful, it will return true otherwise false.
239 */
240static bool execButtonAction(const String& topic, const JsonObjectConst& value)
241{
242 bool isSuccessful = true;
243 int32_t i32ActionId = BUTTON_ACTION_ID_MAX;
244 ButtonActionId actionId = BUTTON_ACTION_ID_ACTIVATE_NEXT_SLOT; /* Default */
245 JsonVariantConst jsonActionId = value["actionId"];
246
247 UTIL_NOT_USED(topic);
248
249 /* Action id validation? */
250 if (false == jsonActionId.isNull())
251 {
252 if (true == jsonActionId.is<String>())
253 {
254 i32ActionId = jsonActionId.as<String>().toInt();
255 }
256 else if (true == jsonActionId.is<int>())
257 {
258 i32ActionId = jsonActionId.as<int>();
259 }
260 else
261 {
262 isSuccessful = false;
263 }
264
265 if (BUTTON_ACTION_ID_MAX > i32ActionId)
266 {
267 actionId = static_cast<ButtonActionId>(i32ActionId);
268 }
269 }
270
271 if (true == isSuccessful)
272 {
273 VirtualButton button;
274
275 button.executeAction(actionId);
276 }
277
278 return isSuccessful;
279}
280
281/**
282 * Get display state.

Callers

nothing calls this directly

Calls 2

toIntMethod · 0.80
executeActionMethod · 0.45

Tested by

no test coverage detected