mirror of
https://github.com/yanyuandi/7.5inch_Multifunctional_E-Paper.git
synced 2025-12-06 09:12:49 +08:00
Add files via upload
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
#include <GxEPD2_3C.h>
|
||||
#include <U8g2_for_Adafruit_GFX.h>
|
||||
#include <WiFiManager.h>
|
||||
#include "jpg.h"
|
||||
#include <ArduinoJson.h>
|
||||
#include <OneButton.h>
|
||||
#include <driver/adc.h>
|
||||
#include "esp_adc_cal.h"
|
||||
|
||||
#define BATTERY_PIN ADC1_CHANNEL_3 // 电池电压采样引脚
|
||||
#define R1 220000.0 // 电阻R1的阻值,单位为欧姆
|
||||
#define R2 100000.0 // 电阻R2的阻值,单位为欧姆
|
||||
#define V_MIN 3.3 // 电池电压最小值,单位为伏特
|
||||
#define V_MAX 4.2 // 电池电压最大值,单位为伏特
|
||||
|
||||
|
||||
#define NORMAL_FONT u8g2_font_wqy16_t_gb2312 //设置NORMAL_FONT默认字体
|
||||
|
||||
#define TZ 8 // 时区偏移值,以 UTC+8 为例
|
||||
#define DST_MN 0 // 夏令时持续时间(分钟)
|
||||
|
||||
#define TZ_SEC ((TZ)*3600) // 时区偏移值(秒)
|
||||
#define DST_SEC ((DST_MN)*60) // 夏令时持续时间(秒)
|
||||
|
||||
#define REFRESH_BUTTON_PIN 34
|
||||
OneButton REFRESHButton(REFRESH_BUTTON_PIN, true);
|
||||
|
||||
U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;
|
||||
|
||||
GxEPD2_3C<GxEPD2_750c_Z08, GxEPD2_750c_Z08::HEIGHT / 2> display(GxEPD2_750c_Z08(/*CS=D8*/ 4, /*DC=D3*/ 27, /*RST=D4*/ 26, /*BUSY=D2*/ 25));
|
||||
void yiyan_get();
|
||||
void refresh_all();
|
||||
void refresh_10s();
|
||||
void configModeCallback(WiFiManager *myWiFiManager) {
|
||||
Serial.println("开始配网");
|
||||
peiwang();
|
||||
}
|
||||
void REFRESHButtonClick() {
|
||||
|
||||
Serial.println("开始刷新");
|
||||
refresh_all();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
analogReadResolution(12); // 设置ADC分辨率为12位
|
||||
|
||||
SPI.end();
|
||||
SPI.begin(13, 14, 14, 4);
|
||||
|
||||
display.init(115200, true, 2, false);
|
||||
display.setRotation(0); // 0 是横向
|
||||
u8g2Fonts.begin(display);
|
||||
u8g2Fonts.setFontDirection(0);
|
||||
u8g2Fonts.setForegroundColor(GxEPD_BLACK); // 设置前景色
|
||||
u8g2Fonts.setBackgroundColor(GxEPD_WHITE); // 设置背景色
|
||||
u8g2Fonts.setFont(NORMAL_FONT);
|
||||
|
||||
// 配置ADC
|
||||
adc1_config_width(ADC_WIDTH_BIT_12); // 采样位数为12位
|
||||
adc1_config_channel_atten(BATTERY_PIN, ADC_ATTEN_DB_11); // 采样电压范围为0-3.9V
|
||||
|
||||
logo_show(); //显示正在连接wifi开机画面
|
||||
|
||||
delay(5000);
|
||||
|
||||
WiFiManager wifiManager;
|
||||
|
||||
Serial.println("连接结果:");
|
||||
Serial.println(WiFi.waitForConnectResult());
|
||||
wifiManager.setAPCallback(configModeCallback);
|
||||
wifiManager.autoConnect("桌面多功能E-paper"); //wifiManager自动配网开始
|
||||
Serial.println("连接结果2:");
|
||||
Serial.println(WiFi.waitForConnectResult());
|
||||
uint8_t i = 0;
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
i = 0;
|
||||
Serial.print("NTP");
|
||||
configTime(TZ_SEC, DST_SEC, "ntp1.aliyun.com"); // 向 NTP 服务器请求时间,使用给定的时区和夏令时参数
|
||||
while ((time(nullptr) < 1000000000) & (i < 20)) {
|
||||
i++;
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
Serial.println("时间同步成功");
|
||||
}
|
||||
REFRESHButton.attachClick(REFRESHButtonClick);
|
||||
refresh_all();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
refresh_10s();
|
||||
REFRESHButton.tick();
|
||||
time_t now = time(nullptr);
|
||||
struct tm *ltm = localtime(&now);
|
||||
if (ltm->tm_min == 0 && (ltm->tm_hour % 2 == 0) && ltm->tm_sec == 10) {
|
||||
Serial.print("开始刷新所有内容,两小时一次刷新\n");
|
||||
|
||||
refresh_all();
|
||||
delay(5000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float read_battery_voltage() {
|
||||
uint32_t adc_value = adc1_get_raw(BATTERY_PIN); // 读取ADC采样值
|
||||
float voltage = adc_value * 3.9 / 4095 * (R1 + R2) / R2; // 计算电压值
|
||||
return voltage;
|
||||
}
|
||||
|
||||
float get_battery_level(float voltage) {
|
||||
if (voltage <= V_MIN) {
|
||||
return 0; // 电量低于警戒线
|
||||
} else if (voltage >= V_MAX) {
|
||||
return 100; // 电量满格
|
||||
} else {
|
||||
return (voltage - V_MIN) / (V_MAX - V_MIN) * 100; // 电量百分比
|
||||
}
|
||||
}
|
||||
116
7.5inch_Multifunctional_E-Paper/displaymain.ino
Normal file
116
7.5inch_Multifunctional_E-Paper/displaymain.ino
Normal file
@@ -0,0 +1,116 @@
|
||||
#include "font.c"
|
||||
void text12(const char *str, int16_t x, int16_t y, uint16_t fg_color, uint16_t bg_color);
|
||||
void peiwang() {
|
||||
//display.clearScreen();
|
||||
display.setFullWindow();
|
||||
display.firstPage();
|
||||
display.fillScreen(GxEPD_WHITE);
|
||||
do {
|
||||
|
||||
u8g2Fonts.setFont(logo_24_35);
|
||||
u8g2Fonts.setForegroundColor(GxEPD_BLACK);
|
||||
int16_t ww = (u8g2Fonts.getUTF8Width("Multifunctional E-Paper Desktop"));
|
||||
u8g2Fonts.drawUTF8((800-ww)/2, 180, "Multifunctional E-Paper Desktop"); // 在透明背景上绘制文本
|
||||
|
||||
u8g2Fonts.setFont(u8g2_font_wqy12_t_gb2312);
|
||||
int16_t aa = (u8g2Fonts.getUTF8Width("WIFI连接失败"));
|
||||
int16_t bb = (u8g2Fonts.getUTF8Width("请用手机或者笔记本连接下面wifi进行配网"));
|
||||
int16_t cc = (u8g2Fonts.getUTF8Width("SSID:桌面多功能E-paper"));
|
||||
int16_t dd = (u8g2Fonts.getUTF8Width("Design by YYD"));
|
||||
int16_t ee = (u8g2Fonts.getUTF8Width("配置成功后请耐心等待,获取到天气等所有数据后进行刷新"));
|
||||
|
||||
|
||||
text12("WIFI连接失败", (800-aa)/2, 230, GxEPD_BLACK, GxEPD_WHITE);
|
||||
text12("请用手机或者笔记本连接下面wifi进行配网", (800-bb)/2, 253, GxEPD_BLACK, GxEPD_WHITE);
|
||||
text12("SSID:桌面多功能E-paper", (800-cc)/2, 275, GxEPD_BLACK, GxEPD_WHITE);
|
||||
text12("Design by YYD", (800-dd)/2, 451, GxEPD_BLACK, GxEPD_WHITE);
|
||||
text12("配置成功后请耐心等待,获取到天气等所有数据后进行刷新", (800-ee)/2, 297, GxEPD_BLACK, GxEPD_WHITE);
|
||||
|
||||
} while (display.nextPage());
|
||||
display.powerOff();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
void logo_show() {
|
||||
|
||||
display.setFullWindow();
|
||||
display.firstPage();
|
||||
display.fillScreen(GxEPD_WHITE);
|
||||
do {
|
||||
|
||||
display.drawInvertedBitmap(0, 0, logo_BW, 800, 480, GxEPD_BLACK);
|
||||
display.drawInvertedBitmap(0, 0, logo_R, 800, 480, GxEPD_RED);
|
||||
|
||||
u8g2Fonts.setFontMode(1); // 设置透明模式
|
||||
u8g2Fonts.setFont(u8g2_font_wqy12_t_gb2312);
|
||||
u8g2Fonts.setForegroundColor(GxEPD_WHITE);
|
||||
u8g2Fonts.drawUTF8(557, 462, "WIFI正在连接中......"); // 在透明背景上绘制文本
|
||||
|
||||
|
||||
|
||||
} while (display.nextPage());
|
||||
display.powerOff();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
void displaymain() {
|
||||
|
||||
|
||||
display.drawFastHLine(0, 78, 800, GxEPD_BLACK);
|
||||
display.drawFastHLine(0, 455, 800, GxEPD_BLACK);
|
||||
display.drawFastVLine(195, 24, 456, GxEPD_BLACK);
|
||||
display.drawFastVLine(586, 24, 431, GxEPD_BLACK);
|
||||
display.fillRect(0, 0, 800, 24, GxEPD_RED);
|
||||
display.fillRect(0, 456, 195, 25, GxEPD_BLACK);
|
||||
text12("桌面多功能E-Paper", 10, 7, GxEPD_WHITE, GxEPD_RED);
|
||||
display.drawBitmap(370, 3, dingmid, 80, 17, GxEPD_WHITE);
|
||||
display.drawInvertedBitmap(10, 462, weizhi, 9, 12, GxEPD_WHITE);
|
||||
text12("北京", 24, 462, GxEPD_WHITE, GxEPD_BLACK);
|
||||
|
||||
//电量部分
|
||||
float voltage = read_battery_voltage(); // 读取电池电压
|
||||
float level = get_battery_level(voltage); // 计算电量百分比
|
||||
// 使用 String 构造函数将 float 转换为 String
|
||||
String dianya = String(voltage, 2); // 保留 2 位小数
|
||||
String dianliang2 = String(level, 0); // 保留 2 位小数
|
||||
String dianliang = "电池电压:" + dianya + "V" + " " + "电量:" + dianliang2 + "%";
|
||||
const char* diandian = dianliang.c_str();
|
||||
text12(diandian, 56, 462, GxEPD_WHITE, GxEPD_BLACK);
|
||||
|
||||
display.drawInvertedBitmap(326, 34, weiboBW, 131, 34, GxEPD_BLACK);
|
||||
display.drawInvertedBitmap(326, 34, weiboR, 131, 34, GxEPD_RED);
|
||||
|
||||
display.drawInvertedBitmap(628, 34, daibanBW, 131, 34, GxEPD_BLACK);
|
||||
display.drawInvertedBitmap(628, 34, daibanR, 131, 34, GxEPD_RED);
|
||||
|
||||
display.fillRoundRect(202, 460, 31, 16, 2, GxEPD_RED);
|
||||
text12("一言", 205, 462, GxEPD_WHITE, GxEPD_RED);
|
||||
|
||||
display.drawInvertedBitmap(0, 278, yyd_bw, 161, 177, GxEPD_BLACK);
|
||||
display.drawInvertedBitmap(0, 278, yyd_r, 161, 177, GxEPD_RED);
|
||||
|
||||
display.drawInvertedBitmap(592, 8, refresh, 14, 12, GxEPD_WHITE);
|
||||
time_t now = time(nullptr);
|
||||
char timeStr[20];
|
||||
strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", localtime(&now));
|
||||
//const char* timeChar = timeStr;
|
||||
String shijian = timeStr;
|
||||
String timesst = "更新于" + shijian;
|
||||
const char* timeChar = timesst.c_str();
|
||||
text12(timeChar, 610, 8, GxEPD_WHITE, GxEPD_RED);
|
||||
|
||||
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
display.drawBitmap(781, 8, digital_ok, 16, 13, GxEPD_WHITE);
|
||||
|
||||
} else {
|
||||
display.drawBitmap(781, 8, digital_no, 16, 13, GxEPD_WHITE);
|
||||
}
|
||||
|
||||
}
|
||||
151
7.5inch_Multifunctional_E-Paper/font.c
Normal file
151
7.5inch_Multifunctional_E-Paper/font.c
Normal file
@@ -0,0 +1,151 @@
|
||||
#include <u8g2_fonts.h>
|
||||
#ifdef U8G2_USE_LARGE_FONTS
|
||||
|
||||
/*
|
||||
Fontname: -FreeType-baotuxiaobaiti-Medium-R-Normal--23-720-23-23-P-195-ISO10646-1
|
||||
Copyright: Copyright(c) ibaotu
|
||||
Glyphs: 95/7707
|
||||
BBX Build Mode: 0
|
||||
*/
|
||||
const uint8_t logo_24_35[4398] U8G2_FONT_SECTION("logo_24_35") =
|
||||
"_\0\3\2\5\6\3\6\6\34 \0\372\26\373\32\375\5S\14\34\21\21 \6\0 \230\2!\21\346"
|
||||
"\352\207f\312\376\377M\31N\331&\16C\2\42\26Ji\313\346\224U\262l\313\266l\313\266l\313&"
|
||||
"M\31\6\5#\64R\352Ws\33r$R\42\35\210\206l\270\203;eG\7e;H\332&g\233"
|
||||
"\234mrvH\206l\7t\222N\231\267A\331\66\35\30\224A\207\302!\3$=mk\367v\207\262"
|
||||
"\34\311t \23\207lHrl\307v\354p\310t \323\201l\30\242\34\333\261\35S\206!\323\201L"
|
||||
"\7\62\35\310\224a\310vl\307\346a\331t \323\201LG\6\21%h\333\352\327g\70\244:T\326"
|
||||
"\242\34\211b)\323\201h\220\244L\7\242AR\262\35\210\244H\311t$\222\242mG\262!\332t("
|
||||
"\315\246\35J\63;\30\16\333\62\14\331\240eR\254c\231\24\353P\66\15\222\16e\323 \351P\64D"
|
||||
"R\244#\231\22I\221\216DK\66D:\220Ii\246#\203\224f:\64\206\303N\33T\0&\71\357"
|
||||
"\252'gx\312A%\7\225\34\215\262A\253)Y\61\311\264lSFm\310\301\35\335\321M\33\224\354"
|
||||
"\220d\207$Sbm\210uX\7\207xS\262A\223\6-\331\301\5'\21Fi\213f\312\222,\311"
|
||||
"\336\222,\311\242!\1(-\251k\267VN\304L\312\246L\312\264Lk\323\62\255\230\205Y\230\205Y"
|
||||
"\230\205Y\230\205\231\226\211Y\230\205Y\232\205mb\262\356@\4)\61\252k\307J\7\242\64\14\65\61"
|
||||
"\24\63\65\23\63\61\23\253\231\230\211\231\230\211\231\230\211\231\230\211\231\230\205\231\230i\241\226M\241\24N"
|
||||
"\331\70\350\200\12*\37\255\261\12s\207\262q\33\242Z%\307\206\34\231\322\61\7\262j\224\331\222a\20"
|
||||
"\67\71\215\0+-Oj\30{\7\63\35\312t(\323\241L\207\62\35\312\324A\33\224\34\335\321\35U"
|
||||
"\6mX\63\35\312t(\323\241L\207\62\35\32F\0,\20\7)\227f\313\224\360\220E\221\22\35\42"
|
||||
"\0-\16\252(\312\342%\7v`\7\36\24\0.\13\246\350\207fH\262\233\62\10/\60\355\252\367\36"
|
||||
"\321\261HG\62\71\323\201L\16\345L\7\62\71\233\63\71\224\63\35\310\344l\316t \223\63\35\310\344"
|
||||
"l\316t \323\1e\207v\4\60;\357*\30\37\70\15C\234d\71\262\345\310\66l\233\226mZ\266"
|
||||
"i\331\246e\233\226mZ\266i\331\246e\233\226mZ\266i\331\246e\233\262]\264\35\311v$\222r"
|
||||
" \222\206\207\4\61\14\306*\210f\312\376\377\337\224A\62\66\355\352\367f\70D\71\266c\243e\30\62"
|
||||
"i\312t \323\201L\31\206l\316\346l\316\16\203\222\15i\246\3\231\16d:\220IS\70DI\216"
|
||||
"\355\230\62\274\15*\0\63\65\315*\370\342K\216\355\330\270)\303\220\351@\246\3\231\16d\322\260)i"
|
||||
"\246\244\231\62\14\231\16d:\220\351@\246\3\231\62\14\331\234\315\331\34)q$\15\7\5\64@\356*"
|
||||
"\10c\220\306L\211\244L\211\244L\211\244L\211\244L\211\244,\212\244,\212\244,\212\244,\212\244,"
|
||||
"\212\226lHuTG\223\34:L;\22\351P\244C\221\16E:\24\351P\244cC\4\65\65\315*"
|
||||
"\370f\70(Y\274\305[\274\15\207L\7\62\35\310t \33\206(\307\222\34\333\261\341\220\351@\246\3"
|
||||
"\231\16d:\220)\303\220\355\330\216\355\300\240\14\7\5\66\63\315*\370\342K\216\355\330\216\35\206(\323"
|
||||
"\201L\7\62\35\310\206A\311\342-\336\6i\33\244m\220\66)\332\244h\33\244\255\264\3\321\16DJ"
|
||||
"\34I\303A\67-\314*\370f\70$\71\244c:\66\34\42\35\210t \322\201H\316\344L\316\344L"
|
||||
"\316\344L\316\344L\316\344L\316\344h\216tdH\0\70\65\316*\30\347\60(Y\16l\71\260\15\323"
|
||||
"\246E\233\26mZ\264\15\323\16\356\340\16n\303\264\15\332&e\233\224mRv\320\266\332\16d;\20"
|
||||
"Iq\244\15\7\5\71\64\355*\370z\310\206Q\311\342$\213\267!\333J[i+m\245m\220v "
|
||||
"\332\201h\226\224a\220t$\322\221HG\42\35\310\206\343\216\355\330\216\14\311\360\0:\21\206\352\207f"
|
||||
"H\262\233\62\350\374u\312n\312 ;\31\307*\227f\210\62%S\62i\320\371\247-S\302C\26E"
|
||||
"Jt\210\0<\42\316\251\10\37\323\241)\36\65\35\30td\310\201A\11\207-]sD\324\21qV"
|
||||
"G\35\31vl\1=\30Li\351f\70$\71\264C;\244\14\207hx\207vh\207\224\341 >!"
|
||||
"\316\351\10G\7\243\35I\345\34\30u$\235\325Q\233\25\35\31rdX\207)\33\344a\207t\14\77"
|
||||
":\356\352\7k\30R\35\320rH\312\61)\31Di\210\62\35\311t$\323\221L\7\262\71\324\201l"
|
||||
"\316v \323\221hG\42\35Rtl\310\241!\207\62\35\311t$\323\241A\4@Q\30+\250w\370"
|
||||
"e\320i;\303\316\260\15\337\16\203\252mZ\16h\233\226\3\332\246\325\264M\33\64m\63e\332f\312"
|
||||
"\264\315\224i\233)\323\66m\20\263M\7r`\310t \7\206,I\207lH\262h\370\220d\303\247"
|
||||
":Y\311\311RN\325\206\277\0AE\362\352G\37\330\11\231\216f:\230\346`\252cQ\244CY\35"
|
||||
"\312\62\35\211&\35\310\266\34H\63\71\315\324\34\310\322l\320\304hH\62-\23\263\232\230I\231\230)"
|
||||
"\231\234%\231\234mr\264\14:\60H;\264\0BA\357\42\10K\7\245\341\224\305R\26K\331 I"
|
||||
"\331 I\231\42I\231\42I\231\24I\331 IY\216\324rd\313\221m\30\242M\214\66\61\332\304h"
|
||||
"\33\266\35\311v$\333\221,\311\221,\32\36\22\0C\71\317\42\10gxH\262\34\331rd\313\221m"
|
||||
"\70$\231\16e:\224\351P\246C\231\16e:\224\351P\246C\231\16e:\224\351P&G\331\60("
|
||||
";\252\344\240\64<d\303\15D<\320\42\30\347\60hu@\312rD\311r(\311\206!\273e\233\230"
|
||||
"mb\266\211\331&f\233\230mb\266\211\331&f\233\230mZ\270i\331\220\15\233\222\345\210\222\345\300"
|
||||
"\222\305\333\360\6E\70\316*\10g\70H\71\270\203\363\260d\303%\323\221LG\62\35\311\206!\253J"
|
||||
"Y*e\321 e\303 e:\222\351H\246#\231\64D\331\20&\71\230\344\340\16\35\216\0F\66\315"
|
||||
"b\350\342K\16\352\240\66h\332p\310t \323\201L\7\262dX\262T\311R%K\225l\30\224L"
|
||||
"\7\62\35\310t \323\201L\7\62\35\310t \323\221A\7G\66\317\42\10gx\312A%\7\225l"
|
||||
"\70e:\224\351P\246C\231\16e\312\60e\363\66o\363\246l\233\226mZ\266i\331a\333\221lG"
|
||||
"\262\35\311\224t\30\244a\7H\67\317\42\10g\236\62-\333\264l\323\262M\313\66-\333\264l\323\262"
|
||||
"\303\266#\331\216d;\222\35\266M\313\66-\333\264l\323\262M\313\66-\333\264l\323\62eH\207\4"
|
||||
"I\14\306\42xf\312\376\377\337\224AJ)\313\42\270z\7\62\65S\63\65S\63\65S\63\65S\63"
|
||||
"\65S\63\65S\63\65S\63%\313\226!\333\221\35\31Ti\270\0K:\317\342\7g\326\62\61Q\62"
|
||||
"-\333\244l\310\244l\310\224l\311F);e\242\26f[\232\214\361\232\3q\216\244Y(f\242\226"
|
||||
"\215R\246\204J&\205\233\226mbr\210\27\0L\70\315*\350f\310\221L\7\62\35\310t \323\201"
|
||||
"L\7\62\35\310t \323\201L\7\62\35\310t \323\201L\7\62\35\310t \223\246l\310\222\34\333"
|
||||
"\261\35\31\222\341\240\0MC\322\42\70g\310\201A\311\344lT\263Q\14\327\60\134\265p\216\322Y\211"
|
||||
"\242-\323\242-\323\242M\62m\262\264\311\322\66N\333\70mJ\66mJ\244D\233\224(\321\246-\321"
|
||||
"\246\3\321\35\30\224!\307\24\0N\66\320\42\30g\7\246L\314\306\332\250ek\226\255R\66G\331\254"
|
||||
"d;\220d[v\263m\266[v\313\66%\336\224x\223\322MJ\67-\334\264p\23\63e\210\207\4"
|
||||
"O<\357\42\10\37\70\15C\274\345\310\226#\333\60D\233\30mb\264\211\321&F\233\30mb\264\211"
|
||||
"\321&F\233\30mb\264\211\321&F\233\30m\311 \355P\264C\355H\24\15\17\11\0P:\317\42"
|
||||
"\370\346\60HY\16(Y\216\324\206\355\260mZ\266i\331\246e\353\220\355H\266#Y\222\15\207$S"
|
||||
"\245L\207\62\35\312t(\323\241L\207\62\35\312t(\323\261!\307\0Q@/c\7\37\70\15C\234"
|
||||
"d\71\262\345\310\66l\233\226mZ\266i\331\246e\233\226mZ\266i\331\246e\233\226mZ\266i\331"
|
||||
"!\311\266L\333rd\7\207\34\224lC\66LC\216D;\66d\0R<\317\42\10\347\60HY\16"
|
||||
"(Y\216\324\206\355\260mZ\266i\331\246e\353\220\355H\266#Y\222\15\223\222I\303\222ii&\326"
|
||||
"\306,S\62)S\64%\223\302M\213\226A\33\264Y\2S\65\315\42\350f\70(\71\266c\207C\246"
|
||||
"\3\231\16d:\220\351@\66\14Q\216\355\330\216)\303\220\351@\246\3\231\16d:\220)\303\220\355\330"
|
||||
"\216\355\310\220\14\7\5T\66\320\42\10gxPrx\207\207_\206I\307\62\35\313t,\323\261L\307"
|
||||
"\62\35\313t,\323\261L\307\62\35\313t,\323\261L\307\62\35\313t,\323\261L\7\7\25U\70\317"
|
||||
"\42\10gH\247L\313\66-\333\264l\323\262M\313\66-\333\264l\323\262M\313\66-\333\264l\323\262"
|
||||
"M\313\66-\333\264lS\266C\222\355H\266#\231\242\15\247\341\5VD\323\42\70k\310\201\61\322\201"
|
||||
"H\11\343P\311\324l\311\324L\12\323L\313\264l\313\264L\254ej\246dk\246dr\230d:\220"
|
||||
"%\221\216dv(\322t(\213t,\326\301T\7C\35\15u\70\323\11C\16W]\332b\250g\20"
|
||||
"\7u\210\302Z\232%aM\13\225,\314\264L\312\244P\313\244LJ\263L+\245Q&fQ\252d"
|
||||
"b\246D\221\222\211\331\26)\231\232i\231\71\223\64s&i\346,\233\354H\224M\231\216\304\263\216\244"
|
||||
"J\254#\251\222\352X(\205:\26J\241\216eZ\246\243\203\70\310\0XB\361j\70+\207B%\7"
|
||||
"\22)K\63%\23\63E\223B)\214\62\61\273f\241\234\3;\20\353P\250c\241\16\305\71\24\353@"
|
||||
"\26\252\241\230fC\230\205J(eZ\70\212\231\22\311\311A\36B\35\221\0Y:\320\342\27g\210\207"
|
||||
"$\23\263Q\313\224\60\12\245L\311\264\320X\223\243P\216\62\35\21u(\323\261L\307\62\35\313t,"
|
||||
"\323\261L\307\62\35\313t,\323\261L\307\62\35\33F\0Z<\320\42\10\343C\226C\221\222#a\222"
|
||||
"#\331\62\14\242\16e;\22\352H\250C\331\216\204:\224\351P\266#\241\16e;\22\352H\250C\331"
|
||||
"\216\204\303)G\225\34UrT\32\36\24\0[\67\352\353\306f\30\224,\333\262-;(\231\230\211\231"
|
||||
"\230\211\231\230\211\231\230\211\231\230\211\231\230\211\231\230\211\231\230\211\231\230\211\231\230\211\331\20\345\300\16\354"
|
||||
"\200\62\234\6\15\134\70\355\352\367J\207\244\34\311t$\313\221L\7\62\35\311r$\323\221,G\62\35"
|
||||
"\310t$\313\221LG\262\34\311t \323\221,G\62\35\311r$\323\201LG\6\35\222\0]\67\352"
|
||||
"\353\306\342 e\225,\333\62e\310\304L\314\304L\314\304L\314\304L\314\304L\314\304L\314\304L\314"
|
||||
"\304L\314\304L\314\304L\314\224!\333\201\35\330\1e\270j\0^\37\216\351\12[\7\207\34\12s$"
|
||||
"\224\253\71 fa\226\215I\250dJ\264D\207l\10U\11_\17\260\350&gx\210rx\207wX"
|
||||
"\31>`\21\7\261\254*T\244,\312\224\60\312\224\350\220\0a\61\360!\30\347\60\204Y\16HY\16"
|
||||
"HY\16H\331\240I\331\240I\231\224I\231\224I\231\224I\231\242I\331\222&\71\220\356@\252\204\303"
|
||||
"!\32t\10b\67\355\342\347f\207\62\35\310t \323\201L\7\62\35\310t \323\201l\30\224,\336"
|
||||
"\342m\220\266A\332\244h\223\242M\311\66%;d\207l\316\346L\11\207!\32d\0c \354\341\327"
|
||||
"f\70e\351\226n\351\66\334\344L\316\344L\316\344l\270C;\244\304C\64\14\31\0d\64\355\342\347"
|
||||
"\36\331!;\220\351@\246\3\231\16d:\220\351@\246\334\266x\213\267x\33\262M\212\66)\332\244h"
|
||||
"\223\242m\220fi\7\242\35\210\224t\230\206\25e)\356\341\347\346\60DY\16l\71\260)\332A;"
|
||||
"hS\216L\71\60d\303%\33\306l\30\244\34SrL\322\206!\34\206\20f\61\314b\330n\30\304"
|
||||
"X\213\245l\230\262a\312\344L\316\304m\313\21%G$u\223\6\61\322\201H\7\42\35\210t \322"
|
||||
"\201H\7\42\35\30th\4g\63n\342\366f\32\206$\223\267\34\330r`\33\246-\214\266\60\332\206"
|
||||
"iG\242\35\211\224\34\210\244a\220t(\322\241H\32\6I\311\61%\307\224\34\223\206\7h:\316\42"
|
||||
"\350f\307\62\35\311t$\323\221LG\62\35\311t$\323\221l\30\244,\7\266\34\330\42\355\240mR"
|
||||
"\266I\331&e\233\224mR\266I\221\222I\221\222I\221\64hC\2i\23\306\42xbP\262M\31"
|
||||
"t\306!\311\376\337\224!\1j\60\213\243\266v\310\201L\315\324L\36r^w S\63\65S\63\65"
|
||||
"S\63\65S\63\65S\63\65S\63\65S\262l\31\262\35\331\221A]\206\13\0k;\356\342\347f\307"
|
||||
"\62\35\311t$\323\221LG\62\35\311t$\323\221LG\62I\314\224H\312F%\23\227\34\231rD"
|
||||
"\313\201-G\302,\315\62U\311\206p\223\262MK\244!]\0l\14\306\42xf\312\376\377\337\224A"
|
||||
"m\67\323!Hg\70$\203\224\245\352\226\306[\32oC\64d\233\22\15\331\246DJ\266)\221\222m"
|
||||
"J\244d\233\22)\331\246DJ\266)\221\222mJ\244d\312\220\15\321 n%\315!\350f\70(Y"
|
||||
"\274\305[\274\15\331\246d\233\222mJ\266)\331\246d\233\222mJ\266)\231\62d\203\0o%\355\341"
|
||||
"\347f\70(Y\274\305[\274\15\322\66H\233\24mJ\266)\331\246d\207l\316\346L\11\207!\32d"
|
||||
"\0p\65\217\242\366\346\60HY\16(Y\216\324\206\355\260mZ\266i\331\246e\353\220\355H\266#Y"
|
||||
"\222\15\207$S\245L\207\62\35\312t(\323\241L\207\62\35\33t\10q\61\215\242\346j\270\305\321\16"
|
||||
"D;\20m\203\264I\321&E\233\24m\203\264\305[\274\305\312\60H:\22\351H\244#\221\216D:"
|
||||
"\22\351H\244CC\0r\36\353\341\307JG\22i\311\246\35\322\221u\330\6)S\63\65S\63\65S"
|
||||
"\63\65\223\207\30s$\354\341\327f\70D\71R\207\222l\30\222,\7\262a\312\241$\207\206\233\234\15"
|
||||
"\267\35\332\241\35\230\206C\2t.\354\342\327j\320\201L\316\344L\316\344L\316\344\354\234\203:\246l"
|
||||
"\203\226\311\231\234\311\231\234\311\331\20\346\200\224\3R\16H\303!\34\206\4u\60\360\341\7g\33\322L"
|
||||
"\311\264L\311\264L\311\264L\311\264H\312\264H\312\264H\312\264H\312\264l\310\264\34UrT\311\321"
|
||||
"%T\247A\31\64\0v%\316)\370f\310\206(+)\231\22\216I\266dI&e\242\224\31\263L"
|
||||
"\314\1\61\226S\71\225C\35\31F\0w\60\325)hK\34\302I\252I\221\222)a\224mJ\250d"
|
||||
"J\66nK&kR&kZ)\313\266\330\30[Su\15\225P\16\225P\7N\203\10x%\316i"
|
||||
"\10g\310\206(S\62%\334\226\60\333r@M\347P\256\346\200\26\206R\66\216J\246DZ\62\255\22"
|
||||
"\0y\65\215\242\346f\34\222L\311\66%\333\224lS\262M\311\66%\333\24i\33\244\35\210v R"
|
||||
"\342H\32\206H\314\42\35\220\224aTrH\311!%\36\262\341\220\0z#\356\341\367f\70h\71\20"
|
||||
"\225\303$-\15\252\232\252\251\232\252\251\232\216\351\60$\71\270\203J\216I\303\3{\65\13\244\266ZG"
|
||||
"\42\65LC-\324\302-\33\63\65S\63\65S\63\65S\63\243\26\212\241\252\305\231\232\251\231\232\251\231"
|
||||
"\232\251a\32\252\241\32\246UI\36tD\1|\16fcgf\312\376\377\377M\31\264\10}\66\353\243"
|
||||
"\266JG\242\70LC\65T\303\70S\63\65S\63\65S\63\65S\63\65\25C-\334\262!\313\324L"
|
||||
"\315\324L\315\324L\14\265pJuDGFe\7f\0~\24\315`\331&\34\302aSrP\226\206"
|
||||
"lP\244AS\0\0\0\0\4\377\377\0";
|
||||
|
||||
|
||||
#endif /* U8G2_USE_LARGE_FONTS */
|
||||
84
7.5inch_Multifunctional_E-Paper/gettianqi.ino
Normal file
84
7.5inch_Multifunctional_E-Paper/gettianqi.ino
Normal file
@@ -0,0 +1,84 @@
|
||||
#include <HTTPClient.h>
|
||||
|
||||
|
||||
void text12(const char *str, int16_t x, int16_t y, uint16_t fg_color, uint16_t bg_color);
|
||||
void text40(const char *str, int16_t x, int16_t y, uint16_t fg_color, uint16_t bg_color);
|
||||
|
||||
|
||||
void tianqi_show(const char *now_temp2, const char *now_text, const char *now_feelsLike3, const char *now_windSpeed2) {
|
||||
|
||||
u8g2Fonts.setFont(u8g2_font_fub42_tf);
|
||||
int16_t dd = (u8g2Fonts.getUTF8Width(now_temp2));
|
||||
u8g2Fonts.setForegroundColor(GxEPD_BLACK);
|
||||
u8g2Fonts.setBackgroundColor(GxEPD_WHITE);
|
||||
text40(now_temp2, (81 - dd) / 2 + 11, 32,GxEPD_BLACK,GxEPD_WHITE);
|
||||
text12(now_text, 100, 46,GxEPD_BLACK,GxEPD_WHITE);
|
||||
text12(now_windSpeed2, 100, 32,GxEPD_BLACK,GxEPD_WHITE);
|
||||
text12(now_feelsLike3, 100, 60,GxEPD_BLACK,GxEPD_WHITE);
|
||||
|
||||
}
|
||||
|
||||
void tianqi_get() {
|
||||
|
||||
HTTPClient http; // 声明HTTPClient对象
|
||||
http.begin("http://天气.php");//这里更换php文件夹中的天气.php实际地址,具体操作请仔细阅读README.md
|
||||
int httpCode = http.GET();
|
||||
if (httpCode != 200) {
|
||||
Serial.println(HTTPClient::errorToString(httpCode));
|
||||
http.end();
|
||||
Serial.println("天气获取失败");
|
||||
return;
|
||||
}
|
||||
|
||||
String jsoninput = http.getString();
|
||||
StaticJsonDocument<200> filter;
|
||||
filter["code"] = true;
|
||||
|
||||
JsonObject filter_now = filter.createNestedObject("now");
|
||||
filter_now["temp"] = true;
|
||||
filter_now["text"] = true;
|
||||
filter_now["feelsLike"] = true;
|
||||
filter_now["windSpeed"] = true;
|
||||
|
||||
StaticJsonDocument<2000> doc;
|
||||
|
||||
DeserializationError error = deserializeJson(doc, jsoninput, DeserializationOption::Filter(filter));
|
||||
|
||||
if (error) {
|
||||
Serial.print(F("111update_weather_now_data deserializeJson() failed: "));
|
||||
Serial.println(error.f_str());
|
||||
return;
|
||||
}
|
||||
http.end();
|
||||
const char *code = doc["code"];
|
||||
const char *success_code = "200";
|
||||
if (strstr(code, success_code) == nullptr) {
|
||||
return;
|
||||
}
|
||||
const char *now_temp1 = doc["now"]["temp"]; // 温度
|
||||
const char *now_text = doc["now"]["text"]; // 天气
|
||||
const char *now_feelsLike1 = doc["now"]["feelsLike"]; // "体感温度"
|
||||
const char *now_windSpeed = doc["now"]["windSpeed"]; // "体感温度"
|
||||
|
||||
|
||||
String now_feelsLike = now_feelsLike1;
|
||||
String B = "体感温度" + now_feelsLike + "°";
|
||||
const char *now_feelsLike3 = B.c_str();
|
||||
|
||||
String now_temp = now_temp1;
|
||||
String C = now_temp + "°";
|
||||
const char *now_temp2 = C.c_str();
|
||||
|
||||
String now_windSpeed1 = now_windSpeed;
|
||||
String D = "风速" + now_windSpeed1 + "公里/小时";
|
||||
const char *now_windSpeed2 = D.c_str();
|
||||
|
||||
//Serial.println(now_temp1);
|
||||
//Serial.println(now_temp2);
|
||||
//Serial.println(now_feelsLike1);
|
||||
//Serial.println(now_feelsLike3);
|
||||
|
||||
Serial.println("天气获取成功!");
|
||||
|
||||
tianqi_show(now_temp2, now_text, now_feelsLike3, now_windSpeed2);
|
||||
}
|
||||
137
7.5inch_Multifunctional_E-Paper/gettime.ino
Normal file
137
7.5inch_Multifunctional_E-Paper/gettime.ino
Normal file
@@ -0,0 +1,137 @@
|
||||
|
||||
void text12(const char *str, int16_t x, int16_t y, uint16_t fg_color, uint16_t bg_color);
|
||||
void text40(const char *str, int16_t x, int16_t y, uint16_t fg_color, uint16_t bg_color);
|
||||
|
||||
void drawBoldRoundRect(int x, int y, int w, int h, int r, int thickness, uint16_t color) {
|
||||
for (int i = 0; i < thickness; i++) {
|
||||
display.drawRoundRect(x + i, y + i, w - i * 2, h - i * 2, r, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void time_show(const char *data_line11,const char *data_ri,const char *ganzhi_shengxiao,const char *data_nongli,const char *xingqi,const char *suit,const char *avoid) {
|
||||
drawBoldRoundRect(55,104,85,79,4,2,GxEPD_RED);
|
||||
display.fillRoundRect(55,104,85,20,4,GxEPD_RED);
|
||||
|
||||
drawBoldRoundRect(63,96,10,15,0,3,GxEPD_RED);
|
||||
drawBoldRoundRect(83,96,10,15,0,3,GxEPD_RED);
|
||||
drawBoldRoundRect(103,96,10,15,0,3,GxEPD_RED);
|
||||
drawBoldRoundRect(123,96,10,15,0,3,GxEPD_RED);
|
||||
|
||||
u8g2Fonts.setFont(u8g2_font_wqy12_t_gb2312);
|
||||
int16_t aa = (u8g2Fonts.getUTF8Width(data_line11));
|
||||
text12(data_line11, (85-aa)/2+55, 108,GxEPD_WHITE,GxEPD_RED);
|
||||
|
||||
u8g2Fonts.setFont(u8g2_font_fub42_tf);
|
||||
int16_t bb = (u8g2Fonts.getUTF8Width(data_ri));
|
||||
text40(data_ri, (81-bb)/2+57, 131,GxEPD_BLACK,GxEPD_WHITE);
|
||||
|
||||
u8g2Fonts.setFont(u8g2_font_wqy12_t_gb2312);
|
||||
int16_t cc = (u8g2Fonts.getUTF8Width(ganzhi_shengxiao));
|
||||
text12(ganzhi_shengxiao, (195-cc)/2, 191,GxEPD_BLACK,GxEPD_WHITE);
|
||||
|
||||
u8g2Fonts.setFont(u8g2_font_wqy12_t_gb2312);
|
||||
int16_t dd = (u8g2Fonts.getUTF8Width(data_nongli));
|
||||
text12(data_nongli, (91-dd)/2+27, 209,GxEPD_BLACK,GxEPD_WHITE);
|
||||
|
||||
text12(xingqi,118, 209,GxEPD_RED,GxEPD_WHITE);
|
||||
|
||||
display.fillRoundRect(11,230,16,16,4,GxEPD_BLACK);
|
||||
display.fillRoundRect(11,254,16,16,4,GxEPD_RED);
|
||||
|
||||
text12("宜",13, 232,GxEPD_WHITE,GxEPD_BLACK);
|
||||
text12("忌",13, 256,GxEPD_WHITE,GxEPD_RED);
|
||||
|
||||
text12(suit,33, 232,GxEPD_BLACK,GxEPD_WHITE);
|
||||
text12(avoid,33, 256,GxEPD_BLACK,GxEPD_WHITE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void time_get() {
|
||||
|
||||
HTTPClient http; // 声明HTTPClient对象
|
||||
WiFiClient Client;
|
||||
|
||||
http.begin(Client, "http://日期.php");//这里更换php文件夹中的日期.php实际地址,具体操作请仔细阅读README.md
|
||||
int httpCode = http.GET();
|
||||
|
||||
if (httpCode != 200) {
|
||||
Serial.println(HTTPClient::errorToString(httpCode));
|
||||
Serial.println("时间获取失败");
|
||||
http.end();
|
||||
return;
|
||||
}
|
||||
|
||||
StaticJsonDocument<250> filter;
|
||||
filter["code"] = true;
|
||||
JsonObject filter_data = filter.createNestedObject("data");
|
||||
filter_data["ri"] = true;
|
||||
filter_data["xingqi"] = true;
|
||||
filter_data["nongli"] = true;
|
||||
filter_data["ganzhi"] = true;
|
||||
filter_data["shengxiao"] = true;
|
||||
filter_data["line11"] = true;
|
||||
|
||||
StaticJsonDocument<256> doc;
|
||||
|
||||
DeserializationError error = deserializeJson(doc, http.getString(), DeserializationOption::Filter(filter));
|
||||
|
||||
if (error) {
|
||||
Serial.print(F("时间获取 deserializeJson() failed: "));
|
||||
Serial.println(error.f_str());
|
||||
return;
|
||||
}
|
||||
http.end();
|
||||
|
||||
const char *data_line11 = doc["data"]["line11"]; // 日期
|
||||
const char *data_nongli = doc["data"]["nongli"]; // 农历
|
||||
const char *data_ri = doc["data"]["ri"]; //日
|
||||
const char *xingqi = doc["data"]["xingqi"]; // 星期
|
||||
String data_ganzhi = doc["data"]["ganzhi"]; // 干支
|
||||
String data_shengxiao = doc["data"]["shengxiao"]; // 生肖
|
||||
String ganzhi_shengxiao0 = data_ganzhi + " " + data_shengxiao;
|
||||
const char* ganzhi_shengxiao = ganzhi_shengxiao0.c_str();
|
||||
//String nongli_xingqi0 = data_nongli + " " + data_xingqi;
|
||||
//const char* nongli_xingqi = nongli_xingqi0.c_str();
|
||||
|
||||
http.begin(Client, "http://忌宜.php");//这里更换php文件夹中的忌宜.php实际地址,具体操作请仔细阅读README.md
|
||||
int httpCode2 = http.GET();
|
||||
if (httpCode2 != 200) {
|
||||
Serial.println(HTTPClient::errorToString(httpCode));
|
||||
Serial.println("禁忌获取失败");
|
||||
http.end();
|
||||
return;
|
||||
}
|
||||
//Serial.printf("禁忌: %8d\n", ESP.getFreeHeap());
|
||||
//Serial.println(httpCode2);
|
||||
String jsoninput2 = http.getString();
|
||||
//Serial.println(jsoninput2);
|
||||
|
||||
StaticJsonDocument<100> filter2;
|
||||
JsonObject filter_data2 = filter2.createNestedObject("data");
|
||||
filter_data2["suit"] = true;
|
||||
filter_data2["avoid"] = true;
|
||||
|
||||
StaticJsonDocument<2000> doc2;
|
||||
|
||||
DeserializationError error2 = deserializeJson(doc2, jsoninput2, DeserializationOption::Filter(filter2));
|
||||
|
||||
if (error) {
|
||||
Serial.print("禁忌获取 deserializeJson() failed: ");
|
||||
Serial.println(error2.c_str());
|
||||
return;
|
||||
}
|
||||
http.end();
|
||||
const char *suit = doc2["data"]["suit"]; // 日期
|
||||
const char *avoid = doc2["data"]["avoid"]; // 农历
|
||||
time_show(data_line11, data_ri,ganzhi_shengxiao,data_nongli,xingqi,suit,avoid);
|
||||
// Serial.println(data_line11);
|
||||
// Serial.println(data_nongli);
|
||||
// Serial.println(data_ri);
|
||||
// Serial.println(data_xingqi);
|
||||
// Serial.println(data_ganzhi);
|
||||
// Serial.println(data_shengxiao);
|
||||
//Serial.println(suit);
|
||||
Serial.println("时间相关获取成功!");
|
||||
}
|
||||
110
7.5inch_Multifunctional_E-Paper/gettodo.ino
Normal file
110
7.5inch_Multifunctional_E-Paper/gettodo.ino
Normal file
@@ -0,0 +1,110 @@
|
||||
#include <ArduinoJson.h>
|
||||
unsigned long todo_lastMillis = 0;
|
||||
|
||||
unsigned long todo_interval = 10 * 1000; // 待办事件触发时间10s钟,如果有内容更新则上传新内容否则啥也不做
|
||||
|
||||
String todo_old = ""; //定义待办事件json初始内容
|
||||
String todo_new = ""; //定义待办事件json最新内容
|
||||
|
||||
|
||||
// 声明一个结构体,用来存储每个数据项的信息
|
||||
struct TodoItem {
|
||||
const char* isimp;
|
||||
const char* thing;
|
||||
const char* isdone;
|
||||
};
|
||||
|
||||
// 声明一个数组,用来存储所有数据项的信息
|
||||
std::vector<TodoItem> todo_items;
|
||||
|
||||
|
||||
|
||||
void text16(const char* str, int16_t x, int16_t y, uint16_t fg_color, uint16_t bg_color);
|
||||
void text12(const char* str, int16_t x, int16_t y, uint16_t fg_color, uint16_t bg_color);
|
||||
|
||||
void todo_show() {
|
||||
for (uint8_t j = 0; j < todo_items.size(); j++) {
|
||||
if (strcmp(todo_items[j].isimp, "1") == 0) {
|
||||
// 显示重要标记
|
||||
uint16_t y = 104 + j * (16 + 17);
|
||||
uint16_t x = 106 + j * (16 + 17);
|
||||
display.fillRoundRect(622, y, 29, 16, 4, GxEPD_RED);
|
||||
text12("重要", 625, x, GxEPD_WHITE, GxEPD_RED);
|
||||
}
|
||||
|
||||
if (todo_items[j].thing != 0) {
|
||||
// 显示待办事项
|
||||
uint16_t y = 104 + j * (16 + 17);
|
||||
if (strcmp(todo_items[j].isimp, "1") == 0) {
|
||||
text16(todo_items[j].thing, 655, y, GxEPD_RED, GxEPD_WHITE);
|
||||
} else {
|
||||
text16(todo_items[j].thing, 622, y, GxEPD_BLACK, GxEPD_WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
// 显示完成状态
|
||||
display.drawFastHLine(598, 129 + j * (16 + 8 + 8 + 1), 191, GxEPD_BLACK);
|
||||
display.drawRoundRect(598, 104 + j * (16 + 17), 16, 16, 4, GxEPD_BLACK);
|
||||
if (strcmp(todo_items[j].isdone, "1") == 0) {
|
||||
uint16_t y = 104 + j * (16 + 17);
|
||||
text16("√", 600, y, GxEPD_BLACK, GxEPD_WHITE);
|
||||
}
|
||||
}
|
||||
Serial.println("todo显示成功!");
|
||||
}
|
||||
|
||||
void todo_get(unsigned long current_millis) {
|
||||
todo_lastMillis = current_millis;
|
||||
|
||||
HTTPClient http; // 声明HTTPClient对象
|
||||
|
||||
|
||||
http.begin("http://待办.php");//这里更换php文件夹中的待办.php实际地址,具体操作请仔细阅读README.md
|
||||
int httpCode = http.GET();
|
||||
|
||||
//Serial.printf("time: %8d\n", ESP.getFreeHeap());
|
||||
|
||||
//Serial.println(httpCode);
|
||||
|
||||
if (httpCode != 200) {
|
||||
Serial.println(HTTPClient::errorToString(httpCode));
|
||||
Serial.println("TODO获取失败");
|
||||
http.end();
|
||||
return;
|
||||
}
|
||||
|
||||
todo_new = http.getString(); //新获取到的json赋值给todo_new
|
||||
|
||||
DynamicJsonDocument doc(6000);
|
||||
|
||||
|
||||
|
||||
DeserializationError error = deserializeJson(doc, todo_new);
|
||||
|
||||
if (error) {
|
||||
Serial.print(F("update_weather_now_data deserializeJson() failed: "));
|
||||
Serial.println(error.f_str());
|
||||
//todo_lastMillis = current_millis - todo_interval + 87000;
|
||||
return;
|
||||
}
|
||||
http.end();
|
||||
|
||||
todo_items.clear();
|
||||
|
||||
|
||||
// 解析JSON数据并存储到数组中
|
||||
for (JsonObject data_item : doc["data"].as<JsonArray>()) {
|
||||
const char* data_item_isimp = data_item["isimp"];
|
||||
const char* data_item_thing = data_item["thing"];
|
||||
const char* data_item_isdone = data_item["isdone"];
|
||||
todo_items.push_back({data_item_isimp, data_item_thing, data_item_isdone});
|
||||
}
|
||||
Serial.println("TODO获取成功!");
|
||||
}
|
||||
|
||||
void refresh_10s() {
|
||||
unsigned long current_millis = millis();
|
||||
if (current_millis - todo_lastMillis >= todo_interval) {
|
||||
refresh_todo();
|
||||
}
|
||||
}
|
||||
110
7.5inch_Multifunctional_E-Paper/getweibo.ino
Normal file
110
7.5inch_Multifunctional_E-Paper/getweibo.ino
Normal file
@@ -0,0 +1,110 @@
|
||||
#include <vector>
|
||||
|
||||
// 定义 DataItem 结构体
|
||||
struct DataItem {
|
||||
String word;
|
||||
String label_name;
|
||||
};
|
||||
|
||||
// 定义全局的向量,用于存储 DataItem 数据
|
||||
std::vector<DataItem> data_items;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void text12(const char *str, int16_t x, int16_t y, uint16_t fg_color, uint16_t bg_color);
|
||||
|
||||
void weibo_show(){
|
||||
|
||||
|
||||
int8_t i = 0;
|
||||
uint16_t x = 0;
|
||||
uint16_t y = 0;
|
||||
for (const auto& item : data_items) {
|
||||
|
||||
// 判断 i 是否大于等于 19,然后设置 x 的值
|
||||
if (i >= 17) {
|
||||
x = 401;
|
||||
y = 92 + (i-17) * (12 + 9);
|
||||
} else {
|
||||
x = 207;
|
||||
y = 92 + i * (12 + 9);
|
||||
}
|
||||
|
||||
String data_item_word = item.word;
|
||||
String word_with_index = String(i + 1) + "." + data_item_word; // Combine the index and word with the prefix, as a UTF-8-encoded string
|
||||
const char *data_item_word1 = word_with_index.c_str();
|
||||
if (data_item_word != 0) {
|
||||
|
||||
display.fillRect(x, y-5, 180, 19 + 9, GxEPD_WHITE);
|
||||
text12(data_item_word1, x, y,GxEPD_BLACK,GxEPD_WHITE); // Insert the UTF-8 string into the buffer using buf_ins_text16hei()
|
||||
//Serial.println(data_item_word1);
|
||||
//display.drawFastHLine(x, y + 24, 232, GxEPD_BLACK);
|
||||
}
|
||||
String label_name = item.label_name;
|
||||
const char *data_item_label_name = label_name.c_str();
|
||||
|
||||
std::string data_item_label_name1 = data_item_label_name;
|
||||
if (!data_item_label_name1.empty()) {
|
||||
|
||||
|
||||
int16_t aa = (u8g2Fonts.getUTF8Width(data_item_word1));
|
||||
display.fillRoundRect(x + aa + 2, y - 1, 14, 14, 2, GxEPD_RED);
|
||||
text12(data_item_label_name, x + aa + 3, y,GxEPD_WHITE,GxEPD_RED);
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void weibo_get() {
|
||||
|
||||
HTTPClient http; // 声明HTTPClient对象
|
||||
|
||||
http.begin("http://微博.php");//这里更换php文件夹中的微博.php实际地址,具体操作请仔细阅读README.md
|
||||
int httpCode = http.GET();
|
||||
|
||||
//Serial.printf("time: %8d\n", ESP.getFreeHeap());
|
||||
//Serial.println("微博获取状态码");
|
||||
//Serial.println(httpCode);
|
||||
|
||||
//Serial.println(http.getString());
|
||||
String jsoninput = http.getString();
|
||||
if (httpCode != 200) {
|
||||
Serial.println(HTTPClient::errorToString(httpCode));
|
||||
http.end();
|
||||
return;
|
||||
}
|
||||
DynamicJsonDocument doc(8000);
|
||||
|
||||
DeserializationError error = deserializeJson(doc, jsoninput);
|
||||
|
||||
if (error) {
|
||||
Serial.print(F("微博 deserializeJson() failed: "));
|
||||
Serial.println(error.f_str());
|
||||
return;
|
||||
}
|
||||
http.end();
|
||||
data_items.clear();
|
||||
|
||||
|
||||
for (JsonObject data_item : doc["data"].as<JsonArray>()) {
|
||||
|
||||
DataItem item;
|
||||
item.word = data_item["word"].as<String>();
|
||||
item.label_name = data_item["label_name"].as<String>();
|
||||
data_items.push_back(item);
|
||||
}
|
||||
|
||||
Serial.println("微博获取成功!");
|
||||
}
|
||||
57
7.5inch_Multifunctional_E-Paper/getyiyan.ino
Normal file
57
7.5inch_Multifunctional_E-Paper/getyiyan.ino
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
void text12(const char *str, int16_t x, int16_t y, uint16_t fg_color, uint16_t bg_color);
|
||||
|
||||
|
||||
|
||||
void yiyan_show(const char *yiyan) {
|
||||
|
||||
u8g2Fonts.setFont(u8g2_font_wqy16_t_gb2312);
|
||||
int16_t dd = (u8g2Fonts.getUTF8Width(yiyan));
|
||||
u8g2Fonts.setForegroundColor(GxEPD_BLACK);
|
||||
u8g2Fonts.setBackgroundColor(GxEPD_WHITE);
|
||||
text12(yiyan, (553-dd)/2 + 240, 462,GxEPD_BLACK,GxEPD_WHITE);
|
||||
}
|
||||
|
||||
void yiyan_get() {
|
||||
|
||||
HTTPClient http; // 声明HTTPClient对象
|
||||
http.begin("http://一言.php");//这里更换php文件夹中的一言.php实际地址,具体操作请仔细阅读README.md
|
||||
int httpCode = http.GET();
|
||||
if (httpCode != 200) {
|
||||
Serial.println(HTTPClient::errorToString(httpCode));
|
||||
http.end();
|
||||
Serial.println("一言获取失败");
|
||||
return;
|
||||
}
|
||||
|
||||
String jsoninput = http.getString();
|
||||
StaticJsonDocument<100> filter;
|
||||
filter["hitokoto"] = true;
|
||||
filter["from_who"] = true;
|
||||
|
||||
StaticJsonDocument<500> doc;
|
||||
|
||||
DeserializationError error = deserializeJson(doc, jsoninput, DeserializationOption::Filter(filter));
|
||||
|
||||
if (error) {
|
||||
Serial.print("deserializeJson() failed: ");
|
||||
Serial.println(error.c_str());
|
||||
return;
|
||||
}
|
||||
http.end();
|
||||
//const char* hitokoto = doc["hitokoto"]; // "眼睛为她下着雨,心却为她打着伞,这就是爱情。 "
|
||||
//const char* who = doc["from_who"]; // "d"
|
||||
|
||||
String hitokoto = doc["hitokoto"]; // "眼睛为她下着雨,心却为她打着伞,这就是爱情。 "
|
||||
String who = doc["from_who"]; // "d"
|
||||
if (who == "null") {
|
||||
who = "--佚名";
|
||||
}
|
||||
String combined = hitokoto + " " + who;
|
||||
const char* yiyan = combined.c_str();
|
||||
//Serial.println(yiyan);
|
||||
|
||||
Serial.println("一言获取成功!");
|
||||
|
||||
yiyan_show(yiyan);
|
||||
}
|
||||
1537
7.5inch_Multifunctional_E-Paper/jpg.h
Normal file
1537
7.5inch_Multifunctional_E-Paper/jpg.h
Normal file
File diff suppressed because it is too large
Load Diff
65
7.5inch_Multifunctional_E-Paper/refresh.ino
Normal file
65
7.5inch_Multifunctional_E-Paper/refresh.ino
Normal file
@@ -0,0 +1,65 @@
|
||||
void refresh_yiyan(){//暂时用不到,有数据更新可以全部刷新屏幕
|
||||
display.setPartialWindow(235, 458, 563, 20);
|
||||
display.firstPage();
|
||||
do {
|
||||
yiyan_get();
|
||||
} while (display.nextPage());
|
||||
display.powerOff();
|
||||
}
|
||||
|
||||
|
||||
void refresh_weibo(){ //暂时用不到,有数据更新可以全部刷新屏幕
|
||||
weibo_get();
|
||||
display.setPartialWindow(200, 80, 384, 368);
|
||||
display.firstPage();
|
||||
do {
|
||||
weibo_show();
|
||||
} while (display.nextPage());
|
||||
display.powerOff();
|
||||
}
|
||||
|
||||
void refresh_todo(){ //
|
||||
todo_old = todo_new;
|
||||
todo_get(millis());
|
||||
int num = todo_new.compareTo(todo_old); //将新获取的值与旧的进行对比,定义mun为对比结果
|
||||
Serial.println("对比结果2:");
|
||||
Serial.println(num); //打印对比结果方便调试
|
||||
if (num == 0) //如果todo_old值跟todo_new一样那啥也不做
|
||||
{
|
||||
display.powerOff();
|
||||
Serial.println("结果一样,不刷新");
|
||||
Serial.println("内存剩余:");
|
||||
Serial.println(ESP.getFreeHeap());
|
||||
} else {
|
||||
Serial.println(todo_new);
|
||||
Serial.println(todo_old);
|
||||
todo_old = todo_new;
|
||||
display.setPartialWindow(592, 80, 208, 368);
|
||||
display.firstPage();
|
||||
do {
|
||||
todo_show();
|
||||
} while (display.nextPage());
|
||||
display.powerOff();
|
||||
}
|
||||
}
|
||||
|
||||
void refresh_all(){
|
||||
weibo_get();
|
||||
todo_get(millis());
|
||||
display.setFullWindow();
|
||||
display.firstPage();
|
||||
display.fillScreen(GxEPD_WHITE);
|
||||
do {
|
||||
|
||||
displaymain();
|
||||
tianqi_get();
|
||||
time_get();
|
||||
yiyan_get();
|
||||
time_get();
|
||||
weibo_show();
|
||||
todo_show();
|
||||
} while (display.nextPage());
|
||||
display.powerOff();
|
||||
}
|
||||
|
||||
|
||||
51
7.5inch_Multifunctional_E-Paper/textstyle.ino
Normal file
51
7.5inch_Multifunctional_E-Paper/textstyle.ino
Normal file
@@ -0,0 +1,51 @@
|
||||
void text16(const char *str, int16_t x, int16_t y, uint16_t fg_color = GxEPD_WHITE, uint16_t bg_color = GxEPD_BLACK) //16px黑字
|
||||
{
|
||||
bool r2l = false;
|
||||
int8_t baseline = 14;
|
||||
u8g2Fonts.setFontMode(1);
|
||||
u8g2Fonts.setFont(u8g2_font_wqy16_t_gb2312);
|
||||
u8g2Fonts.setBackgroundColor(bg_color);
|
||||
u8g2Fonts.setForegroundColor(fg_color);
|
||||
if (!r2l) {
|
||||
u8g2Fonts.drawUTF8(x, y + baseline, str);
|
||||
} else {
|
||||
int16_t w = u8g2Fonts.getUTF8Width(str);
|
||||
int16_t new_x = display.width() - x - w;
|
||||
u8g2Fonts.drawUTF8(new_x, y + baseline, str);
|
||||
}
|
||||
}
|
||||
|
||||
void text12(const char *str, int16_t x, int16_t y, uint16_t fg_color = GxEPD_WHITE, uint16_t bg_color = GxEPD_BLACK) //16px黑字
|
||||
{
|
||||
bool r2l = false;
|
||||
int8_t baseline = 10;
|
||||
u8g2Fonts.setFontMode(1);
|
||||
u8g2Fonts.setFont(u8g2_font_wqy12_t_gb2312);
|
||||
u8g2Fonts.setBackgroundColor(bg_color);
|
||||
u8g2Fonts.setForegroundColor(fg_color);
|
||||
|
||||
if (!r2l) {
|
||||
u8g2Fonts.drawUTF8(x, y + baseline, str);
|
||||
} else {
|
||||
int16_t w = u8g2Fonts.getUTF8Width(str);
|
||||
int16_t new_x = display.width() - x - w;
|
||||
u8g2Fonts.drawUTF8(new_x, y + baseline, str);
|
||||
}
|
||||
}
|
||||
|
||||
void text40(const char *str, int16_t x, int16_t y, uint16_t fg_color = GxEPD_WHITE, uint16_t bg_color = GxEPD_BLACK) //时间天气什么的小字
|
||||
{
|
||||
bool r2l = false;
|
||||
int8_t baseline = 42;
|
||||
u8g2Fonts.setFontMode(1);
|
||||
u8g2Fonts.setFont(u8g2_font_fub42_tf);
|
||||
u8g2Fonts.setBackgroundColor(bg_color);
|
||||
u8g2Fonts.setForegroundColor(fg_color);
|
||||
if (!r2l) {
|
||||
u8g2Fonts.drawUTF8(x, y + baseline, str);
|
||||
} else {
|
||||
int16_t w = u8g2Fonts.getUTF8Width(str);
|
||||
int16_t new_x = display.width() - x - w;
|
||||
u8g2Fonts.drawUTF8(new_x, y + baseline, str);
|
||||
}
|
||||
}
|
||||
8
html/db.php
Normal file
8
html/db.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
// 连接数据库
|
||||
$conn = new mysqli('你的服务器数据库地址', 'root', '数据库密码', '数据表名');
|
||||
|
||||
if ($conn->connect_error) {
|
||||
die("连接失败: " . $conn->connect_error);
|
||||
}
|
||||
?>
|
||||
81
html/index.php
Normal file
81
html/index.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>待办事件提交</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=0.8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=0.8, maximum-scale=0.8, user-scalable=no">
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
<script>
|
||||
window.onload = function() {
|
||||
// 获取视窗宽度
|
||||
var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
||||
console.log("视窗宽度为:" + windowWidth + " 像素");
|
||||
|
||||
// 获取文档宽度
|
||||
var documentWidth = document.documentElement.clientWidth || document.body.clientWidth;
|
||||
console.log("文档宽度为:" + documentWidth + " 像素");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>待办事件E-Paper</h1>
|
||||
<form method="post" action="process.php">
|
||||
<!-- <label for="name">姓名:</label>
|
||||
<input type="text" name="name" id="name"><br><br> -->
|
||||
<!-- <label for="thing">待办事件内容:</label> -->
|
||||
<input name="thing" id="thing" rows="1" maxlength="10" autofocus=true placeholder="待办事件限制13个文字" required=true></input>
|
||||
<button type="submit" name="action" value="add">提交待办事件</button>
|
||||
</form>
|
||||
<hr>
|
||||
<div class="weather">
|
||||
<?php
|
||||
include 'db.php';
|
||||
// 查询所有留言
|
||||
//$sql = "SELECT * FROM daiban ORDER BY create_time DESC";
|
||||
$sql = "SELECT * FROM daiban";
|
||||
$result = $conn->query($sql);
|
||||
if ($result->num_rows > 0) {
|
||||
// 输出每个待办事件
|
||||
$count = 0;
|
||||
while($row = $result->fetch_assoc()) {
|
||||
//echo "<p>{$row['thing']}";
|
||||
$count++;
|
||||
$style = '';
|
||||
if ($row['isimp']) {
|
||||
$style .= 'color:red;';
|
||||
}
|
||||
if ($row['isimp'] && $row['isdone']) {
|
||||
$style .= 'text-decoration:line-through;color:red;';
|
||||
} elseif ($row['isdone']) {
|
||||
$style .= 'text-decoration:line-through;';
|
||||
}
|
||||
echo "<div style=\"text-align: left;\"><p style=\"$style\">{$count}. {$row['thing']}</p>";
|
||||
echo " <button onclick=\"location.href='process.php?action=delete&id={$row['id']}'\"> 删除</button> ";
|
||||
if($row['isimp']) {
|
||||
echo "<span><button style=\"color:red;\" onclick=\" location.href='process.php?action=notimp&id={$row['id']}'\">重要</button></span>";
|
||||
} else {
|
||||
echo "<button onclick=\"location.href='process.php?action=isimp&id={$row['id']}'\"> 设为重要事件</button>";
|
||||
}
|
||||
if ($row['isdone']) {
|
||||
// 如果已完成,则显示“已完成”按钮
|
||||
echo " <button onclick=\"location.href='process.php?action=notdone&id={$row['id']}'\"> 已完成</button>";
|
||||
} else {
|
||||
// 否则,显示“设为已完成”按钮
|
||||
echo " <button onclick=\"location.href='process.php?action=isdone&id={$row['id']}'\"> 设为已完成</button>";
|
||||
}
|
||||
echo "</div>";
|
||||
// echo "<hr>";
|
||||
}
|
||||
} else {
|
||||
echo "<p>暂无待办事件</p>";
|
||||
}
|
||||
$conn->close();
|
||||
?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
|
||||
99
html/process.php
Normal file
99
html/process.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
include 'db.php';
|
||||
|
||||
// 处理提交留言请求
|
||||
if ($_POST['action'] == 'add') {
|
||||
// $name = $_POST['name'];
|
||||
$sql = "SELECT COUNT(*) as count FROM daiban";
|
||||
$result = $conn->query($sql);
|
||||
|
||||
if ($result) {
|
||||
$row = $result->fetch_assoc();
|
||||
$count = $row['count'];
|
||||
|
||||
// 如果记录数大于等于6,则禁止添加新待办事项并弹出提醒
|
||||
if ($count >= 10) {
|
||||
echo "<script>alert('已达到最多10条待办事项');window.location.href='index.php';</script>";
|
||||
|
||||
} else {
|
||||
// 否则,插入新的待办事项
|
||||
$thing = $_POST['thing'];
|
||||
$sql = "INSERT INTO daiban (thing) VALUES ('$thing')";
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
header("Location: index.php");
|
||||
} else {
|
||||
echo "Error: " . $sql . "<br>" . $conn->error;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo "Error: " . $sql . "<br>" . $conn->error;
|
||||
}
|
||||
}
|
||||
// 处理删除留言请求
|
||||
if ($_GET['action'] == 'delete') {
|
||||
$id = $_GET['id'];
|
||||
|
||||
$sql = "DELETE FROM daiban WHERE id=$id";
|
||||
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
header("Location: index.php");
|
||||
} else {
|
||||
echo "Error: " . $sql . "<br>" . $conn->error;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理设为精选请求
|
||||
if ($_GET['action'] == 'isimp') {
|
||||
$id = $_GET['id'];
|
||||
|
||||
$sql = "UPDATE daiban SET isimp=1 WHERE id=$id";
|
||||
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
header("Location: index.php");
|
||||
} else {
|
||||
echo "Error: " . $sql . "<br>" . $conn->error;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理取消设为精选请求
|
||||
if ($_GET['action'] == 'notimp') {
|
||||
$id = $_GET['id'];
|
||||
|
||||
$sql = "UPDATE daiban SET isimp=0 WHERE id=$id"; // 将isimp字段更新为0
|
||||
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
header("Location: index.php");
|
||||
} else {
|
||||
echo "Error: " . $sql . "<br>" . $conn->error;
|
||||
}
|
||||
}
|
||||
|
||||
// 完成
|
||||
if ($_GET['action'] == 'isdone') {
|
||||
$id = $_GET['id'];
|
||||
|
||||
$sql = "UPDATE daiban SET isdone=1 WHERE id=$id"; // 将isimp字段更新为0
|
||||
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
header("Location: index.php");
|
||||
} else {
|
||||
echo "Error: " . $sql . "<br>" . $conn->error;
|
||||
}
|
||||
}
|
||||
|
||||
// 未完成
|
||||
if ($_GET['action'] == 'notdone') {
|
||||
$id = $_GET['id'];
|
||||
|
||||
$sql = "UPDATE daiban SET isdone=0 WHERE id=$id"; // 将isimp字段更新为0
|
||||
|
||||
if ($conn->query($sql) === TRUE) {
|
||||
header("Location: index.php");
|
||||
} else {
|
||||
echo "Error: " . $sql . "<br>" . $conn->error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
178
html/style.css
Normal file
178
html/style.css
Normal file
@@ -0,0 +1,178 @@
|
||||
body {
|
||||
font-family: "Microsoft YaHei", sans-serif;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
/*height: 100vh;*/
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/*div {
|
||||
text-align: left;
|
||||
|
||||
white-space: nowrap;
|
||||
|
||||
}*/
|
||||
.weather {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
|
||||
text-align: left;
|
||||
align-content:flex-end;
|
||||
align-items: flex-start
|
||||
|
||||
}
|
||||
|
||||
.weather2 {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.weather2 p {
|
||||
margin: 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
form {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
hr {
|
||||
|
||||
width: 500px;
|
||||
border-color: #5581ff;
|
||||
height: 0px;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
button {
|
||||
padding: 6px;
|
||||
background-color: #5581ff;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #516dbf;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 10px 0;
|
||||
padding: 5px;
|
||||
font-size: 22px;
|
||||
display: inline-block;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
a {
|
||||
color: green;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* 为 input 添加样式 */
|
||||
input {
|
||||
padding: 8px; /* 内边距 */
|
||||
font-size: 16px; /* 字体大小 */
|
||||
border: 1px solid #ccc; /* 边框 */
|
||||
border-radius: 5px; /* 圆角 */
|
||||
box-shadow: inset 0px 2px 2px rgba(0,0,0,0.1); /* 内阴影 */
|
||||
}
|
||||
|
||||
/* 当输入框获得焦点时添加样式 */
|
||||
input:focus {
|
||||
outline: none; /* 移除默认的外描边效果 */
|
||||
border-color: #6b9ce9; /* 修改边框颜色 */
|
||||
box-shadow: inset 0px 2px 2px rgba(0,0,0,0.1), 0px 0px 5px #6b9ce9; /*添加投影*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* 移动设备 */
|
||||
@media screen and (max-width: 480px) {
|
||||
/* 调整标题字体大小和间距 */
|
||||
|
||||
|
||||
|
||||
body {
|
||||
font-family: "Microsoft YaHei", sans-serif;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
/*height: 100vh;*/
|
||||
margin: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 20px;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
/* 调整表单字段样式 */
|
||||
form label, input {
|
||||
display: block;
|
||||
width: 100%;
|
||||
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
/* 调整提交按钮样式 */
|
||||
form button {
|
||||
display: block;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
|
||||
margin: 2px auto 22px;
|
||||
}
|
||||
|
||||
/* 调整每个待办事项的样式 */
|
||||
p {
|
||||
margin: 10px 0;
|
||||
padding: 5px;
|
||||
font-size: 20px;
|
||||
display: inline-block;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
hr {
|
||||
|
||||
width: 500px;
|
||||
border-color: #5581ff;
|
||||
height: 0px;
|
||||
|
||||
}
|
||||
div {
|
||||
|
||||
|
||||
white-space: nowrap;
|
||||
|
||||
}
|
||||
.weather {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
|
||||
text-align: left;
|
||||
align-content:flex-end;
|
||||
align-items: flex-start
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
BIN
jpg/109A0671.jpg
Normal file
BIN
jpg/109A0671.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 301 KiB |
BIN
jpg/109A0672.jpg
Normal file
BIN
jpg/109A0672.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 252 KiB |
BIN
jpg/109A0673.jpg
Normal file
BIN
jpg/109A0673.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 242 KiB |
BIN
jpg/109A0674.jpg
Normal file
BIN
jpg/109A0674.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 257 KiB |
BIN
jpg/109A0676.jpg
Normal file
BIN
jpg/109A0676.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 246 KiB |
75
php/todo.sql
Normal file
75
php/todo.sql
Normal file
@@ -0,0 +1,75 @@
|
||||
-- phpMyAdmin SQL Dump
|
||||
-- version 4.8.1
|
||||
-- https://www.phpmyadmin.net/
|
||||
--
|
||||
-- Host: 127.0.0.1
|
||||
-- Generation Time: 2023-05-26 14:23:43
|
||||
-- 服务器版本: 5.5.60-log
|
||||
-- PHP Version: 7.4.33
|
||||
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
SET AUTOCOMMIT = 0;
|
||||
START TRANSACTION;
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8mb4 */;
|
||||
|
||||
--
|
||||
-- Database: `todo`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- 表的结构 `daiban`
|
||||
--
|
||||
|
||||
CREATE TABLE `daiban` (
|
||||
`id` int(11) NOT NULL,
|
||||
`thing` varchar(200) NOT NULL,
|
||||
`isdone` varchar(200) NOT NULL,
|
||||
`isimp` varchar(200) NOT NULL
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
--
|
||||
-- 转存表中的数据 `daiban`
|
||||
--
|
||||
|
||||
INSERT INTO `daiban` (`id`, `thing`, `isdone`, `isimp`) VALUES
|
||||
(3, 'BOSS直聘上投简历', '0', '1'),
|
||||
(130, '设计开机画面', '', ''),
|
||||
(131, '设计配网界面', '', ''),
|
||||
(129, '增加温湿度显示', '', '0'),
|
||||
(128, '写每个区域更新代码', '1', '0'),
|
||||
(127, '设置自动更新间隔', '1', ''),
|
||||
(126, '三个按钮设置功能', '1', ''),
|
||||
(125, '增加电量显示', '1', '');
|
||||
|
||||
--
|
||||
-- Indexes for dumped tables
|
||||
--
|
||||
|
||||
--
|
||||
-- Indexes for table `daiban`
|
||||
--
|
||||
ALTER TABLE `daiban`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- 在导出的表使用AUTO_INCREMENT
|
||||
--
|
||||
|
||||
--
|
||||
-- 使用表AUTO_INCREMENT `daiban`
|
||||
--
|
||||
ALTER TABLE `daiban`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=148;
|
||||
COMMIT;
|
||||
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
28
php/一言.php
Normal file
28
php/一言.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
$url = 'https://v1.hitokoto.cn/';//
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$data = json_decode($result, true);
|
||||
|
||||
if ($data['length'] < 12 || $data['length'] > 29) {
|
||||
sleep(1); // 等待1秒钟
|
||||
$result = file_get_contents($url);
|
||||
$data = json_decode($result, true);
|
||||
}
|
||||
|
||||
if ($data['from_who'] !== null) {
|
||||
$data['from_who'] = '---' . $data['from_who'];
|
||||
}
|
||||
|
||||
$result = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
echo $result;
|
||||
|
||||
?>
|
||||
32
php/微博.php
Normal file
32
php/微博.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
// 1. 使用 cURL 获取 JSON 数据
|
||||
$url = "https://weibo.com/ajax/side/hotSearch";
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
// 2. 解析 JSON 数据,筛选出需要的数据
|
||||
$data = json_decode($result, true); // 将 JSON 字符串解码为 PHP 关联数组
|
||||
$realtime_words = $data["data"]["realtime"]; // 只获取"data"数组中的"realtime"数组
|
||||
|
||||
$words_assoc = array(); // 保存每个"word"键和对应值的关联数组
|
||||
|
||||
foreach ($realtime_words as $key => $word) {
|
||||
if ($key >= 34) { // 当遍历到第21个元素时退出循环
|
||||
break;
|
||||
}
|
||||
$words_assoc[] = [
|
||||
"word" => mb_substr($word["word"], 0, 12, "UTF-8"), // 截取word键的前6个字符作为输出
|
||||
"label_name" => isset($word["label_name"]) ? $word["label_name"] : ""
|
||||
];
|
||||
}
|
||||
|
||||
// 3. 添加 code 值,并重新组装 JSON 数据并输出
|
||||
$output_arr = [ "code" => 200, "data" => $words_assoc ];
|
||||
$output_json = json_encode($output_arr, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); // 将包含"word"键和"label_name"键的关联数组编码为 JSON 字符串,并保留中文字符和缩进
|
||||
echo $output_json;
|
||||
|
||||
50
php/忌宜.php
Normal file
50
php/忌宜.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// 设置时区为东八区
|
||||
date_default_timezone_set('Asia/Shanghai');
|
||||
// 获取当前日期
|
||||
$date = date('Y-m-j');
|
||||
// 对日期进行格式化,确保月份和日份的格式都是一位数的
|
||||
$date = sprintf('%d-%d-%d', ...explode('-', $date));
|
||||
|
||||
|
||||
// API地址
|
||||
$url = 'https://api.topthink.com/calendar/day?appCode=这里替换你的秘钥&date=' . $date;
|
||||
|
||||
// 初始化cURL
|
||||
$ch = curl_init();
|
||||
|
||||
// 设置cURL参数
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 忽略SSL证书验证
|
||||
|
||||
// 发送请求并获取响应数据
|
||||
$response = curl_exec($ch);
|
||||
|
||||
// 关闭cURL
|
||||
curl_close($ch);
|
||||
|
||||
// 解析JSON数据
|
||||
$data = json_decode($response, true);
|
||||
|
||||
// 判断suit是否存在,如果存在则将其中的"."替换为空格,并截取前14个字符
|
||||
if (isset($data['data']['suit'])) {
|
||||
$data['data']['suit'] = mb_substr(str_replace(".", " ", $data['data']['suit']), 0, 14, 'UTF-8');
|
||||
}
|
||||
|
||||
// 判断avoid是否存在,如果存在则将其中的"."替换为空格,并截取前14个字符
|
||||
if (isset($data['data']['avoid'])) {
|
||||
$data['data']['avoid'] = mb_substr(str_replace(".", " ", $data['data']['avoid']), 0, 14, 'UTF-8');
|
||||
}
|
||||
|
||||
// 编码JSON数据并进行UTF-8编码转换
|
||||
$json = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
$json = iconv("UTF-8", "UTF-8//IGNORE", $json);
|
||||
|
||||
// 检查JSON编码是否出错
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
echo 'JSON编码出错:' . json_last_error_msg();
|
||||
} else {
|
||||
// 输出JSON数据
|
||||
echo $json;
|
||||
}
|
||||
43
thinkphp6/天气.php
Normal file
43
thinkphp6/天气.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace app\controller;
|
||||
|
||||
use app\BaseController;
|
||||
use think\Request;
|
||||
|
||||
|
||||
class Weather extends BaseController
|
||||
{
|
||||
public function index(int $id = 101010100)
|
||||
{
|
||||
$url = "https://devapi.qweather.com/v7/weather/now?location=". $id ."&key=这里替换你的秘钥&gzip=n";
|
||||
$data = $this->get_request($url);
|
||||
// 数据返回
|
||||
return $data;
|
||||
}
|
||||
function post_request($url, $data = null)
|
||||
{
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
curl_setopt($curl, CURLOPT_ENCODING, "gzip"); // 添加此行以支持 gzip 解压缩
|
||||
$output = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
return $output;
|
||||
}
|
||||
function get_request($url)
|
||||
{
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
curl_setopt($curl, CURLOPT_ENCODING, "gzip"); // 添加此行以支持 gzip 解压缩
|
||||
$output = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
42
thinkphp6/待办.php
Normal file
42
thinkphp6/待办.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace app\controller;
|
||||
|
||||
use app\BaseController;
|
||||
|
||||
class Api extends Base
|
||||
{
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$servername = "你的数据库地址";
|
||||
$username = "root";
|
||||
$password = "数据库密码";
|
||||
$dbname = "todo";
|
||||
$data = array();
|
||||
|
||||
// 创建连接
|
||||
$conn =mysqli_connect($servername, $username, $password, $dbname);
|
||||
|
||||
// 检测连接
|
||||
$sql = "SELECT * FROM daiban";
|
||||
$result = $conn->query($sql);
|
||||
|
||||
if($result) {
|
||||
//echo "查询成功";
|
||||
$key = 0;
|
||||
while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
|
||||
// $user = new User();
|
||||
// $user->id = $row["id"];
|
||||
// $user->user = $row["user"];
|
||||
// $user->comment = $row["comment"];
|
||||
// $user->addtime = $row["addtime"];
|
||||
// $data[]=$user;
|
||||
$data[$key] = $row;
|
||||
$key++;
|
||||
}
|
||||
}
|
||||
return $this->api($data,'获取成功');
|
||||
}
|
||||
|
||||
}
|
||||
521
thinkphp6/日期.php
Normal file
521
thinkphp6/日期.php
Normal file
@@ -0,0 +1,521 @@
|
||||
<?php
|
||||
namespace app\controller;
|
||||
|
||||
// use app\model\Message as MessageModel;
|
||||
// use app\model\Article as ArticleModel;
|
||||
//use app\controller\Base;
|
||||
// use app\hdweb\model\Printlist as PrintlistModel;
|
||||
// use think\facade\Cookie;
|
||||
use app\BaseController;
|
||||
// use think\facade\View;
|
||||
// use think\Request;
|
||||
|
||||
|
||||
class Time extends Base
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
// 获取时间
|
||||
$data['time'] = date('Y-m-d H:i:s', time());
|
||||
$data['riqi'] = date('Y-m-d', time());
|
||||
$data['shijian'] = date('H:i:s', time());
|
||||
$data['nian'] = date('Y', time());
|
||||
$data['yue'] = date('m', time());
|
||||
$data['ri'] = date('j', time());
|
||||
$data['shi'] = date('H', time());
|
||||
$data['fen'] = date('i', time());
|
||||
$data['miao'] = date('s', time());
|
||||
// 获取星期
|
||||
$data['xingqi'] = $this->get_week($data['riqi']);
|
||||
// 获取农历
|
||||
$today= $this->convertSolarToLunar($data['nian'], $data['yue'], $data['ri']);
|
||||
$data['nongli'] = $today[1]."".$today[2];
|
||||
$data['shengxiao'] = '生肖'.$today[6];
|
||||
$data['ganzhi'] = $this->getLunarYearName($data['nian']).'年';
|
||||
// 获取时辰
|
||||
$data['shichen'] = $this->getTheHour($data['shi']);
|
||||
// 获取节气
|
||||
$data['jieqi'] = $this->getJieQi($data['nian'], $data['yue'], $data['ri']);
|
||||
// 数据组合
|
||||
// 示例-兔年二月三十
|
||||
$data['line1'] = $today[6].'年'.$data['nongli'];
|
||||
// 示例-2023年3月21日
|
||||
$data['line2'] = $data['nian']."年".date('n', time())."月".date('j', time())."日";
|
||||
// 示例-2023-03-21 星期二
|
||||
$data['line3'] = $data['riqi']." ".$data['xingqi'];
|
||||
// 示例-2023年3月21日 星期二
|
||||
$data['line4'] = $data['line2']." ".$data['xingqi'];
|
||||
// 示例-2023-03-21 星期二 兔年二月三十
|
||||
$data['line5'] = $data['riqi']." ".$data['xingqi']." ".$data['line1'];
|
||||
// 示例-09:48
|
||||
$data['line6'] = date('H:i', time());
|
||||
// 不带0的小时
|
||||
$data['line7'] = date('G', time());
|
||||
// 不带0的分钟
|
||||
$data['line8'] = preg_replace('/^0+/','', date('i', time()));
|
||||
if($data['line8'] == null){
|
||||
$data['line8'] = "0";
|
||||
}
|
||||
// 不带0的秒
|
||||
$data['line9'] = preg_replace('/^0+/','', date('s', time()));
|
||||
if($data['line9'] == null){
|
||||
$data['line9'] = "0";
|
||||
}
|
||||
// 示例-20230321094856
|
||||
$data['line10'] = date('YmdHis', time());
|
||||
// 示例-2023年3月
|
||||
$data['line11'] = $data['nian']."年".date('n', time())."月";
|
||||
// 数据返回
|
||||
return $this->api($data, '时间日期获取成功');
|
||||
}
|
||||
|
||||
public function get_week($date){
|
||||
//强制转换日期格式
|
||||
$date_str=date('Y-m-d',strtotime($date));
|
||||
//封装成数组
|
||||
$arr=explode("-", $date_str);
|
||||
//参数赋值
|
||||
//年
|
||||
$year=$arr[0];
|
||||
//月,输出2位整型,不够2位右对齐
|
||||
$month=sprintf('%02d',$arr[1]);
|
||||
//日,输出2位整型,不够2位右对齐
|
||||
$day=sprintf('%02d',$arr[2]);
|
||||
//时分秒默认赋值为0;
|
||||
$hour = $minute = $second = 0;
|
||||
//转换成时间戳
|
||||
$strap = mktime($hour,$minute,$second,$month,$day,$year);
|
||||
//获取数字型星期几
|
||||
$number_wk=date("w",$strap);
|
||||
//自定义星期数组
|
||||
$weekArr=array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
|
||||
//获取数字对应的星期
|
||||
return $weekArr[$number_wk];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function index2()
|
||||
{
|
||||
//示例代码:
|
||||
//$lunar=new Date();
|
||||
$today=$this->convertSolarToLunar(date('Y'),date('m'),date('d'));
|
||||
echo "今天是公元".date('Y')."年".date('m')."月".date('d')."日<br/>";
|
||||
echo "今天是农历".$today[0]."年".$today[1]."".$today[2]."农历".$today[3]."年".$today[4]."月".$today[5]."日".$today[6]."年<br/>";
|
||||
$month=$this->getJieQi(date('Y'),date('m'),date('d'));//获取当前节气
|
||||
echo "今天节气:".$month['name2'];
|
||||
}
|
||||
|
||||
public function returnDate()
|
||||
{
|
||||
$today=$this->convertSolarToLunar(date('Y'),date('m'),date('d'));
|
||||
return $today;
|
||||
}
|
||||
var $MIN_YEAR = 1891;
|
||||
var $MAX_YEAR = 2100;
|
||||
var $lunarInfo = array(
|
||||
array(0,2,9,21936),array(6,1,30,9656),array(0,2,17,9584),array(0,2,6,21168),array(5,1,26,43344),array(0,2,13,59728),
|
||||
array(0,2,2,27296),array(3,1,22,44368),array(0,2,10,43856),array(8,1,30,19304),array(0,2,19,19168),array(0,2,8,42352),
|
||||
array(5,1,29,21096),array(0,2,16,53856),array(0,2,4,55632),array(4,1,25,27304),array(0,2,13,22176),array(0,2,2,39632),
|
||||
array(2,1,22,19176),array(0,2,10,19168),array(6,1,30,42200),array(0,2,18,42192),array(0,2,6,53840),array(5,1,26,54568),
|
||||
array(0,2,14,46400),array(0,2,3,54944),array(2,1,23,38608),array(0,2,11,38320),array(7,2,1,18872),array(0,2,20,18800),
|
||||
array(0,2,8,42160),array(5,1,28,45656),array(0,2,16,27216),array(0,2,5,27968),array(4,1,24,44456),array(0,2,13,11104),
|
||||
array(0,2,2,38256),array(2,1,23,18808),array(0,2,10,18800),array(6,1,30,25776),array(0,2,17,54432),array(0,2,6,59984),
|
||||
array(5,1,26,27976),array(0,2,14,23248),array(0,2,4,11104),array(3,1,24,37744),array(0,2,11,37600),array(7,1,31,51560),
|
||||
array(0,2,19,51536),array(0,2,8,54432),array(6,1,27,55888),array(0,2,15,46416),array(0,2,5,22176),array(4,1,25,43736),
|
||||
array(0,2,13,9680),array(0,2,2,37584),array(2,1,22,51544),array(0,2,10,43344),array(7,1,29,46248),array(0,2,17,27808),
|
||||
array(0,2,6,46416),array(5,1,27,21928),array(0,2,14,19872),array(0,2,3,42416),array(3,1,24,21176),array(0,2,12,21168),
|
||||
array(8,1,31,43344),array(0,2,18,59728),array(0,2,8,27296),array(6,1,28,44368),array(0,2,15,43856),array(0,2,5,19296),
|
||||
array(4,1,25,42352),array(0,2,13,42352),array(0,2,2,21088),array(3,1,21,59696),array(0,2,9,55632),array(7,1,30,23208),
|
||||
array(0,2,17,22176),array(0,2,6,38608),array(5,1,27,19176),array(0,2,15,19152),array(0,2,3,42192),array(4,1,23,53864),
|
||||
array(0,2,11,53840),array(8,1,31,54568),array(0,2,18,46400),array(0,2,7,46752),array(6,1,28,38608),array(0,2,16,38320),
|
||||
array(0,2,5,18864),array(4,1,25,42168),array(0,2,13,42160),array(10,2,2,45656),array(0,2,20,27216),array(0,2,9,27968),
|
||||
array(6,1,29,44448),array(0,2,17,43872),array(0,2,6,38256),array(5,1,27,18808),array(0,2,15,18800),array(0,2,4,25776),
|
||||
array(3,1,23,27216),array(0,2,10,59984),array(8,1,31,27432),array(0,2,19,23232),array(0,2,7,43872),array(5,1,28,37736),
|
||||
array(0,2,16,37600),array(0,2,5,51552),array(4,1,24,54440),array(0,2,12,54432),array(0,2,1,55888),array(2,1,22,23208),
|
||||
array(0,2,9,22176),array(7,1,29,43736),array(0,2,18,9680),array(0,2,7,37584),array(5,1,26,51544),array(0,2,14,43344),
|
||||
array(0,2,3,46240),array(4,1,23,46416),array(0,2,10,44368),array(9,1,31,21928),array(0,2,19,19360),array(0,2,8,42416),
|
||||
array(6,1,28,21176),array(0,2,16,21168),array(0,2,5,43312),array(4,1,25,29864),array(0,2,12,27296),array(0,2,1,44368),
|
||||
array(2,1,22,19880),array(0,2,10,19296),array(6,1,29,42352),array(0,2,17,42208),array(0,2,6,53856),array(5,1,26,59696),
|
||||
array(0,2,13,54576),array(0,2,3,23200),array(3,1,23,27472),array(0,2,11,38608),array(11,1,31,19176),array(0,2,19,19152),
|
||||
array(0,2,8,42192),array(6,1,28,53848),array(0,2,15,53840),array(0,2,4,54560),array(5,1,24,55968),array(0,2,12,46496),
|
||||
array(0,2,1,22224),array(2,1,22,19160),array(0,2,10,18864),array(7,1,30,42168),array(0,2,17,42160),array(0,2,6,43600),
|
||||
array(5,1,26,46376),array(0,2,14,27936),array(0,2,2,44448),array(3,1,23,21936),array(0,2,11,37744),array(8,2,1,18808),
|
||||
array(0,2,19,18800),array(0,2,8,25776),array(6,1,28,27216),array(0,2,15,59984),array(0,2,4,27424),array(4,1,24,43872),
|
||||
array(0,2,12,43744),array(0,2,2,37600),array(3,1,21,51568),array(0,2,9,51552),array(7,1,29,54440),array(0,2,17,54432),
|
||||
array(0,2,5,55888),array(5,1,26,23208),array(0,2,14,22176),array(0,2,3,42704),array(4,1,23,21224),array(0,2,11,21200),
|
||||
array(8,1,31,43352),array(0,2,19,43344),array(0,2,7,46240),array(6,1,27,46416),array(0,2,15,44368),array(0,2,5,21920),
|
||||
array(4,1,24,42448),array(0,2,12,42416),array(0,2,2,21168),array(3,1,22,43320),array(0,2,9,26928),array(7,1,29,29336),
|
||||
array(0,2,17,27296),array(0,2,6,44368),array(5,1,26,19880),array(0,2,14,19296),array(0,2,3,42352),array(4,1,24,21104),
|
||||
array(0,2,10,53856),array(8,1,30,59696),array(0,2,18,54560),array(0,2,7,55968),array(6,1,27,27472),array(0,2,15,22224),
|
||||
array(0,2,5,19168),array(4,1,25,42216),array(0,2,12,42192),array(0,2,1,53584),array(2,1,21,55592),array(0,2,9,54560)
|
||||
);
|
||||
/**
|
||||
* 将阳历转换为阴历
|
||||
* @param year 公历-年
|
||||
* @param month 公历-月
|
||||
* @param date 公历-日
|
||||
*/
|
||||
function convertSolarToLunar($year,$month,$date)
|
||||
{
|
||||
//debugger;
|
||||
$yearData = $this->lunarInfo[$year-$this->MIN_YEAR];
|
||||
if($year==$this->MIN_YEAR&&$month<=2&&$date<=9) return array(1891,'正月','初一','辛卯',1,1,'兔');
|
||||
return $this->getLunarByBetween($year,$this->getDaysBetweenSolar($year,$month,$date,$yearData[1],$yearData[2]));
|
||||
}
|
||||
function convertSolarMonthToLunar($year,$month)
|
||||
{
|
||||
$yearData = $this->lunarInfo[$year-$this->MIN_YEAR];
|
||||
if($year==$this->MIN_YEAR&&$month<=2&&$date<=9) return array(1891,'正月','初一','辛卯',1,1,'兔');
|
||||
$month_days_ary = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
|
||||
$dd = $month_days_ary[$month];
|
||||
if($this->isLeapYear($year) && $month == 2) $dd++;
|
||||
$lunar_ary = array();
|
||||
for ($i = 1; $i < $dd; $i++)
|
||||
{
|
||||
$array = $this->getLunarByBetween($year,$this->getDaysBetweenSolar($year, $month, $i, $yearData[1], $yearData[2]));
|
||||
$array[] = $year . '-' . $month . '-' . $i;
|
||||
$lunar_ary[$i] = $array;
|
||||
}
|
||||
return $lunar_ary;
|
||||
}
|
||||
/**
|
||||
* 将阴历转换为阳历
|
||||
* @param year 阴历-年
|
||||
* @param month 阴历-月,闰月处理:例如如果当年闰五月,那么第二个五月就传六月,相当于阴历有13个月,只是有的时候第13个月的天数为0
|
||||
* @param date 阴历-日
|
||||
*/
|
||||
function convertLunarToSolar($year,$month,$date)
|
||||
{
|
||||
$yearData = $this->lunarInfo[$year-$this->MIN_YEAR];
|
||||
$between = $this->getDaysBetweenLunar($year,$month,$date);
|
||||
$res = mktime(0,0,0,$yearData[1],$yearData[2],$year);
|
||||
$res = date('Y-m-d', $res+$between*24*60*60);
|
||||
$day = explode('-', $res);
|
||||
$year = $day[0];
|
||||
$month= $day[1];
|
||||
$day = $day[2];
|
||||
return array($year, $month, $day);
|
||||
}
|
||||
/**
|
||||
* 判断是否是闰年
|
||||
* @param year
|
||||
*/
|
||||
function isLeapYear($year)
|
||||
{
|
||||
return (($year%4==0 && $year%100 !=0) || ($year%400==0));
|
||||
}
|
||||
/**
|
||||
* 获取干支纪年
|
||||
* @param year
|
||||
*/
|
||||
function getLunarYearName($year)
|
||||
{
|
||||
$sky = array('庚','辛','壬','癸','甲','乙','丙','丁','戊','己');
|
||||
$earth = array('申','酉','戌','亥','子','丑','寅','卯','辰','巳','午','未');
|
||||
$year = $year.'';
|
||||
return $sky[$year[3]].$earth[$year%12];
|
||||
}
|
||||
/**
|
||||
* 根据阴历年获取生肖
|
||||
* @param year 阴历年
|
||||
*/
|
||||
function getYearZodiac($year)
|
||||
{
|
||||
$zodiac = array('猴','鸡','狗','猪','鼠','牛','虎','兔','龙','蛇','马','羊');
|
||||
return $zodiac[$year%12];
|
||||
}
|
||||
/**
|
||||
* 获取阳历月份的天数
|
||||
* @param year 阳历-年
|
||||
* @param month 阳历-月
|
||||
*/
|
||||
function getSolarMonthDays($year,$month)
|
||||
{
|
||||
$monthHash = array('1'=>31,'2'=>$this->isLeapYear($year)?29:28,'3'=>31,'4'=>30,'5'=>31,'6'=>30,'7'=>31,'8'=>31,'9'=>30,'10'=>31,'11'=>30,'12'=>31);
|
||||
return $monthHash["$month"];
|
||||
}
|
||||
/**
|
||||
* 获取阴历月份的天数
|
||||
* @param year 阴历-年
|
||||
* @param month 阴历-月,从一月开始
|
||||
*/
|
||||
function getLunarMonthDays($year,$month)
|
||||
{
|
||||
$monthData = $this->getLunarMonths($year);
|
||||
return $monthData[$month-1];
|
||||
}
|
||||
/**
|
||||
* 获取阴历每月的天数的数组
|
||||
* @param year
|
||||
*/
|
||||
function getLunarMonths($year)
|
||||
{
|
||||
$yearData = $this->lunarInfo[$year - $this->MIN_YEAR];
|
||||
$leapMonth = $yearData[0];
|
||||
$bit = decbin($yearData[3]);
|
||||
for ($i = 0; $i < strlen($bit);$i ++) $bitArray[$i] = substr($bit, $i, 1);
|
||||
for($k=0,$klen=16-count($bitArray);$k<$klen;$k++) array_unshift($bitArray, '0');
|
||||
$bitArray = array_slice($bitArray,0,($leapMonth==0?12:13));
|
||||
for($i=0; $i<count($bitArray); $i++) $bitArray[$i] = $bitArray[$i] + 29;
|
||||
return $bitArray;
|
||||
}
|
||||
/**
|
||||
* 获取农历每年的天数
|
||||
* @param year 农历年份
|
||||
*/
|
||||
function getLunarYearDays($year)
|
||||
{
|
||||
$yearData = $this->lunarInfo[$year-$this->MIN_YEAR];
|
||||
$monthArray = $this->getLunarYearMonths($year);
|
||||
$len = count($monthArray);
|
||||
return ($monthArray[$len-1]==0?$monthArray[$len-2]:$monthArray[$len-1]);
|
||||
}
|
||||
function getLunarYearMonths($year)
|
||||
{
|
||||
//debugger;
|
||||
$monthData = $this->getLunarMonths($year);
|
||||
$res=array();
|
||||
$temp=0;
|
||||
$yearData = $this->lunarInfo[$year-$this->MIN_YEAR];
|
||||
$len = ($yearData[0]==0?12:13);
|
||||
for($i=0;$i<$len;$i++)
|
||||
{
|
||||
$temp=0;
|
||||
for($j=0;$j<=$i;$j++) $temp+=$monthData[$j];
|
||||
array_push($res, $temp);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
/**
|
||||
* 获取闰月
|
||||
* @param year 阴历年份
|
||||
*/
|
||||
function getLeapMonth($year)
|
||||
{
|
||||
$yearData = $this->lunarInfo[$year-$this->MIN_YEAR];
|
||||
return $yearData[0];
|
||||
}
|
||||
/**
|
||||
* 计算阴历日期与正月初一相隔的天数
|
||||
* @param year
|
||||
* @param month
|
||||
* @param date
|
||||
*/
|
||||
function getDaysBetweenLunar($year,$month,$date)
|
||||
{
|
||||
$yearMonth = $this->getLunarMonths($year);
|
||||
$res=0;
|
||||
for($i=1;$i<$month;$i++) $res +=$yearMonth[$i-1];
|
||||
$res+=$date-1;
|
||||
return $res;
|
||||
}
|
||||
/**
|
||||
* 计算2个阳历日期之间的天数
|
||||
* @param year 阳历年
|
||||
* @param cmonth
|
||||
* @param cdate
|
||||
* @param dmonth 阴历正月对应的阳历月份
|
||||
* @param ddate 阴历初一对应的阳历天数
|
||||
*/
|
||||
function getDaysBetweenSolar($year,$cmonth,$cdate,$dmonth,$ddate)
|
||||
{
|
||||
$a = mktime(0,0,0,$cmonth,$cdate,$year);
|
||||
$b = mktime(0,0,0,$dmonth,$ddate,$year);
|
||||
return ceil(($a-$b)/24/3600);
|
||||
}
|
||||
/**
|
||||
* 根据距离正月初一的天数计算阴历日期
|
||||
* @param year 阳历年
|
||||
* @param between 天数
|
||||
*/
|
||||
function getLunarByBetween($year,$between)
|
||||
{
|
||||
//debugger;
|
||||
$lunarArray = array();
|
||||
$yearMonth=array();
|
||||
$t=0;
|
||||
$e=0;
|
||||
$leapMonth=0;
|
||||
$m='';
|
||||
if($between==0)
|
||||
{
|
||||
array_push($lunarArray, $year,'正月','初一');
|
||||
$t = 1;
|
||||
$e = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$year = $between>0? $year : ($year-1);
|
||||
$yearMonth = $this->getLunarYearMonths($year);
|
||||
$leapMonth = $this->getLeapMonth($year);
|
||||
$between = $between>0?$between : ($this->getLunarYearDays($year)+$between);
|
||||
for($i=0;$i<13;$i++)
|
||||
{
|
||||
if($between==$yearMonth[$i])
|
||||
{
|
||||
$t=$i+2;
|
||||
$e=1;
|
||||
break;
|
||||
}else if($between<$yearMonth[$i])
|
||||
{
|
||||
$t=$i+1;
|
||||
$e=$between-(empty($yearMonth[$i-1])?0:$yearMonth[$i-1])+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$m = ($leapMonth!=0&&$t==$leapMonth+1)?('闰'.$this->getCapitalNum($t- 1,true)):$this->getCapitalNum(($leapMonth!=0&&$leapMonth+1<$t?($t-1):$t),true);
|
||||
array_push($lunarArray,$year,$m,$this->getCapitalNum($e,false));
|
||||
}
|
||||
array_push($lunarArray,$this->getLunarYearName($year));// 天干地支
|
||||
array_push($lunarArray,$t,$e);
|
||||
array_push($lunarArray,$this->getYearZodiac($year));// 12生肖
|
||||
array_push($lunarArray,$leapMonth);// 闰几月
|
||||
return $lunarArray;
|
||||
}
|
||||
/**
|
||||
* 获取数字的阴历叫法
|
||||
* @param num 数字
|
||||
* @param isMonth 是否是月份的数字
|
||||
*/
|
||||
function getCapitalNum($num,$isMonth)
|
||||
{
|
||||
$isMonth = $isMonth || false;
|
||||
$dateHash=array('0'=>'','1'=>'一','2'=>'二','3'=>'三','4'=>'四','5'=>'五','6'=>'六','7'=>'七','8'=>'八','9'=>'九','10'=>'十 ');
|
||||
$monthHash=array('0'=>'','1'=>'正月','2'=>'二月','3'=>'三月','4'=>'四月','5'=>'五月','6'=>'六月','7'=>'七月','8'=>'八月','9'=>'九月','10'=>'十月','11'=>'十一月','12'=>'腊月');
|
||||
$res='';
|
||||
if($isMonth) $res = $monthHash[$num];
|
||||
else
|
||||
{
|
||||
if($num<=10) $res = '初'.$dateHash[$num];
|
||||
else if($num>10&&$num<20) $res = '十'.$dateHash[$num-10];
|
||||
else if($num==20) $res = "二十";
|
||||
else if($num>20&&$num<30) $res = "廿".$dateHash[$num-20];
|
||||
else if($num==30) $res = "三十";
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
/*
|
||||
* 节气通用算法
|
||||
*/
|
||||
function getJieQi($_year,$month,$day)
|
||||
{
|
||||
$year = substr($_year,-2)+0;
|
||||
$coefficient = array(
|
||||
array(5.4055,2019,-1),//小寒
|
||||
array(20.12,2082,1),//大寒
|
||||
array(3.87),//立春
|
||||
array(18.74,2026,-1),//雨水
|
||||
array(5.63),//惊蛰
|
||||
array(20.646,2084,1),//春分
|
||||
array(4.81),//清明
|
||||
array(20.1),//谷雨
|
||||
array(5.52,1911,1),//立夏
|
||||
array(21.04,2008,1),//小满
|
||||
array(5.678,1902,1),//芒种
|
||||
array(21.37,1928,1),//夏至
|
||||
array(7.108,2016,1),//小暑
|
||||
array(22.83,1922,1),//大暑
|
||||
array(7.5,2002,1),//立秋
|
||||
array(23.13),//处暑
|
||||
array(7.646,1927,1),//白露
|
||||
array(23.042,1942,1),//秋分
|
||||
array(8.318),//寒露
|
||||
array(23.438,2089,1),//霜降
|
||||
array(7.438,2089,1),//立冬
|
||||
array(22.36,1978,1),//小雪
|
||||
array(7.18,1954,1),//大雪
|
||||
array(21.94,2021,-1)//冬至
|
||||
);
|
||||
$term_name = array(
|
||||
"小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨",
|
||||
"立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑",
|
||||
"白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至");
|
||||
$idx1 = ($month-1)*2;
|
||||
$_leap_value = floor(($year-1)/4);
|
||||
$day1 = floor($year*0.2422+$coefficient[$idx1][0])-$_leap_value;
|
||||
if(isset($coefficient[$idx1][1])&&$coefficient[$idx1][1]==$_year) $day1 += $coefficient[$idx1][2];
|
||||
$day2 = floor($year*0.2422+$coefficient[$idx1+1][0])-$_leap_value;
|
||||
if(isset($coefficient[$idx1+1][1])&&$coefficient[$idx1+1][1]==$_year) $day1 += $coefficient[$idx1+1][2];
|
||||
//echo __FILE__.'->'.__LINE__.' $day1='.$day1,',$day2='.$day2.'<br/>'.chr(10);
|
||||
$data=array();
|
||||
if($day<$day1){
|
||||
$data['name1']=$term_name[$idx1-1];
|
||||
$data['name2']=$term_name[$idx1-1].'后';
|
||||
}else if($day==$day1){
|
||||
$data['name1']=$term_name[$idx1];
|
||||
$data['name2']=$term_name[$idx1];
|
||||
}else if($day>$day1 && $day<$day2){
|
||||
$data['name1']=$term_name[$idx1];
|
||||
$data['name2']=$term_name[$idx1].'后';
|
||||
}else if($day==$day2){
|
||||
$data['name1']=$term_name[$idx1+1];
|
||||
$data['name2']=$term_name[$idx1+1];
|
||||
}else if($day>$day2){
|
||||
$data['name1']=$term_name[$idx1+1];
|
||||
$data['name2']=$term_name[$idx1+1].'后';
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
/*
|
||||
* 获取节日:特殊的节日只能修改此函数来计算
|
||||
*/
|
||||
function getFestival($today, $nl_info = false,$config = 1)
|
||||
{
|
||||
if($config == 1)
|
||||
{
|
||||
$arr_lunar=array('01-01'=>'春节','01-15'=>'元宵节','02-02'=>'二月二','05-05'=>'端午节','07-07'=>'七夕节','08-15'=>'中秋节','09-09'=>'重阳节','12-08'=>'腊八节','12-23'=>'小年');
|
||||
$arr_solar=array('01-01'=>'元旦','02-14'=>'情人节','03-12'=>'植树节','04-01'=>'愚人节','05-01'=>'劳动节','06-01'=>'儿童节','10-01'=>'国庆节','10-31'=>'万圣节','12-24'=>'平安夜','12-25'=>'圣诞节');
|
||||
}//需要不同节日的,用不同的$config,然后配置$arr_lunar和$arr_solar
|
||||
$festivals = array();
|
||||
list($y,$m,$d) = explode('-',$today);
|
||||
if(!$nl_info) $nl_info = $this->convertSolarToLunar($y,intval($m),intval($d));
|
||||
if($nl_info[7]>0&&$nl_info[7]<$nl_info[4]) $nl_info[4]-=1;
|
||||
$md_lunar = substr('0'.$nl_info[4],-2).'-'.substr('0'.$nl_info[5],-2);
|
||||
$md_solar=substr_replace($today,'',0,5);
|
||||
isset($arr_lunar[$md_lunar])?array_push($festivals, $arr_lunar[$md_lunar]):'';
|
||||
isset($arr_solar[$md_solar])?array_push($festivals, $arr_solar[$md_solar]):'';
|
||||
$glweek = date("w",strtotime($today)); //0-6
|
||||
if($m==5&&($d>7)&&($d<15)&&($glweek==0))array_push($festivals, "母亲节");
|
||||
if($m==6&&($d>14)&&($d<22)&&($glweek==0))array_push($festivals,"父亲节");
|
||||
$jieqi = $this->getJieQi($y,$m,$d);
|
||||
if($jieqi)array_push($festivals,$jieqi);
|
||||
return implode('/',$festivals);
|
||||
}
|
||||
/*
|
||||
* 获取当前时间属于哪个时辰
|
||||
@param int $time 时间戳
|
||||
*/
|
||||
function getTheHour($h){
|
||||
$d=$h;
|
||||
if($d==23 || $d==0){
|
||||
return '子时';
|
||||
}else if($d==1 || $d==2){
|
||||
return '丑时';
|
||||
}else if($d==3 || $d==4){
|
||||
return '寅时';
|
||||
}else if($d==5 || $d==6){
|
||||
return '卯时';
|
||||
}else if($d==7 || $d==8){
|
||||
return '辰时';
|
||||
}else if($d==9 || $d==10){
|
||||
return '巳时';
|
||||
}else if($d==11 || $d==12){
|
||||
return '午时';
|
||||
}else if($d==13 || $d==14){
|
||||
return '未时';
|
||||
}else if($d==15 || $d==16){
|
||||
return '申时';
|
||||
}else if($d==17 || $d==18){
|
||||
return '酉时';
|
||||
}else if($d==19 || $d==20){
|
||||
return '戌时';
|
||||
}else if($d==21 || $d==22){
|
||||
return '亥时';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user