Job_SignsPads/STM32/Code/STM32F405/USER/main.h

201 lines
4.8 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @Description:
* @Version: 1.0
* @Autor: lzc
* @Date: 2022-08-19 12:48:36
* @LastEditors: lzc
* @LastEditTime: 2025-01-07 14:23:40
*/
#ifndef __MAIN_H
#define __MAIN_H
#include "stdio.h"
#include <stdlib.h>
#include "string.h"
#include "math.h"
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "key.h"
#include "wificom.h"
#include "timer.h"
#include "opm.h"
#include "adc.h"
#include "gpio.h"
#include "com.h"
#include "usart_send.h"
#include "spi.h"
#include "general.h"
#include "en25qx64.h"
#include "stmflash.h"
#include "system_stm32f4xx.h"
// 1 表示是 养老 0 表示 是BCS
#define THE_VERSION 0
// 1 表示是 提速 0 表示 正常
#define SPEED_UP_MODE_EN 0
// 1 表示是 开启睡眠报告 0 表示 关闭睡眠报告
#define SLEEP_REPORT_EN 0
// 1 表示是 850nm 0 表示 1310nm
#define LINE_COEFF_EN 0
// 1 表示DSP库中的FFT算法 0 表示自己写的FFT算法
#define FFT_VERSION 1
// 1 表示开启上报工厂测试 0 表示没有工厂测试
#define FACTORY_ENABLE 0
#define SYSTEM_CLOCK_FRQ 168 // 系统频率 MHZ
#define model_num 500
#define model_num_send 1024
#define model_time 2
#define TEST_SEND_BH_STAGE 0
#define TEST_SEND_SINGAL 0
#define NOT_PRE_STAGE 1
#define DEFAULT_FF 0xff
#define SLEEP_DEBUG_MODE 0 // 用于调试(弃用)
#define REPORT_SAVE_SIZE 4 // 定义最大睡眠报告的存储4天的数据弃用
#define REPORT_SEND_COUNTS 300 // 300*12 =3600 sec = 1 hour弃用
#define BODY_CHECK_ENABLE 1 // 使能人体检测
#define BODY_CHECK_DISABLE 0 // 失能人体检测
#define OPM_SEND_MODE 0 // 是否发送光功
#define REPORT_BUFFER_MAX 720 // 睡眠报告的最大暂存数组大小 单位1分钟 一天1440 半天 720
#define TIME_CLOCK_MAX_TIMES 7200 // 1小时校准一次0.5s/次 7200 表示1小时
#define ID_ADDR 0x1FFF7A10 /*STM32F4唯一ID起始地址*/
#define ONE_MINUTES_COUNT 120 // ONE_MINUTES_COUNT / 2
#define TYPE_HEART 1
#define TYPE_BREATH 0
#define FILTER_HI_TYPE 1
#define FILTER_LO_TYPE 2
#define ARRAY_NUMBER 2
enum Calculate_STATE
{
// 此时正常计算心率呼吸率
FFT_Start_Calculate = 0,
// 此时停止计算
FFT_Stop_Calculate = 1,
};
enum CWT_STATE
{
// 此时正常计算心率呼吸率
FFT_Still_state = 0,
// 此时应跳过呼吸计算,直接把呼吸率置零;心率正常计算
FFT_No_breath = 2,
// 此时跳过心率呼吸率计算,直接取前一次计算结果
FFT_Mild_body_motion,
FFT_Medium_body_motion,
FFT_Large_body_motion,
};
#if SLEEP_DEBUG_MODE
#define DEBUG_SIZE
#endif
#ifdef DEBUG_SIZE
#undef REPORT_SEND_COUNTS
#define REPORT_SEND_COUNTS 5 // 5 * 12 =60 sec = 1 Min
#endif
extern int health_flg;
extern int opticalFibre_flg;
extern int sensorLoad_flg;
extern int lightSignal_flg;
extern char uart_flg;
extern int uart_time;
extern int led_time;
extern char start_calculate_flg;
extern char start_stage_flg;
extern uint8_t USART_DealFlag;
extern int BH_time;
extern int stage_time;
extern char stage_len;
extern unsigned short int ppg_data2[];
extern unsigned short int ppg_stage_buf[];
extern unsigned short int BH_data_500[];
extern char ppg_stage_index;
extern signed long int max_min2[];
extern float fft_HeartBeatRate_StashBuffer[15];
extern float ppg_data_500_buf[];
extern uint32_t FlashPtr;
extern char Breathe_H;
extern char Breathe_L;
extern char HeartRate_H;
extern char HeartRate_L;
extern char OffBed_Time;
extern char OffBed_Flag;
extern char queue_flg;
extern int currentSize_num; // 进行睡眠计算时间
extern uint16_t Roll_Over_Count;
enum BootReason
{
Low_Power_Reset = 1,
WWDG_Reset,
IWDG_Reset,
SoftWare_Reset,
PowerOn_Reset,
Pin_Reset,
};
enum SleepStatus
{
Wake_Up,
Light_Sleep,
Rapid_Eye_Movement,
Deep_Sleep,
};
enum SleepStatusValue
{
Wake_Up_Value = 1,
Light_Sleep_Value,
Rapid_Eye_Movement_Value,
Deep_Sleep_Value,
Leave_Value = 0,
};
typedef struct WarningMsg_T
{
// 超过阈值时的滴答计数器
uint64_t Breath_OverThreshold_CountTick;
uint64_t Heart_OverThreshold_CountTick;
uint64_t Move_OverThreshold_CountTick;
// 超过阈值时的时间戳
uint64_t Breath_OverThreshold_TimeStamp;
uint64_t Heart_OverThreshold_TimeStamp;
uint64_t Move_OverThreshold_TimeStamp;
// 持续时间的记录ms
uint64_t Breath_KeepTime_Record;
uint64_t Heart_KeepTime_Record;
uint64_t Move_KeepTime_Record;
// 滴答定时器的时间记录
uint64_t SysTick_Count;
} WarningMsg_t;
float three_avg(unsigned short int data, unsigned short int max, unsigned short int min);
void PowerOn_OneMinuteBLEScan(void);
void get_data_max_min(void);
void wifi_buf_synthesis(void);
void wifi_json_send(void);
void IWDG_Feed(void);
#endif /* __MAIN_H */