blynk & neopixelring & w7500
Fork of WIZwiki-7500_Blynk by
WidgetTable.h@7:8879692d4e6c, 2016-10-12 (annotated)
- Committer:
- Volodymyr Shymanskyy
- Date:
- Wed Oct 12 09:18:39 2016 +0300
- Revision:
- 7:8879692d4e6c
- Child:
- 9:7369ec77a3ea
Update library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Volodymyr Shymanskyy |
7:8879692d4e6c | 1 | /** |
Volodymyr Shymanskyy |
7:8879692d4e6c | 2 | * @file WidgetTable.h |
Volodymyr Shymanskyy |
7:8879692d4e6c | 3 | * @author Volodymyr Shymanskyy |
Volodymyr Shymanskyy |
7:8879692d4e6c | 4 | * @license This project is released under the MIT License (MIT) |
Volodymyr Shymanskyy |
7:8879692d4e6c | 5 | * @copyright Copyright (c) 2015 Volodymyr Shymanskyy |
Volodymyr Shymanskyy |
7:8879692d4e6c | 6 | * @date Sep 2016 |
Volodymyr Shymanskyy |
7:8879692d4e6c | 7 | * @brief |
Volodymyr Shymanskyy |
7:8879692d4e6c | 8 | * |
Volodymyr Shymanskyy |
7:8879692d4e6c | 9 | */ |
Volodymyr Shymanskyy |
7:8879692d4e6c | 10 | |
Volodymyr Shymanskyy |
7:8879692d4e6c | 11 | #ifndef WidgetTable_h |
Volodymyr Shymanskyy |
7:8879692d4e6c | 12 | #define WidgetTable_h |
Volodymyr Shymanskyy |
7:8879692d4e6c | 13 | |
Volodymyr Shymanskyy |
7:8879692d4e6c | 14 | #include <Blynk/BlynkApi.h> |
Volodymyr Shymanskyy |
7:8879692d4e6c | 15 | |
Volodymyr Shymanskyy |
7:8879692d4e6c | 16 | class WidgetTable |
Volodymyr Shymanskyy |
7:8879692d4e6c | 17 | { |
Volodymyr Shymanskyy |
7:8879692d4e6c | 18 | public: |
Volodymyr Shymanskyy |
7:8879692d4e6c | 19 | typedef void (*ItemSelectChange)(int index, bool selected); |
Volodymyr Shymanskyy |
7:8879692d4e6c | 20 | typedef void (*ItemOrderChange)(int indexFrom, int indexTo); |
Volodymyr Shymanskyy |
7:8879692d4e6c | 21 | |
Volodymyr Shymanskyy |
7:8879692d4e6c | 22 | public: |
Volodymyr Shymanskyy |
7:8879692d4e6c | 23 | WidgetTable(uint8_t pin = -1) |
Volodymyr Shymanskyy |
7:8879692d4e6c | 24 | : mPin(pin) |
Volodymyr Shymanskyy |
7:8879692d4e6c | 25 | , mOnOrderChange(NULL) |
Volodymyr Shymanskyy |
7:8879692d4e6c | 26 | , mOnSelectChange(NULL) |
Volodymyr Shymanskyy |
7:8879692d4e6c | 27 | {} |
Volodymyr Shymanskyy |
7:8879692d4e6c | 28 | |
Volodymyr Shymanskyy |
7:8879692d4e6c | 29 | void setVPin(int vPin) { mPin = vPin; } |
Volodymyr Shymanskyy |
7:8879692d4e6c | 30 | |
Volodymyr Shymanskyy |
7:8879692d4e6c | 31 | void onWrite(BlynkReq BLYNK_UNUSED &request, const BlynkParam& param) { |
Volodymyr Shymanskyy |
7:8879692d4e6c | 32 | if (mOnOrderChange && 0 == strcmp(param[0].asStr(), "order")) { |
Volodymyr Shymanskyy |
7:8879692d4e6c | 33 | mOnOrderChange(param[1].asInt(), param[2].asInt()); |
Volodymyr Shymanskyy |
7:8879692d4e6c | 34 | } else if (mOnSelectChange && 0 == strcmp(param[0].asStr(), "select")) { |
Volodymyr Shymanskyy |
7:8879692d4e6c | 35 | mOnSelectChange(param[1].asInt(), true); |
Volodymyr Shymanskyy |
7:8879692d4e6c | 36 | } else if (mOnSelectChange && 0 == strcmp(param[0].asStr(), "deselect")) { |
Volodymyr Shymanskyy |
7:8879692d4e6c | 37 | mOnSelectChange(param[1].asInt(), false); |
Volodymyr Shymanskyy |
7:8879692d4e6c | 38 | } |
Volodymyr Shymanskyy |
7:8879692d4e6c | 39 | } |
Volodymyr Shymanskyy |
7:8879692d4e6c | 40 | |
Volodymyr Shymanskyy |
7:8879692d4e6c | 41 | void onOrderChange(ItemOrderChange cbk) { mOnOrderChange = cbk; } |
Volodymyr Shymanskyy |
7:8879692d4e6c | 42 | void onSelectChange(ItemSelectChange cbk) { mOnSelectChange = cbk; } |
Volodymyr Shymanskyy |
7:8879692d4e6c | 43 | |
Volodymyr Shymanskyy |
7:8879692d4e6c | 44 | void clear() { |
Volodymyr Shymanskyy |
7:8879692d4e6c | 45 | Blynk.virtualWrite(mPin, "clr"); |
Volodymyr Shymanskyy |
7:8879692d4e6c | 46 | } |
Volodymyr Shymanskyy |
7:8879692d4e6c | 47 | |
Volodymyr Shymanskyy |
7:8879692d4e6c | 48 | template <typename T1, typename T2> |
Volodymyr Shymanskyy |
7:8879692d4e6c | 49 | void addRow(int index, const T1& name, const T2& value) { |
Volodymyr Shymanskyy |
7:8879692d4e6c | 50 | Blynk.virtualWrite(mPin, "add", index, name, value); |
Volodymyr Shymanskyy |
7:8879692d4e6c | 51 | } |
Volodymyr Shymanskyy |
7:8879692d4e6c | 52 | |
Volodymyr Shymanskyy |
7:8879692d4e6c | 53 | void pickRow(int index) { |
Volodymyr Shymanskyy |
7:8879692d4e6c | 54 | Blynk.virtualWrite(mPin, "pick", index); |
Volodymyr Shymanskyy |
7:8879692d4e6c | 55 | } |
Volodymyr Shymanskyy |
7:8879692d4e6c | 56 | |
Volodymyr Shymanskyy |
7:8879692d4e6c | 57 | private: |
Volodymyr Shymanskyy |
7:8879692d4e6c | 58 | uint8_t mPin; |
Volodymyr Shymanskyy |
7:8879692d4e6c | 59 | ItemOrderChange mOnOrderChange; |
Volodymyr Shymanskyy |
7:8879692d4e6c | 60 | ItemSelectChange mOnSelectChange; |
Volodymyr Shymanskyy |
7:8879692d4e6c | 61 | |
Volodymyr Shymanskyy |
7:8879692d4e6c | 62 | }; |
Volodymyr Shymanskyy |
7:8879692d4e6c | 63 | |
Volodymyr Shymanskyy |
7:8879692d4e6c | 64 | #endif |