Mercurial > public > ostc4
diff Small_CPU/Src/pressure.c @ 186:f11f0bf6ef2d cleanup-2
cleanup: remove obsolete code, make static, etc.
Some rather trivial cleanup things like putting demo code into
ifdefs, making functions static where possible, and against my
normal policy of hard removing unused code, commenting it out
at this point in time. Somehow, I think that this commented code
might be useful in the near future as a new pressure sensor is coming.
And finally, fixed some typo's in comment.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Fri, 15 Mar 2019 12:39:28 +0100 |
parents | 5f11787b4f42 |
children | 2b9775f71e30 |
line wrap: on
line diff
--- a/Small_CPU/Src/pressure.c Fri Mar 15 08:22:16 2019 +0000 +++ b/Small_CPU/Src/pressure.c Fri Mar 15 12:39:28 2019 +0100 @@ -46,30 +46,24 @@ #define CMD_ADC_4096 0x08 // ADC OSR=4096 #define CMD_PROM_RD 0xA0 // Prom read command +static uint16_t get_ci_by_coef_num(uint8_t coef_num); +//void pressure_calculation_new(void); +//void pressure_calculation_old(void); +static void pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(void); +static uint8_t crc4(uint16_t n_prom[]); -//uint16_t get_ci(uint8_t cmd); -//uint8_t get_ci_crc(void); -uint16_t get_ci_by_coef_num(uint8_t coef_num); -void pressure_calculation_new(void); -void pressure_calculation_old(void); -void pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(void); - -uint8_t crc4(uint16_t n_prom[]); - -HAL_StatusTypeDef pressure_sensor_get_data(void); -uint32_t get_adc(void); +static HAL_StatusTypeDef pressure_sensor_get_data(void); +static uint32_t get_adc(void); uint8_t pressureSensorInitSuccess = 0; -//void test_calculation(void); +static uint16_t C[8] = { 1 }; +static uint32_t D1 = 1; +static uint32_t D2 = 1; +static uint8_t n_crc; -uint16_t C[8] = { 1 }; -uint32_t D1 = 1; -uint32_t D2 = 1; -uint8_t n_crc; - -int64_t C5_x_2p8 = 1; -int64_t C2_x_2p16 = 1; -int64_t C1_x_2p15 = 1; +static int64_t C5_x_2p8 = 1; +static int64_t C2_x_2p16 = 1; +static int64_t C1_x_2p15 = 1; /* short C2plus10000 = -1; @@ -79,10 +73,10 @@ short C6plus100 = -1; */ -float ambient_temperature = 0; -float ambient_pressure_mbar = 0; -float surface_pressure_mbar = 1000; -float surface_ring_mbar[31] = { 0 }; +static float ambient_temperature = 0; +static float ambient_pressure_mbar = 0; +static float surface_pressure_mbar = 1000; +static float surface_ring_mbar[31] = { 0 }; uint8_t secondCounterSurfaceRing = 0; @@ -91,15 +85,11 @@ return ambient_temperature; } -//float test = 1000; - float get_pressure_mbar(void) { -// return test; return ambient_pressure_mbar; } - float get_surface_mbar(void) { return surface_pressure_mbar; @@ -142,7 +132,7 @@ surface_ring_mbar[hole] = 0; } - +#ifdef DEMOMODE float demo_modify_temperature_helper(float bottom_mbar_diff_to_surface) { const float temperature_surface = 31.0; @@ -217,9 +207,11 @@ return 0; } } +#endif /* called just once on power on */ +/* TBD old DR5 code? */ void init_pressure_DRx(void) { uint8_t resetCommand[1] = {0x1E}; @@ -277,12 +269,12 @@ } -uint32_t get_adc(void) +static uint32_t get_adc(void) { uint8_t buffer[1]; uint8_t resivebuf[4]; uint32_t answer = 0; - // + buffer[0] = 0x00; // Get ADC I2C_Master_Transmit( DEVICE_PRESSURE, buffer, 1); I2C_Master_Receive( DEVICE_PRESSURE, resivebuf, 4); @@ -293,7 +285,7 @@ } -uint16_t get_ci_by_coef_num(uint8_t coef_num) +static uint16_t get_ci_by_coef_num(uint8_t coef_num) { uint8_t resivebuf[2]; @@ -315,7 +307,7 @@ } -uint32_t pressure_sensor_get_one_value(uint8_t cmd, HAL_StatusTypeDef *statusReturn) +static uint32_t pressure_sensor_get_one_value(uint8_t cmd, HAL_StatusTypeDef *statusReturn) { uint8_t command = CMD_ADC_CONV + cmd; HAL_StatusTypeDef statusReturnTemp = HAL_TIMEOUT; @@ -339,7 +331,7 @@ } -HAL_StatusTypeDef pressure_sensor_get_data(void) +static HAL_StatusTypeDef pressure_sensor_get_data(void) { HAL_StatusTypeDef statusReturn1 = HAL_TIMEOUT; HAL_StatusTypeDef statusReturn2 = HAL_TIMEOUT; @@ -372,14 +364,9 @@ return; pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(); - return; - - // before October 2016: pressure_calculation_old(); - -// pressure_calculation_new(); } -void pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(void) +static void pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(void) { uint32_t local_D1; // ADC value of the pressure conversion uint32_t local_D2; // ADC value of the temperature conversion @@ -446,6 +433,7 @@ } +/* void pressure_calculation_new(void) { #define POW2_8 (256) @@ -511,8 +499,9 @@ ambient_temperature = ((float)T) / 100; ambient_pressure_mbar = ((float)P) / 10; } +*/ - +/* void pressure_calculation_old(void) { // double ambient_temperature_centigrad = 0; @@ -528,12 +517,6 @@ static int64_t sens2 = 0; static int64_t t2 = 0; -/* info -uint16_t C[8] = { 1 }; -uint32_t D1 = 1; -uint32_t D2 = 1; -uint8_t n_crc; -*/ if((D2 == 0) || (D1 == 0)) return; // @@ -597,12 +580,13 @@ ambient_pressure_decimbar = temp; // to float/double ambient_pressure_mbar = ambient_pressure_decimbar / 10; } +*/ /* taken from AN520 by meas-spec.com dated 9. Aug. 2011 * short and int are both 16bit according to AVR/GCC google results */ -uint8_t crc4(uint16_t n_prom[]) +static uint8_t crc4(uint16_t n_prom[]) { uint16_t cnt; // simple counter uint16_t n_rem; // crc reminder