Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: iks01a1_acc LoRaWAN-demo-72_mdotIKS01A1 MTDOT-UDKDemo_Senet MTDOT-UDKDemo
Fork of X_NUCLEO_IKS01A1 by
Components/Common/TempSensor.h@42:5490ac2d0a10, 2015-06-08 (annotated)
- Committer:
- Wolfgang Betz
- Date:
- Mon Jun 08 13:46:20 2015 +0200
- Revision:
- 42:5490ac2d0a10
- Parent:
- 38:e06de1c26727
Prepare expansion board for having individually removable sensors
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Wolfgang Betz |
20:c20c8bd5be6b | 1 | /** |
| Wolfgang Betz |
20:c20c8bd5be6b | 2 | ****************************************************************************** |
| Wolfgang Betz |
20:c20c8bd5be6b | 3 | * @file TempSensor.h |
| Wolfgang Betz |
20:c20c8bd5be6b | 4 | * @author AST / EST |
| Wolfgang Betz |
20:c20c8bd5be6b | 5 | * @version V0.0.1 |
| Wolfgang Betz |
20:c20c8bd5be6b | 6 | * @date 13-April-2015 |
| Wolfgang Betz |
20:c20c8bd5be6b | 7 | * @brief This file contains the abstract class describing in general |
| Wolfgang Betz |
20:c20c8bd5be6b | 8 | * the interfaces of a temperature sensor |
| Wolfgang Betz |
20:c20c8bd5be6b | 9 | ****************************************************************************** |
| Wolfgang Betz |
20:c20c8bd5be6b | 10 | * @attention |
| Wolfgang Betz |
20:c20c8bd5be6b | 11 | * |
| Wolfgang Betz |
20:c20c8bd5be6b | 12 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
| Wolfgang Betz |
20:c20c8bd5be6b | 13 | * |
| Wolfgang Betz |
20:c20c8bd5be6b | 14 | * Redistribution and use in source and binary forms, with or without modification, |
| Wolfgang Betz |
20:c20c8bd5be6b | 15 | * are permitted provided that the following conditions are met: |
| Wolfgang Betz |
20:c20c8bd5be6b | 16 | * 1. Redistributions of source code must retain the above copyright notice, |
| Wolfgang Betz |
20:c20c8bd5be6b | 17 | * this list of conditions and the following disclaimer. |
| Wolfgang Betz |
20:c20c8bd5be6b | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| Wolfgang Betz |
20:c20c8bd5be6b | 19 | * this list of conditions and the following disclaimer in the documentation |
| Wolfgang Betz |
20:c20c8bd5be6b | 20 | * and/or other materials provided with the distribution. |
| Wolfgang Betz |
20:c20c8bd5be6b | 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
| Wolfgang Betz |
20:c20c8bd5be6b | 22 | * may be used to endorse or promote products derived from this software |
| Wolfgang Betz |
20:c20c8bd5be6b | 23 | * without specific prior written permission. |
| Wolfgang Betz |
20:c20c8bd5be6b | 24 | * |
| Wolfgang Betz |
20:c20c8bd5be6b | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| Wolfgang Betz |
20:c20c8bd5be6b | 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| Wolfgang Betz |
20:c20c8bd5be6b | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| Wolfgang Betz |
20:c20c8bd5be6b | 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| Wolfgang Betz |
20:c20c8bd5be6b | 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| Wolfgang Betz |
20:c20c8bd5be6b | 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| Wolfgang Betz |
20:c20c8bd5be6b | 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| Wolfgang Betz |
20:c20c8bd5be6b | 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| Wolfgang Betz |
20:c20c8bd5be6b | 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| Wolfgang Betz |
20:c20c8bd5be6b | 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| Wolfgang Betz |
20:c20c8bd5be6b | 35 | * |
| Wolfgang Betz |
20:c20c8bd5be6b | 36 | ****************************************************************************** |
| Wolfgang Betz |
20:c20c8bd5be6b | 37 | */ |
| Wolfgang Betz |
20:c20c8bd5be6b | 38 | |
| Wolfgang Betz |
20:c20c8bd5be6b | 39 | /* Define to prevent from recursive inclusion --------------------------------*/ |
| Wolfgang Betz |
20:c20c8bd5be6b | 40 | #ifndef __TEMP_SENSOR_CLASS_H |
| Wolfgang Betz |
20:c20c8bd5be6b | 41 | #define __TEMP_SENSOR_CLASS_H |
| Wolfgang Betz |
20:c20c8bd5be6b | 42 | |
| Wolfgang Betz |
20:c20c8bd5be6b | 43 | /* Includes ------------------------------------------------------------------*/ |
| Wolfgang Betz |
28:501726e9220d | 44 | #include <stdint.h> |
| Wolfgang Betz |
20:c20c8bd5be6b | 45 | |
| Wolfgang Betz |
20:c20c8bd5be6b | 46 | /* Classes ------------------------------------------------------------------*/ |
| Wolfgang Betz |
20:c20c8bd5be6b | 47 | /** An abstract class for Temperature sensors |
| Wolfgang Betz |
20:c20c8bd5be6b | 48 | */ |
| Wolfgang Betz |
20:c20c8bd5be6b | 49 | class TempSensor |
| Wolfgang Betz |
20:c20c8bd5be6b | 50 | { |
| Wolfgang Betz |
20:c20c8bd5be6b | 51 | public: |
| Wolfgang Betz |
28:501726e9220d | 52 | /** |
| Wolfgang Betz |
28:501726e9220d | 53 | * @brief Initialization of temperature sensor |
| Wolfgang Betz |
30:7b36639ee80a | 54 | * @param[out] ptr Pointer to device specific initalization structure |
| Wolfgang Betz |
32:2bb1d4ced32b | 55 | * @return 0 in case of success, an error code otherwise |
| Wolfgang Betz |
28:501726e9220d | 56 | */ |
| Wolfgang Betz |
30:7b36639ee80a | 57 | virtual int Init(void *ptr) = 0; |
| Wolfgang Betz |
20:c20c8bd5be6b | 58 | |
| Wolfgang Betz |
28:501726e9220d | 59 | /** |
| Wolfgang Betz |
28:501726e9220d | 60 | * @brief Enter sensor shutdown mode |
| Wolfgang Betz |
32:2bb1d4ced32b | 61 | * @return 0 in case of success, an error code otherwise |
| Wolfgang Betz |
28:501726e9220d | 62 | */ |
| Wolfgang Betz |
20:c20c8bd5be6b | 63 | virtual int PowerOff(void) = 0; |
| Wolfgang Betz |
28:501726e9220d | 64 | |
| Wolfgang Betz |
28:501726e9220d | 65 | /** |
| Wolfgang Betz |
28:501726e9220d | 66 | * @brief Get ID of temperature sensor |
| Wolfgang Betz |
30:7b36639ee80a | 67 | * @param[out] id Pointer to where to store the ID to |
| Wolfgang Betz |
32:2bb1d4ced32b | 68 | * @return 0 in case of success, an error code otherwise |
| Wolfgang Betz |
28:501726e9220d | 69 | */ |
| Wolfgang Betz |
30:7b36639ee80a | 70 | virtual int ReadID(uint8_t *id) = 0; |
| Wolfgang Betz |
28:501726e9220d | 71 | |
| Wolfgang Betz |
28:501726e9220d | 72 | /** |
| Wolfgang Betz |
28:501726e9220d | 73 | * @brief Reset sensor |
| Wolfgang Betz |
32:2bb1d4ced32b | 74 | * @return 0 in case of success, an error code otherwise |
| Wolfgang Betz |
28:501726e9220d | 75 | */ |
| Wolfgang Betz |
20:c20c8bd5be6b | 76 | virtual int Reset(void) = 0; |
| Wolfgang Betz |
20:c20c8bd5be6b | 77 | |
| Wolfgang Betz |
28:501726e9220d | 78 | /** |
| Wolfgang Betz |
38:e06de1c26727 | 79 | * @brief Get current temperature in degrees Celsius [°C] |
| Wolfgang Betz |
30:7b36639ee80a | 80 | * @param[out] pfData Pointer to where to store temperature to |
| Wolfgang Betz |
32:2bb1d4ced32b | 81 | * @return 0 in case of success, an error code otherwise |
| Wolfgang Betz |
28:501726e9220d | 82 | */ |
| Wolfgang Betz |
30:7b36639ee80a | 83 | virtual int GetTemperature(float *pfData) = 0; |
| Wolfgang Betz |
28:501726e9220d | 84 | |
| Wolfgang Betz |
38:e06de1c26727 | 85 | /** |
| Wolfgang Betz |
38:e06de1c26727 | 86 | * @brief Get current temperature in degrees Fahrenheit [°F] |
| Wolfgang Betz |
38:e06de1c26727 | 87 | * @param[out] pfData Pointer to where to store temperature to |
| Wolfgang Betz |
38:e06de1c26727 | 88 | * @return 0 in case of success, an error code otherwise |
| Wolfgang Betz |
38:e06de1c26727 | 89 | */ |
| Wolfgang Betz |
38:e06de1c26727 | 90 | virtual int GetFahrenheit(float *pfData) { |
| Wolfgang Betz |
38:e06de1c26727 | 91 | float celsius; |
| Wolfgang Betz |
38:e06de1c26727 | 92 | int ret; |
| Wolfgang Betz |
38:e06de1c26727 | 93 | |
| Wolfgang Betz |
38:e06de1c26727 | 94 | ret = GetTemperature(&celsius); |
| Wolfgang Betz |
38:e06de1c26727 | 95 | if(ret) return ret; |
| Wolfgang Betz |
38:e06de1c26727 | 96 | |
| Wolfgang Betz |
38:e06de1c26727 | 97 | *pfData = ((celsius * 1.8f) + 32.0f); |
| Wolfgang Betz |
38:e06de1c26727 | 98 | return 0; |
| Wolfgang Betz |
38:e06de1c26727 | 99 | } |
| Wolfgang Betz |
38:e06de1c26727 | 100 | |
| Wolfgang Betz |
20:c20c8bd5be6b | 101 | virtual void ConfigIT(uint16_t) = 0; |
| Wolfgang Betz |
20:c20c8bd5be6b | 102 | virtual void EnableIT(uint8_t) = 0; |
| Wolfgang Betz |
20:c20c8bd5be6b | 103 | virtual void DisableIT(uint8_t) = 0; |
| Wolfgang Betz |
20:c20c8bd5be6b | 104 | virtual uint8_t ITStatus(uint16_t, uint16_t) = 0; |
| Wolfgang Betz |
20:c20c8bd5be6b | 105 | virtual void ClearIT(uint16_t, uint16_t) = 0; |
| Wolfgang Betz |
20:c20c8bd5be6b | 106 | |
| Wolfgang Betz |
28:501726e9220d | 107 | /** |
| Wolfgang Betz |
28:501726e9220d | 108 | * @brief Attach a function to be called when an interrupt occurs |
| Wolfgang Betz |
28:501726e9220d | 109 | * @param[in] fptr A pointer to a void function, or 0 to set as none |
| Wolfgang Betz |
28:501726e9220d | 110 | */ |
| Wolfgang Betz |
20:c20c8bd5be6b | 111 | virtual void AttachIT(void (*fptr)(void)) = 0; |
| Wolfgang Betz |
20:c20c8bd5be6b | 112 | }; |
| Wolfgang Betz |
20:c20c8bd5be6b | 113 | |
| Wolfgang Betz |
20:c20c8bd5be6b | 114 | #endif /* __TEMP_SENSOR_CLASS_H */ |
