first commit
This commit is contained in:
1
code/xiaoai/.pydio
Normal file
1
code/xiaoai/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
11624fc7-d39b-4a8a-bc99-896338ebf37e
|
||||
1
code/xiaoai/colorDeng/.pydio
Normal file
1
code/xiaoai/colorDeng/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
7aa191ad-811b-4adf-bd3e-db3d9ecdb572
|
||||
522
code/xiaoai/colorDeng/colorDeng.ino
Normal file
522
code/xiaoai/colorDeng/colorDeng.ino
Normal file
@@ -0,0 +1,522 @@
|
||||
#define BLINKER_PRINT Serial
|
||||
#define BLINKER_MIOT_LIGHT
|
||||
#define BLINKER_WIFI
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <Blinker.h>
|
||||
#include <WS2812FX.h>
|
||||
#define BLINKER_OTA_VERSION_CODE "1.0.1"
|
||||
|
||||
//【据自己情况修改】Blinker 的秘钥
|
||||
char auth[] = "b082a19ce985";
|
||||
// 自己家中的 2.4G wifi名称
|
||||
char ssid[] = "bmy";
|
||||
// 自己家中的 2.4G wifi密码
|
||||
char pswd[] = "lb714500";
|
||||
|
||||
//【据自己情况修改】WS2812的 GPIO 引脚编号
|
||||
#define LED_PIN 0 // 对应开发板上的 D3
|
||||
#define LED_PIN_TWO 2 // 对应开发板上的 D4
|
||||
|
||||
#define LED_COUNT 60 //【据自己情况修改】灯珠个数
|
||||
#define DEFAULT_COLOR 0xFF5900 // 初始化灯的颜色
|
||||
#define DEFAULT_BRIGHTNESS 255 // 初始化亮度
|
||||
#define DEFAULT_SPEED 1000 // 初始化速度
|
||||
#define DEFAULT_MODE FX_MODE_STATIC // 初始化灯的模式
|
||||
|
||||
|
||||
//【据自己情况修改】HC-SR501红外人体感应模块的 GPIO 引脚编号
|
||||
#define irSensor_PIN 5 // 对应开发板上的 D1
|
||||
bool sensorReading = 0; // 红外人体感应模块 读到的数值 1 表示有人,0 表示无人,默认0无人
|
||||
bool isUseSensor = false; // 是否使用人体红外感应模块 true 使用, false 不使用
|
||||
|
||||
|
||||
#define TIMER_MS 5000 // 随机主题模式间隔切换时间
|
||||
bool isUseRandomTheme = false; // 是否使用随机主题模式 true 使用,false 不使用,默认false不使用
|
||||
unsigned long last_change = 0; // 上一次切换的事件
|
||||
unsigned long now = 0; // 当前的时候
|
||||
|
||||
|
||||
// 初始化 WS2812FX
|
||||
WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
|
||||
WS2812FX ws2812two = WS2812FX(30, LED_PIN_TWO, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
// 颜色选择器
|
||||
BlinkerRGB RGB1("RGB");
|
||||
// 开灯按钮
|
||||
BlinkerButton openButton("open");
|
||||
// 工作模式按钮
|
||||
BlinkerButton workButton("work");
|
||||
// 默认模式按钮
|
||||
BlinkerButton defaultButton("default");
|
||||
// 红外人体传感器按钮
|
||||
BlinkerButton sensorButton("sensor");
|
||||
// 休眠模式按钮
|
||||
BlinkerButton sleepButton("sleep");
|
||||
// 随机模式按钮
|
||||
BlinkerButton randomButton("random");
|
||||
// 亮度调节
|
||||
BlinkerSlider brightnessSlider("brightness");
|
||||
|
||||
|
||||
//APP RGB颜色设置回调
|
||||
void rgb1_callback(uint8_t r_value, uint8_t g_value, uint8_t b_value, uint8_t bright_value) {
|
||||
ws2812fx.setColor(ws2812fx.Color(r_value, g_value, b_value));
|
||||
ws2812two.setColor(ws2812two.Color(r_value, g_value, b_value));
|
||||
if (bright_value != 0) {
|
||||
ws2812fx.setBrightness(bright_value);
|
||||
ws2812two.setBrightness(bright_value);
|
||||
}
|
||||
}
|
||||
|
||||
// 开灯
|
||||
void openLamp() {
|
||||
if (!ws2812fx.isRunning() || !ws2812two.isRunning()) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
openButton.color("#F0AA41");
|
||||
openButton.text("已开启");
|
||||
openButton.print("on");
|
||||
ws2812fx.start();
|
||||
ws2812two.start();
|
||||
}
|
||||
}
|
||||
|
||||
// 关灯
|
||||
void closeLamp() {
|
||||
if (ws2812fx.isRunning() || ws2812two.isRunning()) {
|
||||
digitalWrite(LED_BUILTIN, HIGH); // 无人状态保持LED关闭
|
||||
closeRandom();
|
||||
openButton.color("#595959");
|
||||
openButton.text("已关闭");
|
||||
openButton.print("off");
|
||||
ws2812fx.stop();
|
||||
ws2812two.stop();
|
||||
}
|
||||
}
|
||||
|
||||
// 开关灯的回调函数
|
||||
void openLamp_Callback(const String & state) {
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
openLamp();
|
||||
} else if (state == BLINKER_CMD_OFF) {
|
||||
closeLamp();
|
||||
}
|
||||
}
|
||||
|
||||
// 亮度:将 0 ~ 255 的数值转换为 0 ~ 100 亮度
|
||||
int BrightTransformation(int Bright) {
|
||||
return 100 * Bright / 255;
|
||||
}
|
||||
|
||||
// 默认模式按钮被点击的回调函数
|
||||
void defaultButton_Callback(const String & state) {
|
||||
closeRandom();
|
||||
|
||||
ws2812two.setBrightness(DEFAULT_BRIGHTNESS);
|
||||
ws2812two.setSpeed(DEFAULT_SPEED);
|
||||
ws2812two.setColor(DEFAULT_COLOR);
|
||||
ws2812two.setMode(DEFAULT_MODE);
|
||||
|
||||
ws2812fx.setBrightness(DEFAULT_BRIGHTNESS);
|
||||
ws2812fx.setSpeed(DEFAULT_SPEED);
|
||||
ws2812fx.setColor(DEFAULT_COLOR);
|
||||
ws2812fx.setMode(DEFAULT_MODE);
|
||||
brightnessSlider.print(BrightTransformation(127));
|
||||
}
|
||||
|
||||
// 工作模式按钮被点击的回调函数
|
||||
void workButton_Callback(const String & state) {
|
||||
closeRandom();
|
||||
|
||||
ws2812two.setBrightness(127);
|
||||
ws2812two.setSpeed(1000);
|
||||
ws2812two.setMode(FX_MODE_COLOR_WIPE_RANDOM);
|
||||
|
||||
ws2812fx.setBrightness(127);
|
||||
ws2812fx.setSpeed(1000);
|
||||
ws2812fx.setMode(FX_MODE_COLOR_WIPE_RANDOM);
|
||||
brightnessSlider.print(BrightTransformation(127));
|
||||
}
|
||||
|
||||
// 休眠模式按钮被点击的回调函数
|
||||
void sleepButton_Callback(const String & state) {
|
||||
closeRandom();
|
||||
|
||||
ws2812two.setColor(255, 89, 0);
|
||||
ws2812two.setBrightness(50);
|
||||
ws2812two.setMode(FX_MODE_BREATH);
|
||||
|
||||
ws2812fx.setColor(255, 89, 0);
|
||||
ws2812fx.setBrightness(50);
|
||||
ws2812fx.setMode(FX_MODE_BREATH);
|
||||
brightnessSlider.print(BrightTransformation(10));
|
||||
}
|
||||
|
||||
// 拖动调节亮度
|
||||
void brightnessSlider_Callback(int32_t value) {
|
||||
uint8_t set_brightness = 255 * int(value) / 100;
|
||||
ws2812two.setBrightness(set_brightness);
|
||||
ws2812fx.setBrightness(set_brightness);
|
||||
brightnessSlider.print(value);
|
||||
}
|
||||
|
||||
// 随机模式的按钮
|
||||
void randomButton_Callback(const String & state) {
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
isUseRandomTheme = true;
|
||||
changeRandomTheme();
|
||||
randomButton.text("已开启");
|
||||
randomButton.color("#F0AA41");
|
||||
randomButton.print("on");
|
||||
} else if (state == BLINKER_CMD_OFF) {
|
||||
closeRandom();
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭随机模式
|
||||
void closeRandom() {
|
||||
isUseRandomTheme = false;
|
||||
randomButton.text("随机模式");
|
||||
randomButton.color("#595959");
|
||||
randomButton.print("off");
|
||||
}
|
||||
|
||||
// 是否开启传感器的回调
|
||||
void sensorButton_Callback(const String & state) {
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
openSensor();
|
||||
} else if (state == BLINKER_CMD_OFF) {
|
||||
closeSensor();
|
||||
}
|
||||
}
|
||||
|
||||
// 开关红外人体传感器
|
||||
void changeUseSensor() {
|
||||
// 为 true 则使用红外人体传感器
|
||||
if (isUseSensor) {
|
||||
bool sensorReading = digitalRead(irSensor_PIN);
|
||||
|
||||
Serial.println(sensorReading);
|
||||
int8_t hour = Blinker.hour();
|
||||
// 判断如果是晚上六点以后,早上六点以前,并且有人,那么开灯
|
||||
if (sensorReading && (hour >= 18 || hour <= 6)) {
|
||||
openLamp();
|
||||
// Serial.println("yes.....");
|
||||
} else {
|
||||
closeLamp();
|
||||
// closeSensor();
|
||||
// Serial.println("no.....");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void closeSensor() {
|
||||
BLINKER_LOG("Toggle off!");
|
||||
isUseSensor = false;
|
||||
sensorButton.text("已关闭人体传感");
|
||||
sensorButton.color("#595959");
|
||||
sensorButton.print("off");
|
||||
}
|
||||
|
||||
void openSensor() {
|
||||
BLINKER_LOG("Toggle on!");
|
||||
isUseSensor = true;
|
||||
sensorButton.text("已开启人体传感");
|
||||
sensorButton.color("#F0AA41");
|
||||
sensorButton.print("on");
|
||||
}
|
||||
|
||||
void switch_callback(const String & state) {
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
openLamp();
|
||||
BUILTIN_SWITCH.print("on");
|
||||
} else if (state == BLINKER_CMD_OFF) {
|
||||
closeLamp();
|
||||
BUILTIN_SWITCH.print("off");
|
||||
}
|
||||
}
|
||||
|
||||
// 小音箱控制亮度
|
||||
void miotBright(const String & bright) {
|
||||
BLINKER_LOG("need set brightness: ", bright);
|
||||
uint8_t colorW = 0;
|
||||
if (bright == BLINKER_CMD_MAX) {
|
||||
colorW = 100;
|
||||
} else if (bright == BLINKER_CMD_MIN) {
|
||||
colorW = 0;
|
||||
} else {
|
||||
colorW = bright.toInt();
|
||||
}
|
||||
//进行亮度值转换
|
||||
uint8_t set_brightness = 255 * colorW / 100;
|
||||
|
||||
ws2812two.setBrightness(set_brightness);
|
||||
ws2812fx.setBrightness(set_brightness);
|
||||
|
||||
brightnessSlider.print(colorW);
|
||||
|
||||
BlinkerMIOT.brightness(colorW);
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
|
||||
|
||||
// 灯的颜色设置
|
||||
void miotColor(int32_t color) {
|
||||
BLINKER_LOG("need set color: ", color);
|
||||
ws2812two.setColor(color);
|
||||
ws2812fx.setColor(color);
|
||||
BlinkerMIOT.color(color);
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
|
||||
// 灯的状态查询
|
||||
void miotQuery(int32_t queryCode) {
|
||||
BLINKER_LOG("MIOT Query codes: ", queryCode);
|
||||
|
||||
switch (queryCode) {
|
||||
case BLINKER_CMD_QUERY_ALL_NUMBER :
|
||||
BLINKER_LOG("MIOT Query All ---- : ", ws2812fx.getBrightness());
|
||||
BlinkerMIOT.powerState(ws2812fx.isRunning() ? "on" : "off");
|
||||
BlinkerMIOT.color(ws2812fx.getColor());
|
||||
BlinkerMIOT.mode(ws2812fx.getMode());
|
||||
BlinkerMIOT.brightness(100 * ws2812fx.getBrightness() / 255);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
|
||||
BLINKER_LOG("MIOT Query Power State");
|
||||
BlinkerMIOT.powerState(ws2812fx.isRunning() ? "on" : "off");
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_COLOR_NUMBER :
|
||||
BLINKER_LOG("MIOT Query Color");
|
||||
BlinkerMIOT.color(ws2812fx.getColor());
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_MODE_NUMBER :
|
||||
BLINKER_LOG("MIOT Query Mode");
|
||||
BlinkerMIOT.mode(ws2812fx.getMode());
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
case BLINKER_CMD_QUERY_BRIGHTNESS_NUMBER :
|
||||
BLINKER_LOG("MIOT Query Brightness");
|
||||
BlinkerMIOT.brightness(100 * ws2812fx.getBrightness() / 255);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
default :
|
||||
BlinkerMIOT.powerState(ws2812fx.isRunning() ? "on" : "off");
|
||||
BlinkerMIOT.color(ws2812fx.getColor());
|
||||
BlinkerMIOT.mode(ws2812fx.getMode());
|
||||
BlinkerMIOT.brightness(100 * ws2812fx.getBrightness() / 255);
|
||||
BlinkerMIOT.print();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 灯的模式控制
|
||||
void miotMode(uint8_t mode) {
|
||||
BLINKER_LOG("need set mode: ", mode);
|
||||
|
||||
// 日光 模式
|
||||
if (mode == BLINKER_CMD_MIOT_DAY) {
|
||||
ws2812two.setColor(255, 255, 255);
|
||||
ws2812two.setBrightness(255);
|
||||
ws2812two.setMode(DEFAULT_MODE);
|
||||
|
||||
ws2812fx.setColor(255, 255, 255);
|
||||
ws2812fx.setBrightness(255);
|
||||
ws2812fx.setMode(DEFAULT_MODE);
|
||||
brightnessSlider.print(BrightTransformation(255));
|
||||
}
|
||||
// 月光 模式
|
||||
else if (mode == BLINKER_CMD_MIOT_NIGHT) {
|
||||
ws2812two.setColor(255, 89, 0);
|
||||
ws2812two.setBrightness(255);
|
||||
ws2812two.setMode(FX_MODE_STATIC);
|
||||
|
||||
ws2812fx.setColor(255, 89, 0);
|
||||
ws2812fx.setBrightness(255);
|
||||
ws2812fx.setMode(FX_MODE_STATIC);
|
||||
brightnessSlider.print(BrightTransformation(100));
|
||||
}
|
||||
// 彩光 模式
|
||||
else if (mode == BLINKER_CMD_MIOT_COLOR) {
|
||||
ws2812two.setBrightness(255);
|
||||
ws2812two.setSpeed(200);
|
||||
ws2812two.setMode(FX_MODE_RAINBOW_CYCLE);
|
||||
|
||||
ws2812fx.setBrightness(255);
|
||||
ws2812fx.setSpeed(200);
|
||||
ws2812fx.setMode(FX_MODE_RAINBOW_CYCLE);
|
||||
brightnessSlider.print(BrightTransformation(255));
|
||||
}
|
||||
// 温馨 模式
|
||||
else if (mode == BLINKER_CMD_MIOT_WARMTH) {
|
||||
ws2812two.setMode(FX_MODE_TWINKLEFOX);
|
||||
ws2812fx.setMode(FX_MODE_TWINKLEFOX);
|
||||
}
|
||||
// 电视模式
|
||||
else if (mode == BLINKER_CMD_MIOT_TV) {
|
||||
ws2812two.setBrightness(20);
|
||||
ws2812two.setSpeed(1000);
|
||||
ws2812two.setMode(FX_MODE_CHASE_RAINBOW);
|
||||
|
||||
ws2812fx.setBrightness(20);
|
||||
ws2812fx.setSpeed(1000);
|
||||
ws2812fx.setMode(FX_MODE_CHASE_RAINBOW);
|
||||
brightnessSlider.print(BrightTransformation(20));
|
||||
}
|
||||
// 阅读 模式
|
||||
else if (mode == BLINKER_CMD_MIOT_READING) {
|
||||
|
||||
ws2812two.setBrightness(255);
|
||||
ws2812two.setSpeed(200);
|
||||
ws2812two.setMode(FX_MODE_MULTI_STROBE);
|
||||
|
||||
ws2812fx.setBrightness(255);
|
||||
ws2812fx.setSpeed(200);
|
||||
ws2812fx.setMode(FX_MODE_MULTI_STROBE);
|
||||
brightnessSlider.print(BrightTransformation(255));
|
||||
}
|
||||
// 电脑模式
|
||||
else if (mode == BLINKER_CMD_MIOT_COMPUTER) {
|
||||
ws2812two.setBrightness(255);
|
||||
ws2812two.setMode(FX_MODE_COLOR_SWEEP_RANDOM);
|
||||
|
||||
ws2812fx.setBrightness(255);
|
||||
ws2812fx.setMode(FX_MODE_COLOR_SWEEP_RANDOM);
|
||||
brightnessSlider.print(BrightTransformation(255));
|
||||
}
|
||||
|
||||
BlinkerMIOT.mode(mode);
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
|
||||
// 电源控制
|
||||
void miotPowerState(const String & state) {
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
openLamp();
|
||||
BlinkerMIOT.powerState("on");
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
closeLamp();
|
||||
BlinkerMIOT.powerState("off");
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
}
|
||||
|
||||
// 心跳包Heartbeat
|
||||
void heartbeat() {
|
||||
if (ws2812fx.isRunning()) {
|
||||
BUILTIN_SWITCH.print("on");
|
||||
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
openButton.color("#F0AA41");
|
||||
openButton.text("已开启");
|
||||
openButton.print("on");
|
||||
|
||||
if (isUseSensor) {
|
||||
openSensor();
|
||||
}
|
||||
} else {
|
||||
BUILTIN_SWITCH.print("off");
|
||||
};
|
||||
}
|
||||
|
||||
// 随机切换主题
|
||||
void changeRandomTheme() {
|
||||
if (isUseRandomTheme) {
|
||||
if (now - last_change > TIMER_MS) {
|
||||
ws2812two.setMode((ws2812two.getMode() + 1) % ws2812two.getModeCount());
|
||||
ws2812fx.setMode((ws2812fx.getMode() + 1) % ws2812fx.getModeCount());
|
||||
BlinkerMIOT.brightness(100 * ws2812fx.getBrightness() / 255);
|
||||
last_change = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Ws2812fxInit() {
|
||||
|
||||
|
||||
ws2812fx.init();
|
||||
ws2812fx.setBrightness(DEFAULT_BRIGHTNESS);
|
||||
ws2812fx.setSpeed(DEFAULT_SPEED);
|
||||
ws2812fx.setColor(DEFAULT_COLOR);
|
||||
ws2812fx.setMode(DEFAULT_MODE);
|
||||
ws2812fx.start();
|
||||
|
||||
ws2812two.init();
|
||||
ws2812two.setBrightness(DEFAULT_BRIGHTNESS);
|
||||
ws2812two.setSpeed(DEFAULT_SPEED);
|
||||
ws2812two.setColor(DEFAULT_COLOR);
|
||||
ws2812two.setMode(DEFAULT_MODE);
|
||||
ws2812two.start();
|
||||
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
openButton.color("#F0AA41");
|
||||
openButton.text("已开启");
|
||||
openButton.print("on");
|
||||
}
|
||||
|
||||
// 初始化 Blinker,并绑定各种事件监听
|
||||
void BlinkerInit() {
|
||||
|
||||
// 初始化blinker链接wifi
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
// 开启 DEBUG
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
//注册调节颜色的回调函数
|
||||
RGB1.attach(rgb1_callback);
|
||||
// 打开按钮的回调
|
||||
openButton.attach(openLamp_Callback);
|
||||
// 亮度调节
|
||||
brightnessSlider.attach(brightnessSlider_Callback);
|
||||
// 工作模式
|
||||
workButton.attach(workButton_Callback);
|
||||
// 默认模式
|
||||
defaultButton.attach(defaultButton_Callback);
|
||||
// 休眠模式
|
||||
sleepButton.attach(sleepButton_Callback);
|
||||
// 红外人体传感器
|
||||
sensorButton.attach(sensorButton_Callback);
|
||||
// 随机模式
|
||||
randomButton.attach(randomButton_Callback);
|
||||
|
||||
// 在列表首页显示开关按钮
|
||||
BUILTIN_SWITCH.attach(switch_callback);
|
||||
// 自定义心跳的监听处理
|
||||
Blinker.attachHeartbeat(heartbeat);
|
||||
|
||||
// 语音电源控制
|
||||
BlinkerMIOT.attachPowerState(miotPowerState);
|
||||
// 语音亮度调节
|
||||
BlinkerMIOT.attachBrightness(miotBright);
|
||||
// 语音颜色设置
|
||||
BlinkerMIOT.attachColor(miotColor);
|
||||
// 语音状态查询设置
|
||||
BlinkerMIOT.attachQuery(miotQuery);
|
||||
// 语音设置模式
|
||||
BlinkerMIOT.attachMode(miotMode);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
// 初始化串口
|
||||
Serial.begin(115200);
|
||||
// 设置主板上灯为输出模式
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
// 设置WS2812为输出模式
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
pinMode(LED_PIN_TWO, OUTPUT);
|
||||
// 设置传感器为输入模式
|
||||
pinMode(irSensor_PIN, INPUT);
|
||||
Ws2812fxInit();
|
||||
BlinkerInit();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
now = millis();
|
||||
changeUseSensor();
|
||||
ws2812fx.service();
|
||||
ws2812two.service();
|
||||
Blinker.run();
|
||||
changeRandomTheme();
|
||||
}
|
||||
BIN
code/xiaoai/colorDeng/colorDeng.ino.nodemcu.bin
Normal file
BIN
code/xiaoai/colorDeng/colorDeng.ino.nodemcu.bin
Normal file
Binary file not shown.
1
code/xiaoai/colorDeng/config/.pydio
Normal file
1
code/xiaoai/colorDeng/config/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
6da0aaa1-d398-4798-953f-93aca4d4fe14
|
||||
6
code/xiaoai/colorDeng/config/config.cpp
Normal file
6
code/xiaoai/colorDeng/config/config.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "config.h"
|
||||
|
||||
// 亮度:将 0 ~ 255 的数值转换为 0 ~ 100 亮度
|
||||
int config::BrightTransformation(int Bright) {
|
||||
return 100 * Bright / 255;
|
||||
}
|
||||
36
code/xiaoai/colorDeng/config/config.h
Normal file
36
code/xiaoai/colorDeng/config/config.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
//【据自己情况修改】Blinker 的秘钥
|
||||
char auth[] = "21c311b88cbb";
|
||||
// 自己家中的 2.4G wifi名称
|
||||
char ssid[] = "bmy";
|
||||
// 自己家中的 2.4G wifi密码
|
||||
char pswd[] = "lb714500";
|
||||
|
||||
//【据自己情况修改】GPIO 引脚编号
|
||||
#define LED_PIN 0
|
||||
//【据自己情况修改】灯珠个数
|
||||
#define LED_COUNT 30
|
||||
|
||||
// 彩光模式间隔切换时间
|
||||
#define TIMER_MS 5000
|
||||
|
||||
// 初始化灯的颜色
|
||||
#define DEFAULT_COLOR 0xFFFFFF
|
||||
// 初始化亮度
|
||||
#define DEFAULT_BRIGHTNESS 127
|
||||
// 初始化速度
|
||||
#define DEFAULT_SPEED 1000
|
||||
// 初始化灯的模式
|
||||
#define DEFAULT_MODE FX_MODE_STATIC
|
||||
|
||||
|
||||
class config {
|
||||
public:
|
||||
int
|
||||
BrightTransformation(int);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
1
code/xiaoai/data/.pydio
Normal file
1
code/xiaoai/data/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
326aee6f-0523-4f02-ac13-2c2d5a55f49d
|
||||
1
code/xiaoai/data/img/.pydio
Normal file
1
code/xiaoai/data/img/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
450847a1-2060-4e25-97b4-07feb99b1562
|
||||
BIN
code/xiaoai/data/img/taichi-maker.jpg
Executable file
BIN
code/xiaoai/data/img/taichi-maker.jpg
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 33 KiB |
62
code/xiaoai/data/index.html
Executable file
62
code/xiaoai/data/index.html
Executable file
@@ -0,0 +1,62 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>太极创客-零基础入门学用物联网教程</title>
|
||||
<script src="jquery.min.js"></script>
|
||||
<script src="knob.js"></script>
|
||||
|
||||
<script>
|
||||
$(".dial").trigger("configure", {
|
||||
min: 0,
|
||||
max: 255,
|
||||
width: 150,
|
||||
fgColor: "#ffec03",
|
||||
skin: "tron",
|
||||
thickness: 0.2,
|
||||
displayPrevious: true,
|
||||
cursor: true,
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<center>
|
||||
<a href="http://www.taichi-maker.com" target="_blank"
|
||||
><img src="/img/taichi-maker.jpg" alt="太极创客"
|
||||
/></a>
|
||||
<h1>以下旋钮可控制ESP8266开发板LED亮度</h1>
|
||||
<input
|
||||
type="text"
|
||||
class="dial"
|
||||
data-displayPrevious="true"
|
||||
data-fgColor="#00A8A9"
|
||||
data-thickness=".3"
|
||||
value="29"
|
||||
/>
|
||||
|
||||
<script>
|
||||
$(".dial").knob({
|
||||
change: function (v) {
|
||||
console.log(Math.round(v, 0));
|
||||
$.ajax({
|
||||
url: "/setLED?pwm=" + Math.round(v, 0),
|
||||
success: function (result) {
|
||||
$("#div1").html(result);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
</script>
|
||||
<p style="text-align: center">
|
||||
此页面用于演示如何通过网页控制ESP8266引脚的PWM数值。
|
||||
本教程可在太极创客网站免费获取。
|
||||
</p>
|
||||
<p style="text-align: center">
|
||||
太极创客网址:
|
||||
<a href="http://www.taichi-maker.com" target="_blank"
|
||||
>www.taichi-maker.com</a
|
||||
>
|
||||
</p>
|
||||
</center>
|
||||
</body>
|
||||
</html>
|
||||
2
code/xiaoai/data/jquery.min.js
vendored
Executable file
2
code/xiaoai/data/jquery.min.js
vendored
Executable file
File diff suppressed because one or more lines are too long
805
code/xiaoai/data/knob.js
Executable file
805
code/xiaoai/data/knob.js
Executable file
@@ -0,0 +1,805 @@
|
||||
/*!jQuery Knob*/
|
||||
/**
|
||||
* Downward compatible, touchable dial
|
||||
*
|
||||
* Version: 1.2.12
|
||||
* Requires: jQuery v1.7+
|
||||
*
|
||||
* Copyright (c) 2012 Anthony Terrien
|
||||
* Under MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*
|
||||
* Thanks to vor, eskimoblood, spiffistan, FabrizioC
|
||||
*/
|
||||
(function (factory) {
|
||||
if (typeof exports === 'object') {
|
||||
// CommonJS
|
||||
module.exports = factory(require('jquery'));
|
||||
} else if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['jquery'], factory);
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(jQuery);
|
||||
}
|
||||
}(function ($) {
|
||||
|
||||
/**
|
||||
* Kontrol library
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Definition of globals and core
|
||||
*/
|
||||
var k = {}, // kontrol
|
||||
max = Math.max,
|
||||
min = Math.min;
|
||||
|
||||
k.c = {};
|
||||
k.c.d = $(document);
|
||||
k.c.t = function (e) {
|
||||
return e.originalEvent.touches.length - 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Kontrol Object
|
||||
*
|
||||
* Definition of an abstract UI control
|
||||
*
|
||||
* Each concrete component must call this one.
|
||||
* <code>
|
||||
* k.o.call(this);
|
||||
* </code>
|
||||
*/
|
||||
k.o = function () {
|
||||
var s = this;
|
||||
|
||||
this.o = null; // array of options
|
||||
this.$ = null; // jQuery wrapped element
|
||||
this.i = null; // mixed HTMLInputElement or array of HTMLInputElement
|
||||
this.g = null; // deprecated 2D graphics context for 'pre-rendering'
|
||||
this.v = null; // value ; mixed array or integer
|
||||
this.cv = null; // change value ; not commited value
|
||||
this.x = 0; // canvas x position
|
||||
this.y = 0; // canvas y position
|
||||
this.w = 0; // canvas width
|
||||
this.h = 0; // canvas height
|
||||
this.$c = null; // jQuery canvas element
|
||||
this.c = null; // rendered canvas context
|
||||
this.t = 0; // touches index
|
||||
this.isInit = false;
|
||||
this.fgColor = null; // main color
|
||||
this.pColor = null; // previous color
|
||||
this.dH = null; // draw hook
|
||||
this.cH = null; // change hook
|
||||
this.eH = null; // cancel hook
|
||||
this.rH = null; // release hook
|
||||
this.scale = 1; // scale factor
|
||||
this.relative = false;
|
||||
this.relativeWidth = false;
|
||||
this.relativeHeight = false;
|
||||
this.$div = null; // component div
|
||||
|
||||
this.run = function () {
|
||||
var cf = function (e, conf) {
|
||||
var k;
|
||||
for (k in conf) {
|
||||
s.o[k] = conf[k];
|
||||
}
|
||||
s._carve().init();
|
||||
s._configure()
|
||||
._draw();
|
||||
};
|
||||
|
||||
if (this.$.data('kontroled')) return;
|
||||
this.$.data('kontroled', true);
|
||||
|
||||
this.extend();
|
||||
this.o = $.extend({
|
||||
// Config
|
||||
min: this.$.data('min') !== undefined ? this.$.data('min') : 0,
|
||||
max: this.$.data('max') !== undefined ? this.$.data('max') : 255,
|
||||
stopper: true,
|
||||
readOnly: this.$.data('readonly') || (this.$.attr('readonly') === 'readonly'),
|
||||
|
||||
// UI
|
||||
cursor: this.$.data('cursor') === true && 30
|
||||
|| this.$.data('cursor') || 0,
|
||||
thickness: this.$.data('thickness')
|
||||
&& Math.max(Math.min(this.$.data('thickness'), 1), 0.01)
|
||||
|| 0.35,
|
||||
lineCap: this.$.data('linecap') || 'butt',
|
||||
width: this.$.data('width') || 200,
|
||||
height: this.$.data('height') || 200,
|
||||
displayInput: this.$.data('displayinput') == null || this.$.data('displayinput'),
|
||||
displayPrevious: this.$.data('displayprevious'),
|
||||
fgColor: this.$.data('fgcolor') || '#87CEEB',
|
||||
inputColor: this.$.data('inputcolor'),
|
||||
font: this.$.data('font') || 'Arial',
|
||||
fontWeight: this.$.data('font-weight') || 'bold',
|
||||
inline: false,
|
||||
step: this.$.data('step') || 1,
|
||||
rotation: this.$.data('rotation'),
|
||||
|
||||
// Hooks
|
||||
draw: null, // function () {}
|
||||
change: null, // function (value) {}
|
||||
cancel: null, // function () {}
|
||||
release: null, // function (value) {}
|
||||
|
||||
// Output formatting, allows to add unit: %, ms ...
|
||||
format: function(v) {
|
||||
return v;
|
||||
},
|
||||
parse: function (v) {
|
||||
return parseFloat(v);
|
||||
}
|
||||
}, this.o
|
||||
);
|
||||
|
||||
// finalize options
|
||||
this.o.flip = this.o.rotation === 'anticlockwise' || this.o.rotation === 'acw';
|
||||
if (!this.o.inputColor) {
|
||||
this.o.inputColor = this.o.fgColor;
|
||||
}
|
||||
|
||||
// routing value
|
||||
if (this.$.is('fieldset')) {
|
||||
|
||||
// fieldset = array of integer
|
||||
this.v = {};
|
||||
this.i = this.$.find('input');
|
||||
this.i.each(function(k) {
|
||||
var $this = $(this);
|
||||
s.i[k] = $this;
|
||||
s.v[k] = s.o.parse($this.val());
|
||||
|
||||
$this.bind(
|
||||
'change blur',
|
||||
function () {
|
||||
var val = {};
|
||||
val[k] = $this.val();
|
||||
s.val(s._validate(val));
|
||||
}
|
||||
);
|
||||
});
|
||||
this.$.find('legend').remove();
|
||||
} else {
|
||||
|
||||
// input = integer
|
||||
this.i = this.$;
|
||||
this.v = this.o.parse(this.$.val());
|
||||
this.v === '' && (this.v = this.o.min);
|
||||
this.$.bind(
|
||||
'change blur',
|
||||
function () {
|
||||
s.val(s._validate(s.o.parse(s.$.val())));
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
!this.o.displayInput && this.$.hide();
|
||||
|
||||
// adds needed DOM elements (canvas, div)
|
||||
this.$c = $(document.createElement('canvas')).attr({
|
||||
width: this.o.width,
|
||||
height: this.o.height
|
||||
});
|
||||
|
||||
// wraps all elements in a div
|
||||
// add to DOM before Canvas init is triggered
|
||||
this.$div = $('<div style="'
|
||||
+ (this.o.inline ? 'display:inline;' : '')
|
||||
+ 'width:' + this.o.width + 'px;height:' + this.o.height + 'px;'
|
||||
+ '"></div>');
|
||||
|
||||
this.$.wrap(this.$div).before(this.$c);
|
||||
this.$div = this.$.parent();
|
||||
|
||||
if (typeof G_vmlCanvasManager !== 'undefined') {
|
||||
G_vmlCanvasManager.initElement(this.$c[0]);
|
||||
}
|
||||
|
||||
this.c = this.$c[0].getContext ? this.$c[0].getContext('2d') : null;
|
||||
|
||||
if (!this.c) {
|
||||
throw {
|
||||
name: "CanvasNotSupportedException",
|
||||
message: "Canvas not supported. Please use excanvas on IE8.0.",
|
||||
toString: function(){return this.name + ": " + this.message}
|
||||
}
|
||||
}
|
||||
|
||||
// hdpi support
|
||||
this.scale = (window.devicePixelRatio || 1) / (
|
||||
this.c.webkitBackingStorePixelRatio ||
|
||||
this.c.mozBackingStorePixelRatio ||
|
||||
this.c.msBackingStorePixelRatio ||
|
||||
this.c.oBackingStorePixelRatio ||
|
||||
this.c.backingStorePixelRatio || 1
|
||||
);
|
||||
|
||||
// detects relative width / height
|
||||
this.relativeWidth = this.o.width % 1 !== 0
|
||||
&& this.o.width.indexOf('%');
|
||||
this.relativeHeight = this.o.height % 1 !== 0
|
||||
&& this.o.height.indexOf('%');
|
||||
this.relative = this.relativeWidth || this.relativeHeight;
|
||||
|
||||
// computes size and carves the component
|
||||
this._carve();
|
||||
|
||||
// prepares props for transaction
|
||||
if (this.v instanceof Object) {
|
||||
this.cv = {};
|
||||
this.copy(this.v, this.cv);
|
||||
} else {
|
||||
this.cv = this.v;
|
||||
}
|
||||
|
||||
// binds configure event
|
||||
this.$
|
||||
.bind("configure", cf)
|
||||
.parent()
|
||||
.bind("configure", cf);
|
||||
|
||||
// finalize init
|
||||
this._listen()
|
||||
._configure()
|
||||
._xy()
|
||||
.init();
|
||||
|
||||
this.isInit = true;
|
||||
|
||||
this.$.val(this.o.format(this.v));
|
||||
this._draw();
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
this._carve = function() {
|
||||
if (this.relative) {
|
||||
var w = this.relativeWidth ?
|
||||
this.$div.parent().width() *
|
||||
parseInt(this.o.width) / 100
|
||||
: this.$div.parent().width(),
|
||||
h = this.relativeHeight ?
|
||||
this.$div.parent().height() *
|
||||
parseInt(this.o.height) / 100
|
||||
: this.$div.parent().height();
|
||||
|
||||
// apply relative
|
||||
this.w = this.h = Math.min(w, h);
|
||||
} else {
|
||||
this.w = this.o.width;
|
||||
this.h = this.o.height;
|
||||
}
|
||||
|
||||
// finalize div
|
||||
this.$div.css({
|
||||
'width': this.w + 'px',
|
||||
'height': this.h + 'px'
|
||||
});
|
||||
|
||||
// finalize canvas with computed width
|
||||
this.$c.attr({
|
||||
width: this.w,
|
||||
height: this.h
|
||||
});
|
||||
|
||||
// scaling
|
||||
if (this.scale !== 1) {
|
||||
this.$c[0].width = this.$c[0].width * this.scale;
|
||||
this.$c[0].height = this.$c[0].height * this.scale;
|
||||
this.$c.width(this.w);
|
||||
this.$c.height(this.h);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
this._draw = function () {
|
||||
|
||||
// canvas pre-rendering
|
||||
var d = true;
|
||||
|
||||
s.g = s.c;
|
||||
|
||||
s.clear();
|
||||
|
||||
s.dH && (d = s.dH());
|
||||
|
||||
d !== false && s.draw();
|
||||
};
|
||||
|
||||
this._touch = function (e) {
|
||||
var touchMove = function (e) {
|
||||
var v = s.xy2val(
|
||||
e.originalEvent.touches[s.t].pageX,
|
||||
e.originalEvent.touches[s.t].pageY
|
||||
);
|
||||
|
||||
if (v == s.cv) return;
|
||||
|
||||
if (s.cH && s.cH(v) === false) return;
|
||||
|
||||
s.change(s._validate(v));
|
||||
s._draw();
|
||||
};
|
||||
|
||||
// get touches index
|
||||
this.t = k.c.t(e);
|
||||
|
||||
// First touch
|
||||
touchMove(e);
|
||||
|
||||
// Touch events listeners
|
||||
k.c.d
|
||||
.bind("touchmove.k", touchMove)
|
||||
.bind(
|
||||
"touchend.k",
|
||||
function () {
|
||||
k.c.d.unbind('touchmove.k touchend.k');
|
||||
s.val(s.cv);
|
||||
}
|
||||
);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
this._mouse = function (e) {
|
||||
var mouseMove = function (e) {
|
||||
var v = s.xy2val(e.pageX, e.pageY);
|
||||
|
||||
if (v == s.cv) return;
|
||||
|
||||
if (s.cH && (s.cH(v) === false)) return;
|
||||
|
||||
s.change(s._validate(v));
|
||||
s._draw();
|
||||
};
|
||||
|
||||
// First click
|
||||
mouseMove(e);
|
||||
|
||||
// Mouse events listeners
|
||||
k.c.d
|
||||
.bind("mousemove.k", mouseMove)
|
||||
.bind(
|
||||
// Escape key cancel current change
|
||||
"keyup.k",
|
||||
function (e) {
|
||||
if (e.keyCode === 27) {
|
||||
k.c.d.unbind("mouseup.k mousemove.k keyup.k");
|
||||
|
||||
if (s.eH && s.eH() === false)
|
||||
return;
|
||||
|
||||
s.cancel();
|
||||
}
|
||||
}
|
||||
)
|
||||
.bind(
|
||||
"mouseup.k",
|
||||
function (e) {
|
||||
k.c.d.unbind('mousemove.k mouseup.k keyup.k');
|
||||
s.val(s.cv);
|
||||
}
|
||||
);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
this._xy = function () {
|
||||
var o = this.$c.offset();
|
||||
this.x = o.left;
|
||||
this.y = o.top;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
this._listen = function () {
|
||||
if (!this.o.readOnly) {
|
||||
this.$c
|
||||
.bind(
|
||||
"mousedown",
|
||||
function (e) {
|
||||
e.preventDefault();
|
||||
s._xy()._mouse(e);
|
||||
}
|
||||
)
|
||||
.bind(
|
||||
"touchstart",
|
||||
function (e) {
|
||||
e.preventDefault();
|
||||
s._xy()._touch(e);
|
||||
}
|
||||
);
|
||||
|
||||
this.listen();
|
||||
} else {
|
||||
this.$.attr('readonly', 'readonly');
|
||||
}
|
||||
|
||||
if (this.relative) {
|
||||
$(window).resize(function() {
|
||||
s._carve().init();
|
||||
s._draw();
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
this._configure = function () {
|
||||
|
||||
// Hooks
|
||||
if (this.o.draw) this.dH = this.o.draw;
|
||||
if (this.o.change) this.cH = this.o.change;
|
||||
if (this.o.cancel) this.eH = this.o.cancel;
|
||||
if (this.o.release) this.rH = this.o.release;
|
||||
|
||||
if (this.o.displayPrevious) {
|
||||
this.pColor = this.h2rgba(this.o.fgColor, "0.4");
|
||||
this.fgColor = this.h2rgba(this.o.fgColor, "0.6");
|
||||
} else {
|
||||
this.fgColor = this.o.fgColor;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
this._clear = function () {
|
||||
this.$c[0].width = this.$c[0].width;
|
||||
};
|
||||
|
||||
this._validate = function (v) {
|
||||
var val = (~~ (((v < 0) ? -0.5 : 0.5) + (v/this.o.step))) * this.o.step;
|
||||
return Math.round(val * 100) / 100;
|
||||
};
|
||||
|
||||
// Abstract methods
|
||||
this.listen = function () {}; // on start, one time
|
||||
this.extend = function () {}; // each time configure triggered
|
||||
this.init = function () {}; // each time configure triggered
|
||||
this.change = function (v) {}; // on change
|
||||
this.val = function (v) {}; // on release
|
||||
this.xy2val = function (x, y) {}; //
|
||||
this.draw = function () {}; // on change / on release
|
||||
this.clear = function () { this._clear(); };
|
||||
|
||||
// Utils
|
||||
this.h2rgba = function (h, a) {
|
||||
var rgb;
|
||||
h = h.substring(1,7);
|
||||
rgb = [
|
||||
parseInt(h.substring(0,2), 16),
|
||||
parseInt(h.substring(2,4), 16),
|
||||
parseInt(h.substring(4,6), 16)
|
||||
];
|
||||
|
||||
return "rgba(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "," + a + ")";
|
||||
};
|
||||
|
||||
this.copy = function (f, t) {
|
||||
for (var i in f) {
|
||||
t[i] = f[i];
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* k.Dial
|
||||
*/
|
||||
k.Dial = function () {
|
||||
k.o.call(this);
|
||||
|
||||
this.startAngle = null;
|
||||
this.xy = null;
|
||||
this.radius = null;
|
||||
this.lineWidth = null;
|
||||
this.cursorExt = null;
|
||||
this.w2 = null;
|
||||
this.PI2 = 2*Math.PI;
|
||||
|
||||
this.extend = function () {
|
||||
this.o = $.extend({
|
||||
bgColor: this.$.data('bgcolor') || '#EEEEEE',
|
||||
angleOffset: this.$.data('angleoffset') || 0,
|
||||
angleArc: this.$.data('anglearc') || 360,
|
||||
inline: true
|
||||
}, this.o);
|
||||
};
|
||||
|
||||
this.val = function (v, triggerRelease) {
|
||||
if (null != v) {
|
||||
|
||||
// reverse format
|
||||
v = this.o.parse(v);
|
||||
|
||||
if (triggerRelease !== false
|
||||
&& v != this.v
|
||||
&& this.rH
|
||||
&& this.rH(v) === false) { return; }
|
||||
|
||||
this.cv = this.o.stopper ? max(min(v, this.o.max), this.o.min) : v;
|
||||
this.v = this.cv;
|
||||
this.$.val(this.o.format(this.v));
|
||||
this._draw();
|
||||
} else {
|
||||
return this.v;
|
||||
}
|
||||
};
|
||||
|
||||
this.xy2val = function (x, y) {
|
||||
var a, ret;
|
||||
|
||||
a = Math.atan2(
|
||||
x - (this.x + this.w2),
|
||||
- (y - this.y - this.w2)
|
||||
) - this.angleOffset;
|
||||
|
||||
if (this.o.flip) {
|
||||
a = this.angleArc - a - this.PI2;
|
||||
}
|
||||
|
||||
if (this.angleArc != this.PI2 && (a < 0) && (a > -0.5)) {
|
||||
|
||||
// if isset angleArc option, set to min if .5 under min
|
||||
a = 0;
|
||||
} else if (a < 0) {
|
||||
a += this.PI2;
|
||||
}
|
||||
|
||||
ret = (a * (this.o.max - this.o.min) / this.angleArc) + this.o.min;
|
||||
|
||||
this.o.stopper && (ret = max(min(ret, this.o.max), this.o.min));
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
this.listen = function () {
|
||||
|
||||
// bind MouseWheel
|
||||
var s = this, mwTimerStop,
|
||||
mwTimerRelease,
|
||||
mw = function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var ori = e.originalEvent,
|
||||
deltaX = ori.detail || ori.wheelDeltaX,
|
||||
deltaY = ori.detail || ori.wheelDeltaY,
|
||||
v = s._validate(s.o.parse(s.$.val()))
|
||||
+ (
|
||||
deltaX > 0 || deltaY > 0
|
||||
? s.o.step
|
||||
: deltaX < 0 || deltaY < 0 ? -s.o.step : 0
|
||||
);
|
||||
|
||||
v = max(min(v, s.o.max), s.o.min);
|
||||
|
||||
s.val(v, false);
|
||||
|
||||
if (s.rH) {
|
||||
// Handle mousewheel stop
|
||||
clearTimeout(mwTimerStop);
|
||||
mwTimerStop = setTimeout(function () {
|
||||
s.rH(v);
|
||||
mwTimerStop = null;
|
||||
}, 100);
|
||||
|
||||
// Handle mousewheel releases
|
||||
if (!mwTimerRelease) {
|
||||
mwTimerRelease = setTimeout(function () {
|
||||
if (mwTimerStop)
|
||||
s.rH(v);
|
||||
mwTimerRelease = null;
|
||||
}, 200);
|
||||
}
|
||||
}
|
||||
},
|
||||
kval,
|
||||
to,
|
||||
m = 1,
|
||||
kv = {
|
||||
37: -s.o.step,
|
||||
38: s.o.step,
|
||||
39: s.o.step,
|
||||
40: -s.o.step
|
||||
};
|
||||
|
||||
this.$
|
||||
.bind(
|
||||
"keydown",
|
||||
function (e) {
|
||||
var kc = e.keyCode;
|
||||
|
||||
// numpad support
|
||||
if (kc >= 96 && kc <= 105) {
|
||||
kc = e.keyCode = kc - 48;
|
||||
}
|
||||
|
||||
kval = parseInt(String.fromCharCode(kc));
|
||||
|
||||
if (isNaN(kval)) {
|
||||
(kc !== 13) // enter
|
||||
&& kc !== 8 // bs
|
||||
&& kc !== 9 // tab
|
||||
&& kc !== 189 // -
|
||||
&& (kc !== 190
|
||||
|| s.$.val().match(/\./)) // . allowed once
|
||||
&& e.preventDefault();
|
||||
|
||||
// arrows
|
||||
if ($.inArray(kc,[37,38,39,40]) > -1) {
|
||||
e.preventDefault();
|
||||
|
||||
var v = s.o.parse(s.$.val()) + kv[kc] * m;
|
||||
s.o.stopper && (v = max(min(v, s.o.max), s.o.min));
|
||||
|
||||
s.change(s._validate(v));
|
||||
s._draw();
|
||||
|
||||
// long time keydown speed-up
|
||||
to = window.setTimeout(function () {
|
||||
m *= 2;
|
||||
}, 30);
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
.bind(
|
||||
"keyup",
|
||||
function (e) {
|
||||
if (isNaN(kval)) {
|
||||
if (to) {
|
||||
window.clearTimeout(to);
|
||||
to = null;
|
||||
m = 1;
|
||||
s.val(s.$.val());
|
||||
}
|
||||
} else {
|
||||
// kval postcond
|
||||
(s.$.val() > s.o.max && s.$.val(s.o.max))
|
||||
|| (s.$.val() < s.o.min && s.$.val(s.o.min));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
this.$c.bind("mousewheel DOMMouseScroll", mw);
|
||||
this.$.bind("mousewheel DOMMouseScroll", mw);
|
||||
};
|
||||
|
||||
this.init = function () {
|
||||
if (this.v < this.o.min
|
||||
|| this.v > this.o.max) { this.v = this.o.min; }
|
||||
|
||||
this.$.val(this.v);
|
||||
this.w2 = this.w / 2;
|
||||
this.cursorExt = this.o.cursor / 100;
|
||||
this.xy = this.w2 * this.scale;
|
||||
this.lineWidth = this.xy * this.o.thickness;
|
||||
this.lineCap = this.o.lineCap;
|
||||
this.radius = this.xy - this.lineWidth / 2;
|
||||
|
||||
this.o.angleOffset
|
||||
&& (this.o.angleOffset = isNaN(this.o.angleOffset) ? 0 : this.o.angleOffset);
|
||||
|
||||
this.o.angleArc
|
||||
&& (this.o.angleArc = isNaN(this.o.angleArc) ? this.PI2 : this.o.angleArc);
|
||||
|
||||
// deg to rad
|
||||
this.angleOffset = this.o.angleOffset * Math.PI / 180;
|
||||
this.angleArc = this.o.angleArc * Math.PI / 180;
|
||||
|
||||
// compute start and end angles
|
||||
this.startAngle = 1.5 * Math.PI + this.angleOffset;
|
||||
this.endAngle = 1.5 * Math.PI + this.angleOffset + this.angleArc;
|
||||
|
||||
var s = max(
|
||||
String(Math.abs(this.o.max)).length,
|
||||
String(Math.abs(this.o.min)).length,
|
||||
2
|
||||
) + 2;
|
||||
|
||||
this.o.displayInput
|
||||
&& this.i.css({
|
||||
'width' : ((this.w / 2 + 4) >> 0) + 'px',
|
||||
'height' : ((this.w / 3) >> 0) + 'px',
|
||||
'position' : 'absolute',
|
||||
'vertical-align' : 'middle',
|
||||
'margin-top' : ((this.w / 3) >> 0) + 'px',
|
||||
'margin-left' : '-' + ((this.w * 3 / 4 + 2) >> 0) + 'px',
|
||||
'border' : 0,
|
||||
'background' : 'none',
|
||||
'font' : this.o.fontWeight + ' ' + ((this.w / s) >> 0) + 'px ' + this.o.font,
|
||||
'text-align' : 'center',
|
||||
'color' : this.o.inputColor || this.o.fgColor,
|
||||
'padding' : '0px',
|
||||
'-webkit-appearance': 'none'
|
||||
}) || this.i.css({
|
||||
'width': '0px',
|
||||
'visibility': 'hidden'
|
||||
});
|
||||
};
|
||||
|
||||
this.change = function (v) {
|
||||
this.cv = v;
|
||||
this.$.val(this.o.format(v));
|
||||
};
|
||||
|
||||
this.angle = function (v) {
|
||||
return (v - this.o.min) * this.angleArc / (this.o.max - this.o.min);
|
||||
};
|
||||
|
||||
this.arc = function (v) {
|
||||
var sa, ea;
|
||||
v = this.angle(v);
|
||||
if (this.o.flip) {
|
||||
sa = this.endAngle + 0.00001;
|
||||
ea = sa - v - 0.00001;
|
||||
} else {
|
||||
sa = this.startAngle - 0.00001;
|
||||
ea = sa + v + 0.00001;
|
||||
}
|
||||
this.o.cursor
|
||||
&& (sa = ea - this.cursorExt)
|
||||
&& (ea = ea + this.cursorExt);
|
||||
|
||||
return {
|
||||
s: sa,
|
||||
e: ea,
|
||||
d: this.o.flip && !this.o.cursor
|
||||
};
|
||||
};
|
||||
|
||||
this.draw = function () {
|
||||
var c = this.g, // context
|
||||
a = this.arc(this.cv), // Arc
|
||||
pa, // Previous arc
|
||||
r = 1;
|
||||
|
||||
c.lineWidth = this.lineWidth;
|
||||
c.lineCap = this.lineCap;
|
||||
|
||||
if (this.o.bgColor !== "none") {
|
||||
c.beginPath();
|
||||
c.strokeStyle = this.o.bgColor;
|
||||
c.arc(this.xy, this.xy, this.radius, this.endAngle - 0.00001, this.startAngle + 0.00001, true);
|
||||
c.stroke();
|
||||
}
|
||||
|
||||
if (this.o.displayPrevious) {
|
||||
pa = this.arc(this.v);
|
||||
c.beginPath();
|
||||
c.strokeStyle = this.pColor;
|
||||
c.arc(this.xy, this.xy, this.radius, pa.s, pa.e, pa.d);
|
||||
c.stroke();
|
||||
r = this.cv == this.v;
|
||||
}
|
||||
|
||||
c.beginPath();
|
||||
c.strokeStyle = r ? this.o.fgColor : this.fgColor ;
|
||||
c.arc(this.xy, this.xy, this.radius, a.s, a.e, a.d);
|
||||
c.stroke();
|
||||
};
|
||||
|
||||
this.cancel = function () {
|
||||
this.val(this.v);
|
||||
};
|
||||
};
|
||||
|
||||
$.fn.dial = $.fn.knob = function (o) {
|
||||
return this.each(
|
||||
function () {
|
||||
var d = new k.Dial();
|
||||
d.o = o;
|
||||
d.$ = $(this);
|
||||
d.run();
|
||||
}
|
||||
).parent();
|
||||
};
|
||||
|
||||
}));
|
||||
151
code/xiaoai/xiaoai.ino
Normal file
151
code/xiaoai/xiaoai.ino
Normal file
@@ -0,0 +1,151 @@
|
||||
/* *****************************************************************
|
||||
*
|
||||
* Download latest Blinker library here:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
*
|
||||
* Blinker is a cross-hardware, cross-platform solution for the IoT.
|
||||
* It provides APP, device and server support,
|
||||
* and uses public cloud services for data transmission and storage.
|
||||
* It can be used in smart home, data monitoring and other fields
|
||||
* to help users build Internet of Things projects better and faster.
|
||||
*
|
||||
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
|
||||
* if use ESP8266 with Blinker.
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* Make sure installed 1.0.5 or later ESP32/Arduino package,
|
||||
* if use ESP32 with Blinker.
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* Docs: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************
|
||||
*
|
||||
* Blinker 库下载地址:
|
||||
* https://github.com/blinker-iot/blinker-library/archive/master.zip
|
||||
*
|
||||
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
|
||||
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
|
||||
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
|
||||
*
|
||||
* 如果使用 ESP8266 接入 Blinker,
|
||||
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
|
||||
* https://github.com/esp8266/Arduino/releases
|
||||
*
|
||||
* 如果使用 ESP32 接入 Blinker,
|
||||
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
|
||||
* https://github.com/espressif/arduino-esp32/releases
|
||||
*
|
||||
* 文档: https://diandeng.tech/doc
|
||||
*
|
||||
*
|
||||
* *****************************************************************/
|
||||
|
||||
#define BLINKER_PRINT Serial
|
||||
#define BLINKER_WIFI
|
||||
#define BLINKER_MIOT_LIGHT
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <Blinker.h>
|
||||
|
||||
// key 秘钥
|
||||
char auth[] = "75cb805d0c29";
|
||||
// 2.4G wifi名
|
||||
char ssid[] = "bmy";
|
||||
// 2.4G wifi密码
|
||||
char pswd[] = "lb714500";
|
||||
|
||||
// 新建组件对象
|
||||
BlinkerButton Button1("btn-abc");
|
||||
BlinkerNumber Number1("num-abc");
|
||||
|
||||
// 按下按键即会执行该函数
|
||||
void button1_callback(const String & state)
|
||||
{
|
||||
BLINKER_LOG("button 状态 ==== : ", state);
|
||||
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
||||
}
|
||||
|
||||
// 如果未绑定的组件被触发,则会执行其中内容
|
||||
void dataRead(const String & data)
|
||||
{
|
||||
BLINKER_LOG("Blinker dataRead =====: ", data);
|
||||
}
|
||||
|
||||
// 电源设置
|
||||
void miotPowerState(const String & state)
|
||||
{
|
||||
BLINKER_LOG("need set power state: ", state);
|
||||
if (state == BLINKER_CMD_ON) {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
BlinkerMIOT.powerState("off");
|
||||
// 发送数据
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
else if (state == BLINKER_CMD_OFF) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
|
||||
BlinkerMIOT.powerState("on");
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
}
|
||||
|
||||
// 自定义亮度控制
|
||||
void miotBright(const String & bright)
|
||||
{
|
||||
BLINKER_LOG("need set brightness: ", bright);
|
||||
|
||||
int ledPwmVal = bright.toInt();
|
||||
|
||||
BLINKER_LOG("now set brightness: ", ledPwmVal);
|
||||
analogWrite(LED_BUILTIN, ledPwmVal);
|
||||
BlinkerMIOT.brightness(ledPwmVal);
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
|
||||
// 色温设置
|
||||
void miotColoTemp(int32_t colorTemp)
|
||||
{
|
||||
BLINKER_LOG("need set colorTemperature: ", colorTemp);
|
||||
BlinkerMIOT.colorTemp(colorTemp);
|
||||
BlinkerMIOT.print();
|
||||
}
|
||||
|
||||
// 当日天气
|
||||
void airData(const String & data) {
|
||||
BLINKER_LOG("air: ", data);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
// 初始化串口
|
||||
Serial.begin(115200);
|
||||
|
||||
|
||||
// WiFi.softAP(wifiSsid, wifiPassword);
|
||||
|
||||
// 开启 DEBUG
|
||||
BLINKER_DEBUG.stream(Serial);
|
||||
|
||||
// 初始化有LED的IO
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
// 关闭LED
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
// 初始化blinker
|
||||
Blinker.begin(auth, ssid, pswd);
|
||||
Blinker.attachData(dataRead);
|
||||
BlinkerMIOT.attachPowerState(miotPowerState);
|
||||
BlinkerMIOT.attachBrightness(miotBright);
|
||||
Button1.attach(button1_callback);
|
||||
BlinkerMIOT.attachColorTemperature(miotColoTemp);
|
||||
Blinker.attachAir(airData);
|
||||
Blinker.air(340100);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Blinker.run();
|
||||
}
|
||||
Reference in New Issue
Block a user