annotate Small_CPU/Inc/i2c.h @ 224:ceecabfddb57 div-fixes-3

Bugfix, deco: fix 2 (small) problems with calculated ceiling This fixes 1 trivial, and 1 not really trivial bug in the calculation of the ceiling. When simulating a bounce dive to 80m, things become clear (tried this on a CCR dive, fixed setpoint 1.2bar, about 15 minutes of bottom time). Closely watch the behavior of the ceiling data. At some point during the ascent, the ceiling begins to decrease in 10cm steps. Then suddenly (while still ascending), the ceiling increases again with 1m, does not change for some time, and then suddenly steps 1.1m less deep. While not very relevant to real deco diving, it is simply wrong. The reason for this is subtle. The algorithm used to find the ceiling is a sort of linear search, stepping down a meter, overshoot the depth, and search back in 10cm steps. It seems some numerical instability. Fixing this, was a bit more computational intensive search by stepping up down in equal steps of 10cm. But, I'm pretty sure that things can be speeded up here, as a ceiling does not change fast, so it should be not that difficult to limit the search space, or use a binary search algorithm instead. The trivial second problem fixed, is that the ceiling ends at the surface and not at 1m depth. This small issue became visible after changing the step down size above. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Sun, 31 Mar 2019 19:35:51 +0200
parents 9ecc2e60418d
children cb3870f79e9d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /* Define to prevent recursive inclusion -------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 #ifndef I2C_H
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 #define I2C_H
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4
165
e9cce686fe41 Minor: Some documentation for new hardware
heinrichsweikamp
parents: 38
diff changeset
5 /* Pressure Sensor */
e9cce686fe41 Minor: Some documentation for new hardware
heinrichsweikamp
parents: 38
diff changeset
6 #define DEVICE_PRESSURE 0xEE // 2019 hardware (gen 3) will use 0xEC (MS5837), all other use 0xEE (MS5803)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7
165
e9cce686fe41 Minor: Some documentation for new hardware
heinrichsweikamp
parents: 38
diff changeset
8 /* Compass/Accelerometer */
e9cce686fe41 Minor: Some documentation for new hardware
heinrichsweikamp
parents: 38
diff changeset
9 #define DEVICE_ACCELARATOR_MMA8452Q 0x38 // Hardware gen 1 (Two chip solution with MMA8452Q and HMC5883L)
e9cce686fe41 Minor: Some documentation for new hardware
heinrichsweikamp
parents: 38
diff changeset
10 #define DEVICE_COMPASS_HMC5883L 0x3C // Hardware gen 1
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11
165
e9cce686fe41 Minor: Some documentation for new hardware
heinrichsweikamp
parents: 38
diff changeset
12 #define DEVICE_COMPASS_303D 0x3C // Hardware gen 2 (Single chip solution LSM303D)
e9cce686fe41 Minor: Some documentation for new hardware
heinrichsweikamp
parents: 38
diff changeset
13 #define DEVICE_COMPASS_303AGR 0x3C // Hardware gen 3 (Single chip solution LSM303AGR)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 /* Battery Gas Gauge */
165
e9cce686fe41 Minor: Some documentation for new hardware
heinrichsweikamp
parents: 38
diff changeset
16 #define DEVICE_BATTERYGAUGE 0xC8 // LTC2941 battery gauge
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 HAL_StatusTypeDef I2C_Master_Transmit( uint16_t DevAddress, uint8_t *pData, uint16_t Size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 HAL_StatusTypeDef I2C_Master_TransmitNoStop( uint16_t DevAddress, uint8_t *pData, uint16_t Size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 HAL_StatusTypeDef I2C_Master_Receive( uint16_t DevAddress, uint8_t *pData, uint16_t Size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 HAL_StatusTypeDef MX_I2C1_Init(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 void I2C_DeInit(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 HAL_StatusTypeDef I2C1_Status(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 GPIO_PinState MX_I2C1_TestAndClear(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 //void I2C_Error(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 #endif /* I2C_H */