diff --git a/Core/Src/sts_cmox_hmac_sha.c b/Core/Src/sts_cmox_hmac_sha.c index 195d98f..65b4979 100644 --- a/Core/Src/sts_cmox_hmac_sha.c +++ b/Core/Src/sts_cmox_hmac_sha.c @@ -41,11 +41,7 @@ uint32_t sts_hmac_verify(void) GetUniqueId(uid); ret = sts_hmac_sha1((const uint8_t *) mKey, sizeof(mKey), (const uint8_t*)(uid+4), 4, &hmac_result); -/* - for (i=0;iI2cDevAddr = FinalAddress; /* Check all is OK with the new I2C address and initialize the sensor */ status = VL53L0X_RdWord(pDev, VL53L0X_REG_IDENTIFICATION_MODEL_ID, &Id); + if (status !=0) + { + APP_LOG(TS_OFF, VLEVEL_H, "#i VL53L0X_RdWord fail\r\n"); + break; + } status = VL53L0X_DataInit(pDev); if( status == 0 ){ pDev->Present = 1; //APP_LOG(TS_OFF, VLEVEL_H, "#%u VL53L0X_SetDeviceAddress to 0x%02x\r\n",i, pDev->I2cDevAddr); - nDevPresent++; - nDevMask |= 1 << i; - pDev->Present = 1; - APP_LOG(TS_OFF, VLEVEL_H, "VL53L0X %d Present and initiated to final 0x%2x, Position Mask=0x%02x\r\n", pDev->Id, pDev->I2cDevAddr, nDevMask); } else{ APP_LOG(TS_OFF, VLEVEL_H, "VL53L0X_DataInit %d fail\r\n", Id); break; } + nDevPresent++; + nDevMask |= 1 << i; + pDev->Present = 1; + APP_LOG(TS_OFF, VLEVEL_H, "VL53L0X %d Present and initiated to final 0x%2x, Position Mask=0x%02x\r\n", pDev->Id, pDev->I2cDevAddr, nDevMask); } else { APP_LOG(TS_OFF, VLEVEL_H, "# unknown ID %x\r\n", Id); @@ -368,9 +373,9 @@ void STS_TOF_VL53L0X_Range_Process(void) nSensorPresent = sts_tof_vl53l0x_DetectSensors(); // confirm sensor online APP_LOG(TS_OFF, VLEVEL_H, "\r\n %u pcs sensor(s) online \r\n", nSensorPresent); } - sts_tof_distance_data[0] = STS_MAX_L0_RANGE; - sts_tof_distance_data[1] = STS_MAX_L0_RANGE; - sts_tof_distance_data[2] = STS_MAX_L0_RANGE; + sts_tof_distance_data[0] = 0; + sts_tof_distance_data[1] = 0; + sts_tof_distance_data[2] = 0; if (nSensorPresent > 0) { @@ -382,33 +387,40 @@ void STS_TOF_VL53L0X_Range_Process(void) { if (VL53L0XDevs[i].Present ==1) { - status = VL53L0X_PerformSingleRangingMeasurement(&VL53L0XDevs[i], &RangingMeasurementData); - if( status ==0 ) - { - sts_tof_vl53l0x_Sensor_SetNewRange(&VL53L0XDevs[i],&RangingMeasurementData); - if( RangingMeasurementData.RangeStatus == 0 ) + uint8_t rep=0; + do { + rep++; + status = VL53L0X_PerformSingleRangingMeasurement(&VL53L0XDevs[i], &RangingMeasurementData); + if (status ==0) { - sts_tof_distance_data[i] = (int)VL53L0XDevs[i].LeakyRange; - if (sts_tof_distance_data[i] ==0) sts_tof_distance_data[i]+= STS_MAX_L0_RANGE; - nDevMask |= (1 << i); - sensor_data_ready |= 1; - } else - { - //HandleError(ERR_DEMO_RANGE_ONE); - APP_LOG(TS_OFF, VLEVEL_H,"\r\n#%u sensor ERR code = %04u\r\n",i, ERR_DEMO_RANGE_ONE); - } - // ########## two conditions - // ########## 1) return status ==0, - // ########## 2) and ranging status for valid ranging value !!!!!!!!!!!!!!!!! - } - } + sts_tof_vl53l0x_Sensor_SetNewRange(&VL53L0XDevs[i],&RangingMeasurementData); + if( RangingMeasurementData.RangeStatus == 0 ) + { + sts_tof_distance_data[i] = (int)VL53L0XDevs[i].LeakyRange; - HAL_Delay(30); - } // for i < MAX_TOF_COUNT - if (sensor_data_ready != 0) { - APP_LOG(TS_OFF, VLEVEL_H, "\r\n## Measured Range: \r\nTOF #0 = %4u mm, \r\nTOF #1 = %4u mm, \r\nTOF #2 = %4u mm\r\n", + nDevMask |= (1 << i); + sensor_data_ready |= 1; + } else + { + //HandleError(ERR_DEMO_RANGE_ONE); + APP_LOG(TS_OFF, VLEVEL_H,"\r\n#%u sensor ERR code = %04u\r\n",i, ERR_DEMO_RANGE_ONE); + } + // ########## two conditions + // ########## 1) return status ==0, + // ########## 2) and ranging status for valid ranging value !!!!!!!!!!!!!!!!! + } + HAL_Delay(1); + } while ((RangingMeasurementData.RangeStatus != 0)&&(rep <10)); + sts_tof_distance_data[i] = (RangingMeasurementData.RangeStatus!=0)?STS_MAX_L0_RANGE:sts_tof_distance_data[i]; + } + + HAL_Delay(5); + } // for i < MAX_TOF_COUNT + + if (sensor_data_ready != 0) { + APP_LOG(TS_OFF, VLEVEL_H, "\r\n## Measured Range: \r\nTOF #0 = %4u mm, \r\nTOF #1 = %4u mm, \r\nTOF #2 = %4u mm\r\n", (int)sts_tof_distance_data[0],(int)sts_tof_distance_data[1],(int)sts_tof_distance_data[2]); - } + } } // nSensorPresent >0