6 Star 20 Fork 2

FredyXu / CW_ESP8266_SSD1306_I2C_4PIN

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
op_code.h 2.69 KB
Copy Edit Web IDE Raw Blame History
FredyXu authored 2020-01-04 20:51 . 修正显示内容
#ifndef _OP_CODE_H
#define _OP_CODE_H
// 函数声明
// 识别字符
bool check_code(String code, int to);
// 识别字符
void check_letter();
// 播放电码
void play_code(String p_code);
// 识别字符
void check_letter()
{
// 如果输入字符检查标识开启,则检查字符
if (flag_letter == 1)
{
int diff_letter = millis() - cs_time;
if ((s_key_type && diff_letter > u_time * 1 && key_code != "") || (!s_key_type && diff_letter > u_time * 0.6 && key_code != ""))
{
cs_time = millis();
send_code += " ";
check_code(key_code, 1);
key_code = "";
flag_letter = 0;
// 检查空格标识开启
flag_space = 1;
}
}
// 空格检查
if (flag_space == 1)
{
int diff_space = millis() - cs_time;
if (diff_space > u_time * 3)
{
// 加上分割用的空格
send_code += " ";
d_text_code += " ";
d_text_letter += " ";
flag_d_ref = 1;
flag_space = 0;
flag_send = 1;
cs_time = millis();
}
}
}
// 将莫尔斯电码翻译为字符
// 1 是自己输入
// 0 是接收来的
bool check_code(String code, int to)
{
for (int i = 0; i < arr_len; i++)
{
if (code == c[i])
{
Serial.print(w[i]);
Serial.print(" ");
// 在显示屏上显示
if (to == 1)
{
d_text_letter += w[i];
d_text_code += " ";
}
else if (to == 0)
{
d_text_rec_letter += w[i];
// d_text_rec_letter += " ";
}
return true;
}
}
Serial.print("*");
if (to == 1)
{
d_text_letter += "*";
d_text_code += " ";
}
else if (to == 0)
{
d_text_rec_letter += "*";
d_text_rec_code += " ";
}
return false;
}
// 播放电码
void play_code(String p_code)
{
String rcd_code = "";
// 连续空格记录
bool sp_rcd = false;
for (int i = 0; i < p_code.length(); i++)
{
if (p_code[i] == '.')
{
bee(true);
int s = millis();
sp_rcd = false;
d_home_update("rec_code", ".");
delay(play_u_time - (millis() - s));
bee(false);
delay(play_u_time * 0.2);
rcd_code += p_code[i];
}
else if (p_code[i] == '-')
{
bee(true);
int s = millis();
sp_rcd = false;
d_home_update("rec_code", "-");
delay(play_u_time * 2 - (millis() - s));
bee(false);
delay(play_u_time * 0.2);
rcd_code += p_code[i];
}
else if (p_code[i] == ' ')
{
int s = millis();
if(sp_rcd == true) {
d_text_rec_letter += ' ';
}
sp_rcd = true;
d_text_rec_code += ' ';
if (rcd_code != "" && s_show_code)
{
check_code(rcd_code, 0);
}
d_home_ref();
delay(play_u_time - (millis() - s));
rcd_code = "";
}
// 将最后一个代码也送去播放
if (i == p_code.length() - 1 && rcd_code != "" && s_show_code)
{
check_code(rcd_code, 0);
rcd_code = "";
}
}
Serial.println();
}
#endif

Comment ( 0 )

Sign in for post a comment

C
1
https://gitee.com/FredyXu/cw_esp8266_ssd1306_i2c_4pin.git
git@gitee.com:FredyXu/cw_esp8266_ssd1306_i2c_4pin.git
FredyXu
cw_esp8266_ssd1306_i2c_4pin
CW_ESP8266_SSD1306_I2C_4PIN
master

Search

103611 48b8ff67 1899542 103622 4d02230c 1899542