SinricPro Library
Loading...
Searching...
No Matches
KeypadController.h
1#pragma once
2
3#include "../SinricProRequest.h"
4#include "../SinricProStrings.h"
5
6#include "../SinricProNamespace.h"
7namespace SINRICPRO_NAMESPACE {
8
9FSTR(KEYPAD, sendKeystroke); // "sendKeystroke"
10FSTR(KEYPAD, keystroke); // "keystroke"
11
26using KeystrokeCallback = std::function<bool(const String &, String &)>;
27
28
33template <typename T>
35 public:
37
38 void onKeystroke(KeystrokeCallback cb);
39
40 protected:
41 bool handleKeypadController(SinricProRequest &request);
42
43 private:
44 KeystrokeCallback keystrokeCallback;
45};
46
47template <typename T>
49 T* device = static_cast<T*>(this);
50 device->registerRequestHandler(std::bind(&KeypadController<T>::handleKeypadController, this, std::placeholders::_1));
51}
52
60template <typename T>
62
63
64template <typename T>
66 T* device = static_cast<T*>(this);
67
68 bool success = false;
69 if (request.action != FSTR_KEYPAD_sendKeystroke) return false;
70
71 if (keystrokeCallback) {
72 String keystroke = request.request_value[FSTR_KEYPAD_keystroke] | "";
73 success = keystrokeCallback(device->deviceId, keystroke);
74 request.response_value[FSTR_KEYPAD_keystroke] = keystroke;
75 return success;
76 }
77
78 return success;
79}
80
81} // SINRICPRO_NAMESPACE
82
83template <typename T>
84using KeypadController = SINRICPRO_NAMESPACE::KeypadController<T>;
AirQuality.
Definition AirQualitySensor.h:19
KeypadController.
Definition KeypadController.h:34
std::function< bool(const String &, String &)> KeystrokeCallback
Callback definition for onKeystroke function.
Definition KeypadController.h:26