mini glider FSG
Fork of MS5837 by
Diff: MS5837.cpp
- Revision:
- 1:a8eea2a2263f
- Parent:
- 0:5f6034409fd0
diff -r 5f6034409fd0 -r a8eea2a2263f MS5837.cpp --- a/MS5837.cpp Sun May 28 10:29:51 2017 +0000 +++ b/MS5837.cpp Mon Aug 13 18:48:45 2018 +0000 @@ -19,7 +19,7 @@ /* transmit out 1 byte reset command */ ms5837_tx_data[0] = ms5837_reset; if ( i2c.write( device_address, ms5837_tx_data, 1 ) ); - printf("send soft reset\n"); + //printf("send soft reset\n\r"); wait_ms(20); } @@ -103,6 +103,30 @@ } } -float MS5837::depth(void) { - return (P_MS5837/100)*1.019716; +float MS5837::get_depth_initial(void){ + depth_iter = 0; + Depth_0 = 0; + for(int i = 0; i < 5; i++){ + Barometer_MS5837(); + depth_iter = ((P_MS5837)*1.019716); + Depth_0 = depth_iter + Depth_0; + } + Depth_0 = Depth_0/5; + if(Depth_0 < 1000 || Depth_0 > 1100){ + MS5837Init(); + get_depth_initial(); + } + return Depth_0; +} + +float MS5837::get_depth(void) { + depth_iter = 0; + depth = 0; + for(int i = 0; i <= 2; i++){ + Barometer_MS5837(); + depth_iter = ((P_MS5837)*1.019716)-Depth_0; + depth = depth_iter + depth; + } + depth = depth/3; + return depth; } \ No newline at end of file