Mercurial > public > ostc4
comparison Discovery/Src/data_exchange_main.c @ 367:e309f78f89a5 MotionDetection
Merge default
author | Ideenmodellierer |
---|---|
date | Sat, 20 Jul 2019 21:42:45 +0200 |
parents | b0045281cb2d |
children | ea3fda8eb93e |
comparison
equal
deleted
inserted
replaced
366:3c7030d6d67a | 367:e309f78f89a5 |
---|---|
858 settingsGetPointer()->bluetoothActive = 0; | 858 settingsGetPointer()->bluetoothActive = 0; |
859 MX_Bluetooth_PowerOff(); | 859 MX_Bluetooth_PowerOff(); |
860 //Init dive Mode | 860 //Init dive Mode |
861 decoLock = DECO_CALC_init_as_is_start_of_dive; | 861 decoLock = DECO_CALC_init_as_is_start_of_dive; |
862 pStateReal->lifeData.boolResetAverageDepth = 1; | 862 pStateReal->lifeData.boolResetAverageDepth = 1; |
863 pStateReal->lifeData.boolResetStopwatch = 1; | |
864 } | 863 } |
865 | 864 |
866 pStateReal->lifeData.cns = dataIn.data[dataIn.boolToxicData].cns; | 865 pStateReal->lifeData.cns = dataIn.data[dataIn.boolToxicData].cns; |
867 pStateReal->lifeData.otu = dataIn.data[dataIn.boolToxicData].otu; | 866 pStateReal->lifeData.otu = dataIn.data[dataIn.boolToxicData].otu; |
868 pStateReal->lifeData.no_fly_time_minutes = dataIn.data[dataIn.boolToxicData].no_fly_time_minutes; | 867 pStateReal->lifeData.no_fly_time_minutes = dataIn.data[dataIn.boolToxicData].no_fly_time_minutes; |
888 dataOut.setAccidentFlag += ACCIDENT_DECOSTOP; | 887 dataOut.setAccidentFlag += ACCIDENT_DECOSTOP; |
889 } | 888 } |
890 pStateReal->mode = dataIn.mode; | 889 pStateReal->mode = dataIn.mode; |
891 pStateReal->chargeStatus = dataIn.chargeStatus; | 890 pStateReal->chargeStatus = dataIn.chargeStatus; |
892 | 891 |
893 if(is_ambient_pressure_close_to_surface(&pStateReal->lifeData)) | 892 pStateReal->lifeData.depth_meter = meter; |
894 { | |
895 pStateReal->lifeData.depth_meter = 0; | |
896 } | |
897 else | |
898 { | |
899 pStateReal->lifeData.depth_meter = meter; | |
900 } | |
901 | 893 |
902 pStateReal->lifeData.temperature_celsius = getTemperature(&dataIn); | 894 pStateReal->lifeData.temperature_celsius = getTemperature(&dataIn); |
903 pStateReal->lifeData.ascent_rate_meter_per_min = dataIn.data[dataIn.boolPressureData].ascent_rate_meter_per_min; | 895 pStateReal->lifeData.ascent_rate_meter_per_min = dataIn.data[dataIn.boolPressureData].ascent_rate_meter_per_min; |
904 if(pStateReal->mode != MODE_DIVE) | 896 if(pStateReal->mode != MODE_DIVE) |
905 pStateReal->lifeData.max_depth_meter = 0; | 897 pStateReal->lifeData.max_depth_meter = 0; |
997 pStateReal->lifeData.apnea_last_max_depth_meter = pStateReal->lifeData.max_depth_meter; | 989 pStateReal->lifeData.apnea_last_max_depth_meter = pStateReal->lifeData.max_depth_meter; |
998 } | 990 } |
999 // reset max_depth_meter, average_depth_meter and internal values | 991 // reset max_depth_meter, average_depth_meter and internal values |
1000 pStateReal->lifeData.max_depth_meter = 0; | 992 pStateReal->lifeData.max_depth_meter = 0; |
1001 pStateReal->lifeData.boolResetAverageDepth = 1; | 993 pStateReal->lifeData.boolResetAverageDepth = 1; |
1002 pStateReal->lifeData.boolResetStopwatch = 1; | 994 } |
1003 } | 995 } |
1004 } | 996 |
1005 | 997 setAvgDepth(pStateReal); |
1006 /* average depth | 998 } |
1007 */ | 999 |
1000 void setAvgDepth(SDiveState *pStateReal) { | |
1001 | |
1008 float *AvgDepthValue = &pStateReal->lifeData.average_depth_meter; | 1002 float *AvgDepthValue = &pStateReal->lifeData.average_depth_meter; |
1009 float DepthNow = pStateReal->lifeData.depth_meter; | 1003 float DepthNow = pStateReal->lifeData.depth_meter; |
1010 uint32_t *AvgDepthCount = &pStateReal->lifeData.internal.average_depth_meter_Count; | 1004 static uint32_t AvgDepthCount = 0; |
1011 uint32_t *AvgDepthTimer = &pStateReal->lifeData.internal.average_depth_last_update_dive_time_seconds_without_surface_time; | 1005 static uint32_t AvgDepthTimer = 0; |
1012 uint32_t AvgSecondsSinceLast; | 1006 uint32_t AvgSecondsSinceLast; |
1013 uint32_t DiveTime = pStateReal->lifeData.dive_time_seconds_without_surface_time; | 1007 uint32_t DiveTime = pStateReal->lifeData.dive_time_seconds_without_surface_time; |
1014 | 1008 |
1015 if(pStateReal->lifeData.boolResetAverageDepth) | 1009 if(pStateReal->lifeData.boolResetAverageDepth) |
1016 { | 1010 { |
1017 *AvgDepthValue = DepthNow; | 1011 *AvgDepthValue = DepthNow; |
1018 *AvgDepthCount = 1; | 1012 AvgDepthCount = 0; |
1019 *AvgDepthTimer = DiveTime; | 1013 AvgDepthTimer = DiveTime; |
1020 pStateReal->lifeData.boolResetAverageDepth = 0; | 1014 pStateReal->lifeData.boolResetAverageDepth = 0; |
1021 } | 1015 } |
1022 else if (DiveTime > *AvgDepthTimer) | 1016 else if (DiveTime > AvgDepthTimer) |
1023 { | 1017 { |
1024 AvgSecondsSinceLast = DiveTime - *AvgDepthTimer; | 1018 AvgSecondsSinceLast = DiveTime - AvgDepthTimer; |
1025 for(int i=0;i<AvgSecondsSinceLast;i++) | 1019 for(int i=0;i<AvgSecondsSinceLast;i++) |
1026 { | 1020 { |
1027 *AvgDepthValue = (*AvgDepthValue * *AvgDepthCount + DepthNow) / (*AvgDepthCount + 1); | 1021 *AvgDepthValue = (*AvgDepthValue * AvgDepthCount + DepthNow) / (AvgDepthCount + 1); |
1028 *AvgDepthCount += 1; | 1022 AvgDepthCount += 1; |
1029 } | 1023 } |
1030 *AvgDepthTimer = DiveTime; | 1024 AvgDepthTimer = DiveTime; |
1031 } | 1025 } |
1032 if(*AvgDepthCount == 0) | 1026 if(AvgDepthCount == 0) |
1033 *AvgDepthValue = 0; | 1027 *AvgDepthValue = DepthNow; |
1034 | |
1035 | |
1036 /* stop watch | |
1037 */ | |
1038 if(pStateReal->lifeData.boolResetStopwatch) | |
1039 { | |
1040 pStateReal->lifeData.internal.stopwatch_start_at_this_dive_time_seconds = pStateReal->lifeData.dive_time_seconds; | |
1041 pStateReal->lifeData.boolResetStopwatch = 0; | |
1042 } | |
1043 pStateReal->lifeData.stopwatch_seconds = pStateReal->lifeData.dive_time_seconds - pStateReal->lifeData.internal.stopwatch_start_at_this_dive_time_seconds; | |
1044 } | 1028 } |
1045 | 1029 |
1046 | 1030 |
1047 uint8_t DataEX_check_RTE_version__needs_update(void) | 1031 uint8_t DataEX_check_RTE_version__needs_update(void) |
1048 { | 1032 { |