From 2ebb8217f43b69f491620423ea4d5d5944d1f91d Mon Sep 17 00:00:00 2001 From: yincheng.zhong <634916154@qq.com> Date: 星期六, 05 七月 2025 22:43:58 +0800 Subject: [PATCH] 格式化部分代码 --- keil/include/drivers/dps368_test.c | 122 ++++++++++++++++++++-------------------- 1 files changed, 61 insertions(+), 61 deletions(-) diff --git a/keil/include/drivers/dps368_test.c b/keil/include/drivers/dps368_test.c index 0da93c7..27f0286 100644 --- a/keil/include/drivers/dps368_test.c +++ b/keil/include/drivers/dps368_test.c @@ -12,7 +12,7 @@ #include "lis3dh_driver.h" /*bus communication protocol stubs * Please wrap around platform specific implementation -* for low level bus handling (I2C or SPI), that matches +* for low level bus handling (I2C or SPI), that matches * prototypes provided by dps310_bus_connection structure * in dps310.h */ @@ -20,50 +20,50 @@ /* Should return -1 in case of failure otherwise valid contents*/ s16 test_read_byte(u8 ReadAddr) { - - uint8_t temp=0; - IIC2_Start(); - IIC2_Send_Byte(0xee); //发送写命令 - IIC2_Wait_Ack(); - IIC2_Send_Byte(ReadAddr); //发送读地址 - IIC2_Wait_Ack(); - IIC2_Start(); - IIC2_Send_Byte(0xef); //发送读命令,进入接收模式 - IIC2_Wait_Ack(); - temp=IIC2_Read_Byte(0); - IIC2_Stop(); //产生一个停止条件 - return temp; + + uint8_t temp=0; + IIC2_Start(); + IIC2_Send_Byte(0xee); //发送写命令 + IIC2_Wait_Ack(); + IIC2_Send_Byte(ReadAddr); //发送读地址 + IIC2_Wait_Ack(); + IIC2_Start(); + IIC2_Send_Byte(0xef); //发送读命令,进入接收模式 + IIC2_Wait_Ack(); + temp=IIC2_Read_Byte(0); + IIC2_Stop(); //产生一个停止条件 + return temp; } -/* Should return -1 or negative value in case of failure otherwise length of +/* Should return -1 or negative value in case of failure otherwise length of * read contents in read_buffer * and shall place read contents in read_buffer */ s16 test_read_block(u8 ReadAddr, u8 Len, u8 *read_buffer) { - uint8_t t; - uint32_t temp=0; - for(t=0;t<Len;t++) - { - *read_buffer=test_read_byte(ReadAddr+t); - read_buffer++; - } - //return temp; + uint8_t t; + uint32_t temp=0; + for(t=0; t<Len; t++) + { + *read_buffer=test_read_byte(ReadAddr+t); + read_buffer++; + } + //return temp; return Len; } /* Should return -1 in case of failure otherwise non negative number*/ s16 test_write_byte(u8 WriteAddr, u8 DataToWrite) { - IIC2_Start(); - IIC2_Send_Byte(0xee); //发送写命令 - IIC2_Wait_Ack(); - IIC2_Send_Byte(WriteAddr); //发送地址 - IIC2_Wait_Ack(); - IIC2_Send_Byte(DataToWrite); //发送字节 - IIC2_Wait_Ack(); - IIC2_Stop();//产生一个停止条件 - delay_us(10); + IIC2_Start(); + IIC2_Send_Byte(0xee); //发送写命令 + IIC2_Wait_Ack(); + IIC2_Send_Byte(WriteAddr); //发送地址 + IIC2_Wait_Ack(); + IIC2_Send_Byte(DataToWrite); //发送字节 + IIC2_Wait_Ack(); + IIC2_Stop();//产生一个停止条件 + delay_us(10); } /* Shall implement delay in milliseconds*/ @@ -72,50 +72,50 @@ // printf("Waiting for %dms\n",delay); } struct dps310_state drv_state; -f64 pressure,temperature; +f64 pressure,temperature; int BarInit(void) { /*Instantiate driver state*/ - + /*Instantiate bus connection callback holder*/ dps310_bus_connection cnn; - - /* Assign/register platform specific bus handlers*/ + + /* Assign/register platform specific bus handlers*/ cnn.read_byte=&test_read_byte; cnn.read_block=&test_read_block; cnn.write_byte=&test_write_byte; - /*If platform doesn't support delay or sleep - *please assign NULL to this callback i.e cnn.delayms = NULL - */ + /*If platform doesn't support delay or sleep + *please assign NULL to this callback i.e cnn.delayms = NULL + */ cnn.delayms = &test_wait_ms; /*First call _init - * this function verifies chip with appropriate id and - * reads and stores calibration data, configures the sensor + * this function verifies chip with appropriate id and + * reads and stores calibration data, configures the sensor * to meet default configuration set in dps310.h. * This also puts the sensor in background mode - * making it measure both pressure and temperature continuously + * making it measure both pressure and temperature continuously */ int ret = dps310_init(&drv_state,&cnn); - // printf("init ret val = %d\n",ret); +// printf("init ret val = %d\n",ret); /* once sensor is put into background mode * pressure and temperature values are available and can be read * Here get_processed_data synchrounuously reads 6 bytes of raw data * and returns computed double precision pressure and temperature value - */ + */ ret = dps310_get_processed_data(&drv_state,&pressure,&temperature); GetPressAndHeight(); - + // printf("get_processed_data ret val = %d, pressure = %lf, temp = %lf\n",ret,pressure,temperature); - /*To change configuration we first need to put sensor in - *idle mode by calling _standby - */ + /*To change configuration we first need to put sensor in + *idle mode by calling _standby + */ // ret = dps310_standby(&drv_state); // printf("standby ret val = %d\n",ret); @@ -132,27 +132,27 @@ // drv_state.tmp_ext); // printf("config ret val = %d\n",ret); -// +// // /*Resume the sensor in background mode again*/ // ret = dps310_resume(&drv_state); // printf("resume ret val = %d\n",ret); - + return 0; } float Height; float GetPressAndHeight(void) -{ u8 ret; - - +{ u8 ret; + + /*Instantiate driver state*/ - - ret = dps310_get_processed_data(&drv_state,&pressure,&temperature); - + + ret = dps310_get_processed_data(&drv_state,&pressure,&temperature); + Height = 44330 * (1.0 - pow((pressure / 1013.25), (1 / 5.255))); if(pressure==0) - Height = 0; - return Height; - //height=PressToHeight(pressure,temperature); - // printf("get_processed_data ret val = %d, pressure = %lf, temp = %lf\n",ret,pressure,temperature); - } \ No newline at end of file + Height = 0; + return Height; + //height=PressToHeight(pressure,temperature); + // printf("get_processed_data ret val = %d, pressure = %lf, temp = %lf\n",ret,pressure,temperature); +} \ No newline at end of file -- Gitblit v1.9.3