Mercurial > public > ostc4
changeset 482:230aed360da0
Merged in Ideenmodellierer/ostc4/Improve_Button_Sleep (pull request #45)
Improve Button Sleep
author | heinrichsweikamp <bitbucket@heinrichsweikamp.com> |
---|---|
date | Tue, 19 May 2020 07:27:18 +0000 |
parents | 8a375f0544d9 (current diff) 89f6857276f8 (diff) |
children | 90d1f793dcf2 0f5080f50ba7 |
files | |
diffstat | 8 files changed, 142 insertions(+), 103 deletions(-) [+] |
line wrap: on
line diff
--- a/Common/Inc/data_central.h Tue Apr 28 15:37:47 2020 +0000 +++ b/Common/Inc/data_central.h Tue May 19 07:27:18 2020 +0000 @@ -248,6 +248,9 @@ int8_t betterGas; int8_t fallback; int8_t betterSetpoint; +#ifdef ENABLE_BOTTLE_SENSOR + int8_t newPressure; +#endif } SWarnings;
--- a/Discovery/Src/base.c Tue Apr 28 15:37:47 2020 +0000 +++ b/Discovery/Src/base.c Tue May 19 07:27:18 2020 +0000 @@ -426,6 +426,7 @@ tInfoLog_init(); tComm_init(); DataEX_init(); + settingsHelperButtonSens_keepPercentageValues(settingsGetPointer()->ButtonResponsiveness[3], settingsGetPointer()->ButtonResponsiveness); setButtonResponsiveness( settingsGetPointer()->ButtonResponsiveness ); set_globalState_tHome();
--- a/Discovery/Src/check_warning.c Tue Apr 28 15:37:47 2020 +0000 +++ b/Discovery/Src/check_warning.c Tue May 19 07:27:18 2020 +0000 @@ -54,7 +54,9 @@ static int8_t check_BetterGas(SDiveState * pDiveState); static int8_t check_BetterSetpoint(SDiveState * pDiveState); static int8_t check_Battery(SDiveState * pDiveState); - +#ifdef ENABLE_BOTTLE_SENSOR +static int8_t check_pressureSensor(SDiveState * pDiveState); +#endif static int8_t check_helper_same_oxygen_and_helium_content(SGasLine * gas1, SGasLine * gas2); /* Exported functions --------------------------------------------------------*/ @@ -79,6 +81,9 @@ pDiveState->warnings.numWarnings += check_BetterSetpoint(pDiveState); pDiveState->warnings.numWarnings += check_Battery(pDiveState); pDiveState->warnings.numWarnings += check_fallback(pDiveState); +#ifdef ENABLE_BOTTLE_SENSOR + pDiveState->warnings.numWarnings += check_pressureSensor(pDiveState); +#endif } @@ -406,5 +411,21 @@ return pDiveState->warnings.aGf; } +#ifdef ENABLE_BOTTLE_SENSOR +static int8_t check_pressureSensor(SDiveState * pDiveState) +{ + int8_t ret = 0; + if(pDiveState->lifeData.bottle_bar_age_MilliSeconds[pDiveState->lifeData.actualGas.GasIdInSettings] < 50) /* we received a new value */ + { + pDiveState->warnings.newPressure = stateUsed->lifeData.bottle_bar[stateUsed->lifeData.actualGas.GasIdInSettings]; + ret = 1; + } + else + { + pDiveState->warnings.newPressure = 0; + } + return ret; +} +#endif /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/
--- a/Discovery/Src/gfx_engine.c Tue Apr 28 15:37:47 2020 +0000 +++ b/Discovery/Src/gfx_engine.c Tue May 19 07:27:18 2020 +0000 @@ -3085,6 +3085,8 @@ uint8_t gfx_selected_language; uint32_t pText; uint16_t decodeUTF8; + uint8_t tinyState = 0; /* used to identify the usage of tiny font */ + tFont* ptargetFont; #ifndef BOOTLOADER_STANDALONE SSettings *pSettings; @@ -3102,6 +3104,22 @@ j = 0; while (*(char*)pText != 0)// und fehlend: Abfrage window / image size { + if(*(char*)pText == '\016') /* request font change */ + { + tinyState++; + } + if(*(char*)pText == '\017') /* request font reset */ + { + tinyState = 0; + } + if(tinyState > 1) + { + ptargetFont = (tFont *)cfg->TinyFont; + } + else + { + ptargetFont = (tFont *)cfg->font; + } if((*(char*)pText) & 0x80) /* Identify a UNICODE character other than standard ASCII using the highest bit */ { decodeUTF8 = ((*(char*)pText) & 0x1F) << 6; /* use 5bits of first byte for upper part of unicode */ @@ -3113,20 +3131,20 @@ decodeUTF8 = *(char*)pText; /* place ASCII char */ } - for(i=0;i<((tFont *)cfg->font)->length;i++) + for(i=0;i<ptargetFont->length;i++) { - if(((tFont *)cfg->font)->chars[i].code == decodeUTF8) + if(ptargetFont->chars[i].code == decodeUTF8) { - Xsum += ((tFont *)cfg->font)->chars[i].image->width; + Xsum += ptargetFont->chars[i].image->width; break; } } pText++; j++; - if(((tFont *)cfg->font == &FontT144) && (*(char*)pText != 0)) + if((ptargetFont == &FontT144) && (*(char*)pText != 0)) Xsum += 3; else - if(((tFont *)cfg->font == &FontT105) && (*(char*)pText != 0)) + if((ptargetFont == &FontT105) && (*(char*)pText != 0)) Xsum += 2; } pText -= j;
--- a/Discovery/Src/t7.c Tue Apr 28 15:37:47 2020 +0000 +++ b/Discovery/Src/t7.c Tue May 19 07:27:18 2020 +0000 @@ -789,16 +789,18 @@ { text[0] = '\001'; text[1] = '\004'; - text[2] = TXT_2BYTE; - text[3] = TXT2BYTE_Sunday; - text[4] = 0; + text[2] = '\016'; + text[3] = '\016'; + text[4] = TXT_2BYTE; + text[5] = TXT2BYTE_Sunday; + text[6] = 0; if(Sdate.WeekDay != RTC_WEEKDAY_SUNDAY) - text[3] += Sdate.WeekDay; + text[5] += Sdate.WeekDay; if(!(Stime.Seconds % 2) && (dateNotSet == 1)) text[1] = '\021'; - GFX_write_string(&FontT24,&t7surfaceR,text,4); + GFX_write_string(&FontT48,&t7surfaceR,text,4); } /* DEBUG uTick Pressure and Compass */ @@ -828,8 +830,7 @@ */ /* noFlyTime or DesaturationTime */ - - if((!display_count_high_time) && (stateUsed->lifeData.no_fly_time_minutes)) + if((stateUsed->lifeData.no_fly_time_minutes) && ((!display_count_high_time) || (stateUsed->lifeData.desaturation_time_minutes == 0))) { SSurfacetime NoFlyTime = {0,0,0,0}; t7_fill_surfacetime_helper(&NoFlyTime,stateUsed->lifeData.no_fly_time_minutes, 0); @@ -1321,6 +1322,12 @@ //count += stateUsed->warnings.lowBattery; count += stateUsed->warnings.sensorLinkLost; count += stateUsed->warnings.fallback; +#ifdef ENABLE_BOTTLE_SENSOR + if(stateUsed->warnings.newPressure) + { + count++; + } +#endif return count; } @@ -1331,6 +1338,12 @@ count = 0; count += stateUsed->cnsHigh_at_the_end_of_dive; count += stateUsed->decoMissed_at_the_end_of_dive; +#ifdef ENABLE_BOTTLE_SENSOR + if(stateUsed->warnings.newPressure) + { + count++; + } +#endif return count; } @@ -1369,6 +1382,14 @@ text[textpointer] = 0; lineFree--; } +#ifdef ENABLE_BOTTLE_SENSOR + if(stateUsed->warnings.newPressure) + { + sprintf(&text[textpointer] ," %u Bar\n", stateUsed->warnings.newPressure); + textpointer++; + lineFree--; + } +#endif if(textpointer != 0) GFX_write_string(&FontT48,&t7cW,text,1); } @@ -1438,6 +1459,14 @@ text[textpointer] = 0; lineFree--; } +#ifdef ENABLE_BOTTLE_SENSOR + if(stateUsed->warnings.newPressure) + { + sprintf(&text[textpointer]," %u Bar\n", stateUsed->warnings.newPressure); + textpointer++; + lineFree--; + } +#endif /* if(lineFree && stateUsed->warnings.lowBattery) {
--- a/Small_CPU/Src/baseCPU2.c Tue Apr 28 15:37:47 2020 +0000 +++ b/Small_CPU/Src/baseCPU2.c Tue May 19 07:27:18 2020 +0000 @@ -343,29 +343,32 @@ init_battery_gas_gauge(); HAL_Delay(10); battery_gas_gauge_get_data(); - if(coldstart != 0xA5) + + MX_SPI3_Init(); + + if(coldstart != 0xA5) /* Not reading a 0xA5 means the memory cells has not been initialized before => cold start */ { coldstart = 0xA5; battery_gas_gauge_set(0); + global.dataSendToMaster.power_on_reset = 1; + global.deviceDataSendToMaster.power_on_reset = 1; + + if (!scheduleSetButtonResponsiveness()) + { + HAL_Delay(1); + if (!scheduleSetButtonResponsiveness()) // send again, if problem it's not my problem here. + { + HAL_Delay(1); + scheduleSetButtonResponsiveness(); // init + HAL_Delay(1); + } + } } global.lifeData.battery_voltage = get_voltage(); global.lifeData.battery_charge = get_charge(); copyBatteryData(); - MX_SPI3_Init(); - if (!scheduleSetButtonResponsiveness()) { - HAL_Delay(1); - scheduleSetButtonResponsiveness(); // init - HAL_Delay(1); - if (!scheduleSetButtonResponsiveness()) // send again, if problem it's not my problem here. - { - HAL_Delay(1); - scheduleSetButtonResponsiveness(); // init - HAL_Delay(1); - } - } - ADCx_Init(); GPIO_Power_MainCPU_Init(); global.mode = MODE_POWERUP;
--- a/Small_CPU/Src/pressure.c Tue Apr 28 15:37:47 2020 +0000 +++ b/Small_CPU/Src/pressure.c Tue May 19 07:27:18 2020 +0000 @@ -50,7 +50,6 @@ /* #define SIMULATE_PRESSURE */ #define PRESSURE_SURFACE_MAX_MBAR (1030.0f) /* It is unlikely that pressure at surface is greater than this value => clip to it */ -#define PRESSURE_HISTORY_SIZE (8u) #define PRESSURE_SURFACE_QUE (30u) /* history buffer [minutes] for past pressure measurements */ #define PRESSURE_SURFACE_EVA_WINDOW (15u) /* Number of entries evaluated during instability test. Used to avoid detection while dive enters water */ @@ -100,8 +99,6 @@ static float surface_pressure_stable_value = 0; static uint8_t surface_pressure_stable = 0; -static float pressure_history_mbar[PRESSURE_HISTORY_SIZE]; - static uint8_t secondCounterSurfaceRing = 0; static uint8_t avgCount = 0; static float runningAvg = 0; @@ -137,14 +134,6 @@ } } -void init_pressure_history(void) -{ - for(int i=0; i<PRESSURE_HISTORY_SIZE; i++) - { - pressure_history_mbar[i] = 1000.0; - } -} - uint8_t is_surface_pressure_stable(void) { return surface_pressure_stable; @@ -220,8 +209,6 @@ } void update_surface_pressure(uint8_t call_rhythm_seconds) { - - if(is_init_pressure_done()) { runningAvg = (runningAvg * avgCount + ambient_pressure_mbar) / (avgCount +1); @@ -343,7 +330,6 @@ uint8_t retValue = 0xFF; pressureSensorInitSuccess = false; - init_pressure_history(); /* Probe new sensor first */ retValue = I2C_Master_Transmit( DEVICE_PRESSURE_MS5837, buffer, 1); @@ -391,7 +377,6 @@ { pressureSensorInitSuccess = 1; retValue = pressure_update(); - } return retValue; } @@ -401,14 +386,17 @@ { uint8_t buffer[1]; uint8_t resivebuf[4]; - uint32_t answer = 0; + uint32_t answer = 0xFFFFFFFF; buffer[0] = 0x00; // Get ADC - I2C_Master_Transmit( PRESSURE_ADDRESS, buffer, 1); - I2C_Master_Receive( PRESSURE_ADDRESS, resivebuf, 4); - resivebuf[3] = 0; - answer = 256*256 *(uint32_t)resivebuf[0] + 256 * (uint32_t)resivebuf[1] + (uint32_t)resivebuf[2]; - + if(I2C_Master_Transmit( PRESSURE_ADDRESS, buffer, 1) == HAL_OK) + { + if(I2C_Master_Receive( PRESSURE_ADDRESS, resivebuf, 4) == HAL_OK) + { + resivebuf[3] = 0; + answer = 256*256 *(uint32_t)resivebuf[0] + 256 * (uint32_t)resivebuf[1] + (uint32_t)resivebuf[2]; + } + } return answer; } @@ -460,6 +448,7 @@ static uint32_t pressure_sensor_get_one_value(uint8_t cmd, HAL_StatusTypeDef *statusReturn) { uint8_t command = CMD_ADC_CONV + cmd; + uint32_t adcValue = 0; HAL_StatusTypeDef statusReturnTemp = HAL_TIMEOUT; statusReturnTemp = I2C_Master_Transmit( PRESSURE_ADDRESS, &command, 1); @@ -468,16 +457,26 @@ { *statusReturn = statusReturnTemp; } - + switch (cmd & 0x0f) // wait necessary conversion time { - case CMD_ADC_256 : HAL_Delay(1); break; - case CMD_ADC_512 : HAL_Delay(3); break; - case CMD_ADC_1024: HAL_Delay(4); break; - case CMD_ADC_2048: HAL_Delay(6); break; - case CMD_ADC_4096: HAL_Delay(10); break; - } - return get_adc(); + case CMD_ADC_256 : HAL_Delay(1); break; + case CMD_ADC_512 : HAL_Delay(3); break; + case CMD_ADC_1024: HAL_Delay(4); break; + case CMD_ADC_2048: HAL_Delay(6); break; + case CMD_ADC_4096: HAL_Delay(10); break; + default: + break; + } + adcValue = get_adc(); + if(adcValue == 0xFFFFFFFF) + { + if(statusReturn) + { + *statusReturn = HAL_ERROR; + } + } + return adcValue; } @@ -606,39 +605,6 @@ #endif } -static uint8_t pressure_plausible(float pressurevalue) -{ - static uint8_t pressurewriteindex = 0; - uint8_t retval = 0; - uint8_t index; - float pressure_average = 0; - - for(index = 0; index < PRESSURE_HISTORY_SIZE; index++) - { - pressure_average += pressure_history_mbar[index]; - } - pressure_average /= PRESSURE_HISTORY_SIZE; - if(pressure_average == 1000.0) /* first pressure calculation */ - { - if(fabs(pressurevalue - pressure_average) < 11000.0) /* just in case a reset occur during dive assume value equal < 100m as valid */ - { - for(index = 0; index < PRESSURE_HISTORY_SIZE; index++) - { - pressure_history_mbar[index] = pressurevalue; /* set history to current value */ - retval = 1; - } - } - } - else - { - pressure_history_mbar[pressurewriteindex++] = pressurevalue; - pressurewriteindex &= 0x7; /* wrap around if necessary */ - retval = 1; - } - - return retval; -} - static void pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(void) { static float runningAvg = 0; @@ -712,15 +678,12 @@ calc_pressure = ((float)local_Px10) / 10; calc_pressure += pressure_offset; - if(pressure_plausible(calc_pressure)) - { - runningAvg = (avgCnt * runningAvg + calc_pressure) / (avgCnt + 1); - if (avgCnt < 10) /* build an average considering the last measurements to have a weight "1 of 10" */ - { /* Main reason for this is the jitter of up to +-10 HPa in surface mode which is caused */ - avgCnt++; /* by the measurement range of the sensor which is focused on under water pressure measurement */ - } - ambient_pressure_mbar = runningAvg; + runningAvg = (avgCnt * runningAvg + calc_pressure) / (avgCnt + 1); + if (avgCnt < 10) /* build an average considering the last measurements to have a weight "1 of 10" */ + { /* Main reason for this is the jitter of up to +-10 HPa in surface mode which is caused */ + avgCnt++; /* by the measurement range of the sensor which is focused on under water pressure measurement */ } + ambient_pressure_mbar = runningAvg; }
--- a/Small_CPU/Src/scheduler.c Tue Apr 28 15:37:47 2020 +0000 +++ b/Small_CPU/Src/scheduler.c Tue May 19 07:27:18 2020 +0000 @@ -45,7 +45,7 @@ /* uncomment to enable restoting of last known date in case of a power loss (RTC looses timing data) */ /* #define RESTORE_LAST_KNOWN_DATE */ -#define INVALID_PREASURE_VALUE (100.0f) +#define INVALID_PREASURE_VALUE (0.0f) #define START_DIVE_MOUNTAIN_MODE_BAR (0.88f) #define START_DIVE_IMMEDIATLY_BAR (1.16f) @@ -110,7 +110,7 @@ global.aktualGas[0] = Air; global.lifeData.actualGas = global.aktualGas[0]; - const uint8_t button_standard_sensitivity = 85; + const uint8_t button_standard_sensitivity = 51; /* 51 equals a percentage of 85% which was the default value before */ global.ButtonResponsiveness[0] = button_standard_sensitivity; global.ButtonResponsiveness[1] = button_standard_sensitivity; global.ButtonResponsiveness[2] = button_standard_sensitivity; @@ -138,7 +138,7 @@ global.dataSendToMaster.RTE_VERSION_low = firmwareVersionLow();//RTE_VERSION_LOW;; global.dataSendToMaster.chargeStatus = 0; - global.dataSendToMaster.power_on_reset = 1; + global.dataSendToMaster.power_on_reset = 0; global.dataSendToMaster.header.checkCode[0] = 0xA1; global.dataSendToMaster.header.checkCode[1] = SPI_RX_STATE_OFFLINE; global.dataSendToMaster.header.checkCode[2] = 0xA3; @@ -156,7 +156,7 @@ global.deviceDataSendToMaster.RTE_VERSION_low = firmwareVersionLow();//RTE_VERSION_LOW; global.deviceDataSendToMaster.chargeStatus = 0; - global.deviceDataSendToMaster.power_on_reset = 1; + global.deviceDataSendToMaster.power_on_reset = 0; global.deviceDataSendToMaster.header.checkCode[0] = 0xDF; global.deviceDataSendToMaster.header.checkCode[1] = 0xDE; global.deviceDataSendToMaster.header.checkCode[2] = 0xDD; @@ -1032,12 +1032,13 @@ MX_I2C1_Init(); pressure_sensor_get_pressure_raw(); -/* check if I2C is not up an running and try to reactivate if necessary. Also do initialization if problem occurred during startup */ +/* check if I2C is not up and running and try to reactivate if necessary. Also do initialization if problem occurred during startup */ if(global.I2C_SystemStatus != HAL_OK) { MX_I2C1_TestAndClear(); MX_I2C1_Init(); - if(global.I2C_SystemStatus == HAL_OK) + + if((global.I2C_SystemStatus == HAL_OK) && (!is_init_pressure_done())) { init_pressure(); }