blynk & neopixelring & w7500

Fork of WIZwiki-7500_Blynk by IOP

Committer:
vshymanskyy
Date:
Sat May 07 08:02:50 2016 +0000
Revision:
0:58b20b438383
Child:
3:31e4b850b126
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vshymanskyy 0:58b20b438383 1 /**
vshymanskyy 0:58b20b438383 2 * @file BlynkHandlers.cpp
vshymanskyy 0:58b20b438383 3 * @author Volodymyr Shymanskyy
vshymanskyy 0:58b20b438383 4 * @license This project is released under the MIT License (MIT)
vshymanskyy 0:58b20b438383 5 * @copyright Copyright (c) 2015 Volodymyr Shymanskyy
vshymanskyy 0:58b20b438383 6 * @date Jan 2015
vshymanskyy 0:58b20b438383 7 * @brief Virtual pin utilities
vshymanskyy 0:58b20b438383 8 */
vshymanskyy 0:58b20b438383 9
vshymanskyy 0:58b20b438383 10 #include <Blynk/BlynkConfig.h>
vshymanskyy 0:58b20b438383 11 #include <Blynk/BlynkHandlers.h>
vshymanskyy 0:58b20b438383 12 #include <Blynk/BlynkDebug.h>
vshymanskyy 0:58b20b438383 13
vshymanskyy 0:58b20b438383 14 void BlynkNoOpCbk()
vshymanskyy 0:58b20b438383 15 {}
vshymanskyy 0:58b20b438383 16
vshymanskyy 0:58b20b438383 17 void BlynkWidgetRead(BlynkReq& request)
vshymanskyy 0:58b20b438383 18 {
vshymanskyy 0:58b20b438383 19 BLYNK_LOG2(BLYNK_F("No handler for reading from pin "), request.pin);
vshymanskyy 0:58b20b438383 20 }
vshymanskyy 0:58b20b438383 21
vshymanskyy 0:58b20b438383 22 void BlynkWidgetWrite(BlynkReq& request, const BlynkParam& param)
vshymanskyy 0:58b20b438383 23 {
vshymanskyy 0:58b20b438383 24 BLYNK_LOG2(BLYNK_F("No handler for writing to pin "), request.pin);
vshymanskyy 0:58b20b438383 25 }
vshymanskyy 0:58b20b438383 26
vshymanskyy 0:58b20b438383 27 #define BLYNK_ON_READ_IMPL(pin) void BlynkWidgetRead ## pin (BlynkReq& req) \
vshymanskyy 0:58b20b438383 28 __attribute__((weak, alias("BlynkWidgetRead")))
vshymanskyy 0:58b20b438383 29
vshymanskyy 0:58b20b438383 30 #define BLYNK_ON_WRITE_IMPL(pin) void BlynkWidgetWrite ## pin (BlynkReq& req, const BlynkParam& param) \
vshymanskyy 0:58b20b438383 31 __attribute__((weak, alias("BlynkWidgetWrite")))
vshymanskyy 0:58b20b438383 32
vshymanskyy 0:58b20b438383 33 BLYNK_CONNECTED() __attribute__((weak, alias("BlynkNoOpCbk")));
vshymanskyy 0:58b20b438383 34 BLYNK_DISCONNECTED() __attribute__((weak, alias("BlynkNoOpCbk")));
vshymanskyy 0:58b20b438383 35
vshymanskyy 0:58b20b438383 36 BLYNK_ON_READ_IMPL(Default);
vshymanskyy 0:58b20b438383 37 BLYNK_ON_WRITE_IMPL(Default);
vshymanskyy 0:58b20b438383 38
vshymanskyy 0:58b20b438383 39 BLYNK_ON_READ_IMPL(0 );
vshymanskyy 0:58b20b438383 40 BLYNK_ON_READ_IMPL(1 );
vshymanskyy 0:58b20b438383 41 BLYNK_ON_READ_IMPL(2 );
vshymanskyy 0:58b20b438383 42 BLYNK_ON_READ_IMPL(3 );
vshymanskyy 0:58b20b438383 43 BLYNK_ON_READ_IMPL(4 );
vshymanskyy 0:58b20b438383 44 BLYNK_ON_READ_IMPL(5 );
vshymanskyy 0:58b20b438383 45 BLYNK_ON_READ_IMPL(6 );
vshymanskyy 0:58b20b438383 46 BLYNK_ON_READ_IMPL(7 );
vshymanskyy 0:58b20b438383 47 BLYNK_ON_READ_IMPL(8 );
vshymanskyy 0:58b20b438383 48 BLYNK_ON_READ_IMPL(9 );
vshymanskyy 0:58b20b438383 49 BLYNK_ON_READ_IMPL(10);
vshymanskyy 0:58b20b438383 50 BLYNK_ON_READ_IMPL(11);
vshymanskyy 0:58b20b438383 51 BLYNK_ON_READ_IMPL(12);
vshymanskyy 0:58b20b438383 52 BLYNK_ON_READ_IMPL(13);
vshymanskyy 0:58b20b438383 53 BLYNK_ON_READ_IMPL(14);
vshymanskyy 0:58b20b438383 54 BLYNK_ON_READ_IMPL(15);
vshymanskyy 0:58b20b438383 55 BLYNK_ON_READ_IMPL(16);
vshymanskyy 0:58b20b438383 56 BLYNK_ON_READ_IMPL(17);
vshymanskyy 0:58b20b438383 57 BLYNK_ON_READ_IMPL(18);
vshymanskyy 0:58b20b438383 58 BLYNK_ON_READ_IMPL(19);
vshymanskyy 0:58b20b438383 59 BLYNK_ON_READ_IMPL(20);
vshymanskyy 0:58b20b438383 60 BLYNK_ON_READ_IMPL(21);
vshymanskyy 0:58b20b438383 61 BLYNK_ON_READ_IMPL(22);
vshymanskyy 0:58b20b438383 62 BLYNK_ON_READ_IMPL(23);
vshymanskyy 0:58b20b438383 63 BLYNK_ON_READ_IMPL(24);
vshymanskyy 0:58b20b438383 64 BLYNK_ON_READ_IMPL(25);
vshymanskyy 0:58b20b438383 65 BLYNK_ON_READ_IMPL(26);
vshymanskyy 0:58b20b438383 66 BLYNK_ON_READ_IMPL(27);
vshymanskyy 0:58b20b438383 67 BLYNK_ON_READ_IMPL(28);
vshymanskyy 0:58b20b438383 68 BLYNK_ON_READ_IMPL(29);
vshymanskyy 0:58b20b438383 69 BLYNK_ON_READ_IMPL(30);
vshymanskyy 0:58b20b438383 70 BLYNK_ON_READ_IMPL(31);
vshymanskyy 0:58b20b438383 71
vshymanskyy 0:58b20b438383 72 BLYNK_ON_WRITE_IMPL(0 );
vshymanskyy 0:58b20b438383 73 BLYNK_ON_WRITE_IMPL(1 );
vshymanskyy 0:58b20b438383 74 BLYNK_ON_WRITE_IMPL(2 );
vshymanskyy 0:58b20b438383 75 BLYNK_ON_WRITE_IMPL(3 );
vshymanskyy 0:58b20b438383 76 BLYNK_ON_WRITE_IMPL(4 );
vshymanskyy 0:58b20b438383 77 BLYNK_ON_WRITE_IMPL(5 );
vshymanskyy 0:58b20b438383 78 BLYNK_ON_WRITE_IMPL(6 );
vshymanskyy 0:58b20b438383 79 BLYNK_ON_WRITE_IMPL(7 );
vshymanskyy 0:58b20b438383 80 BLYNK_ON_WRITE_IMPL(8 );
vshymanskyy 0:58b20b438383 81 BLYNK_ON_WRITE_IMPL(9 );
vshymanskyy 0:58b20b438383 82 BLYNK_ON_WRITE_IMPL(10);
vshymanskyy 0:58b20b438383 83 BLYNK_ON_WRITE_IMPL(11);
vshymanskyy 0:58b20b438383 84 BLYNK_ON_WRITE_IMPL(12);
vshymanskyy 0:58b20b438383 85 BLYNK_ON_WRITE_IMPL(13);
vshymanskyy 0:58b20b438383 86 BLYNK_ON_WRITE_IMPL(14);
vshymanskyy 0:58b20b438383 87 BLYNK_ON_WRITE_IMPL(15);
vshymanskyy 0:58b20b438383 88 BLYNK_ON_WRITE_IMPL(16);
vshymanskyy 0:58b20b438383 89 BLYNK_ON_WRITE_IMPL(17);
vshymanskyy 0:58b20b438383 90 BLYNK_ON_WRITE_IMPL(18);
vshymanskyy 0:58b20b438383 91 BLYNK_ON_WRITE_IMPL(19);
vshymanskyy 0:58b20b438383 92 BLYNK_ON_WRITE_IMPL(20);
vshymanskyy 0:58b20b438383 93 BLYNK_ON_WRITE_IMPL(21);
vshymanskyy 0:58b20b438383 94 BLYNK_ON_WRITE_IMPL(22);
vshymanskyy 0:58b20b438383 95 BLYNK_ON_WRITE_IMPL(23);
vshymanskyy 0:58b20b438383 96 BLYNK_ON_WRITE_IMPL(24);
vshymanskyy 0:58b20b438383 97 BLYNK_ON_WRITE_IMPL(25);
vshymanskyy 0:58b20b438383 98 BLYNK_ON_WRITE_IMPL(26);
vshymanskyy 0:58b20b438383 99 BLYNK_ON_WRITE_IMPL(27);
vshymanskyy 0:58b20b438383 100 BLYNK_ON_WRITE_IMPL(28);
vshymanskyy 0:58b20b438383 101 BLYNK_ON_WRITE_IMPL(29);
vshymanskyy 0:58b20b438383 102 BLYNK_ON_WRITE_IMPL(30);
vshymanskyy 0:58b20b438383 103 BLYNK_ON_WRITE_IMPL(31);
vshymanskyy 0:58b20b438383 104
vshymanskyy 0:58b20b438383 105 static const WidgetReadHandler BlynkReadHandlerVector[] BLYNK_PROGMEM = {
vshymanskyy 0:58b20b438383 106 BlynkWidgetRead0, BlynkWidgetRead1, BlynkWidgetRead2, BlynkWidgetRead3,
vshymanskyy 0:58b20b438383 107 BlynkWidgetRead4, BlynkWidgetRead5, BlynkWidgetRead6, BlynkWidgetRead7,
vshymanskyy 0:58b20b438383 108 BlynkWidgetRead8, BlynkWidgetRead9, BlynkWidgetRead10, BlynkWidgetRead11,
vshymanskyy 0:58b20b438383 109 BlynkWidgetRead12, BlynkWidgetRead13, BlynkWidgetRead14, BlynkWidgetRead15,
vshymanskyy 0:58b20b438383 110 BlynkWidgetRead16, BlynkWidgetRead17, BlynkWidgetRead18, BlynkWidgetRead19,
vshymanskyy 0:58b20b438383 111 BlynkWidgetRead20, BlynkWidgetRead21, BlynkWidgetRead22, BlynkWidgetRead23,
vshymanskyy 0:58b20b438383 112 BlynkWidgetRead24, BlynkWidgetRead25, BlynkWidgetRead26, BlynkWidgetRead27,
vshymanskyy 0:58b20b438383 113 BlynkWidgetRead28, BlynkWidgetRead29, BlynkWidgetRead30, BlynkWidgetRead31,
vshymanskyy 0:58b20b438383 114 };
vshymanskyy 0:58b20b438383 115
vshymanskyy 0:58b20b438383 116 static const WidgetWriteHandler BlynkWriteHandlerVector[] BLYNK_PROGMEM = {
vshymanskyy 0:58b20b438383 117 BlynkWidgetWrite0, BlynkWidgetWrite1, BlynkWidgetWrite2, BlynkWidgetWrite3,
vshymanskyy 0:58b20b438383 118 BlynkWidgetWrite4, BlynkWidgetWrite5, BlynkWidgetWrite6, BlynkWidgetWrite7,
vshymanskyy 0:58b20b438383 119 BlynkWidgetWrite8, BlynkWidgetWrite9, BlynkWidgetWrite10, BlynkWidgetWrite11,
vshymanskyy 0:58b20b438383 120 BlynkWidgetWrite12, BlynkWidgetWrite13, BlynkWidgetWrite14, BlynkWidgetWrite15,
vshymanskyy 0:58b20b438383 121 BlynkWidgetWrite16, BlynkWidgetWrite17, BlynkWidgetWrite18, BlynkWidgetWrite19,
vshymanskyy 0:58b20b438383 122 BlynkWidgetWrite20, BlynkWidgetWrite21, BlynkWidgetWrite22, BlynkWidgetWrite23,
vshymanskyy 0:58b20b438383 123 BlynkWidgetWrite24, BlynkWidgetWrite25, BlynkWidgetWrite26, BlynkWidgetWrite27,
vshymanskyy 0:58b20b438383 124 BlynkWidgetWrite28, BlynkWidgetWrite29, BlynkWidgetWrite30, BlynkWidgetWrite31,
vshymanskyy 0:58b20b438383 125 };
vshymanskyy 0:58b20b438383 126
vshymanskyy 0:58b20b438383 127 WidgetReadHandler GetReadHandler(uint8_t pin)
vshymanskyy 0:58b20b438383 128 {
vshymanskyy 0:58b20b438383 129 if (pin >= COUNT_OF(BlynkReadHandlerVector))
vshymanskyy 0:58b20b438383 130 return NULL;
vshymanskyy 0:58b20b438383 131 #ifdef BLYNK_HAS_PROGMEM
vshymanskyy 0:58b20b438383 132 return (WidgetReadHandler)pgm_read_word(&BlynkReadHandlerVector[pin]);
vshymanskyy 0:58b20b438383 133 #else
vshymanskyy 0:58b20b438383 134 return BlynkReadHandlerVector[pin];
vshymanskyy 0:58b20b438383 135 #endif
vshymanskyy 0:58b20b438383 136 }
vshymanskyy 0:58b20b438383 137
vshymanskyy 0:58b20b438383 138 WidgetWriteHandler GetWriteHandler(uint8_t pin)
vshymanskyy 0:58b20b438383 139 {
vshymanskyy 0:58b20b438383 140 if (pin >= COUNT_OF(BlynkWriteHandlerVector))
vshymanskyy 0:58b20b438383 141 return NULL;
vshymanskyy 0:58b20b438383 142 #ifdef BLYNK_HAS_PROGMEM
vshymanskyy 0:58b20b438383 143 return (WidgetWriteHandler)pgm_read_word(&BlynkWriteHandlerVector[pin]);
vshymanskyy 0:58b20b438383 144 #else
vshymanskyy 0:58b20b438383 145 return BlynkWriteHandlerVector[pin];
vshymanskyy 0:58b20b438383 146 #endif
vshymanskyy 0:58b20b438383 147 }