This commit is contained in:
小马_666 2025-06-23 13:24:12 +08:00
parent 588f9429b1
commit 0975c9bb02
3 changed files with 48 additions and 41 deletions

View File

@ -5,7 +5,7 @@
"type": "mrs-debugger",
"request": "launch",
"name": "ble_bjq_ch303rct6_ml307",
"cwd": "c:\\Users\\16586\\Desktop\\ble_-tyq_-bjq_-ch32-v303",
"cwd": "d:\\SXDT\\Project\\CH32\\ble_bjq_ch303rct6_ml307",
"openOCDCfg": {
"useLocalOpenOCD": true,
"executable": "c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/openocd.exe",
@ -39,8 +39,8 @@
"additionalCommands": []
},
"loadedFiles": {
"executableFile": "c:\\Users\\16586\\Desktop\\ble_-tyq_-bjq_-ch32-v303\\obj\\ble_bjq_ch303rct6_ml307.elf",
"symbolFile": "c:\\Users\\16586\\Desktop\\ble_-tyq_-bjq_-ch32-v303\\obj\\ble_bjq_ch303rct6_ml307.elf",
"executableFile": "d:\\SXDT\\Project\\CH32\\ble_bjq_ch303rct6_ml307\\obj\\ble_bjq_ch303rct6_ml307.elf",
"symbolFile": "d:\\SXDT\\Project\\CH32\\ble_bjq_ch303rct6_ml307\\obj\\ble_bjq_ch303rct6_ml307.elf",
"executableFileOffset": 0,
"symbolFileOffset": 0
},

View File

@ -2,7 +2,7 @@
* @Author: mbw
* @Date: 2024-10-23 17:14:16
* @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2025-06-21 10:00:44
* @LastEditTime: 2025-06-23 13:13:56
* @FilePath: \ble_bjq_ch303rct6_ml307\applications\main.c
* @Descrt_thread_
*
@ -153,6 +153,7 @@ void Preheat_Timer_Callback(void *parameter)
LED_STOP(y);
LOG_D("预热完成");
preheat_flag = 1;
if (g_Calibration_status == kSysGasCalibStatus)
{
Send_Laser_Alarm_Event(kNormalDetectionEvents);
@ -225,44 +226,46 @@ int APP_Calibration_Handle(void)
}
#if 1
uint8_t i = 0;
uint16_t gas_buf[20] = {0};
rt_memset(gas_buf, 0, sizeof(gas_buf));
// 采集10s的ADC值
for (i = 0; i < 10; i++)
{
gas_buf[i] = Get_Gas_VoltageInt1000x();
if ((gas_buf[i] == 0) || (gas_buf[i] >= 5000)) // (3.3*1.784*1000)
{
Send_Laser_Alarm_Event(kNotCalibratedEvent);
return 0;
}
rt_thread_mdelay(500);
}
// uint8_t i = 0;
// uint16_t gas_buf[10] = {0};
// rt_memset(gas_buf, 0, sizeof(gas_buf));
// // 采集10s的ADC值
// for (i = 0; i < 10; i++)
// {
// gas_buf[i] = Get_Gas_VoltageInt1000x();
// if ((gas_buf[i] == 0) || (gas_buf[i] >= 5000)) // (3.3*1.784*1000)
// {
// Send_Laser_Alarm_Event(kNotCalibratedEvent);
// return 0;
// }
// rt_thread_mdelay(500);
// }
// 冒泡排序(升序)
for (i = 0; i < 10 - 1; i++)
{
for (int j = 0; j < 10 - i - 1; j++)
{
if (gas_buf[j] > gas_buf[j + 1])
{
uint16_t temp = gas_buf[j];
gas_buf[j] = gas_buf[j + 1];
gas_buf[j + 1] = temp;
}
}
}
// // 冒泡排序(升序)
// for (i = 0; i < 10 - 1; i++)
// {
// for (int j = 0; j < 10 - i - 1; j++)
// {
// if (gas_buf[j] > gas_buf[j + 1])
// {
// uint16_t temp = gas_buf[j];
// gas_buf[j] = gas_buf[j + 1];
// gas_buf[j + 1] = temp;
// }
// }
// }
// 使用索引 1~8 的8个值求平均即去掉一个最小和一个最大
uint32_t sum = 0;
for (i = 1; i <= 8; i++)
{
sum += gas_buf[i];
}
gas_calibration_voltage = (uint16_t)((sum / 8.0f) - 85);
// // 使用索引 1~8 的8个值求平均即去掉一个最小和一个最大
// uint32_t sum = 0;
// for (i = 1; i <= 8; i++)
// {
// sum += gas_buf[i];
// }
// gas_calibration_voltage = (uint16_t)((sum / 8.0f) - 85);
gas_calibration_voltage = (Get_Gas_VoltageInt1000x() - 50); // 写入标定值
// 写入标定值
calibration_buf[0] = gas_calibration_voltage & 0xFF; // 低字节
calibration_buf[1] = (gas_calibration_voltage >> 8) & 0xFF; // 高字节
@ -458,7 +461,7 @@ int main(void)
rt_uint16_t voltage = Get_Gas_VoltageInt1000x();
if (Sensor_device.detection_flag == kSensorAlarm)
{
if ((voltage > Sensor_device.alarm_value) && (voltage < MQ_VOLTAGE_HIGH_LIMIT))
if (voltage >= Sensor_device.alarm_value)
{
Send_Laser_Alarm_Event(kAlarmEvent);
}

View File

@ -81,7 +81,6 @@ static void Sensor_HandleAlarm(uint8_t count, uint8_t threshold)
alarm_flag = 1;
Sensor_device.detection_flag = kSensorAlarm;
Send_Laser_Alarm_Event(kAlarmEvent);
}
else if (alarm_flag == 1 && count == 0)
{
@ -89,6 +88,11 @@ static void Sensor_HandleAlarm(uint8_t count, uint8_t threshold)
Sensor_device.detection_flag = kSensorNormal;
Send_Laser_Alarm_Event(kAlarmRcyEvent);
}
else if ((Get_Gas_VoltageAdcInt1000x() < 1000) && (count == 0))
{
alarm_flag = 0;
Sensor_device.detection_flag = kSensorNormal;
}
}
static void Sensor_HandleFault(uint8_t count, uint8_t threshold)