2020-03-25 08:00:55 +00:00
|
|
|
#include "wled.h"
|
|
|
|
#include "src/dependencies/blynk/Blynk/BlynkHandlers.h"
|
2020-03-31 00:38:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Remote light control with the free Blynk app
|
|
|
|
*/
|
2018-07-16 09:50:09 +00:00
|
|
|
|
|
|
|
uint16_t blHue = 0;
|
|
|
|
byte blSat = 255;
|
|
|
|
|
2020-12-21 23:44:16 +00:00
|
|
|
void initBlynk(const char *auth, const char *host, uint16_t port)
|
2018-07-16 09:50:09 +00:00
|
|
|
{
|
2018-11-01 14:36:13 +00:00
|
|
|
#ifndef WLED_DISABLE_BLYNK
|
2019-10-18 11:26:39 +00:00
|
|
|
if (!WLED_CONNECTED) return;
|
2018-07-16 09:50:09 +00:00
|
|
|
blynkEnabled = (auth[0] != 0);
|
2020-12-21 23:44:16 +00:00
|
|
|
if (blynkEnabled) Blynk.config(auth, host, port);
|
2018-11-01 14:36:13 +00:00
|
|
|
#endif
|
2018-07-16 09:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handleBlynk()
|
|
|
|
{
|
2018-11-01 14:36:13 +00:00
|
|
|
#ifndef WLED_DISABLE_BLYNK
|
2019-10-18 11:26:39 +00:00
|
|
|
if (WLED_CONNECTED && blynkEnabled)
|
2018-07-16 09:50:09 +00:00
|
|
|
Blynk.run();
|
2018-11-01 14:36:13 +00:00
|
|
|
#endif
|
2018-07-16 09:50:09 +00:00
|
|
|
}
|
|
|
|
|
2018-07-29 12:03:02 +00:00
|
|
|
void updateBlynk()
|
|
|
|
{
|
2018-11-01 14:36:13 +00:00
|
|
|
#ifndef WLED_DISABLE_BLYNK
|
2019-10-18 12:06:07 +00:00
|
|
|
if (!WLED_CONNECTED) return;
|
2018-10-08 15:36:22 +00:00
|
|
|
Blynk.virtualWrite(V0, bri);
|
2018-07-29 12:03:02 +00:00
|
|
|
//we need a RGB -> HSB convert here
|
2018-10-08 15:36:22 +00:00
|
|
|
Blynk.virtualWrite(V3, bri? 1:0);
|
|
|
|
Blynk.virtualWrite(V4, effectCurrent);
|
|
|
|
Blynk.virtualWrite(V5, effectSpeed);
|
|
|
|
Blynk.virtualWrite(V6, effectIntensity);
|
|
|
|
Blynk.virtualWrite(V7, nightlightActive);
|
|
|
|
Blynk.virtualWrite(V8, notifyDirect);
|
2018-11-01 14:36:13 +00:00
|
|
|
#endif
|
2018-07-29 12:03:02 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 14:36:13 +00:00
|
|
|
#ifndef WLED_DISABLE_BLYNK
|
2018-07-16 09:50:09 +00:00
|
|
|
BLYNK_WRITE(V0)
|
|
|
|
{
|
2018-11-09 16:00:36 +00:00
|
|
|
bri = param.asInt();//bri
|
2020-02-22 15:17:32 +00:00
|
|
|
colorUpdated(NOTIFIER_CALL_MODE_BLYNK);
|
2018-07-16 09:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BLYNK_WRITE(V1)
|
|
|
|
{
|
2018-11-09 16:00:36 +00:00
|
|
|
blHue = param.asInt();//hue
|
|
|
|
colorHStoRGB(blHue*10,blSat,(false)? colSec:col);
|
2020-02-22 15:17:32 +00:00
|
|
|
colorUpdated(NOTIFIER_CALL_MODE_BLYNK);
|
2018-07-16 09:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BLYNK_WRITE(V2)
|
|
|
|
{
|
2018-11-09 16:00:36 +00:00
|
|
|
blSat = param.asInt();//sat
|
|
|
|
colorHStoRGB(blHue*10,blSat,(false)? colSec:col);
|
2020-02-22 15:17:32 +00:00
|
|
|
colorUpdated(NOTIFIER_CALL_MODE_BLYNK);
|
2018-07-16 09:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BLYNK_WRITE(V3)
|
|
|
|
{
|
2019-03-09 20:41:23 +00:00
|
|
|
bool on = (param.asInt()>0);
|
2020-02-22 15:17:32 +00:00
|
|
|
if (!on != !bri) {toggleOnOff(); colorUpdated(NOTIFIER_CALL_MODE_BLYNK);}
|
2018-07-16 09:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BLYNK_WRITE(V4)
|
|
|
|
{
|
2018-11-09 16:00:36 +00:00
|
|
|
effectCurrent = param.asInt()-1;//fx
|
2020-02-22 15:17:32 +00:00
|
|
|
colorUpdated(NOTIFIER_CALL_MODE_BLYNK);
|
2018-07-16 09:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BLYNK_WRITE(V5)
|
|
|
|
{
|
2018-11-09 16:00:36 +00:00
|
|
|
effectSpeed = param.asInt();//sx
|
2020-02-22 15:17:32 +00:00
|
|
|
colorUpdated(NOTIFIER_CALL_MODE_BLYNK);
|
2018-07-16 09:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BLYNK_WRITE(V6)
|
|
|
|
{
|
2018-11-09 16:00:36 +00:00
|
|
|
effectIntensity = param.asInt();//ix
|
2020-02-22 15:17:32 +00:00
|
|
|
colorUpdated(NOTIFIER_CALL_MODE_BLYNK);
|
2018-07-16 09:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BLYNK_WRITE(V7)
|
|
|
|
{
|
2019-03-09 20:41:23 +00:00
|
|
|
nightlightActive = (param.asInt()>0);
|
2018-07-16 09:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BLYNK_WRITE(V8)
|
|
|
|
{
|
|
|
|
notifyDirect = (param.asInt()>0); //send notifications
|
|
|
|
}
|
2018-11-01 14:36:13 +00:00
|
|
|
#endif
|