SinricPro Library
KeypadController.h
1 #ifndef _KEYPADCONTROLLER_H_
2 #define _KEYPADCONTROLLER_H_
3 
4 #include "SinricProRequest.h"
5 
10 template <typename T>
12  public:
13  KeypadController() { static_cast<T &>(*this).requestHandlers.push_back(std::bind(&KeypadController<T>::handleKeypadController, this, std::placeholders::_1)); }
28  using KeystrokeCallback = std::function<bool(const String &, String &)>;
29 
31 
32  protected:
33  bool handleKeypadController(SinricProRequest &request);
34 
35  private:
36  KeystrokeCallback keystrokeCallback;
37 };
38 
46 template <typename T>
47 void KeypadController<T>::onKeystroke(KeystrokeCallback cb) { keystrokeCallback = cb; }
48 
49 
50 template <typename T>
51 bool KeypadController<T>::handleKeypadController(SinricProRequest &request) {
52  T &device = static_cast<T &>(*this);
53 
54  bool success = false;
55  if (request.action != "SendKeystroke") return false;
56 
57  if (keystrokeCallback) {
58  String keystroke = request.request_value["keystroke"] | "";
59  success = keystrokeCallback(device.deviceId, keystroke);
60  request.response_value["keystroke"] = keystroke;
61  return success;
62  }
63 
64  return success;
65 }
66 
67 #endif
KeypadController.
Definition: KeypadController.h:11
std::function< bool(const String &, String &)> KeystrokeCallback
Callback definition for onKeystroke function.
Definition: KeypadController.h:28
void onKeystroke(KeystrokeCallback cb)
Set callback function for SendKeystroke request.
Definition: KeypadController.h:47