modified to work with MultiTech mDot on UDK2.0
Dependents: HelloWorld_53L0A1 unh-hackathon-example unh-hackathon-example-raw
Fork of X_NUCLEO_53L0A1 by
Revision 2:58b5e9097aa3, committed 2016-12-01
- Comitter:
- johnAlexander
- Date:
- Thu Dec 01 14:17:46 2016 +0000
- Parent:
- 1:01b8004bc0a7
- Child:
- 3:613d7f1ef60e
- Commit message:
- Use ST_INTERFACES package to access RangeSensor abstract class.
Changed in this revision
--- a/Components/Interfaces/GenericSensor.h Mon Nov 28 14:52:49 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/** - ****************************************************************************** - * @file GenericSensor.h - * @author AST / EST - * @version V0.0.1 - * @date 13-April-2015 - * @brief This file contains the abstract class describing in general - * the interfaces of a generic sensor - ****************************************************************************** - * @attention - * - * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ - -/* Define to prevent from recursive inclusion --------------------------------*/ -#ifndef __GENERIC_SENSOR_CLASS_H -#define __GENERIC_SENSOR_CLASS_H - -/* Includes ------------------------------------------------------------------*/ -#include <stdint.h> - -/* Classes ------------------------------------------------------------------*/ -/** An abstract class for Generic sensors - */ -class GenericSensor -{ - public: - /** - * @brief Initialization of sensor - * @param[out] ptr Pointer to device specific initalization structure - * @return 0 in case of success, an error code otherwise - */ - virtual int Init() = 0; - - /** - * @brief Get ID of sensor - * @param[out] id Pointer to where to store the ID to - * @return 0 in case of success, an error code otherwise - */ - virtual int ReadID() = 0; -}; - -#endif /* __GENERIC_SENSOR_CLASS_H */ -
--- a/Components/Interfaces/RangeSensor.h Mon Nov 28 14:52:49 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/** - ****************************************************************************** - * @file RangeSensor.h - * @author AST / EST - * @version V0.0.1 - * @date 13-April-2015 - * @brief This file contains the abstract class describing in general - * the interfaces of a range sensor - ****************************************************************************** - * @attention - * - * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ - -/* Define to prevent from recursive inclusion --------------------------------*/ -#ifndef __RANGE_SENSOR_CLASS_H -#define __RANGE_SENSOR_CLASS_H - -/* Includes ------------------------------------------------------------------*/ -#include "GenericSensor.h" - -/* Classes ------------------------------------------------------------------*/ -/** An abstract class for range sensors - */ -class RangeSensor : public GenericSensor -{ - public: - /** - * @brief Get current range [mm] - * @param[out] piData Pointer to where to store range to - * @return 0 in case of success, an error code otherwise - */ - virtual int GetRange(int32_t *piData) = 0; -}; - -#endif /* __RANGE_SENSOR_CLASS_H */ -
--- a/Components/VL53L0X/vl53l0x_class.cpp Mon Nov 28 14:52:49 2016 +0000 +++ b/Components/VL53L0X/vl53l0x_class.cpp Thu Dec 01 14:17:46 2016 +0000 @@ -5031,7 +5031,7 @@ } -int VL53L0X::ReadID() +int VL53L0X::ReadID(uint8_t *id) { int status = 0; uint16_t rl_id=0; @@ -5113,7 +5113,7 @@ status=IsPresent(); if(!status) { - status=Init(); + VL53L0X_DataInit(Device); if(status != VL53L0X_ERROR_NONE) { printf("Failed to init VL53L0X sensor!\n\r");
--- a/Components/VL53L0X/vl53l0x_class.h Mon Nov 28 14:52:49 2016 +0000 +++ b/Components/VL53L0X/vl53l0x_class.h Thu Dec 01 14:17:46 2016 +0000 @@ -1,5 +1,5 @@ /******************************************************************************* - Copyright © 2016, STMicroelectronics International N.V. + Copyright © 2016, STMicroelectronics International N.V. All rights reserved. Redistribution and use in source and binary forms, with or without @@ -327,7 +327,7 @@ Device=&MyDevice; gpio0=NULL; if (pin_gpio1 != NC) { gpio1Int = new InterruptIn(pin_gpio1); } - else { gpio1Int = NULL; } + else { gpio1Int = NULL; } } /** Destructor @@ -369,15 +369,8 @@ /** * @brief Initialize the sensor with default values * @return 0 on Success - */ + */ int InitSensor(uint8_t NewAddr); - - int RawInitSensor(void); - int initDevice(VL53L0X_DEV Dev); - int setLongRangePresets(VL53L0X_DEV Dev); - int DoRanging(VL53L0X_Dev_t *pMyDevice); - - /** @@ -491,11 +484,50 @@ * @param void * @return 0 on success, @a #CALIBRATION_WARNING if failed */ - virtual int Init() +// virtual int Init() + virtual int Init(void * NewAddr) { - return VL53L0X_DataInit(&MyDevice); -// return VL53L0X_DataInit(Device); -// return 1; +// return VL53L0X_DataInit(&MyDevice); + return VL53L0X_DataInit(Device); +/* + int status; + + VL6180x_Off(); + VL6180x_On(); + + status=VL6180x_WaitDeviceBooted(Device); + if(status) { + VL6180x_ErrLog("WaitDeviceBooted fail\n\r"); + } + status=IsPresent(); + if(!status) + { + Device->Present=1; + VL6180x_InitData(Device); + if(status) + { + printf("Failed to init VL6180X sensor!\n\r"); + return status; + } + status=Prepare(); + if(status) + { + printf("Failed to prepare VL6180X!\n\r"); + return status; + } + if(*(uint8_t*)NewAddr!=DEFAULT_DEVICE_ADDRESS) + { + status=SetI2CAddress(*(uint8_t*)NewAddr); + if(status) + { + printf("Failed to change I2C address!\n\r"); + return status; + } + } + Device->Ready=1; + } + return status; +*/ } /** @@ -687,10 +719,19 @@ * @param pRange_mm Pointer to range distance * @return 0 on success */ - virtual int GetRange(int32_t *piData) + virtual int GetDistance(uint32_t *piData) { // return VL6180x_RangeGetResult(Device, piData); - return 1; + int status=0; + VL53L0X_RangingMeasurementData_t pRangingMeasurementData; + + status=StartMeasurement(range_single_shot_polling, NULL); + if (!status) { + status=GetMeasurement(range_single_shot_polling, &pRangingMeasurementData); + } + StopMeasurement(range_single_shot_polling); + *piData = pRangingMeasurementData.RangeMilliMeter; + return status; } /** @@ -1325,7 +1366,8 @@ VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo); /* Read function of the ID device */ - virtual int ReadID(); +// virtual int ReadID(); + virtual int ReadID(uint8_t *id); VL53L0X_Error WaitMeasurementDataReady(VL53L0X_DEV Dev); VL53L0X_Error WaitStopCompleted(VL53L0X_DEV Dev); @@ -1351,8 +1393,9 @@ int IsPresent() { int status; + uint8_t id; - status=ReadID(); + status=ReadID(&id); if(status) VL53L0X_ErrLog("Failed to read ID device. Device not present!\n\r"); return status;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ST_INTERFACES.lib Thu Dec 01 14:17:46 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/ST_INTERFACES/#e2bf4d06a8fc
--- a/x_nucleo_53l0a1.cpp Mon Nov 28 14:52:49 2016 +0000 +++ b/x_nucleo_53l0a1.cpp Thu Dec 01 14:17:46 2016 +0000 @@ -120,6 +120,3 @@ return 0; } - - -
--- a/x_nucleo_53l0a1.h Mon Nov 28 14:52:49 2016 +0000 +++ b/x_nucleo_53l0a1.h Thu Dec 01 14:17:46 2016 +0000 @@ -60,7 +60,7 @@ */ class X_NUCLEO_53L0A1 { - public: +protected: /** Constructor 1 * @param[in] &i2c device I2C to be used for communication */ @@ -155,6 +155,8 @@ _instance=NULL; } +public: + /** * @brief Creates a singleton object instance * @param[in] &i2c device I2C to be used for communication