-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWidgetTable.h
executable file
·62 lines (50 loc) · 1.67 KB
/
WidgetTable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* @file WidgetTable.h
* @author Volodymyr Shymanskyy
* @license This project is released under the MIT License (MIT)
* @copyright Copyright (c) 2015 Volodymyr Shymanskyy
* @date Sep 2016
* @brief
*
*/
#ifndef WidgetTable_h
#define WidgetTable_h
#include "BlynkWidgetBase.h"
class WidgetTable
: public BlynkWidgetBase
{
public:
typedef void (*ItemSelectChange)(int index, bool selected);
typedef void (*ItemOrderChange)(int indexFrom, int indexTo);
public:
WidgetTable(uint8_t vPin = -1)
: BlynkWidgetBase(vPin)
, mOnOrderChange(NULL)
, mOnSelectChange(NULL)
{}
void onWrite(BlynkReq BLYNK_UNUSED &request, const BlynkParam& param) {
if (mOnOrderChange && 0 == strcmp(param[0].asStr(), "order")) {
mOnOrderChange(param[1].asInt(), param[2].asInt());
} else if (mOnSelectChange && 0 == strcmp(param[0].asStr(), "select")) {
mOnSelectChange(param[1].asInt(), true);
} else if (mOnSelectChange && 0 == strcmp(param[0].asStr(), "deselect")) {
mOnSelectChange(param[1].asInt(), false);
}
}
void onOrderChange(ItemOrderChange cbk) { mOnOrderChange = cbk; }
void onSelectChange(ItemSelectChange cbk) { mOnSelectChange = cbk; }
void clear() {
Blynk.virtualWrite(mPin, "clr");
}
template <typename T1, typename T2>
void addRow(int index, const T1& name, const T2& value) {
Blynk.virtualWrite(mPin, "add", index, name, value);
}
void pickRow(int index) {
Blynk.virtualWrite(mPin, "pick", index);
}
private:
ItemOrderChange mOnOrderChange;
ItemSelectChange mOnSelectChange;
};
#endif