feat: 全量同步 254 个常用的 Arduino 扩展库文件

This commit is contained in:
yczpf2019
2026-01-24 16:05:38 +08:00
parent c665ba662b
commit 397b9a23a3
6878 changed files with 2732224 additions and 1 deletions

View File

@@ -0,0 +1,112 @@
#ifndef _URLCODE_CPP_
#define _URLCODE_CPP_
#include "URLCode.h"
int URLCode :: hex2dec(char c){
if ('0' <= c && c <= '9')
{
return c - '0';
}
else if ('a' <= c && c <= 'f')
{
return c - 'a' + 10;
}
else if ('A' <= c && c <= 'F')
{
return c - 'A' + 10;
}
else
{
return -1;
}
}
char URLCode :: dec2hex(short int c)
{
if (0 <= c && c <= 9)
{
return c + '0';
}
else if (10 <= c && c <= 15)
{
return c + 'A' - 10;
}
else
{
return -1;
}
}
// Chinese 编码一个url
// English Encode URLCode
void URLCode :: urlencode()
{
urlcode = "";
int i = 0;
int len = strcode.length();
for (i = 0; i < len; ++i)
{
wdtFeed();
char c = strcode[i];
if ( ('0' <= c && c <= '9') ||
('a' <= c && c <= 'z') ||
('A' <= c && c <= 'Z') ||
c == '/' || c == '.')
{
urlcode += String(c);
}
else
{
int j = (short int)c;
if (j < 0)
j += 256;
int i1, i0;
i1 = j / 16;
i0 = j - i1 * 16;
urlcode += String('%');
urlcode += String((char)dec2hex(i1));
urlcode += String((char)dec2hex(i0));
}
}
}
// Chinese 解码url
// English Decode URLCode
void URLCode :: urldecode()
{
strcode = "";
int i = 0;
int len = urlcode.length();
for (i = 0; i < len; ++i)
{
wdtFeed();
char c = urlcode[i];
if (c != '%') {
strcode += String(c);
} else {
char c1 = urlcode[++i];
char c0 = urlcode[++i];
int num = 0;
num = hex2dec(c1) * 16 + hex2dec(c0);
strcode += String((char)num);
}
}
}
// Chinese 喂看门狗
// English Feed Watchdog)
void URLCode :: wdtFeed(){
// 喂看门狗代码 如果需要解码的URL太过长会导致芯片以为运行出错所以需要进行喂狗
// 如果是 ESP8266 只需要 #define ESP8266 即可 其他芯片的喂狗代码请自行添加
#ifdef ESP8266
ESP.wdtFeed();
#endif
}
#endif

View File

@@ -0,0 +1,44 @@
/*****************************************************************************
File name: URLCode.h
Description: 适用于Arduino的URL编码解码
Author: Mr.Xie
Version: 1.0.0
Date: 2022/08/17
History:
* 0.1.0 测试版
* 1.0.0 增加了看门狗代码补充模块
修改了 0.1.0 版本中 URLCode :: urlencode() 的部分错误
给#include "URLCode.cpp" 打上了注释 防止重复调用
*****************************************************************************/
#ifndef _URLCODE_H_
#define _URLCODE_H_
#include <Arduino.h>
#include <String.h>
class URLCode{
private:
char dec2hex(short int c);
int hex2dec(char c);
public:
String urlcode; // URL 编码后
String strcode; // URL 编码前
void urlencode(); // 编码URL
void urldecode(); // 解码URL
void wdtFeed(); // 喂看门狗
};
//如果你不是直接下载到库里而是复制到某个文件夹内报错URLCode里面的函数没有定义的话去掉下面这一行的注释
//#include "URLCode.cpp"
#endif