first commit

This commit is contained in:
2026-07-13 17:18:22 +08:00
commit 895928440b
42 changed files with 6505 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

7
HH3.csv Normal file
View File

@ -0,0 +1,7 @@
; # Name, Type, SubType, Offset, Size
; nvs, data, nvs, 0x9000, 0x8000
; otadata, data, ota, 0x11000, 0x2000
; phy_init, data, phy, 0x13000, 0x1000
; app0, app, ota_0, 0x14000, 0x300000
; app1, app, ota_1, 0x314000, 0x300000
; spiffs, data, spiffs, 0x614000, 0x700000
1 ; # Name Type SubType Offset Size
2 ; nvs data nvs 0x9000 0x8000
3 ; otadata data ota 0x11000 0x2000
4 ; phy_init data phy 0x13000 0x1000
5 ; app0 app ota_0 0x14000 0x300000
6 ; app1 app ota_1 0x314000 0x300000
7 ; spiffs data spiffs 0x614000 0x700000

81
platformio.ini Normal file
View File

@ -0,0 +1,81 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32-s3-devkitc-1]
#platform = espressif32
platform = espressif32 @ 6.5.0
board = esp32-s3-devkitc-1
framework = arduino
platform_packages = toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
board_build.arduino.memory_type = qio_opi
board_build.psram = enabled
board_upload.psram_size = 8MB
board_upload.flash_size = 16MB
; usb 调试
; board_build.embed_usb_device = true
board_build.embed_usb_device = true
board_build.embed_usb_serial_jtag = true
build_flags = -D LV_LVGL_H_INCLUDE_SIMPLE
-DBOARD_HAS_PSRAM
; -DCONFIG_USB_HOST_ENABLED
; -DCONFIG_USB_UVC_ENABLED
; ; usb 调试
-DARDUINO_USB_CDC_ON_BOOT=1
-DARDUINO_USB_MODE=1
lib_deps =
; knolleary/PubSubClient@^2.8
; arduino-libraries/ArduinoHttpClient@^0.4.0
; bblanchon/ArduinoJson@^6.20.1
; ; lvgl/lvgl@8.4.0
; esphome/ESP32-audioI2S @ ^2.0.7
; tamctec/TAMC_GT911 @ ^1.0.2
; esp-arduino-libs/ESP32_USB_STREAM @ ^0.0.1
; adafruit/RTClib @ ^2.1.4
; enjoyneering/AHT10 @ ^1.1.0
; bodmer/TJpg_Decoder @ 1.1.0
; ; pio run --target uploadfs
; ; debug_port=esp-builtin
monitor_filters = esp32_exception_decoder
monitor_speed = 921600
; # Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
; # Name, Type, SubType, Offset, Size, Flags
; nvs, data, nvs, 0x9000, 24k
; phy_init, data, phy, 0xf000, 4k
; factory, app, factory, , 8M
; storage, data, spiffs, , 3M
; # Name, Type, SubType, Offset, Size
; nvs, data, nvs, 0x9000, 0x8000
; otadata, data, ota, 0x11000, 0x2000
; phy_init, data, phy, 0x13000, 0x1000
; app0, app, ota_0, 0x14000, 0x300000
; app1, app, ota_1, 0x314000, 0x300000
; spiffs, data, spiffs, 0x614000, 0x700000

View File

@ -0,0 +1,23 @@
{
"folders": [
{
"path": ".."
}
],
"settings": {
"files.associations": {
"widgets_init.h": "c",
"main.h": "c",
"mymain.h": "c",
"speak.h": "c",
"ds1307.h": "c",
"audio.h": "c",
"gui_guider.h": "c",
"lvgl.h": "c",
"header.h": "c",
"custom.h": "c",
"aht10.h": "c",
"arduino.h": "c"
}
}
}

174
src/IRIS_Method.cpp Normal file
View File

@ -0,0 +1,174 @@
/**
******************************************************************************
* @file : IRIS_Method.c
* @author : xin
* @brief : None
* @attention : None
* @date : 2024/2/1
******************************************************************************
*/
//
// Created by xin on 2024/2/1.
//
#include "IRIS_Method.h"
int32_t IRIS_Protocol_Pack(uint8_t Command, uint16_t LenthofIn, uint8_t *BufferIn, uint8_t *PackData) {
if (PackData == NULL || (LenthofIn != 0 && BufferIn == NULL)) {
return -1;
}
PackData[0] = 0x55;
PackData[1] = 0xAA;
PackData[2] = Command;
uint16_t datalenth = LenthofIn;
PackData[3] = (datalenth >> 8) & 0xFF;
PackData[4] = datalenth & 0xFF;
if (LenthofIn != 0) {
memcpy(&PackData[5], BufferIn, LenthofIn);
}
uint16_t crcbytelenth = LenthofIn;
uint16_t CRC = IRIS_calcCRC(PackData + 5, crcbytelenth);
PackData[LenthofIn + 5] = (CRC >> 8) & 0xFF;
PackData[LenthofIn + 6] = CRC & 0xFF;
return LenthofIn + 7;
}
int32_t IRIS_STM32_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t *Command, uint8_t *BufferOut) {
if (PackData == NULL || BufferOut == NULL) {
return ERROR_INPUT;
}
if (PackData[0] != 0x55 || PackData[1] != 0xAA) {
return ERROR_HEADER;
}
uint16_t LenthofOut = PackData[4] + (PackData[3] << 8); //减去CRC的两个字节
if (LenthofOut > LenthofIn - 7) {
return ERROR_NOT_ENOUGH_DATA;
}
if (PackData[LenthofOut + 6] == 0xEE && PackData[LenthofOut + 5] == 0xEE) {
} else {
uint16_t CRC = IRIS_calcCRC(PackData + 5, LenthofOut);
if (CRC != (PackData[LenthofOut + 6] + (PackData[LenthofOut + 5] << 8))) {
return ERROR_CRC;
}
}
if (LenthofOut == 0) {
return 0;
}
*Command = PackData[2];
memcpy(BufferOut, &PackData[5], LenthofOut);
return LenthofOut;
}
int32_t IRIS_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t Command, uint8_t *BufferOut) {
if (PackData == NULL || BufferOut == NULL) {
return ERROR_INPUT;
}
if (PackData[0] != 0x55 || PackData[1] != 0xAA) {
return ERROR_HEADER;
}
if (PackData[2] != Command) {
return ERROR_COMMAND;
}
uint16_t LenthofOut = PackData[4] + (PackData[3] << 8);
if (LenthofOut > LenthofIn - 7) {
return ERROR_NOT_ENOUGH_DATA;
}
if (PackData[LenthofOut + 6] == 0xEE && PackData[LenthofOut + 5] == 0xEE) {
} else {
uint16_t CRC = IRIS_calcCRC(PackData + 5, LenthofOut);
if (CRC != (PackData[LenthofOut + 6] + (PackData[LenthofOut + 5] << 8))) {
return ERROR_CRC;
}
}
if (LenthofOut == 0) {
return 0;
}
memcpy(BufferOut, &PackData[5], LenthofOut);
return LenthofOut;
}
int32_t IRIS_Cut_Befor_Header(uint8_t *PackData, uint16_t LenthofIn) {
if (PackData == NULL) {
return ERROR_INPUT;
}
uint16_t i = 0;
for (i = 0; i < LenthofIn; i++) {
if (PackData[i] == 0x55 && PackData[i + 1] == 0xAA) {
break;
}
}
if (i == LenthofIn) {
//清空数据
memset(PackData, 0, LenthofIn);
return 0;
}
uint16_t LenthofOut = LenthofIn - i;
memcpy(PackData, &PackData[i], LenthofOut);
return LenthofOut;
}
int32_t IRIS_Check_Data_Valid(uint8_t *PackData, uint16_t LenthofIn) {
if (PackData == NULL) {
return ERROR_INPUT;
}
if (LenthofIn < 7) {
return ERROR_NOT_ENOUGH_DATA;
/* code */
}
if (PackData[0] != 0x55 || PackData[1] != 0xAA) {
return ERROR_HEADER;
}
uint16_t LenthofOut = PackData[4] + (PackData[3] << 8);
if (LenthofOut > LenthofIn - 7) {
return ERROR_NOT_ENOUGH_DATA;
}
if (PackData[LenthofOut + 6] == 0xEE && PackData[LenthofOut + 5] == 0xEE) {
} else {
uint16_t CRC = IRIS_calcCRC(PackData + 5, LenthofOut);
if (CRC != (PackData[LenthofOut + 6] + (PackData[LenthofOut + 5] << 8))) {
return ERROR_CRC;
}
}
return 1;
}
uint16_t IRIS_calcCRC(const void *pBuffer, uint16_t bufferSize) {
const uint8_t *pBytesArray = (const uint8_t *) pBuffer;
uint16_t poly = 0x8408;
uint16_t crc = 0;
uint8_t carry;
uint8_t i_bits;
uint16_t j;
for (j = 0; j < bufferSize; j++) {
crc = crc ^ pBytesArray[j];
for (i_bits = 0; i_bits < 8; i_bits++) {
carry = crc & 1;
crc = crc / 2;
if (carry) {
crc = crc ^ poly;
}
}
}
return crc;
}

60
src/IRIS_Method.h Normal file
View File

@ -0,0 +1,60 @@
/**
******************************************************************************
* @file : IRIS_Method.h
* @author : xin
* @brief : None
* @attention : None
* @date : 2024/2/1
******************************************************************************
*/
//
// Created by xin on 2024/2/1.
//
#ifndef IRIS_COMMUNICATION_PROTOCOL_IRIS_METHOD_H
#define IRIS_COMMUNICATION_PROTOCOL_IRIS_METHOD_H
#define ERROR_NOT_ENOUGH_DATA -200
#define ERROR_HEADER -300
#define ERROR_COMMAND -400
#define ERROR_INPUT -500
#define ERROR_CRC -600
#include <stdint.h>
#include<Arduino.h>
// 成功返回打包后的数据长度
// -1: Error
// 成功返回打包后的数据长度
int32_t IRIS_Protocol_Pack(uint8_t Command,uint16_t LenthofIn, uint8_t *BufferIn, uint8_t *PackData);
// 解包函数 PackData 是接收到的数据 LenthofIn 是数据长度 Command 是命令 BufferOut 是输出
// 下位机使用的打包函数 Command 是输出
// 成功返回解包后的数据长度
// 0: 该命令返回无参数
// 错误返回ERRor
// 成功返回解包后的数据长度
int32_t IRIS_STM32_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t *Command, uint8_t *BufferOut);
// 解包函数 PackData 是接收到的数据 LenthofIn 是数据长度 Command 是命令输入 BufferOut 是输出 上位机使用
// 成功返回解包后的数据长度
// 0: 该命令返回无参数
// 错误返回ERRor
// 成功返回解包后的数据长度
int32_t IRIS_Protocol_Unpack(uint8_t *PackData, uint16_t LenthofIn, uint8_t Command, uint8_t *BufferOut);
// 定义裁切命令
// 成功返回裁切后的数据长度
// -1: Error
int32_t IRIS_Cut_Befor_Header(uint8_t *PackData, uint16_t LenthofIn );
// 检查数据是否有效
// 有效返回值1
// 错误返回ERRor
int32_t IRIS_Check_Data_Valid(uint8_t *PackData, uint16_t LenthofIn );
// 返回CRC校验值
uint16_t IRIS_calcCRC(const void *pBuffer, uint16_t bufferSize);
#endif //IRIS_COMMUNICATION_PROTOCOL_IRIS_METHOD_H

547
src/IS3.cpp Normal file
View File

@ -0,0 +1,547 @@
#include "IS3.h"
#define IS3_usart_port 1
#define IS3_TX 42
#define IS3_RX 41
#define IS3_RST 17
IS3::IS3()
{
a1 = 0.0;
a2 = 0.0;
a3 = 0.0;
a4 = 0.0;
}
void IS3::init()
{
Serial1.setRxBufferSize(1024*2);
Serial1.setTimeout(10);
Serial1.setTxBufferSize(1024*2);
Serial1.begin(921600, SERIAL_8N1, IS3_RX, IS3_TX);
// Serial1.onReceive(onUart1Data, true); // 建议用 true
pinMode(IS3_RST,OUTPUT);
on();
IS3::reset();
// IS3::reset();
// vTaskDelay(1000);
IS3::integration_time = 12;
bool success = false;
String is3_info;
double aa1, aa2, aa3, aa4;
uint32_t is3_bandnum;
do
{
// Serial0.println("IS3 set_shutter_time");
success = IS3::set_shutter_time(IS3::integration_time);
vTaskDelay(10);
} while (!success);
// Serial0.printf("set_shutter_time : %d\n",)
do
{
// Serial0.println("IS3 get_is3_info");
success = IS3::get_is3_info(&is3_info);
vTaskDelay(10);
} while (!success);
// Serial0.printf("IS3_info %s\n", is3_info.c_str());
do
{
// Serial0.println("IS3 get_bochangxishu");
success = IS3::get_bochangxishu(&aa1, &aa2, &aa3, &aa4);
vTaskDelay(10);
} while (!success);
// Serial0.printf("aa1:%f aa2:%f aa3:%f aa4:%f\n",aa1,aa2,aa3,aa4);
do
{
// Serial0.println("IS3 get_bandnum");
success = IS3::get_bandnum(&is3_bandnum);
vTaskDelay(10);
} while (!success);
// Serial0.printf("is3_bandnum:%d\n",is3_bandnum);
}
void IS3::reset()
{
digitalWrite(IS3_RST,LOW);
vTaskDelay(200);
digitalWrite(IS3_RST,HIGH);
vTaskDelay(1000);
}
void IS3::on()
{
digitalWrite(IS3_RST,HIGH);
}
void IS3::off()
{
digitalWrite(IS3_RST,LOW);
}
void IS3::write(uint8_t command,uint8_t *pData, uint16_t Size)
{
uart_flush_input(IS3_usart_port);
uint8_t send_buff[200];
uint32_t send_lenth;
send_lenth = IRIS_Protocol_Pack(command,Size,pData,send_buff);
Serial1.write(send_buff,send_lenth);
}
// int IS3::read1(uint8_t *data_type,uint8_t *read_buf)
// {
// unsigned char command_data[1024 * 2];
// uint16_t data_length = 0;
// // int a = 200;
// int a = is3.integration_time * 3;
// while (a--)
// {
// while(Serial1.available())
// {
// data_length += Serial1.readBytes(&command_data[data_length],1024*2);
// a = 2;
// }
// // if(a< 10) a--;
// vTaskDelay(1);
// }
// if (data_length <= 0)
// {
// return -1;
// }
// data_length = IRIS_Cut_Befor_Header(command_data, data_length);
// int ret = IRIS_STM32_Protocol_Unpack(command_data,data_length,data_type,read_buf);
// if (ret < 0)
// {
// return -1;
// }
// return ret;
// }
uint32_t my_usart_available(uart_port_t uart_port)
{
size_t available = 0;
uart_get_buffered_data_len(uart_port, &available);
// Serial0.printf("available:%d\n",available);
return available;
// if (uart->has_peek) available++;
}
int IS3::read(uint8_t *data_type,uint8_t *read_buf)
{
IS3::read_sta = 1;
unsigned char command_data[1024 * 2];
uint16_t data_length = 0;
// int a = 200;
int a = is3.integration_time * 3 + 50;
while (a--)
{
// while(Serial1.available())
// uint32_t len =0;
// uart_get_buffered_data_len(IS3_usart_port,&len);
while(my_usart_available(IS3_usart_port))
{
// data_length += Serial1.readBytes(&command_data[data_length],1024*2);
data_length += uart_read_bytes(IS3_usart_port,&command_data[data_length],1024*2,10);
a = 2;
}
// if(a< 10) a--;
vTaskDelay(1);
}
if (data_length <= 0)
{
IS3::read_sta = 0;
return -1;
}
data_length = IRIS_Cut_Befor_Header(command_data, data_length);
int ret = IRIS_STM32_Protocol_Unpack(command_data,data_length,data_type,read_buf);
if (ret < 0)
{
IS3::read_sta = 0;
memset(read_buf,0,sizeof(read_buf));
return -1;
}
IS3::read_sta = 0;
return ret;
}
bool IS3::get_is3_info(String *is3_info)
{
if(IS3::read_sta == 1) return false;
uint8_t data = 0;
IS3::write(0x50,&data,1);
uint8_t data_type;
uint8_t command_data[20];
int data_lenth = IS3::read(&data_type,command_data);
if (data_lenth <= 0 || data_type != 0x50)
{
return false;
}
*is3_info = String(command_data,data_lenth);
IS3::info = *is3_info;
return true;
}
bool IS3::set_shutter_time(uint32_t shutter_time)
{
if(IS3::read_sta == 1) return false;
uint8_t data[4]={0,0,0,0};
data[0] |= shutter_time >> 24;
data[1] |= shutter_time >> 16;
data[2] |= shutter_time >> 8;
data[3] |= shutter_time ;
IS3::write(0x51,data,4);
uint8_t data_type;
uint8_t command_data[20];
int data_lenth = IS3::read(&data_type,command_data);
if (data_type != 0x51)
{
return false;
}
IS3::integration_time = shutter_time;
return true;
}
//有问题
bool IS3::opt()
{
if(IS3::read_sta == 1) return false;
uint8_t data = 0;
IS3::write(0x52,&data,1);
uint8_t data_type;
uint8_t command_data[20];
int data_lenth = IS3::read(&data_type,command_data);
if(data_lenth <= 0 || data_type != 0x52)
{
return false;
}
return true;
}
bool IS3::get_shutter_time(uint32_t *shutter_time)
{
if(IS3::read_sta == 1) return false;
uint8_t data = 0;
IS3::write(0x53,&data,1);
uint8_t data_type;
uint8_t command_data[20];
int data_lenth = IS3::read(&data_type,command_data);
if (data_lenth <= 0 || data_type != 0x53)
{
return false;
}
*shutter_time = command_data[0] << 24 | command_data[1] << 16 | command_data[2] << 8 | command_data[3];
IS3::integration_time = *shutter_time;
return true;
}
bool IS3::get_is3_temperature(float *temp)
{
if(IS3::read_sta == 1) return false;
uint8_t data = 0;
IS3::write(0x54,&data,1);
uint8_t data_type;
uint8_t command_data[20];
int data_lenth = IS3::read(&data_type,command_data);
if (data_lenth <= 0 || data_type != 0x54)
{
return false;
}
*temp = command_data[0] << 24 | command_data[1] << 16 | command_data[2] << 8 | command_data[3];
IS3::temperature = *temp;
return true;
}
bool IS3::close_shutter()
{
if(IS3::read_sta == 1) return false;
uint8_t shutter_num = 1;
IS3::write(0x55,&shutter_num,1);
uint8_t data_type;
uint8_t command_data[20];
int data_lenth = IS3::read(&data_type,command_data);
if(data_lenth <= 0 || data_type != 0x55)
{
return false;
}
return true;
}
bool IS3::open_shutter()
{
if(IS3::read_sta == 1) return false;
uint8_t shutter_num = 1;
IS3::write(0x56,&shutter_num,1);
uint8_t data_type;
uint8_t command_data[20];
int data_lenth = IS3::read(&data_type,command_data);
if(data_lenth <= 0 || data_type != 0x56)
{
return false;
}
return true;
}
bool IS3::get_bandnum(uint32_t *is3_bandnum)
{
if(IS3::read_sta == 1) return false;
uint8_t data = 0;
IS3::write(0x57,&data,1);
uint8_t data_type;
uint8_t command_data[20];
int data_lenth = IS3::read(&data_type,command_data);
if(data_lenth <= 0 || data_type != 0x57)
{
return false;
}
*is3_bandnum = command_data[0] << 24 | command_data[1] << 16 | command_data[2] << 8 | command_data[3];
IS3::bandnum = *is3_bandnum;
return true;
}
// bool set_bochangxishu(struct bochangxishu *bochangxishu);
// bool IS3::set_bochangxishu(double aa1,double aa2,double aa3,double aa4)
// {
// uint8_t bochangxishu[32] = {0};
// IS3::write(0x58, (uint8_t *)bochangxishu, 32);
// uint8_t data_type;
// uint8_t command_data[20];
// int data_lenth = IS3::read(&data_type,command_data);
// if(data_lenth <= 0 || data_type != 0x58)
// {
// return false;
// }
// return true;
// }
// 转换每个 double 为大端格式并写入缓冲区
void double_to_big_endian(double value, uint8_t* out) {
uint8_t* p = (uint8_t*)&value;
for (int i = 0; i < 8; ++i) {
out[i] = p[7 - i]; // 反转字节序
}
}
bool IS3::set_bochangxishu(double aa1, double aa2, double aa3, double aa4)
{
if(IS3::read_sta == 1) return false;
uint8_t bochangxishu[32] = {0}; // 4 * 8 = 32 bytes
// 转换每个 double 为大端格式并写入缓冲区
double_to_big_endian(aa1, &bochangxishu[0]);
double_to_big_endian(aa2, &bochangxishu[8]);
double_to_big_endian(aa3, &bochangxishu[16]);
double_to_big_endian(aa4, &bochangxishu[24]);
// 写入地址 0x58
IS3::write(0x58, bochangxishu, 32);
// 读取设备返回数据
uint8_t data_type;
uint8_t command_data[20];
int data_lenth = IS3::read(&data_type, command_data);
// 检查响应类型是否正确
if (data_lenth <= 0 || data_type != 0x58) {
return false;
}
IS3::a1 = aa1;
IS3::a2 = aa2;
IS3::a3 = aa3;
IS3::a4 = aa4;
return true;
}
// 从大端格式转换为 double(适配 ESP32 小端架构)
double big_endian_to_double(const uint8_t* in) {
uint8_t temp[8];
for (int i = 0; i < 8; ++i) {
temp[i] = in[7 - i]; // 字节反转
}
double result;
memcpy(&result, temp, sizeof(double));
return result;
}
bool IS3::get_bochangxishu(double *aa1, double *aa2, double *aa3, double *aa4)
{
if(IS3::read_sta == 1) return false;
uint8_t data = 0;
IS3::write(0x59, &data, 1);
uint8_t data_type;
uint8_t command_data[32];
int data_lenth = IS3::read(&data_type, command_data);
if(data_lenth <= 0 || data_type != 0x59) {
return false;
}
// 解码 4 个 double(每个 8 字节,大端)
*aa1 = big_endian_to_double(&command_data[0]);
*aa2 = big_endian_to_double(&command_data[8]);
*aa3 = big_endian_to_double(&command_data[16]);
*aa4 = big_endian_to_double(&command_data[24]);
// 可选:存到 IS3 的静态成员变量中(如果需要)
IS3::a1 = *aa1;
IS3::a2 = *aa2;
IS3::a3 = *aa3;
IS3::a4 = *aa4;
return true;
}
bool IS3::set_data_processing(enum IS3_data_processing IS3_data_processing,uint32_t average_num)
{
if(IS3::read_sta == 1) return false;
uint8_t data_buff[5];
switch (IS3_data_processing)
{
case none:
data_buff[0] = 0;
break;
case average:
data_buff[0] = 1;
break;
case sgi:
data_buff[0] = 2;
break;
case average_sgi:
data_buff[0] = 3;
break;
case move_average:
data_buff[0] = 4;
break;
default:
break;
}
// memcpy(data_buff+1,(uint8_t *)&average_num, 5);
data_buff[1] |= average_num >> 24;
data_buff[2] |= average_num >> 16;
data_buff[3] |= average_num >> 8;
data_buff[4] |= average_num;
IS3::write(0x60,data_buff, 5);
uint8_t data_type;
uint8_t command_data[32];
int data_lenth = IS3::read(&data_type,command_data);
if(data_lenth <= 0 || data_type != 0x60)
{
return false;
}
return true;
}
bool IS3::get_data(uint8_t *data)
{
if(IS3::read_sta == 1) return false;
uint8_t b = 0 ;
IS3::write(0x61,&b, 1);
uint8_t data_type;
int data_lenth = IS3::read(&data_type,data);
if(data_lenth <= 0 || data_type != 0x61)
{
memset(data,0,515*2);
return false;
}
return true;
}
// bool IS3::get_data(uint8_t *data)
// {
// uint8_t b = 0 ;
// unsigned char command_data[1024 * 2];
// uint16_t data_length = 0;
// int a = is3.integration_time * 3;
// uint8_t data_type;
// IS3::write(0x61,&b, 1);
// while(a--)
// {
// while(Serial1.available())
// {
// data_length += Serial1.readBytes(&command_data[data_length],1024*2);
// a = 10;
// }
// if(data_length == 1037) break;
// // if(a <= 10 ) a--;
// vTaskDelay(1);
// }
// data_length = IRIS_Cut_Befor_Header(command_data, data_length);
// int ret = IRIS_STM32_Protocol_Unpack(command_data,data_length,&data_type,data);
// if (ret < 0)
// {
// return false;
// }
// if(data_type != 0x61)
// {
// return false;
// }
// return true;
// }
bool IS3::get_data_processing(uint8_t *is3_processing)
{
if(IS3::read_sta == 1) return false;
uint8_t b = 0 ;
IS3::write(0x62,&b, 1);
uint8_t data_type;
uint8_t command_data[32];
int data_lenth = IS3::read(&data_type,command_data);
if(data_lenth <= 0 || data_type != 0x62)
{
return false;
}
*is3_processing = command_data[0];
IS3::is3_processing = *is3_processing;
return true;
}

57
src/IS3.h Normal file
View File

@ -0,0 +1,57 @@
#ifndef __IS3_H__
#define __IS3_H__
#include "header.h"
#include "driver/uart.h"
class IS3
{
private:
/* data */
public:
IS3(/* args */);
// ~IS3();
enum IS3_data_processing{
none = 0,
average,
sgi,
average_sgi,
move_average
};
String info = "IS3";
uint32_t integration_time,bandnum;
float temperature;
double a1, a2, a3, a4;
uint8_t is3_processing;
volatile uint8_t read_sta;
void init();
void on();
void off();
void reset();
void write(uint8_t command,uint8_t *pData, uint16_t Size);
int read(uint8_t *data_type,uint8_t *read_buf) ;
// int read1(uint8_t *data_type,uint8_t *read_buf);
bool get_is3_info(String *is3_info);
bool set_shutter_time(uint32_t shutter_time);
bool opt();
bool get_shutter_time(uint32_t *shutter_time);
bool get_is3_temperature(float *temp);
bool close_shutter();
bool open_shutter();
bool get_bandnum(uint32_t *is3_bandnum);
bool set_bochangxishu(double aa1, double aa2, double aa3, double aa4);
bool get_bochangxishu(double *aa1, double *aa2, double *aa3, double *aa4);
bool set_data_processing(enum IS3_data_processing IS3_data_processing,uint32_t average_num);
bool get_data(uint8_t *data);
bool get_data_processing(uint8_t *is3_processing);
};
extern IS3 is3;
uint32_t my_usart_available(uart_port_t uart_port);
#endif

88
src/adc.cpp Normal file
View File

@ -0,0 +1,88 @@
#include "adc.h"
#define ADC_PIN 3
float voltage_buff[200];
void adc_init() {
// pinMode(3,INPUT);
analogReadResolution(12);
voltage_buff[199] = -1;
// analogSetPinAttenuation(ADC_PIN, ADC_11db);
}
float voltage_last1 = 10;
float adc_read() {
uint32_t adcValue = 0;// = analogRead(ADC_PIN);
for(int i = 0; i < 10; i++)
{
adcValue += analogRead(ADC_PIN);
}
adcValue /= 10;
// float voltage = (float)adcValue * (5.5 / 4095);
float voltage = ((float)adcValue / 4095.0f * 3.3f) * 1.6667f;
// Serial0.printf("voltage : %f\n", voltage);
// if((voltage < 4.2) && (voltage > 3.8)) play_music("/baojing.mp3");
// if((voltage < 4.1) && (voltage > 3.8)) xEventGroupSetBits(ui_event_group,POWER_OFF_BIT);
// if((voltage < 2.0)) voltage = 5.5;
voltage = voltage * 0.1f + 0.9f * voltage_last1;
voltage_last1 = voltage;
return voltage;
}
uint32_t v_count = 0;
float temp_last = 1000;
float voltage_to_percent(float voltage) {
if (voltage >= 5.0f) return 100;
else if (voltage >= 4.7f) return 80 + (voltage - 4.7) / 0.3f * 20;
else if (voltage >= 4.4f) return 10 + (voltage - 4.4) / 0.3f * 70;
else if (voltage >= 4.2f) return (voltage - 4.2f) / 0.3f * 10;
else return 0;
}
float get_voltage()
{
float voltage;
float temp;
float sum_voltage = 0;
voltage = adc_read();
voltage_buff[v_count] = voltage;
v_count++;
if(v_count >= 200)
{
// Serial0.printf("voltage : %f\n", voltage);
v_count = 0;
}
if(voltage_buff[199] == -1)
{
// for(int i = 0; i < v_count; i++)
// {
// sum_voltage += voltage_buff[i];
// }
// sum_voltage /= v_count;
return 100;
}
else
{
for(int i = 0; i < 200; i++)
{
sum_voltage += voltage_buff[i];
}
sum_voltage /= 200;
}
// temp = (float)(sum_voltage - 4.2f) / 1.2f * 100;
temp = voltage_to_percent(sum_voltage);
temp = temp > 100 ? 100 : temp;
if(temp > temp_last) temp = temp_last;
else temp_last = temp;
if(temp < 5) temp = 5;
return temp;
}

12
src/adc.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef __ADC_H__
#define __ADC_H__
#include <Arduino.h>
#include "header.h"
void adc_init();
float adc_read();
float get_voltage();
#endif

158
src/button.cpp Normal file
View File

@ -0,0 +1,158 @@
#include "button.h"
#define TAG "BUTTON_ISR"
#define WAKEUP_PIN GPIO_NUM_9
static EventGroupHandle_t gpio_event_group;
static void IRAM_ATTR gpio_isr_handler(void* arg) {
uint32_t gpio_num = (uint32_t)arg;
if (gpio_num == BUTTON1_PIN) {
xEventGroupSetBitsFromISR(gpio_event_group, BUTTON1_BIT, NULL);
} else if (gpio_num == BUTTON2_PIN) {
xEventGroupSetBitsFromISR(gpio_event_group, BUTTON2_BIT, NULL);
}
}
void button1_task(void* arg) {
static TickType_t last_press_time = 0;
static bool waiting_second_click = false;
while (1)
{
xEventGroupWaitBits(gpio_event_group,BUTTON1_BIT,pdTRUE,pdFALSE,portMAX_DELAY);
vTaskDelay(20);
if(digitalRead(BUTTON1_PIN) != LOW) continue;
system_time_count = 0;
uint32_t count = 0;
while(digitalRead(BUTTON1_PIN) == LOW)
{
EventBits_t uxBits = xEventGroupGetBits(ui_event_group);
count++;
if (count == 20)
{
if ((uxBits & MAIN_2_OPT_ING_BIT) || (uxBits & MAIN_2_DC_ING_BIT) || (uxBits & MAIN_2_WR_ING_BIT) || (uxBits & MAIN_2_SAVE_ING_BIT))
{
}
else
{
play_music("/miaozhuan.mp3");
}
}
else if(count > 20)
{
if ((uxBits & MAIN_2_OPT_ING_BIT) || (uxBits & MAIN_2_DC_ING_BIT) || (uxBits & MAIN_2_WR_ING_BIT) || (uxBits & MAIN_2_SAVE_ING_BIT))
{
}
else
{
xEventGroupSetBits(is3_event_group, RED_RAY_BIT);
}
}
vTaskDelay(50);
}
vTaskDelay(150);
if(count < 10)
{
if(digitalRead(BUTTON1_PIN) == LOW)
{
if(digitalRead(BUTTON1_PIN) == LOW)
{
if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS)
{
updata_struct_to_ui.button1_count = 200;
xSemaphoreGive(xMutexInventory);
}
}
xEventGroupClearBits(gpio_event_group, BUTTON1_BIT);
}
else
{
waiting_second_click == false;
EventBits_t uxBits = xEventGroupGetBits(ui_event_group);
if ((uxBits & MAIN_2_OPT_ING_BIT) || (uxBits & MAIN_2_DC_ING_BIT) || (uxBits & MAIN_2_WR_ING_BIT) || (uxBits & MAIN_2_SAVE_ING_BIT)) continue;
if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS)
{
updata_struct_to_ui.button1_count = 100;
xSemaphoreGive(xMutexInventory);
}
}
}
vTaskDelay(10);
xEventGroupClearBits(gpio_event_group, BUTTON1_BIT);
}
}
void button2_task(void* arg) {
while (1)
{
xEventGroupWaitBits(gpio_event_group,BUTTON2_BIT,pdTRUE, pdFALSE,portMAX_DELAY);
uint32_t count = 0;
vTaskDelay(20);
if(digitalRead(BUTTON2_PIN) != LOW) continue;
system_time_count = 0;
// Serial0.println("button2");
while(digitalRead(BUTTON2_PIN) == LOW)
{
count++;
if(count > 200)
{
// xEventGroupSetBits(ui_event_group, POWER_OFF_BIT);
// tft_clear(TFT_BLACK);
esp_restart();
}
vTaskDelay(50);
}
if(count < 10)
{
EventBits_t uxBits = xEventGroupGetBits(ui_event_group);
if ((uxBits & MAIN_2_OPT_ING_BIT) || (uxBits & MAIN_2_DC_ING_BIT) || (uxBits & MAIN_2_WR_ING_BIT) || (uxBits & MAIN_2_SAVE_ING_BIT)) continue;
if(xSemaphoreTake(xMutexInventory, 1000) == pdPASS)
{
updata_struct_to_ui.button2_count++;
if(updata_struct_to_ui.mode == 0)
{
if (updata_struct_to_ui.button2_count == 1)updata_struct_to_ui.button2_count = 3;
}
updata_struct_to_ui.button2_count = updata_struct_to_ui.button2_count > 4 ? 0 : updata_struct_to_ui.button2_count;
xSemaphoreGive(xMutexInventory);
}
}
vTaskDelay(20);
xEventGroupClearBits(gpio_event_group, BUTTON2_BIT);
}
}
void button_init(void) {
gpio_event_group = xEventGroupCreate();
gpio_config_t io_conf = {
.pin_bit_mask = (1ULL << BUTTON1_PIN) | (1ULL << BUTTON2_PIN),
.mode = GPIO_MODE_INPUT,
.pull_up_en = GPIO_PULLUP_ENABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_NEGEDGE, // 按键下降沿触发
};
gpio_config(&io_conf);
gpio_install_isr_service(0);
gpio_isr_handler_add(BUTTON1_PIN, gpio_isr_handler, (void*)BUTTON1_PIN);
gpio_isr_handler_add(BUTTON2_PIN, gpio_isr_handler, (void*)BUTTON2_PIN);
xTaskCreate(button1_task, "button1_task", 1024*1, NULL, 100, NULL);
xTaskCreate(button2_task, "button2_task", 1024*1, NULL, 100, NULL);
}

23
src/button.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef __BUTTON_H__
#define __BUTTON_H__
#include "Arduino.h"
#include "header.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "driver/gpio.h"
#include "esp_log.h"
#define BUTTON1_PIN GPIO_NUM_46 // 输出 "hello"
#define BUTTON2_PIN GPIO_NUM_9 // 输出 "nihao"
#define BUTTON1_BIT (1 << 0)
#define BUTTON2_BIT (1 << 1)
#define clicked_bit (1 << 2)
void button_init(void);
#endif

77
src/ds1307.cpp Normal file
View File

@ -0,0 +1,77 @@
#include "ds1307.h"
// #define TOUCH_SDA 1
// #define TOUCH_SCL 2
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void ds1307_init()
{
if (!rtc.begin())
{
// Serial0.println("Couldn't find RTC");
}
if (!rtc.isrunning())
{
// Serial0.println("RTC is NOT running, setting the time!");
// 设置初始时间
Serial0.println(DateTime(F(__DATE__), F(__TIME__)).timestamp());
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
DateTime now = rtc.now();
String date = String(now.year(), DEC) + "/" + String(now.month(), DEC) + "/" + String(now.day(), DEC) + " "
+ String(now.hour(), DEC) + ":" + String(now.minute(), DEC) + ":" + String(now.second(), DEC);
Serial0.println(date);
struct tm t;
t.tm_year = now.year() - 1900;
t.tm_mon = now.month() - 1;
t.tm_mday = now.day();
t.tm_hour = now.hour();
t.tm_min = now.minute();
t.tm_sec = now.second();
time_t sys_now = mktime(&t);
struct timeval tv = { sys_now, 0 };
settimeofday(&tv, nullptr); // 设置系统时间
}
void ds1307_get_time( ds1307_date *ds1307_date)
{
// Serial0.println("get time");
// getLocalTime(&timeinfo);获取系统时间:
uint32_t a;
DateTime now;
if(a % 5 == 0 ) now = rtc.now();
ds1307_date->year = now.year();
ds1307_date->month = now.month();
ds1307_date->day = now.day();
ds1307_date->hour = now.hour();
ds1307_date->minute = now.minute();
ds1307_date->second = now.second();
a++;
// Serial0.printf("\n%d/%02d/%02d %02d:%02d;%02d\n",ds1307_date->year,ds1307_date->month ,ds1307_date->day ,ds1307_date->hour ,ds1307_date->minute,ds1307_date->second );
}
void ds1307_set_time(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
{
rtc.adjust(DateTime(year, month, day, hour, minute, second)); // 设置为 2025年6月27日 14:30:00
DateTime now = rtc.now();
String date = String(now.year(), DEC) + "/" + String(now.month(), DEC) + "/" + String(now.day(), DEC) + " "
+ String(now.hour(), DEC) + ":" + String(now.minute(), DEC) + ":" + String(now.second(), DEC);
// Serial0.println("set time:");
// Serial0.println(date);
struct tm t;
t.tm_year = now.year() - 1900;
t.tm_mon = now.month() - 1; // 7月,注意从0开始
t.tm_mday = now.day();
t.tm_hour = now.hour();
t.tm_min = now.minute();
t.tm_sec = now.second();
time_t sys_now = mktime(&t);
struct timeval tv = { sys_now, 0 };
settimeofday(&tv, nullptr); // 设置系统时间
}

20
src/ds1307.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef __DS1307_H__
#define __DS1307_H__
#include "RTClib.h"
typedef struct ds1307_t
{
uint16_t year;
uint16_t month;
uint16_t day;
uint16_t hour;
uint16_t minute;
uint16_t second;
} ds1307_date;
void ds1307_init();
void ds1307_get_time( ds1307_date *ds1307_date);
void ds1307_set_time(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
#endif

48
src/header.h Normal file
View File

@ -0,0 +1,48 @@
#ifndef __HEADER_H__
#define __HEADER_H__
#include "Arduino.h"
#include "IRIS_Method.h"
#include "red_ray.h"
#include "hh3_system.h"
#include "hh3_slave.h"
#include "sd_card.h"
#include "save.h"
#include "speak.h"
#include "ui_task.h"
#include "qmi8658.h"
#include "ds1307.h"
#include "IS3.h"
#include "lcd.h"
#include "my_aht10.h"
#include "usb_camera.h"
#include "button.h"
#include "adc.h"
// #include "hh3_system.h"
// #include "speak.h"
// #include "lcd.h"
// #include "events_init.h"
// #include "gui_guider.h"
// #include "sd_card.h"
// #include "ds1307.h"
// #include "qmi8658.h"
// #include "my_aht10.h"
// #include "usb_camera.h"
// #include "adc.h"
// #include "red_ray.h"
// #include "button.h"
#include <ArduinoJson.h>
#include <TFT_eSPI.h>
#include <TAMC_GT911.h>
#include "lvgl.h"
#include "gui_guider.h"
#include "events_init.h"
#include "custom.h"
#include <SPIFFS.h>
#include <TJpg_Decoder.h>
#include "wifi_client.h"
#include "log.h"
#endif

81
src/hh3_slave.cpp Normal file
View File

@ -0,0 +1,81 @@
#include "hh3_slave.h"
// 发送命令给从机
void sendCommand(uint8_t cmd) {
Wire.beginTransmission(SLAVE_ADDRESS);
Wire.write(cmd);
Wire.endTransmission();
// Serial0.print("Sent command: 0x");
// Serial0.println(cmd, HEX);
}
bool requestData(hh3_slave_data *sensor_data) {
// 直接请求结构体大小的数据
Wire.requestFrom(SLAVE_ADDRESS, sizeof(hh3_slave_data));
if (Wire.available() == sizeof(hh3_slave_data))
{
Wire.readBytes((uint8_t*)sensor_data, sizeof(hh3_slave_data));
return true;
} else {
// Serial0.println("Failed to receive data from slave.");
return false;
}
}
uint8_t height_sta = 1;
float height_last;
void get_hh3_slave_data(hh3_slave_data *data)
{
requestData(data);
if(height_sta == 1) height_last = data->height;
else data->height = height_last;
// printSensorData(*data);
}
void open_ceju()
{
sendCommand(0x05);
height_sta = 1;
}
void close_ceju()
{
sendCommand(0x03);
height_sta = 0;
}
void printSensorData(hh3_slave_data sensor_data) {
// 打印原始 hex 数据
uint8_t* pData = (uint8_t*)&sensor_data;
Serial0.print("Received Hex Data: ");
for (int i = 0; i < sizeof(hh3_slave_data); i++) {
Serial0.printf("%02X ", pData[i]);
}
Serial0.println();
Serial0.println("=== Sensor Data ===");
Serial0.print("GPS Status: ");
switch (sensor_data.gps_sta) {
case 0x00: Serial0.println("No Device"); break;
case 0x01: Serial0.println("Power Off"); break;
case 0x02: Serial0.println("No Signal"); break;
case 0x03: Serial0.println("Valid Signal"); break;
default: Serial0.println("Unknown"); break;
}
Serial0.print("Height Status: ");
switch (sensor_data.height_sta) {
case 0x00: Serial0.println("No Device"); break;
case 0x01: Serial0.println("Power Off"); break;
case 0x03: Serial0.println("Valid"); break;
default: Serial0.println("Unknown"); break;
}
Serial0.print("Latitude: "); Serial0.println(sensor_data.gps_lat, 6);
Serial0.print("Longitude: "); Serial0.println(sensor_data.gps_lon, 6);
Serial0.print("Height (m): "); Serial0.println(sensor_data.height, 2);
Serial0.println("===================");
}

62
src/hh3_slave.h Normal file
View File

@ -0,0 +1,62 @@
#ifndef __HH3_SLAVE_H__
#define __HH3_SLAVE_H__
#include "header.h"
#define SLAVE_ADDRESS 0x55
// 命令定义(与从机一致)
#define CMD_MASTER_GET_SLAVE_DATA 0x01
#define CMD_GPS_POWER_OFF 0x02
#define CMD_RANGING_POWER_OFF 0x03
#define CMD_GPS_POWER_ON 0x04
#define CMD_RANGING_POWER_ON 0x05
typedef struct
{
uint8_t gps_sta;
uint8_t height_sta;
float gps_lat;
float gps_lon;
float height;
}hh3_slave_data;
void hh3_slave_init(void);
// void get_hh3_slave_data(hh3_slave_data * data);
// void printSensorData();
// bool requestData();
// void sendCommand(uint8_t cmd);
void get_hh3_slave_data(hh3_slave_data *data);
void sendCommand(uint8_t cmd);
bool requestData(hh3_slave_data *sensor_data) ;
void printSensorData(hh3_slave_data sensor_data);
void close_ceju();
void open_ceju();
// 从机地址 0X55;
// 命令1, 0x01获取数据
// 发送:
// 0x55 0x01
// 回复数据格式:
// typedef struct
// {
// uint8_t gps_sta; //0x00没有设备 , 0x01关机 , 0x02没有搜到gps ,0x03搜到gps
// uint8_t height_sta; //0x00没有设备 , 0x01关机
// float gps_lat; //没有返回0
// float gps_lon; //没有返回0
// float height; //没有返回0
// }hh3_slave_data;
// 命令2,0x02关闭GPS电源。
// 命令3,0x03关闭测距电源。
// 命令4,0x04开启GPS电源。
// 命令5,0x05开启测距电源。
#endif

81
src/hh3_system.cpp Normal file
View File

@ -0,0 +1,81 @@
#include "hh3_system.h"
#define sys_power_pin 48
#define LCD_BL_PIN 14 // 背光引脚连接到 GPIO14
// #define SPK_CTRL 38
// #define BUTTON1_PIN GPIO_NUM_46 // 输出 "hello"
// #define BUTTON2_PIN GPIO_NUM_9 // 输出 "nihao"
void hh3_system_init(void)
{
pinMode(sys_power_pin, OUTPUT);
pinMode(sys_power_pin, OUTPUT);
pinMode(SPK_CTRL, OUTPUT);
pinMode(BUTTON1_PIN, INPUT_PULLUP);
pinMode(BUTTON2_PIN, INPUT_PULLUP);
pinMode(17, OUTPUT);
digitalWrite(17 ,LOW);//IS3_RST
digitalWrite(SPK_CTRL, LOW);
digitalWrite(LCD_BL_PIN, HIGH);
hh3_system_off();
}
void hh3_system_off(void)
{
digitalWrite(sys_power_pin, LOW);
// digitalWrite(LCD_BL_PIN, LOW);
}
void hh3_system_on(void)
{
digitalWrite(sys_power_pin, HIGH);
// digitalWrite(LCD_BL_PIN, LOW);
}
void hh3_system_start(void)
{
// while(1)
// {
// uint32_t count = 0;
// hh3_system_init();
// // hh3_system_off();
// esp_sleep_enable_ext0_wakeup(BUTTON2_PIN, 0); // 低电平唤醒
// // esp_deep_sleep_start();
// esp_light_sleep_start();
// // hh3_system_on();
// while (digitalRead(BUTTON2_PIN) == 0)
// {
// if(digitalRead(BUTTON1_PIN) == 0) count ++;
// if(count > 300) break;
// vTaskDelay(10);
// }
// if(count > 300) break;
// }
hh3_system_on();
// delay(20);
lcd_init();
speak_init();
// is3.init();
audio.connecttoFS(SPIFFS,"/kaiji.mp3" );
while (audio.isRunning())
{
audio.loop();
vTaskDelay(5);
}
vTaskDelay(500);
audio.connecttoFS(SPIFFS,"/huanyinshiyong.mp3" );
while (audio.isRunning())
{
audio.loop();
vTaskDelay(5);
}
}

9
src/hh3_system.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef _HH3HH3_SYSTEM_H_
#define _HHHH3_SYSTEM_H_
#include "header.h"
void hh3_system_init(void);
void hh3_system_off(void);
void hh3_system_on(void);
void hh3_system_start(void);
#endif

185
src/lcd.cpp Normal file
View File

@ -0,0 +1,185 @@
#include "lcd.h"
#define BL_PIN 14 // 背光引脚连接到 GPIO14
#define PWM_CHANNEL 0
#define PWM_FREQ 5000
#define PWM_RESOLUTION 8 // 分辨率:0~255
#define TOUCH_SDA 1
#define TOUCH_SCL 2
#define TOUCH_INT 18
#define TOUCH_RST 47
// #define LCD_BL 14
#define TOUCH_WIDTH 480
#define TOUCH_HEIGHT 320
static const uint16_t screenWidth = 320;
static const uint16_t screenHeight = 480;
TFT_eSPI tft = TFT_eSPI(screenWidth, screenHeight); /* TFT instance */
TAMC_GT911 touch = TAMC_GT911(TOUCH_SDA, TOUCH_SCL, TOUCH_INT, TOUCH_RST, TOUCH_WIDTH, TOUCH_HEIGHT);
SemaphoreHandle_t lvgl_mutex;
static lv_disp_draw_buf_t draw_buf;
lv_color_t *lvgl_buf_1 = NULL;
lv_color_t *lvgl_buf_2 = NULL;
lv_ui guider_ui;
void my_disp_flush( lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p )
{
uint32_t w = ( area->x2 - area->x1 + 1 );
uint32_t h = ( area->y2 - area->y1 + 1 );
tft.startWrite();
tft.setAddrWindow( area->x1, area->y1, w, h );
tft.pushColors( ( uint16_t * )&color_p->full, w * h, true );
tft.endWrite();
lv_disp_flush_ready( disp_drv );
}
/*Read the touchpad*/
bool last_touch = false;
void my_touchpad_read( lv_indev_drv_t * indev_drv, lv_indev_data_t * data )
{
uint16_t touchX, touchY;
static uint16_t touchX_last, touchY_last;
touch.read();
bool touched = touch.isTouched;
touchX = touch.points[0].x;
touchY = touch.points[0].y;
int id = touch.points[0].id;
// Serial0
if( !touched )
{
data->state = LV_INDEV_STATE_REL;
}
else
{
if (last_touch == false)
{
data->state = LV_INDEV_STATE_REL;
last_touch=touched;
return;
/* code */
}
// Serial0.printf("X: %d,Y: %d\n",touchX,touchY);
// if(touchX != touchX_last || touchY != touchY_last)
// {
// touchX_last = touchX;
// touchY_last = touchY;
// data->state = LV_INDEV_STATE_REL;
// return;
// }
// Serial0.printf("X: %d,Y: %d\n , id: %d \n",touchX,touchY,id);
data->state = LV_INDEV_STATE_PR;
system_time_count = 0;
data->point.x = touchX;
data->point.y = touchY;
// digitalWrite(TOUCH_RST, LOW);
// digitalWrite(TOUCH_RST, HIGH);
}
last_touch=touched;
}
void setBrightness(uint8_t brightness) {
ledcWrite(PWM_CHANNEL, brightness); // 写入 PWM 占空比
}
void lcd_BLK_int()
{
// pinMode(TFT_BL, OUTPUT);
// digitalWrite(TFT_BL, HIGH);
ledcSetup(PWM_CHANNEL, PWM_FREQ, PWM_RESOLUTION); // 设置PWM通道
ledcAttachPin(BL_PIN, PWM_CHANNEL); // 绑定GPIO到PWM通道
setBrightness(0); // 设置初始亮度(0~255)
}
void lvgl_loop_task(void *pvParameters)
{
while(1)
{
// lv_timer_handler();
if (xSemaphoreTake(lvgl_mutex, portMAX_DELAY))
{
lv_timer_handler();
xSemaphoreGive(lvgl_mutex);
}
vTaskDelay(5);
}
}
void lcd_init() {
lvgl_mutex = xSemaphoreCreateMutex();
pinMode(TOUCH_RST, OUTPUT);
// setBrightness(0);
lvgl_buf_1 = (lv_color_t*)heap_caps_malloc(screenWidth * screenHeight*5, MALLOC_CAP_SPIRAM);
lvgl_buf_2 = (lv_color_t*)heap_caps_malloc(screenWidth * screenHeight*5, MALLOC_CAP_SPIRAM);
lv_init();
lv_disp_draw_buf_init( &draw_buf, lvgl_buf_1, lvgl_buf_2, screenWidth * screenHeight *5 );
lcd_BLK_int();
tft.begin();
tft.setRotation(1); /* Landscape orientation, flipped */
tft.fillScreen(TFT_WHITE);
// setBrightness(180); // 设置初始亮度(0~255)
setBrightness(255);
// vTaskDelay(30);
touch.begin();
touch.setRotation(2);
// lvgl_buf_1 = (lv_color_t*) malloc(screenWidth * screenHeight*5);
// lvgl_buf_2 = (lv_color_t*) malloc(screenWidth * screenHeight*5);
// lvgl_buf_1 = (lv_color_t*)heap_caps_malloc(screenWidth * screenHeight*5, MALLOC_CAP_SPIRAM);
// lvgl_buf_2 = (lv_color_t*)heap_caps_malloc(screenWidth * screenHeight*5, MALLOC_CAP_SPIRAM);
// lv_disp_draw_buf_init( &draw_buf, lvgl_buf_1, lvgl_buf_2, screenWidth * screenHeight *5 );
static lv_disp_drv_t disp_drv;
lv_disp_drv_init( &disp_drv );
/*Change the following line to your display resolution*/
// disp_drv.hor_res = screenWidth;
// disp_drv.ver_res = screenHeight;
disp_drv.hor_res = 480;
disp_drv.ver_res = 320;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
lv_disp_drv_register( &disp_drv );
/*Initialize the (dummy) input device driver*/
static lv_indev_drv_t indev_drv;
lv_indev_drv_init( &indev_drv );
// indev_drv.long_press_time = 50; // 默认是 500 ms
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = my_touchpad_read;
lv_indev_drv_register( &indev_drv );
setup_ui(&guider_ui);
events_init(&guider_ui);
custom_init(&guider_ui);
xTaskCreatePinnedToCore(lvgl_loop_task,"lvgl_loop_task", 1024*5 , NULL, 20, NULL, 1);
}
void tft_clear(uint16_t color)
{
tft.fillScreen(color);
}

12
src/lcd.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef __LCD_H__
#define __LCD_H__
#include "header.h"
#include <TFT_eSPI.h>
#include <TAMC_GT911.h>
#include "lvgl.h"
extern SemaphoreHandle_t lvgl_mutex;
void lcd_init();
void setBrightness(uint8_t brightness);
void tft_clear(uint16_t color);
#endif

38
src/log.cpp Normal file
View File

@ -0,0 +1,38 @@
#include "log.h"
void write_log(String log_info,unsigned char level)
{
// if(level == LOG_LEVEL_DEBUG)
// {
// Serial0.println(log_info);
// }
// ds1307_date date;
// ds1307_get_time(&date);
// String date_info = String(date.year);
// if(date.month < 10) date_info = date_info + "0" + String(date.month);
// else date_info = date_info + String(date.month);
// if(date.day < 10) date_info = date_info + "0" + String(date.day);
// else date_info = date_info + String(date.day);
// if(date.hour < 10) date_info = date_info + "0" + String(date.hour);
// else date_info = date_info + String(date.hour);
// if(date.minute < 10) date_info = date_info + "0" + String(date.minute);
// else date_info = date_info + String(date.minute);
// if(date.second < 10) date_info = date_info + "0" + String(date.second);
// else date_info = date_info + String(date.second);
// String log_path = LOG_PATH + "" + ".txt";
// date_info = "---------------------------" + date_info + "---------------------------";
// File file;
// file = SD_MMC.open(LOG_PATH,FILE_WRITE);
// file.println(date_info);
// file.println(log_info);
// file.flush();
// file.close();
}

16
src/log.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef LOG_H
#define LOG_H
#include "header.h"
#define LOG_PATH "/log/"
#define LOG_LEVEL_DEBUG 10
#define LOG_LEVEL_INFO 20
void write_log(String log_info,unsigned char level);
#endif

70
src/main.cpp Normal file
View File

@ -0,0 +1,70 @@
#include <Arduino.h>
#include "header.h"
#define ADC_PIN 3
#define i2c_sda 1
#define i2c_scl 2
#define i2c_FREQ_HZ 100000 // 100kHz
void setup()
{
hh3_system_init();
hh3_system_start();
// // // Serial0.begin(115200);
// Serial0.setTimeout(1);
// // Serial0.setRxBufferSize(1024*2);
// // Serial0.setTxBufferSize(1024*2);
Serial0.begin(921600);
// Serial0.setTimeout(1);
Serial0.println("============start=============");
is3.init();
ds1307_init();
sd_card_init();
update_firmware();
system_data_init();
Wire.begin(i2c_sda, i2c_scl,i2c_FREQ_HZ);
open_ceju();
// wifi_init();
qmi8658_init();
aht10_init();
adc_init();
red_ray_init();
ui_task_init();
button_init();
USB_CAM_Init();
// write_log("system start", LOG_LEVEL_INFO);
}
void loop()
{
// lv_timer_handler(); /* let the GUI do its work */
vTaskDelay(portMAX_DELAY);
}
// while (1) {
// sendCommand(0x03);
// delay(100);
// sendCommand(0x05);
// delay(100);
// Serial0.println("start");
// }

47
src/my_aht10.cpp Normal file
View File

@ -0,0 +1,47 @@
#include "my_aht10.h"
uint8_t readStatus = 0;
AHT10 myAHT10(AHT10_ADDRESS_0X38);
bool aht10_init()
{
bool sta = myAHT10.begin();
uint8_t count = 0;
while (!sta)
{
sta = myAHT10.begin();
if (count > 10)
{
return false;
}
// Serial0.println("AHT10 init fail");
count++;
vTaskDelay(10);
}
// Serial0.println("AHT10 init success");
return true;
}
void get_aht10_data()
{
Serial0.print("Temperature: ");
Serial0.print(myAHT10.readTemperature());
Serial0.print(" C");
Serial0.print("Humidity: ");
Serial0.print(myAHT10.readHumidity());
Serial0.println(" %");
}
void get_aht10_data(float *temperature, float *humidity)
{
*temperature = myAHT10.readTemperature();
*humidity = myAHT10.readHumidity();
}

10
src/my_aht10.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef __MY_AHT10_H__
#define __MY_AHT10_H__
#include <Arduino.h>
#include <AHT10.h>
#include <Wire.h>
bool aht10_init();
void get_aht10_data();
void get_aht10_data(float *temperature, float *humidity);
#endif

127
src/qmi8658.cpp Normal file
View File

@ -0,0 +1,127 @@
#include "qmi8658.h"
// 读取QMI8658寄存器的值
esp_err_t qmi8658_register_read(uint8_t reg_addr, uint8_t *data, size_t len)
{
return i2c_master_write_read_device(0, QMI8658_SENSOR_ADDR, &reg_addr, 1, data, len, 1000 / portTICK_PERIOD_MS);
}
// 给QMI8658的寄存器写值
esp_err_t qmi8658_register_write_byte(uint8_t reg_addr, uint8_t data)
{
uint8_t write_buf[2] = {reg_addr, data};
return i2c_master_write_to_device(0, QMI8658_SENSOR_ADDR, write_buf, sizeof(write_buf), 1000 / portTICK_PERIOD_MS);
}
// 初始化qmi8658
esp_err_t qmi8658_init(void)
{
// Serial0.println("11111111 OK!"); // 打印信息
esp_err_t ret = ESP_OK;
uint8_t id = 0; // 芯片的ID号
uint8_t count = 0;
qmi8658_register_read(QMI8658_WHO_AM_I, &id ,1); // 读芯片的ID号
while (id != 0x05) // 判断读到的ID号是否是0x05
{
vTaskDelay(100 / portTICK_PERIOD_MS); // 延时100豪秒
qmi8658_register_read(QMI8658_WHO_AM_I, &id ,1); // 读取ID号
count++;
if (count >= 5){
ret = ESP_FAIL;
return ret;
}
// Serial0.print("."); // 打印信息
}
// Serial0.println("QMI8658 OK!"); // 打印信息
qmi8658_register_write_byte(QMI8658_RESET, 0xb0); // 复位
vTaskDelay(10 / portTICK_PERIOD_MS); // 延时10ms
// 配置运动状态检测
qmi8658_register_write_byte(QMI8658_CATL1_L, 1); // AnyMotionXThr 必须是0~32之间的数
qmi8658_register_write_byte(QMI8658_CATL1_H, 1); // AnyMotionYThr 必须是0~32之间的数
qmi8658_register_write_byte(QMI8658_CATL2_L, 1); // AnyMotionZThr 必须是0~32之间的数
qmi8658_register_write_byte(QMI8658_CATL2_H, 1); // NoMotionXThr 必须是0~32之间的数
qmi8658_register_write_byte(QMI8658_CATL3_L, 1); // NoMotionYThr 必须是0~32之间的数
qmi8658_register_write_byte(QMI8658_CATL3_H, 1); // NoMotionZThr 必须是0~32之间的数
qmi8658_register_write_byte(QMI8658_CATL4_L, 0x77); // MOTION_MODE_CTRL 0111 0111
qmi8658_register_write_byte(QMI8658_CATL4_H, 0x01); // 0x01(means 1st command)
qmi8658_register_write_byte(QMI8658_CTRL9, 0x0E); // CTRL_CMD_CONFIGURE_MOTION
qmi8658_register_write_byte(QMI8658_CATL1_L, 1); // AnyMotionWindow
qmi8658_register_write_byte(QMI8658_CATL1_H, 1); // NoMotionWindow
qmi8658_register_write_byte(QMI8658_CATL2_L, 0xE8); // SigMotionWaitWindow[7:0]
qmi8658_register_write_byte(QMI8658_CATL2_H, 0x03); // SigMotionWaitWindow [15:8]
qmi8658_register_write_byte(QMI8658_CATL3_L, 0xE8); // SigMotionConfirmWindow[7:0]
qmi8658_register_write_byte(QMI8658_CATL3_H, 0x03); // SigMotionConfirmWindow[15:8]
// qmi8658_register_write_byte(QMI8658_CATL4_L, 0x40); // NA
qmi8658_register_write_byte(QMI8658_CATL4_H, 0x02); // 0x02(means 2nd command)
qmi8658_register_write_byte(QMI8658_CTRL9, 0x0E); // CTRL_CMD_CONFIGURE_MOTION
qmi8658_register_write_byte(QMI8658_CTRL1, 0x40); // CTRL1 设置地址自动增加
qmi8658_register_write_byte(QMI8658_CTRL7, 0x03); // CTRL7 允许加速度和陀螺仪
qmi8658_register_write_byte(QMI8658_CTRL2, 0x95); // CTRL2 设置ACC 4g 250Hz
qmi8658_register_write_byte(QMI8658_CTRL3, 0xd5); // CTRL3 设置GRY 512dps 250Hz
qmi8658_register_write_byte(QMI8658_CTRL8, 0x0E); // CTRL7 允许Any-Motion No-Motion and Significant-Motion
return ret;
}
// 关闭芯片运行
void qmi8658_close(void)
{
qmi8658_register_write_byte(QMI8658_CTRL1, 0x01); // 关闭芯片运行
}
// 读取加速度和陀螺仪寄存器值
void qmi8658_Read_AccAndGry(t_sQMI8658 *p)
{
uint8_t status, data_ready=0;
int16_t buf[6];
qmi8658_register_read(QMI8658_STATUS0, &status, 1); // 读状态寄存器
if (status & 0x03) // 判断加速度和陀螺仪数据是否可读
data_ready = 1;
if (data_ready == 1){ // 如果数据可读
data_ready = 0;
qmi8658_register_read(QMI8658_AX_L, (uint8_t *)buf, 12); // 读加速度和陀螺仪值
p->acc_x = buf[0];
p->acc_y = buf[1];
p->acc_z = buf[2];
p->gyr_x = buf[3];
p->gyr_y = buf[4];
p->gyr_z = buf[5];
}
}
// 获取XYZ轴的倾角值
void qmi8658_fetch_angleFromAcc(t_sQMI8658 *p)
{
float temp;
qmi8658_Read_AccAndGry(p); // 读取加速度和陀螺仪的寄存器值
// 根据寄存器值 计算倾角值 并把弧度转换成角度
temp = (float)p->acc_x / sqrt( ((float)p->acc_y * (float)p->acc_y + (float)p->acc_z * (float)p->acc_z) );
p->AngleX = atan(temp)*57.29578f; // 180/π=57.29578
temp = (float)p->acc_y / sqrt( ((float)p->acc_x * (float)p->acc_x + (float)p->acc_z * (float)p->acc_z) );
p->AngleY = atan(temp)*57.29578f; // 180/π=57.29578
temp = sqrt( ((float)p->acc_x * (float)p->acc_x + (float)p->acc_y * (float)p->acc_y) ) / (float)p->acc_z;
p->AngleZ = atan(temp)*57.29578f; // 180/π=57.29578
// Serial0.printf("X:%.1f , Y:%.2f , Z:%.2f\n",p->AngleX,p->AngleY,p->AngleZ);
}
// 获取Motion状态
uint8_t qmi8658_fetch_motion(void)
{
uint8_t status = 0;
qmi8658_register_read(QMI8658_STATUS1, &status, 1); // 读状态寄存器
return status;
}
/*************************** 姿态传感器 QMI8658 ↑ ****************************/
/*******************************************************************************/

97
src/qmi8658.h Normal file
View File

@ -0,0 +1,97 @@
#ifndef __QMI8658_H__
#define __QMI8658_H__
#include "Arduino.h"
#include "Wire.h"
#include "driver/i2c.h"
#define QMI8658_SENSOR_ADDR 0x6A // QMI8658 I2C地址
// QMI8658寄存器地址
enum qmi8658_reg
{
QMI8658_WHO_AM_I,
QMI8658_REVISION_ID,
QMI8658_CTRL1,
QMI8658_CTRL2,
QMI8658_CTRL3,
QMI8658_CTRL4,
QMI8658_CTRL5,
QMI8658_CTRL6,
QMI8658_CTRL7,
QMI8658_CTRL8,
QMI8658_CTRL9,
QMI8658_CATL1_L,
QMI8658_CATL1_H,
QMI8658_CATL2_L,
QMI8658_CATL2_H,
QMI8658_CATL3_L,
QMI8658_CATL3_H,
QMI8658_CATL4_L,
QMI8658_CATL4_H,
QMI8658_FIFO_WTM_TH,
QMI8658_FIFO_CTRL,
QMI8658_FIFO_SMPL_CNT,
QMI8658_FIFO_STATUS,
QMI8658_FIFO_DATA,
QMI8658_STATUSINT = 45,
QMI8658_STATUS0,
QMI8658_STATUS1,
QMI8658_TIMESTAMP_LOW,
QMI8658_TIMESTAMP_MID,
QMI8658_TIMESTAMP_HIGH,
QMI8658_TEMP_L,
QMI8658_TEMP_H,
QMI8658_AX_L,
QMI8658_AX_H,
QMI8658_AY_L,
QMI8658_AY_H,
QMI8658_AZ_L,
QMI8658_AZ_H,
QMI8658_GX_L,
QMI8658_GX_H,
QMI8658_GY_L,
QMI8658_GY_H,
QMI8658_GZ_L,
QMI8658_GZ_H,
QMI8658_COD_STATUS = 70,
QMI8658_dQW_L = 73,
QMI8658_dQW_H,
QMI8658_dQX_L,
QMI8658_dQX_H,
QMI8658_dQY_L,
QMI8658_dQY_H,
QMI8658_dQZ_L,
QMI8658_dQZ_H,
QMI8658_dVX_L,
QMI8658_dVX_H,
QMI8658_dVY_L,
QMI8658_dVY_H,
QMI8658_dVZ_L,
QMI8658_dVZ_H,
QMI8658_TAP_STATUS = 89,
QMI8658_STEP_CNT_LOW,
QMI8658_STEP_CNT_MIDL,
QMI8658_STEP_CNT_HIGH,
QMI8658_RESET = 96
};
// 倾角结构体
typedef struct{
int16_t acc_x;
int16_t acc_y;
int16_t acc_z;
int16_t gyr_x;
int16_t gyr_y;
int16_t gyr_z;
float AngleX;
float AngleY;
float AngleZ;
}t_sQMI8658;
esp_err_t qmi8658_init(void); // QMI8658初始化
void qmi8658_close(void); // 关闭芯片运行
void qmi8658_fetch_angleFromAcc(t_sQMI8658 *p); // 获取倾角
uint8_t qmi8658_fetch_motion(void); // 获取运动状态
#endif

14
src/red_ray.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "red_ray.h"
#define RED_RAY_PIN 8
void red_ray_init() {
pinMode(RED_RAY_PIN, OUTPUT);
red_ray_off();
}
void red_ray_on() {
digitalWrite(RED_RAY_PIN, HIGH);
}
void red_ray_off() {
digitalWrite(RED_RAY_PIN, LOW);
}

9
src/red_ray.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef __RED_RAY_H__
#define __RED_RAY_H__
#include "Arduino.h"
void red_ray_init();
void red_ray_on();
void red_ray_off();
#endif

171
src/save.h Normal file
View File

@ -0,0 +1,171 @@
#ifndef __SAVE_H__
#define __SAVE_H__
#include "Arduino.h"
#pragma pack(1)
#define SpectralData 0x00ff00ff
#define SpectralInfo 0xff00ff00
#define Other 0xf0f0f0f0
#define Image 0x0f0f0f0f
// #define SpectralData_Squantity 0x0003
#define SpectralInfo_Squantity 0x0001
// #define Other_Squantity 0x0000
#define Image_Squantity 0x0001
#define hh3_DCFiberID 0
#define hh3_FiberID 1
#define hh3_FlatFiberID 2
#define s_dn 0
#define rad 1
#define ref 2
#define irad 3
#define califile 4
#define flat_ref 5
#define dark_dn 6
#define flat_dn 7
#define DATA_TYPE_UINT8 0x10
#define DATA_TYPE_INT16 0x11
#define DATA_TYPE_UINT16 0x12
#define DATA_TYPE_INT32 0x13
#define DATA_TYPE_UINT32 0x14
#define DATA_TYPE_FLOAT32 0x20
#define DATA_TYPE_FLOAT64 0x21
typedef struct
{
int8_t timezone; // 时区
uint16_t year; // 年
uint8_t month; // 月
uint8_t day; // 日
uint8_t hour; // 时
uint8_t minute; // 分
uint8_t second; // 秒
uint16_t millisecond; // 毫秒
}IRIS_Time_Struct;
typedef struct {
uint64_t DataLength; // 图像数据长度
char Name[100]; // 图像名称
IRIS_Time_Struct CollectionTime; // 采集时间
uint8_t Type; // 图像类型
uint8_t *ImageDataAddress; // 图像数据地址 (pointer to data)
} One_Image_Info_Struct;
typedef struct {
char name[100]; // basename_number_type字符串 \0结尾
char sensor_id[50]; // 传感器ID \0结束符
uint8_t FiberID; // 光纤ID
IRIS_Time_Struct date; // 时间结构体
double integration_time; //积分时间
float gain; //填0
uint8_t data_type; //数据类型 0x10 uint8_t ,0x11 int16_t, 0x12 uint16_t, 0x13 int32_t, 0x14 uint32_t, 0x20 float, 0x21 double
uint8_t PixelSize; //数据类型长度 1,2,4,8
uint8_t GroundType; //地物类别 0 dn 1 rad 2 ref 3 irad 4 califile 5 flat_ref 6 dark_dn 6 flat_dn
uint16_t band_num; //波段数
uint8_t ValidFlag; //数据是否有效
uint16_t data[515]; //数据
} HH3_data_struct;
typedef struct {
char Name[100]; // 光谱数据名称
char SensorId[50]; // 传感器ID
uint8_t FiberID; // 光纤ID
IRIS_Time_Struct CollectionTime; // 采集时间
double Exposure; // 曝光时间
float Gain; // 增益
uint8_t DataType; // 数据类型
uint8_t PixelSize; // 像素大小
uint8_t GroundType; // 地面类型
uint16_t Bands; // 波段数
uint8_t ValidFlag; // 有效标志
uint8_t *SpectralDataAddress; // 光谱数据地址 (pointer to data)
} One_Spectral_Data_Struct;
typedef struct{
uint32_t SectionFlag;
uint64_t SectionLength;
uint16_t Squantity;
}SpectralData_Section_Header;
typedef struct{
uint32_t SectionFlag;
uint64_t SectionLength;
uint16_t Squantity;
uint16_t info1_length;
uint8_t info1_type;
}SpectralInfo_Section_Header;
typedef struct{
uint32_t SectionFlag;
uint64_t SectionLength;
// uint16_t Squantity;
}Other__Section_Header;
typedef struct{
uint16_t Squantity;
uint64_t length;
uint8_t name[100];
IRIS_Time_Struct date; // 时间结构体
uint8_t type;
uint8_t *data;
}picture;
typedef struct{
uint32_t SectionFlag;
uint64_t SectionLength;
// uint32_t length;
// uint64_t name;
// IRIS_Time_Struct date; // 时间结构体
// uint32_t type;
}Image_Section_Header;
typedef struct{
char name[100]; // basename_number_type字符串 \0结尾
char sensor_id[50]; // 传感器ID \0结束符
uint8_t FiberID; // 光纤ID
IRIS_Time_Struct date; // 时间结构体
double integration_time; //积分时间
float gain; //填0
uint8_t data_type; //数据类型 0x10 uint8_t ,0x11 int16_t, 0x12 uint16_t, 0x13 int32_t, 0x14 uint32_t, 0x20 float, 0x21 double
uint8_t PixelSize; //数据类型长度 1,2,4,8
uint8_t GroundType; //地物类别 0 dn 1 rad 2 ref 3 irad 4 califile 5 flat_ref 6 dark_dn 6 flat_dn
uint16_t band_num; //波段数
uint8_t ValidFlag; //数据是否有效
double data[515]; //数据 //LJ 20250513 512--->515
}califlie_data_struct;
typedef struct{
SpectralData_Section_Header SpectralData_Header;
califlie_data_struct gian;
califlie_data_struct califlie_dn;
califlie_data_struct califlie_lampvalue;
}HH3califlie;
typedef struct{
One_Spectral_Data_Struct *s_dn_data;
One_Spectral_Data_Struct *wr_dn_data;
One_Spectral_Data_Struct *dark_dn_data;
One_Spectral_Data_Struct *flat_ref_data;
One_Spectral_Data_Struct *califile_data;
uint8_t *data_info;
picture *image_info;
} read_file_point;
#pragma pack()
#endif

198
src/sd_card.cpp Normal file
View File

@ -0,0 +1,198 @@
#include "sd_card.h"
#define sd_cmd 7
#define sd_clk 6
#define sd_dat0 5
#define sd_dat1 4
#define sd_dat2 16
#define sd_dat3 15
uint32_t used_percent;
bool sd_card_status = true;
// bool sd_card_init()
// {
// SD_MMC.end();
// SD_MMC.setPins(sd_clk,sd_cmd,sd_dat0,sd_dat1,sd_dat2,sd_dat3);
// int succ = SD_MMC.begin("/sdcard", false, false, 10);
// if (succ)
// {
// // Serial0.println("SD_MMC Mount successful");
// uint8_t cardType = SD_MMC.cardType();
// if (cardType == CARD_MMC) {
// } else if (cardType == CARD_SD) {
// } else if (cardType == CARD_SDHC) {
// } else {
// }
// uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
// // uint32_t c = cardSize;
// // Serial0.printf("SD_MMC Card Size: %lluMB\n", cardSize);
// // float a = SD_MMC.totalBytes() / (1024 * 1024);
// // Serial0.printf("Total space: %lluMB\n", a);
// // float b = SD_MMC.usedBytes() / (1024 * 1024);
// // Serial0.printf("Used space: %lluMB\n", b);
// // used_percent = b/a*100;
// } else {
// Serial0.println("SD_MMC Mount failed");
// sd_card_status = false;
// return false;
// }
// sd_card_status = true;
// SD_MMC.mkdir("/data");
// SD_MMC.mkdir("/log");
// SD_MMC.mkdir("/system");
// // sd_card_status = true;
// // sd_card_status = sd_card_status & SD_MMC.mkdir("/data");
// // sd_card_status = sd_card_status & SD_MMC.mkdir("/log");
// // sd_card_status = sd_card_status & SD_MMC.mkdir("/system");
// // if(sd_card_status == false)
// // {
// // Serial0.println(" sdcard_mkdir_fail ");
// // }
// return sd_card_status;
// }
bool sd_card_init()
{
SD_MMC.end();
SD_MMC.setPins(sd_clk,sd_cmd,sd_dat0,sd_dat1,sd_dat2,sd_dat3);
uint16_t i = 1;
while(i)
{
if(SD_MMC.begin("/sdcard", false, false,SDMMC_FREQ_HIGHSPEED, 10))
{
Serial0.println("SD_MMC begin success");
uint8_t cardType = SD_MMC.cardType();
if (cardType == CARD_MMC) {
} else if (cardType == CARD_SD) {
} else if (cardType == CARD_SDHC) {
} else {
}
uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
break;
}
if(i >= 10)
{
Serial0.println("SD_MMC begin fail");
sd_card_status = false;
return false;
}
i++;
vTaskDelay(20);
}
sd_card_status = true;
SD_MMC.mkdir("/data");
SD_MMC.mkdir("/log");
SD_MMC.mkdir("/system");
return sd_card_status;
}
// bool get_sd_card_status()
// {
// // if(SD_MMC.totalBytes()/(1024 * 1024) < 100) sd_card_status = false;
// return sd_card_status;
// }
bool get_sd_card_status() {
// SD.cardType() 返回 0 表示没有检测到卡
if (SD_MMC.cardType() == CARD_NONE) {
sd_card_status = false;
} else {
sd_card_status = true;
}
return sd_card_status;
}
uint32_t i = 0;
float get_sd_used_percent()
{
if(sd_card_status == false ) return 0;
float used;
if((i % (60 * 5 * 5))== 0)
{
used = ceil((float)SD_MMC.usedBytes() / (float)SD_MMC.totalBytes() * 100.f);
i = 0;
}
i++;
used = used > 1 ? used : 1;
return used;
}
#define OTA_BUF_SIZE 1024
#include "esp_ota_ops.h"
void sdcard_ota_update(void)
{
FILE *f = fopen("/sdcard/config/firmware/firmware.bin", FILE_READ);
if (!f) {
ESP_LOGE("OTA", "Failed to open firmware");
return;
}
const esp_partition_t *update_partition =
esp_ota_get_next_update_partition(NULL);
esp_ota_handle_t ota_handle;
esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &ota_handle);
uint8_t buf[OTA_BUF_SIZE];
int len;
while ((len = fread(buf, 1, OTA_BUF_SIZE, f)) > 0) {
esp_ota_write(ota_handle, buf, len);
// vTaskDelay(1);
}
fclose(f);
esp_ota_end(ota_handle);
esp_ota_set_boot_partition(update_partition);
ESP_LOGI("OTA", "Update success, rebooting...");
esp_restart();
}
void update_firmware()
{
if(get_sd_card_status() == false) return;
String version_now = String(Version_3);
String version_new;
File file = SD_MMC.open("/config/firmware/Version.txt",FILE_READ);
if(file)
{
version_new = file.readString();
Serial0.println(version_new);
file.close();
if(version_new != version_now)
{
Serial0.println("start update");
sdcard_ota_update();
}
}
}

15
src/sd_card.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef __SD_CARD_H__
#define __SD_CARD_H__
#include <Arduino.h>
// #include <SD.h>
#include "FS.h"
#include <SD_MMC.h>
#include "header.h"
bool sd_card_init();
bool get_sd_card_status();
float get_sd_used_percent();
void update_firmware();
#endif

26
src/speak.cpp Normal file
View File

@ -0,0 +1,26 @@
#include "speak.h"
Audio audio;
void speak_init()
{
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
audio.setVolume(21); // 0...21
pinMode(SPK_CTRL, OUTPUT);
digitalWrite(SPK_CTRL, HIGH);
if (!SPIFFS.begin(true)) {
Serial0.println("SPIFFS mount failed!");
return;
}
}
void speak_on()
{
digitalWrite(SPK_CTRL, HIGH);
}
void speak_off()
{
digitalWrite(SPK_CTRL, LOW);
}

15
src/speak.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef __SPEAK_H__
#define __SPEAK_H__
#define I2S_DOUT 45
#define I2S_BCLK 39
#define I2S_LRC 40
#define SPK_CTRL 38
#include "Audio.h"
extern Audio audio;
void speak_init();
void speak_on();
void speak_off();
#endif

3226
src/ui_task.cpp Normal file

File diff suppressed because it is too large Load Diff

102
src/ui_task.h Normal file
View File

@ -0,0 +1,102 @@
#ifndef UI_TASK_H
#define UI_TASK_H
#include "header.h"
#include "driver/i2c.h"
#define system_tem_path "/system/system_tem.json"
#define califile_path "/config/califile"
#define ITEMS_PER_PAGE 10
#define english 0
#define chinese 1
#define language chinese
#define IS3_GET_DATA_DONE_BIT (1<<0)
#define IS3_GET_DATA_DONE0_BIT (1<<1) //plot
#define IS3_GET_DATA_DONE1_BIT (1<<2) //opt
#define IS3_GET_DATA_DONE2_BIT (1<<3) //wr
#define IS3_GET_DATA_DONE3_BIT (1<<4) //save
#define IS3_GET_DATA_DONE4_BIT (1<<5) //dc
#define IS3_GET_DATA_DONE5_BIT (1<<6) //set it
#define RED_RAY_BIT (1<<7)
#define is3_kaijimusic_bit (1<<8)
#define IS3_AVERAGE_DONE1_BIT (1<<9)
#define IS3_AVERAGE_DONE2_BIT (1<<10)
#define IS3_CAM_DONE_BIT (1<<11)
#define IS3_UPDATA_BIT (1<<12)
void ui_task_init(void);
void updata_to_ui(void *pvParameters);
void main_2_opt(void *pvParameters);
void main_2_plot(void *pvParameters);
void main_2_dc(void *pvParameters);
void main_2_save(void *pvParameters);
void main_2_wr(void *pvParameters);
void get_is3_data(void *pvParameters);
void set_it_task(void *pvParameters);
void main_2_rad(void *pvParameters);
void red_ray_task(void* arg);
void power_off_task(void *pvParameters);
void play_music_task(void* arg);
void set_system_time_task(void *pvParameters);
// void kaiji_music_task(void* arg);
void calculate_average_task(void *pvParameters);
void fiber_sel_task(void* arg);
void ui_time_task(void *pvParameters);
void show_data_task(void *pvParameters);
void save_path_task(void *pvParameters);
void save_system_info(String system_info);
String read_system_info();
bool califile_init();
bool califile_read(uint32_t califile_num);
void system_data_init();
// void play_music(String music_path);
// void play_music(const char *music_path);
// void header_pack();
void header_pack(String SpectralInfo_str);
void Ground_DN_pack();
void wr_dn_pack(bool flag);
void dark_dn_pack(bool flag);
void flat_ref_pack();
void picture_pack(String name,String num);
void dark_dn_collect();
uint32_t find_califile(String fiber_type, String fiber_length, String fiber_width);
// void save_data(String path ,String name);
void save_data(String path ,String name,String SpectralInfo_str);
void print_heap_detail();
static uint32_t show_page(String path, uint32_t page);
// static uint32_t get_file_num(String path);
static uint32_t get_file_num(String path_str);
bool read_data_from_file(String path);
bool file_data_analysis(read_file_point *p);
void change_plot_type(read_file_point file_point,uint8_t plot_type);
void show_picture(read_file_point *p);
void pc_mode_task(void *pvParameters);
void flat_task(void *pvParameters);
void reset_flat_sturct();
extern EventGroupHandle_t is3_event_group;
extern uint32_t system_time_count;
extern picture image_picture;
#endif
//////////////
/*
数据查看
*/
//////////////

364
src/usb_camera.cpp Normal file
View File

@ -0,0 +1,364 @@
// #include "usb_camera.h"
// USB_STREAM *usb = NULL;
// static uint8_t *_xferBufferA = NULL;
// static uint8_t *_xferBufferB = NULL;
// static uint8_t *_frameBuffer = NULL;
// const uint16_t img_width = 480;
// const uint16_t img_height = 320;
// const uint16_t CROP_WIDTH = 480;
// const uint16_t CROP_HEIGHT = 230;
// static uint8_t camera_status = 0; //0停止 1运行
// volatile uint16_t camera_W = 480;
// lv_color_t * picture_buff=NULL;
// bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap)
// {
// // if (y >= CROP_HEIGHT) return 0; // 忽略底部多余区域
// for (int j = 0; j < h; j++) {
// int yy = y + j;
// if (yy >= CROP_HEIGHT) continue; // 裁剪下边界
// for (int i = 0; i < w; i++) {
// int xx = x + i;
// // if (xx >= CROP_WIDTH) continue; // 裁剪右边界
// int dst_idx = yy * CROP_WIDTH + xx;
// picture_buff[dst_idx].full = bitmap[j * w + i];
// }
// }
// return 1;
// }
// void initJPEGDecoder() {
// TJpgDec.setJpgScale(1); // 原尺寸
// TJpgDec.setSwapBytes(false); // RGB 转换
// TJpgDec.setCallback(tft_output);
// }
// uint8_t get_cam_status()
// {
// return camera_status;
// }
// uint16_t last_length = 0;
// static void onCameraFrameCallback(uvc_frame *frame, void *user_ptr)
// {
// // Serial0.printf("uvc callback! frame_format = %d, seq = %" PRIu32 ", width = %" PRIu32", height = %" PRIu32 ", length = %u, ptr = %d\n",
// // frame->frame_format, frame->sequence, frame->width, frame->height, frame->data_bytes, (int)user_ptr);
// // uint8_t *ptr = (uint8_t *)frame->data;
// // if (!(ptr[frame->data_bytes - 2] == 0xFF && ptr[frame->data_bytes - 1] == 0xD9)) return;
// if(camera_status == 0 )
// {
// camera_status = 1 ;
// }
// // if((camera_W == 800) && (image_picture.length == 0))
// // {
// // uint8_t *ptr = (uint8_t *)frame->data;
// // if(frame->frame_format == UVC_FRAME_FORMAT_MJPEG)
// // {
// // if(ptr[0] != 0xFF || ptr[1] != 0xD8 || // SOI
// // ptr[frame->data_bytes - 2] != 0xFF || ptr[frame->data_bytes - 1] != 0xD9) // EOI
// // {
// // // Serial0.println("data not eghough");
// // if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS)
// // {
// // image_picture.length = last_length;
// // xSemaphoreGive(xMutexInventory);
// // }
// // return; // 数据不完整
// // }
// // }
// if((camera_W == 800))
// {
// uint8_t *ptr = (uint8_t *)frame->data;
// if(frame->frame_format == UVC_FRAME_FORMAT_MJPEG)
// {
// if(ptr[0] != 0xFF || ptr[1] != 0xD8 || // SOI
// ptr[frame->data_bytes - 2] != 0xFF || ptr[frame->data_bytes - 1] != 0xD9) // EOI
// {
// // Serial0.println("data not eghough");
// if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS)
// {
// image_picture.length = last_length;
// xSemaphoreGive(xMutexInventory);
// }
// return; // 数据不完整
// }
// }
// if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS)
// {
// memcpy(image_picture.data, frame->data, frame->data_bytes);
// image_picture.length = frame->data_bytes;
// last_length = frame->data_bytes;
// xSemaphoreGive(xMutexInventory);
// }
// xEventGroupSetBits(is3_event_group,IS3_CAM_DONE_BIT);
// }
// TJpgDec.drawJpg(0, 0, (uint8_t *)frame->data,frame->data_bytes);
// memcpy(buf_main_2_canvas_2,picture_buff,CROP_WIDTH * CROP_HEIGHT * sizeof(lv_color_t));
// vTaskDelay(1);
// xEventGroupSetBits(ui_event_group,CAM_DONE_BIT);
// }
// void CAM_start_task(void *pvParameters)
// {
// while(1)
// {
// xEventGroupWaitBits(ui_event_group,CAM_START_BIT,pdTRUE,pdFALSE,portMAX_DELAY);
// // Serial0.println("CAM_start_task");
// if(camera_status == 1) continue;
// if(camera_W == 800) continue;
// usb->uvcCamResume(NULL);
// // camera_status = 1;
// }
// }
// void CAM_stop_task(void *pvParameters)
// {
// while(1)
// {
// xEventGroupWaitBits(ui_event_group,CAM_STOP_BIT,pdTRUE,pdFALSE,portMAX_DELAY);
// // Serial0.println("CAM_stop_task");
// if(camera_status == 0) continue;
// if(camera_W == 800) continue;
// usb->uvcCamSuspend(NULL);
// camera_status = 0;
// }
// }
// esp_err_t USB_CAM_Init()
// {
// initJPEGDecoder();
// usb = new USB_STREAM();
// buf_main_2_canvas_2 = (lv_color_t *)heap_caps_malloc(CROP_WIDTH * CROP_HEIGHT * sizeof(lv_color_t), MALLOC_CAP_SPIRAM);
// picture_buff = (lv_color_t *)heap_caps_malloc(CROP_WIDTH * CROP_HEIGHT * sizeof(lv_color_t), MALLOC_CAP_SPIRAM);
// buf_screen_data_canvas_1 = (lv_color_t *)heap_caps_malloc(324 * 204 * sizeof(lv_color_t), MALLOC_CAP_SPIRAM);
// _xferBufferA = (uint8_t *)heap_caps_malloc(55 * 1024, MALLOC_CAP_SPIRAM);
// assert(_xferBufferA != NULL);
// _xferBufferB = (uint8_t *)heap_caps_malloc(55 * 1024, MALLOC_CAP_SPIRAM);
// assert(_xferBufferB != NULL);
// _frameBuffer = (uint8_t *)heap_caps_malloc(55 * 1024, MALLOC_CAP_SPIRAM);
// assert(_frameBuffer != NULL);
// // cam_mode(1);
// usb->uvcConfiguration(480, 320, FRAME_INTERVAL_FPS_15, 55 * 1024, _xferBufferA, _xferBufferB, 55 * 1024, _frameBuffer);
// // uvc_set_ctrl();
// camera_W = 480;
// usb->uvcCamRegisterCb(&onCameraFrameCallback, NULL);
// usb->start();
// usb->connectWait(1000);
// xTaskCreatePinnedToCore(CAM_start_task, "CAM_start_task", 1024*3, NULL, 1, NULL, 1);
// xTaskCreatePinnedToCore(CAM_stop_task, "CAM_stop_task", 1024*3, NULL, 1, NULL, 1);
// // usb_streaming_ctrl_camera();
// return ESP_OK;
// }
// esp_err_t USB_CAM_SetResolution(uint16_t cam_width, uint16_t cam_height)
// {
// // 停止当前摄像头
// // usb->stop();
// // 重新配置摄像头分辨率和其他参数
// // usb->uvcConfiguration(cam_width, cam_height, FRAME_INTERVAL_FPS_15, 55 * 1024, _xferBufferA, _xferBufferB, 55 * 1024, _frameBuffer);
// // 重新启动摄像头
// // usb->start();
// // usb->uvcCamSuspend(NULL);
// // camera_status = 0;
// // // Serial0.println("width = " + String(cam_width) + " height = " + String(cam_height));
// // usb->uvcCamFrameReset(cam_width, cam_height, FRAME_INTERVAL_FPS_15);
// // if(get_cam_status() == 0) xEventGroupSetBits(ui_event_group,CAM_START_BIT);
// // usb->uvcCamResume(NULL);
// // int scroll_x = lv_obj_get_scroll_x(guider_ui.main_2_tileview_1);
// // if(cam_width == 800)
// // {
// // usb->uvcCamResume(NULL);
// // }
// // if(cam_width == 400)
// // {
// // if(scroll_x == 0) usb->uvcCamSuspend(NULL);
// // }
// camera_status = 0;
// camera_W = cam_width;
// return ESP_OK;
// }
/////////////////////////////////////////////////////////////////////////////
#include "usb_camera.h"
#include <USB.h>
static uint8_t *_xferBufferA = NULL;
const uint16_t img_width = 480;
const uint16_t img_height = 320;
const uint16_t CROP_WIDTH = 480;
const uint16_t CROP_HEIGHT = 230;
static uint8_t camera_status = 0; //0停止 1运行
volatile uint16_t camera_W = 480;
lv_color_t * picture_buff=NULL;
bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap)
{
// if (y >= CROP_HEIGHT) return 0; // 忽略底部多余区域
for (int j = 0; j < h; j++) {
int yy = y + j;
if (yy >= CROP_HEIGHT) continue; // 裁剪下边界
for (int i = 0; i < w; i++) {
int xx = x + i;
// if (xx >= CROP_WIDTH) continue; // 裁剪右边界
int dst_idx = yy * CROP_WIDTH + xx;
picture_buff[dst_idx].full = bitmap[j * w + i];
}
}
return 1;
}
void initJPEGDecoder() {
TJpgDec.setJpgScale(1); // 原尺寸
TJpgDec.setSwapBytes(false); // RGB 转换
TJpgDec.setCallback(tft_output);
}
uint8_t get_cam_status()
{
return camera_status;
}
uint16_t last_length = 0;
static void onCameraFrameCallback(void* event_handler_arg,esp_event_base_t event_base,int32_t event_id,void* event_data)
{
if(camera_status == 0 )
{
camera_status = 1 ;
}
size_t len = 0;
while(Serial.available())
{
len += Serial.readBytes(_xferBufferA + len, 55 * 1024);
}
if(camera_W == 800 && len > 0)
{
uint8_t *ptr = _xferBufferA;
if(ptr[0] != 0xFF || ptr[1] != 0xD8 || // SOI
ptr[len - 2] != 0xFF || ptr[len - 1] != 0xD9) // EOI
{
// Serial0.println("data not eghough");
if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS)
{
image_picture.length = last_length;
xSemaphoreGive(xMutexInventory);
}
return; // 数据不完整
}
if(xSemaphoreTake(xMutexInventory, timeOut) == pdPASS)
{
memcpy(image_picture.data, _xferBufferA, len);
image_picture.length = len;
last_length = len;
xSemaphoreGive(xMutexInventory);
}
xEventGroupSetBits(is3_event_group,IS3_CAM_DONE_BIT);
}
if(len > 0)
{
TJpgDec.drawJpg(0, 0, _xferBufferA,len);
memcpy(buf_main_2_canvas_2,picture_buff,CROP_WIDTH * CROP_HEIGHT * sizeof(lv_color_t));
xEventGroupSetBits(ui_event_group,CAM_DONE_BIT);
}
vTaskDelay(1);
}
esp_err_t USB_CAM_Init()
{
initJPEGDecoder();
// usb = new USB_STREAM();
Serial.onEvent(onCameraFrameCallback);
Serial.setRxBufferSize(1024 * 20);
Serial.setTimeout(10);
Serial.begin(12000000);
//lvgl
buf_main_2_canvas_2 = (lv_color_t *)heap_caps_malloc(CROP_WIDTH * CROP_HEIGHT * sizeof(lv_color_t), MALLOC_CAP_SPIRAM);
buf_screen_data_canvas_1 = (lv_color_t *)heap_caps_malloc(324 * 204 * sizeof(lv_color_t), MALLOC_CAP_SPIRAM);
//
picture_buff = (lv_color_t *)heap_caps_malloc(CROP_WIDTH * CROP_HEIGHT * sizeof(lv_color_t), MALLOC_CAP_SPIRAM);
_xferBufferA = (uint8_t *)heap_caps_malloc(55 * 1024, MALLOC_CAP_SPIRAM);
assert(_xferBufferA != NULL);
// _xferBufferB = (uint8_t *)heap_caps_malloc(55 * 1024, MALLOC_CAP_SPIRAM);
// assert(_xferBufferB != NULL);
return ESP_OK;
}
esp_err_t USB_CAM_SetResolution(uint16_t cam_width, uint16_t cam_height)
{
camera_status = 0;
camera_W = cam_width;
return ESP_OK;
}

20
src/usb_camera.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef __USB_CAMERA_H__
#define __USB_CAMERA_H__
#include <Arduino.h>
#include "header.h"
#include "USB_STREAM.h"
// #include <JPEGDecoder.h>
esp_err_t USB_CAM_Init();
// esp_err_t USB_CAM_SetResolution(uint16_t width, uint16_t height);
esp_err_t USB_CAM_SetResolution(uint16_t cam_width, uint16_t cam_height);
uint8_t get_cam_status();
void initJPEGDecoder();
typedef struct {
uint16_t width;
uint16_t height;
uint8_t *data;
} cam_jpg_data;
#endif

115
src/wifi_client.cpp Normal file
View File

@ -0,0 +1,115 @@
#include "wifi_client.h"
const char* ssid = "123";
const char* password = "12345678";
const char* host = "192.168.144.57"; // 服务器 IP 地址
const uint16_t port = 1133; // TCP 端口
WiFiClient client;
bool wifi_init()
{
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial0.println("Connecting to WiFi...");
uint8_t i = 0;
while (WiFi.status() != WL_CONNECTED)
{
i++;
if (i > 20)
{
Serial0.println("Failed to connect to WiFi.");
// continue;
// ESP.restart();
return false;
}
Serial0.print(".");
vTaskDelay(100);
}
Serial0.println("\nWiFi connected.");
Serial0.print("IP address: ");
Serial0.println(WiFi.localIP());
configTime(8 * 3600, 0, "pool.ntp.org", "ntp.aliyun.com");
struct tm timeinfo;
while (!getLocalTime(&timeinfo)) {
Serial0.println("Waiting for NTP time...");
delay(500);
}
Serial0.printf("NTP Time: %04d-%02d-%02d %02d:%02d:%02d\n",
timeinfo.tm_year + 1900, timeinfo.tm_mon + 1, timeinfo.tm_mday,
timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
ds1307_set_time(timeinfo.tm_year + 1900,timeinfo.tm_mon + 1, timeinfo.tm_mday,timeinfo.tm_hour, timeinfo.tm_min,timeinfo.tm_sec);
// // 连接 TCP 服务器
// Serial0.printf("Connecting to %s:%d ...\n", host, port);
// if (client.connect(host, port)) {
// Serial0.println("Connected to server.");
// client.println("Hello from ESP32-S3!");
// // client.stop(); // 关闭连接
// } else {
// Serial0.println("Connection to server failed.");
// }
// client.println("Hello World" + String(count));
// xTaskCreatePinnedToCore(wifi_connect_to, "wifi_connect_to", 1024*5, NULL, 1, NULL, 0);
}
void wifi_connect_to(void *pvParameters)
{
while(1)
{
xEventGroupWaitBits(ui_event_group, WIFI_BIT, pdTRUE, pdFALSE, portMAX_DELAY);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial0.println("Connecting to WiFi...");
uint8_t i = 0;
while (WiFi.status() != WL_CONNECTED)
{
i++;
if (i > 20)
{
Serial0.println("Failed to connect to WiFi.");
continue;
// ESP.restart();
// return false;
}
Serial0.print(".");
vTaskDelay(100);
}
Serial0.println("\nWiFi connected.");
Serial0.print("IP address: ");
Serial0.println(WiFi.localIP());
configTime(8 * 3600, 0, "pool.ntp.org", "ntp.aliyun.com");
struct tm timeinfo;
while (!getLocalTime(&timeinfo)) {
Serial0.println("Waiting for NTP time...");
delay(500);
}
Serial0.printf("NTP Time: %04d-%02d-%02d %02d:%02d:%02d\n",
timeinfo.tm_year + 1900, timeinfo.tm_mon + 1, timeinfo.tm_mday,
timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
ds1307_set_time(timeinfo.tm_year + 1900,timeinfo.tm_mon + 1, timeinfo.tm_mday,timeinfo.tm_hour, timeinfo.tm_min,timeinfo.tm_sec);
}
}
// uint32_t count = 0;
// void loop()
// {
// count++;
// vTaskDelay(1000 / portTICK_PERIOD_MS);
// }

12
src/wifi_client.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef WIFI_CLIENT_H
#define WIFI_CLIENT_H
#include "header.h"
#include "WiFi.h"
void wifi_connect_to(void *pvParameters);
bool wifi_init();
#endif

3
version.txt Normal file
View File

@ -0,0 +1,3 @@
//2026/03/23
//发行版
<version>V2.0.2.5