Mercurial > public > ostc4
changeset 234:73cc47c80657
Merged in janlmulder/ostc4/div-fixes-4-1 (pull request #14)
2 fixes and cleanup
author | heinrichsweikamp <bitbucket@heinrichsweikamp.com> |
---|---|
date | Sat, 06 Apr 2019 07:01:21 +0000 |
parents | d5891007fc4c (current diff) 9f0efc4df01e (diff) |
children | eebad720865f |
files | |
diffstat | 7 files changed, 28 insertions(+), 115 deletions(-) [+] |
line wrap: on
line diff
--- a/Discovery/Src/base.c Tue Apr 02 18:18:22 2019 +0200 +++ b/Discovery/Src/base.c Sat Apr 06 07:01:21 2019 +0000 @@ -294,7 +294,7 @@ uint8_t updateButtonsToDefault = 0; uint8_t wasFirmwareUpdateCheckBattery = 0; -static DoDisplayRefresh = 0; /* trigger to refresh display data */ +static uint8_t DoDisplayRefresh = 0; /* trigger to refresh display data */ /* Private function prototypes -----------------------------------------------*/ static void SystemClock_Config(void);
--- a/Discovery/Src/data_exchange_main.c Tue Apr 02 18:18:22 2019 +0200 +++ b/Discovery/Src/data_exchange_main.c Sat Apr 06 07:01:21 2019 +0000 @@ -405,17 +405,6 @@ { if(!wasUpdateNotPowerOn) wasPowerOn = 1; - - RTC_DateTypeDef Sdate; - RTC_TimeTypeDef Stime; - - translateDate(settings->backup_localtime_rtc_dr, &Sdate); - translateTime(settings->backup_localtime_rtc_tr, &Stime); - - dataOut.data.newTime = Stime; - dataOut.setTimeNow = 1; - dataOut.data.newDate = Sdate; - dataOut.setDateNow = 1; settingsHelperButtonSens_keepPercentageValues(settingsGetPointerStandard()->ButtonResponsiveness[3], settings->ButtonResponsiveness); setButtonResponsiveness(settings->ButtonResponsiveness);
--- a/Discovery/Src/simulation.c Tue Apr 02 18:18:22 2019 +0200 +++ b/Discovery/Src/simulation.c Sat Apr 06 07:01:21 2019 +0000 @@ -237,16 +237,8 @@ /* Exposure Tissues */ decom_tissues_exposure(1, &pDiveState->lifeData); - /* moved to updateSetpointStateUsed() - pDiveState->lifeData.ppO2 = decom_calc_ppO2( pDiveState->lifeData.pressure_ambient_bar, &pDiveState->lifeData.actualGas); - */ decom_oxygen_calculate_cns_exposure(1, &pDiveState->lifeData.actualGas, pDiveState->lifeData.pressure_ambient_bar, &pDiveState->lifeData.cns); - //if((pDiveState->lifeData.depth_meter < 0.1f) || (pDiveState->lifeData.dive_time_seconds > 1*60*60)) -// if(pDiveState->lifeData.dive_time_seconds > 1*60*60) - if(pDiveState->lifeData.dive_time_seconds > 5*60*60) // test Dirk Berben - { - simulation_exit(); - } + if(stateSimGetPointer()->lifeData.counterSecondsShallowDepth) { stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth += 1;
--- a/Discovery/Src/tComm.c Tue Apr 02 18:18:22 2019 +0200 +++ b/Discovery/Src/tComm.c Sat Apr 06 07:01:21 2019 +0000 @@ -97,7 +97,7 @@ uint8_t bluetoothActiveLastTime = 0; uint8_t StartListeningToUART = 0; -unsigned char display_text[256] = { 0 }; +char display_text[256] = { 0 }; uint8_t setForcedBluetoothName = 0;
--- a/Small_CPU/Src/batteryGasGauge.c Tue Apr 02 18:18:22 2019 +0200 +++ b/Small_CPU/Src/batteryGasGauge.c Sat Apr 06 07:01:21 2019 +0000 @@ -27,11 +27,11 @@ #include "stm32f4xx_hal.h" #include "i2c.h" -float battery_f_voltage = 0; -float battery_f_charge_percent = 0; +static float battery_f_voltage = 0; +static float battery_f_charge_percent = 0; #define BGG_BATTERY_OFFSET (26123) //; 65536-(3,35Ah/0,085mAh) -#define BGG_BATTERY_DEVIDER (394) //; 3,35Ah/0,085mAh/100 [%] +#define BGG_BATTERY_DIVIDER (394) //; 3,35Ah/0,085mAh/100 [%] float get_voltage(void) { @@ -61,8 +61,14 @@ uint8_t buffer[2]; buffer[0] = 0x01; - buffer[1] = 0xF8;// true: F8 = 11111000, wrong/old comment: 11101000 - I2C_Master_Transmit( DEVICE_BATTERYGAUGE, buffer, 2); + + // F8 = 11111000: + // Vbat 3.0V (11) + // Prescale M = 128 (111) + // AL/CC pin disable (0) + // Shutdown (0) + buffer[1] = 0xF8; + I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2); } @@ -86,7 +92,7 @@ battery_f_charge_percent_local = (float)(bufferReceive[2] * 256); battery_f_charge_percent_local += (float)(bufferReceive[3]); battery_f_charge_percent_local -= BGG_BATTERY_OFFSET; - battery_f_charge_percent_local /= BGG_BATTERY_DEVIDER; + battery_f_charge_percent_local /= BGG_BATTERY_DIVIDER; if(battery_f_charge_percent_local < 0) battery_f_charge_percent_local = 0; @@ -120,8 +126,9 @@ if(percentage >= 100) mAhSend = 0xFFFF; - else - mAhSend = (uint16_t)(percentage * 655.35f); + else { + mAhSend = (percentage * BGG_BATTERY_DIVIDER) + BGG_BATTERY_OFFSET; + } uint8_t bufferSend[3]; bufferSend[0] = 0x02;
--- a/Small_CPU/Src/rtc.c Tue Apr 02 18:18:22 2019 +0200 +++ b/Small_CPU/Src/rtc.c Sat Apr 06 07:01:21 2019 +0000 @@ -33,7 +33,7 @@ { stimestructure.SubSeconds = 0; - stimestructure.TimeFormat = RTC_HOURFORMAT12_AM; + stimestructure.TimeFormat = RTC_HOURFORMAT_24; stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ; stimestructure.StoreOperation = RTC_STOREOPERATION_RESET; @@ -104,13 +104,7 @@ void MX_RTC_init(void) { - - RTC_TimeTypeDef sTime; - RTC_DateTypeDef sDate; -// RTC_AlarmTypeDef sAlarm; - - /**Initialize RTC and set the Time and Date - */ + /* Initialize RTC */ RTCHandle.Instance = RTC; RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24; RTCHandle.Init.AsynchPrediv = 127; @@ -119,34 +113,6 @@ RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; HAL_RTC_Init(&RTCHandle); - - sTime.Hours = 11; - sTime.Minutes = 0; - sTime.Seconds = 0; - sTime.SubSeconds = 0; - sTime.TimeFormat = RTC_HOURFORMAT12_AM; - sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; - sTime.StoreOperation = RTC_STOREOPERATION_RESET; - HAL_RTC_SetTime(&RTCHandle, &sTime, FORMAT_BCD); - - sDate.WeekDay = RTC_WEEKDAY_SUNDAY; - sDate.Month = RTC_MONTH_FEBRUARY; - sDate.Date = 15; - sDate.Year = 17; - HAL_RTC_SetDate(&RTCHandle, &sDate, FORMAT_BCD); - - -/* - RTCHandle.Instance = RTC; - RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24; - RTCHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV; - RTCHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV; - RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE; - RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; - RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; - - HAL_RTC_Init(&RTCHandle); -*/ }
--- a/Small_CPU/Src/scheduler.c Tue Apr 02 18:18:22 2019 +0200 +++ b/Small_CPU/Src/scheduler.c Sat Apr 06 07:01:21 2019 +0000 @@ -74,7 +74,6 @@ _Bool vpm_crush2(void); void scheduleUpdateDeviceData(void); -void initStructWithZeero(uint8_t* data, uint16_t length); long get_nofly_time_minutes(void); void copyActualGas(SGas gas); void copyPressureData(void); @@ -82,15 +81,12 @@ void copyTimeData(void); void copyCompassData(void); void copyCompassDataDuringCalibration(int16_t dx, int16_t dy, int16_t dz); -//void copyBatteryData(void); now in header void copyAmbientLightData(void); void copyTissueData(void); void copyVpmCrushingData(void); void copyDeviceData(void); void copyPICdata(void); -uint16_t schedule_update_timer_helper(int8_t thisSeconds); - - +static void schedule_update_timer_helper(int8_t thisSeconds); uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow); _Bool scheduleCheck_pressure_reached_dive_mode_level(void); @@ -101,7 +97,7 @@ void initGlobals(void) { - initStructWithZeero((uint8_t*) &global, sizeof(SGlobal)); + bzero(&global, sizeof(SGlobal)); global.dataSendToSlavePending = 0; global.dataSendToSlaveIsValid = 1; @@ -316,17 +312,11 @@ return (10 * multiplesOf16) + inStupidTime; } - -uint32_t minCounterDebug = 0; - uint32_t schedule_time_compare_helper(RTC_TimeTypeDef timeNow, RTC_DateTypeDef dateNow, RTC_TimeTypeDef timeLast, RTC_DateTypeDef dateLast) { uint32_t nowInSeconds; uint32_t lastInSeconds; uint32_t resultDiff; - - if(timeNow.Minutes != timeLast.Minutes) - minCounterDebug++; nowInSeconds = (uint32_t)RtcBugFixChsw(timeNow.Hours) * 3600; nowInSeconds += (uint32_t)RtcBugFixChsw(timeNow.Minutes) * 60; @@ -335,16 +325,6 @@ lastInSeconds = (uint32_t)RtcBugFixChsw(timeLast.Hours) * 3600; lastInSeconds += (uint32_t)RtcBugFixChsw(timeLast.Minutes) * 60; lastInSeconds += (uint32_t)RtcBugFixChsw(timeLast.Seconds); - -/* - nowInSeconds = (uint32_t)timeNow.Hours * 3600; - nowInSeconds += (uint32_t)timeNow.Minutes * 60; - nowInSeconds += (uint32_t)timeNow.Seconds; - - lastInSeconds = (uint32_t)timeLast.Hours * 3600; - lastInSeconds += (uint32_t)timeLast.Minutes * 60; - lastInSeconds += (uint32_t)timeLast.Seconds; -*/ if(dateNow.Date != dateLast.Date) { @@ -372,25 +352,25 @@ */ extern RTC_HandleTypeDef RTCHandle; -uint16_t schedule_update_timer_helper(int8_t thisSeconds) +static void schedule_update_timer_helper(int8_t thisSeconds) { static RTC_TimeTypeDef sTimeLast; static RTC_DateTypeDef sDateLast; RTC_TimeTypeDef sTimeNow; RTC_DateTypeDef sDateNow; uint32_t secondsPast; - uint32_t tempNewValue = 0; HAL_RTC_GetTime(&RTCHandle, &sTimeNow, RTC_FORMAT_BCD); HAL_RTC_GetDate(&RTCHandle, &sDateNow, RTC_FORMAT_BCD); - if(thisSeconds != 0) // otherwise just store sTimeLast, sDateLast and return 0 + if(thisSeconds != 0) // otherwise just store sTimeLast, sDateLast { - secondsPast = schedule_time_compare_helper(sTimeNow, sDateNow, sTimeLast, sDateLast); - if(thisSeconds > 0) // use this value instead, good for pre-loading sTimeLast and sDateLast { secondsPast = thisSeconds; + } else { + // thisSeconds < 0 and not <= ! + secondsPast = schedule_time_compare_helper(sTimeNow, sDateNow, sTimeLast, sDateLast); } if(global.seconds_since_last_dive) @@ -401,7 +381,7 @@ } else { - tempNewValue = ((uint32_t)global.seconds_since_last_dive) + secondsPast; + uint32_t tempNewValue = ((uint32_t)global.seconds_since_last_dive) + secondsPast; if(tempNewValue > 777900) // a bit more than nine days [seconds] global.seconds_since_last_dive = 0; else @@ -412,13 +392,8 @@ sTimeLast = sTimeNow; sDateLast = sDateNow; - - return tempNewValue; } - - - /** ****************************************************************************** * @brief schedule_check_resync. @@ -827,9 +802,6 @@ if(global.seconds_since_last_dive) { schedule_update_timer_helper(-1); -// global.seconds_since_last_dive++; -// if(global.seconds_since_last_dive > 777900) // a bit more than nine days [seconds] -// global.seconds_since_last_dive = 0; } if(global.accidentRemainingSeconds) @@ -946,9 +918,6 @@ if(global.seconds_since_last_dive) { schedule_update_timer_helper(-1); -// global.seconds_since_last_dive += 60; -// if(global.seconds_since_last_dive > 777900) // a bit more than nine days [seconds] -// global.seconds_since_last_dive = 0; } scheduleUpdateLifeData(0); @@ -1013,9 +982,6 @@ if(global.seconds_since_last_dive) { schedule_update_timer_helper(-1); -// global.seconds_since_last_dive += 2; -// if(global.seconds_since_last_dive > 777900) // a bit more than nine days [seconds] -// global.seconds_since_last_dive = 0; } if(global.accidentRemainingSeconds) @@ -1334,13 +1300,6 @@ } return 0; -}; - - -void initStructWithZeero(uint8_t* data, uint16_t length) -{ - for(uint16_t i = 0; i < length; i++) - data[i] = 0; }