Skip to content

Commit e8c827f

Browse files
committed
Update version to 0.3.8
1 parent 2f56b0a commit e8c827f

12 files changed

+713
-149
lines changed

firmware/BlynkApi.h

+35
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,44 @@ class BlynkApi
216216
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_EMAIL, 0, cmd.getBuffer(), cmd.getLength()-1);
217217
}
218218

219+
/**
220+
* Sends an email message
221+
*
222+
* @param subject Subject of message
223+
* @param msg Text of the message
224+
*/
225+
template <typename T1, typename T2>
226+
void email(const T1& subject, const T2& msg) {
227+
char mem[BLYNK_MAX_SENDBYTES];
228+
BlynkParam cmd(mem, 0, sizeof(mem));
229+
cmd.add(subject);
230+
cmd.add(msg);
231+
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_EMAIL, 0, cmd.getBuffer(), cmd.getLength()-1);
232+
}
233+
219234
#if defined(BLYNK_EXPERIMENTAL)
220235
// Attention!
221236
// Every function in this section may be changed, removed or renamed.
222237

238+
/**
239+
* Sets property of a Widget
240+
*
241+
* @experimental
242+
*
243+
* @param pin Virtual Pin number
244+
* @param property Property name ("enabled", "label", "color", "bg_color" ...)
245+
* @param value Property value
246+
*/
247+
template <typename T1, typename T2>
248+
void setProperty(int pin, const T1& property, const T2& value) {
249+
char mem[BLYNK_MAX_SENDBYTES];
250+
BlynkParam cmd(mem, 0, sizeof(mem));
251+
cmd.add(pin);
252+
cmd.add(property);
253+
cmd.add(value);
254+
static_cast<Proto*>(this)->sendCmd(BLYNK_CMD_PROPERTY, 0, cmd.getBuffer(), cmd.getLength()-1);
255+
}
256+
223257
/**
224258
* Refreshes value of a widget by running
225259
* user-defined BLYNK_READ handler of a pin.
@@ -261,6 +295,7 @@ class BlynkApi
261295

262296
protected:
263297
void Init();
298+
static millis_time_t getMillis();
264299
void processCmd(const void* buff, size_t len);
265300
void sendInfo();
266301

firmware/BlynkApiParticle.h

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ void BlynkApi<Proto>::Init()
1919
{
2020
}
2121

22+
template<class Proto>
23+
BLYNK_FORCE_INLINE
24+
millis_time_t BlynkApi<Proto>::getMillis()
25+
{
26+
return millis();
27+
}
28+
2229
#ifdef BLYNK_NO_INFO
2330

2431
template<class Proto>

firmware/BlynkConfig.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* Professional settings
2626
***************************************************/
2727
// Library version.
28-
#define BLYNK_VERSION "0.3.5"
28+
#define BLYNK_VERSION "0.3.8"
2929

3030
// Heartbeat period in seconds.
3131
#ifndef BLYNK_HEARTBEAT
@@ -61,6 +61,9 @@
6161
// Uncomment to enable debug prints.
6262
//#define BLYNK_DEBUG
6363

64+
// Uncomment to force-enable 128 virtual pins
65+
//#define BLYNK_USE_128_VPINS
66+
6467
// Uncomment to enable experimental functions.
6568
//#define BLYNK_EXPERIMENTAL
6669

firmware/BlynkDebug.h

+52-55
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
#include <inttypes.h>
2424
#endif
2525

26+
#if defined(ARDUINO_ARCH_ARC32)
27+
typedef uint64_t millis_time_t;
28+
#else
29+
typedef uint32_t millis_time_t;
30+
#endif
31+
2632
#if defined(SPARK) || defined(PARTICLE)
2733
#include "application.h"
2834
#endif
@@ -77,21 +83,17 @@ void BlynkFatal() BLYNK_NORETURN;
7783
#define BLYNK_LOG_FN() BLYNK_LOG3(BLYNK_F(__FUNCTION__), '@', __LINE__);
7884
#define BLYNK_LOG_TROUBLE(t) BLYNK_LOG2(BLYNK_F("Trouble detected: http://docs.blynk.cc/#troubleshooting-"), t)
7985

80-
#if defined(BLYNK_DEBUG) && !defined(BLYNK_PRINT)
86+
#ifndef BLYNK_PRINT
8187
#undef BLYNK_DEBUG
8288
#endif
8389

8490
#ifdef BLYNK_PRINT
8591

8692
#if defined(ARDUINO) || defined(SPARK) || defined(PARTICLE)
8793

88-
#define BLYNK_DBG_BREAK() { for(;;); }
89-
#define BLYNK_ASSERT(expr) { if(!(expr)) { BLYNK_LOG2(BLYNK_F("Assertion failed: "), BLYNK_F(#expr)); BLYNK_DBG_BREAK() } }
90-
91-
#if defined(__SAM3X8E__)
92-
#define BLYNK_LOG(msg, ...) blynk_dbg_print(msg, ##__VA_ARGS__)
93-
#elif defined(ARDUINO_ARCH_ARC32)
94-
#undef BLYNK_LOG
94+
#if defined(ARDUINO_ARCH_ARC32)
95+
// This will cause error - on purpose
96+
#define BLYNK_LOG(msg, ...) BLYNK_LOG_UNAVAILABLE(msg, ##__VA_ARGS__)
9597
#else
9698
#define BLYNK_LOG(msg, ...) blynk_dbg_print(BLYNK_PSTR(msg), ##__VA_ARGS__)
9799
#endif
@@ -102,17 +104,15 @@ void BlynkFatal() BLYNK_NORETURN;
102104
#define BLYNK_LOG4(p1,p2,p3,p4) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(p1); BLYNK_PRINT.print(p2); BLYNK_PRINT.print(p3); BLYNK_PRINT.println(p4); }
103105
#define BLYNK_LOG6(p1,p2,p3,p4,p5,p6) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(p1); BLYNK_PRINT.print(p2); BLYNK_PRINT.print(p3); BLYNK_PRINT.print(p4); BLYNK_PRINT.print(p5); BLYNK_PRINT.println(p6); }
104106
#define BLYNK_LOG_IP(msg, ip) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(BLYNK_F(msg)); \
105-
BLYNK_PRINT.print(ip[0]); BLYNK_PRINT.print('.'); \
106-
BLYNK_PRINT.print(ip[1]); BLYNK_PRINT.print('.'); \
107-
BLYNK_PRINT.print(ip[2]); BLYNK_PRINT.print('.'); \
108-
BLYNK_PRINT.println(ip[3]); }
107+
BLYNK_PRINT.print(ip[0]); BLYNK_PRINT.print('.'); \
108+
BLYNK_PRINT.print(ip[1]); BLYNK_PRINT.print('.'); \
109+
BLYNK_PRINT.print(ip[2]); BLYNK_PRINT.print('.'); \
110+
BLYNK_PRINT.println(ip[3]); }
109111
#define BLYNK_LOG_IP_REV(msg, ip) { BLYNK_LOG_TIME(); BLYNK_PRINT.print(BLYNK_F(msg)); \
110-
BLYNK_PRINT.print(ip[3]); BLYNK_PRINT.print('.'); \
111-
BLYNK_PRINT.print(ip[2]); BLYNK_PRINT.print('.'); \
112-
BLYNK_PRINT.print(ip[1]); BLYNK_PRINT.print('.'); \
113-
BLYNK_PRINT.println(ip[0]); }
114-
115-
#include <ctype.h>
112+
BLYNK_PRINT.print(ip[3]); BLYNK_PRINT.print('.'); \
113+
BLYNK_PRINT.print(ip[2]); BLYNK_PRINT.print('.'); \
114+
BLYNK_PRINT.print(ip[1]); BLYNK_PRINT.print('.'); \
115+
BLYNK_PRINT.println(ip[0]); }
116116

117117
static
118118
void BLYNK_LOG_TIME() {
@@ -121,23 +121,38 @@ void BlynkFatal() BLYNK_NORETURN;
121121
BLYNK_PRINT.print(BLYNK_F("] "));
122122
}
123123

124+
#ifdef BLYNK_DEBUG
125+
#include <ctype.h>
126+
#define BLYNK_DBG_BREAK() { for(;;); }
127+
#define BLYNK_ASSERT(expr) { if(!(expr)) { BLYNK_LOG2(BLYNK_F("Assertion failed: "), BLYNK_F(#expr)); BLYNK_DBG_BREAK() } }
128+
124129
static
125130
void BLYNK_DBG_DUMP(const char* msg, const void* addr, size_t len) {
126131
if (len) {
132+
BLYNK_LOG_TIME();
127133
BLYNK_PRINT.print(msg);
128-
int l2 = len; char* octets = (char*)(addr);
134+
int l2 = len;
135+
const uint8_t* octets = (const uint8_t*)addr;
136+
bool prev_print = true;
129137
while (l2--) {
130-
if (isprint(*octets)) {
131-
BLYNK_PRINT.print(*octets);
138+
const uint8_t c = *octets++ & 0xFF;
139+
if (isprint(c)) {
140+
if (!prev_print) { BLYNK_PRINT.print(']'); }
141+
BLYNK_PRINT.print((char)c);
142+
prev_print = true;
132143
} else {
133-
BLYNK_PRINT.print('|');
134-
BLYNK_PRINT.print(*octets, HEX);
144+
BLYNK_PRINT.print(prev_print?'[':'|');
145+
if (c < 0x10) { BLYNK_PRINT.print('0'); }
146+
BLYNK_PRINT.print(c, HEX);
147+
prev_print = false;
135148
}
136-
octets++;
137149
}
150+
if (!prev_print)
151+
BLYNK_PRINT.print(']');
138152
BLYNK_PRINT.println();
139153
}
140154
}
155+
#endif
141156

142157
#if !defined(ARDUINO_ARCH_ARC32)
143158
#include <stdio.h>
@@ -170,13 +185,9 @@ void BlynkFatal() BLYNK_NORETURN;
170185
#include <errno.h>
171186
#include <signal.h>
172187

173-
#define BLYNK_DBG_DUMP(msg, addr, len) if (len) { fprintf(BLYNK_PRINT, msg); fwrite(addr, len, 1, BLYNK_PRINT); fputc('\n', BLYNK_PRINT); }
174-
#define BLYNK_DBG_BREAK() raise(SIGTRAP);
175-
#define BLYNK_LOG(msg, ...) { fprintf(BLYNK_PRINT, "[%ld] " msg "\n", millis(), ##__VA_ARGS__); }
176-
#define BLYNK_ASSERT(expr) assert(expr)
177-
178188
#include <iostream>
179189
using namespace std;
190+
#define BLYNK_LOG(msg, ...) { fprintf(BLYNK_PRINT, "[%ld] " msg "\n", millis(), ##__VA_ARGS__); }
180191
#define BLYNK_LOG1(p1) { BLYNK_LOG_TIME(); cout << p1 << endl; }
181192
#define BLYNK_LOG2(p1,p2) { BLYNK_LOG_TIME(); cout << p1 << p2 << endl; }
182193
#define BLYNK_LOG3(p1,p2,p3) { BLYNK_LOG_TIME(); cout << p1 << p2 << p3 << endl; }
@@ -185,40 +196,21 @@ void BlynkFatal() BLYNK_NORETURN;
185196

186197
#define BLYNK_LOG_TIME() cout << '[' << millis() << "] ";
187198

188-
#elif defined(WINDOWS)
189-
190-
#include <windows.h>
191-
#include <stdio.h>
192-
193-
#define BLYNK_DBG_DUMP(msg, addr, len)
194-
#define BLYNK_DBG_BREAK() DebugBreak();
195-
#define BLYNK_LOG(...) { char buff[1024]; snprintf(buff, sizeof(buff), __VA_ARGS__); OutputDebugString(buff); }
196-
#define BLYNK_ASSERT(expr) { if(!(expr)) { BLYNK_DBG_BREAK() } }
199+
#ifdef BLYNK_DEBUG
200+
#define BLYNK_DBG_BREAK() raise(SIGTRAP);
201+
#define BLYNK_ASSERT(expr) assert(expr)
202+
#define BLYNK_DBG_DUMP(msg, addr, len) if (len) { fprintf(BLYNK_PRINT, msg); fwrite(addr, len, 1, BLYNK_PRINT); fputc('\n', BLYNK_PRINT); }
203+
#endif
197204

198205
#else
199206

200207
#warning Could not detect platform
201-
#define BLYNK_DBG_DUMP(msg, addr, len)
202-
#define BLYNK_DBG_BREAK() { *(char*)(NULL) = 0xFF; } // SEGV!!!
203-
#define BLYNK_ASSERT(expr) { if(!(expr)) { BLYNK_DBG_BREAK() } }
204-
205-
#define BLYNK_LOG(...)
206-
#define BLYNK_LOG1(p1)
207-
#define BLYNK_LOG2(p1,p2)
208-
#define BLYNK_LOG3(p1,p2,p3)
209-
#define BLYNK_LOG4(p1,p2,p3,p4)
210-
#define BLYNK_LOG6(p1,p2,p3,p4,p5,p6)
211-
#define BLYNK_LOG_IP(msg, ip)
212-
#define BLYNK_LOG_IP_REV(msg, ip)
213208

214209
#endif
215210

216-
#else
217-
218-
#define BLYNK_DBG_DUMP(msg, addr, len)
219-
#define BLYNK_DBG_BREAK()
220-
#define BLYNK_ASSERT(expr)
211+
#endif
221212

213+
#ifndef BLYNK_LOG
222214
#define BLYNK_LOG(...)
223215
#define BLYNK_LOG1(p1)
224216
#define BLYNK_LOG2(p1,p2)
@@ -227,7 +219,12 @@ void BlynkFatal() BLYNK_NORETURN;
227219
#define BLYNK_LOG6(p1,p2,p3,p4,p5,p6)
228220
#define BLYNK_LOG_IP(msg, ip)
229221
#define BLYNK_LOG_IP_REV(msg, ip)
222+
#endif
230223

224+
#ifndef BLYNK_DBG_BREAK
225+
#define BLYNK_DBG_BREAK()
226+
#define BLYNK_ASSERT(expr)
227+
#define BLYNK_DBG_DUMP(msg, addr, len)
231228
#endif
232229

233230
#endif

0 commit comments

Comments
 (0)