WLED/wled00/wled_blynk.cpp

98 lines
1.8 KiB
C++
Raw Normal View History

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