New Version with OS5

Committer:
tgrosch
Date:
Sun Oct 25 10:45:04 2020 +0000
Revision:
3:0eb6a9927171
Parent:
0:62b846b3988a
New version with OS5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tgrosch 0:62b846b3988a 1 /*!
tgrosch 0:62b846b3988a 2 * \file OPT3101frameData.h
tgrosch 0:62b846b3988a 3 * \author Karthik Rajagopal <krthik@ti.com>
tgrosch 0:62b846b3988a 4 * \version 0.9.1
tgrosch 0:62b846b3988a 5 *
tgrosch 0:62b846b3988a 6 * \section COPYRIGHT
tgrosch 0:62b846b3988a 7 * TEXAS INSTRUMENTS TEXT FILE LICENSE
tgrosch 0:62b846b3988a 8 * Copyright (c) 2018 Texas Instruments Incorporated
tgrosch 0:62b846b3988a 9 * All rights reserved not granted herein.
tgrosch 0:62b846b3988a 10 * Limited License.
tgrosch 0:62b846b3988a 11 * Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive license under copyrights and patents it now or hereafter owns or controls to make, have made, use, import, offer to sell and sell ("Utilize") this software subject to the terms herein. With respect to the foregoing patent license, such license is granted solely to the extent that any such patent is necessary to Utilize the software alone. The patent license shall not apply to any combinations which include this software, other than combinations with devices manufactured by or for TI ("TI Devices"). No hardware patent is licensed hereunder.
tgrosch 0:62b846b3988a 12 * Redistributions must preserve existing copyright notices and reproduce this license (including the above copyright notice and the disclaimer and (if applicable) source code license limitations below) in the documentation and/or other materials provided with the distribution
tgrosch 0:62b846b3988a 13 * Redistribution and use in binary form, without modification, are permitted provided that the following conditions are met:
tgrosch 0:62b846b3988a 14 * * No reverse engineering, decompilation, or disassembly of this software is permitted with respect to any software provided in binary form.
tgrosch 0:62b846b3988a 15 * * any redistribution and use are licensed by TI for use only with TI Devices.
tgrosch 0:62b846b3988a 16 * * Nothing shall obligate TI to provide you with source code for the software licensed and provided to you in object code.
tgrosch 0:62b846b3988a 17 * If software source code is provided to you, modification and redistribution of the source code are permitted provided that the following conditions are met:
tgrosch 0:62b846b3988a 18 * * any redistribution and use of the source code, including any resulting derivative works, are licensed by TI for use only with TI Devices.
tgrosch 0:62b846b3988a 19 * * any redistribution and use of any object code compiled from the source code and any resulting derivative works, are licensed by TI for use only with TI Devices.
tgrosch 0:62b846b3988a 20 * Neither the name of Texas Instruments Incorporated nor the names of its suppliers may be used to endorse or promote products derived from this software without specific prior written permission.
tgrosch 0:62b846b3988a 21 * DISCLAIMER.
tgrosch 0:62b846b3988a 22 * THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "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 TI AND TI'S LICENSORS 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.
tgrosch 0:62b846b3988a 23 *
tgrosch 0:62b846b3988a 24 * \section DESCRIPTION
tgrosch 0:62b846b3988a 25 * This file contains the OPT3101::frameData class declaraction
tgrosch 0:62b846b3988a 26 */
tgrosch 0:62b846b3988a 27
tgrosch 0:62b846b3988a 28 #ifndef OPT3101FRAMEDATA_H_
tgrosch 0:62b846b3988a 29 #define OPT3101FRAMEDATA_H_
tgrosch 0:62b846b3988a 30
tgrosch 0:62b846b3988a 31 #include <stdint.h>
tgrosch 0:62b846b3988a 32 #include "hostController.h"
tgrosch 0:62b846b3988a 33 //#include "OPT3101device.h"
tgrosch 0:62b846b3988a 34
tgrosch 0:62b846b3988a 35 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 36 #include <fstream>
tgrosch 0:62b846b3988a 37 #include <iostream>
tgrosch 0:62b846b3988a 38 #include <istream>
tgrosch 0:62b846b3988a 39 #include <string>
tgrosch 0:62b846b3988a 40 #endif
tgrosch 0:62b846b3988a 41
tgrosch 0:62b846b3988a 42
tgrosch 0:62b846b3988a 43 namespace OPT3101 {
tgrosch 0:62b846b3988a 44 /** \brief OPT3101::device declaration
tgrosch 0:62b846b3988a 45 This is declared here to avoid cyclic reference of classes
tgrosch 0:62b846b3988a 46 */
tgrosch 0:62b846b3988a 47 class device;
tgrosch 0:62b846b3988a 48
tgrosch 0:62b846b3988a 49 /*! \class OPT3101::frameData
tgrosch 0:62b846b3988a 50 \brief Class the data output from OPT3101 device
tgrosch 0:62b846b3988a 51
tgrosch 0:62b846b3988a 52 This is a class that holds output data from OPT3101 AFE.
tgrosch 0:62b846b3988a 53 Measurements by AFE OPT3101 device are stores in registers with address 0x08, x09 & 0x0A. Difference sections of these registers hold different measurements like OPT3101::frameData::phase, OPT3101::frameData::amplitude <br>
tgrosch 0:62b846b3988a 54 This class provides an abstraction where the registers are read, relevant portions of the registers are extracted and assigned to members with meaningful names.
tgrosch 0:62b846b3988a 55 This provides a functional abstraction to the user.
tgrosch 0:62b846b3988a 56 */
tgrosch 0:62b846b3988a 57 class frameData {
tgrosch 0:62b846b3988a 58 public:
tgrosch 0:62b846b3988a 59 uint32_t phase; ///< phase value measured by the AFE. Actually 16 bit unsigned value upscaled to 17 bits with 1 bit of frameData::phaseovl flag added to the MSB. Same as OPT3101::registers::phase_out
tgrosch 0:62b846b3988a 60 bool phaseovl; ///< phase overload flag, specifying if phase value detected exceeds 16 bits. (greater than 65535). OPT3101::registers::.phase_overflow
tgrosch 0:62b846b3988a 61 bool phaseovlf2; ///< phase overload flag for frequency 2, specifying if phase value detected exceeds 16 bits. (greater than 65535). Same as OPT3101::registers::phase_overflow_f2
tgrosch 0:62b846b3988a 62 bool ambovl; ///< ambient over load flag which flags if the AFE is saturated due to very high ambient condition. Same as OPT3101::registers::amb_ovl_flag
tgrosch 0:62b846b3988a 63 bool illumDac; ///< flag that specifies which of the auto-hdr register config from where the measurement is made. Same as OPT3101::registers::hdr_mode
tgrosch 0:62b846b3988a 64 uint8_t ledChannel; ///< value that specifies from which channel the measurement is made. Same as OPT3101::registers::tx_channel
tgrosch 0:62b846b3988a 65 bool frameStatus; ///< flag that specifies if the measurement is a valid data. Same as OPT3101::registers::frame_status
tgrosch 0:62b846b3988a 66 bool dealiasFreq; ///< flag that specifies if the measurement is done with fundamental frequency of de-alias frequency. Same as OPT3101::registers::mod_freq
tgrosch 0:62b846b3988a 67 uint8_t frameCounter; ///< Frame counter which counts every data ready. Same as combination of OPT3101::register::frame_count0 , OPT3101::registers::frame_count1 and OPT3101::registers::frame_count2
tgrosch 0:62b846b3988a 68 uint16_t amplitude; ///< amplitude value measured by AFE. 15 bit representation of the signal. Same as OPT3101::registers::amp_out
tgrosch 0:62b846b3988a 69 bool sigovl; ///< flag that specifies if the AFE is saturated due to signal. Same as OPT3101::registers::sig_ovl_flag
tgrosch 0:62b846b3988a 70 uint8_t dealiasBin; ///< value that specifies the de-aliased bin number. Same as OPT3101::registers::dealias_bin
tgrosch 0:62b846b3988a 71 uint16_t ambient; ///< value specifies the ambient light measured by the ambient cancellation block. Same as OPT3101::registers::amb_data
tgrosch 0:62b846b3988a 72 uint16_t temp; ///< value of internal temp sensor read from register 0x0A. Same as OPT3101::registers::tmain . This is updated every data ready.
tgrosch 0:62b846b3988a 73 uint16_t tmain; ///< value of internal temp sensor read from register OPT3101::registers::tmain
tgrosch 0:62b846b3988a 74 uint16_t tillum; ///< value of external temp sensor read using the I2C Master. Same as OPT3101::registers::tillum
tgrosch 0:62b846b3988a 75 /*!
tgrosch 0:62b846b3988a 76 * \brief initializes the members to 0
tgrosch 0:62b846b3988a 77 *
tgrosch 0:62b846b3988a 78 * \returns Nothing;
tgrosch 0:62b846b3988a 79 */
tgrosch 0:62b846b3988a 80 frameData();
tgrosch 0:62b846b3988a 81 /*!
tgrosch 0:62b846b3988a 82 * \brief captures measurement data from the device
tgrosch 0:62b846b3988a 83 * This method invokes I2C transactions to capture data from the OPT3101 device registers 0x08, 0x09 and 0x0A. Extracts and assigns members their respective values based on their positions in the registers.
tgrosch 0:62b846b3988a 84 * \param[in] host; Pointer to the class hostController used to directly invoke I2C transactions bypassing OPT3101::registers or OPT3101::device class
tgrosch 0:62b846b3988a 85 * \param[in] dev; Pointer to the class OPT3101::device used to read register(s) from device
tgrosch 0:62b846b3988a 86 * \param[in] readTIllulm; Flag which specifies if OPT3101::registers::tillum value needs to be read or not
tgrosch 0:62b846b3988a 87 * \returns Nothing;
tgrosch 0:62b846b3988a 88 */
tgrosch 0:62b846b3988a 89 void capture(hostController *host, device *dev, bool readTIllulm = true);
tgrosch 0:62b846b3988a 90 /*!
tgrosch 0:62b846b3988a 91 * \brief reports members of the instance
tgrosch 0:62b846b3988a 92 * Print the members of the class instance on screen
tgrosch 0:62b846b3988a 93 * \returns Nothing;
tgrosch 0:62b846b3988a 94 */
tgrosch 0:62b846b3988a 95 void report();
tgrosch 0:62b846b3988a 96 /*!
tgrosch 0:62b846b3988a 97 * \brief prints members of the instance
tgrosch 0:62b846b3988a 98 * Print the members of the class instance on screen
tgrosch 0:62b846b3988a 99 * \returns Nothing;
tgrosch 0:62b846b3988a 100 */
tgrosch 0:62b846b3988a 101 void print();
tgrosch 0:62b846b3988a 102 /*!
tgrosch 0:62b846b3988a 103 * \brief prints header
tgrosch 0:62b846b3988a 104 * Print the members of the class instance on screen
tgrosch 0:62b846b3988a 105 * \returns Nothing;
tgrosch 0:62b846b3988a 106 */
tgrosch 0:62b846b3988a 107 void printHeader();
tgrosch 0:62b846b3988a 108 /*!
tgrosch 0:62b846b3988a 109 * \brief calculates mean and assigns to self
tgrosch 0:62b846b3988a 110 * Given a set on input OPT3101::frameData the method calculates the mean frame and assigns to self
tgrosch 0:62b846b3988a 111 * \param[in] inputData; Pointer to the class OPT3101::frameData instance with multiple frame data
tgrosch 0:62b846b3988a 112 * \param[in] nFrames; Number of measurements to step though in the inputData to calculate mean
tgrosch 0:62b846b3988a 113 * \returns Nothing;
tgrosch 0:62b846b3988a 114 */
tgrosch 0:62b846b3988a 115 void populateWithMean(frameData *inputData, uint16_t nFrames);
tgrosch 0:62b846b3988a 116 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 117 /*!
tgrosch 0:62b846b3988a 118 * \brief saves phase temp coff values to file
tgrosch 0:62b846b3988a 119 * This methods saves the phase temp coff values to a non-volatile memory. Storage/Restoration to/from non-volatile memory is important for factory calibration
tgrosch 0:62b846b3988a 120 * \param[in] fileName; Path and name of the file to store
tgrosch 0:62b846b3988a 121 * \returns Nothing;
tgrosch 0:62b846b3988a 122 */
tgrosch 0:62b846b3988a 123 void storeToFile(char *fileName);
tgrosch 0:62b846b3988a 124 /*!
tgrosch 0:62b846b3988a 125 * \brief load phase temp coff values from file
tgrosch 0:62b846b3988a 126 * This methods loads the phase temp coff values to a non-volatile memory. Storage/Restoration to/from non-volatile memory is important for factory calibration
tgrosch 0:62b846b3988a 127 * \param[in] fileName; Path and name of the file from where to load
tgrosch 0:62b846b3988a 128 * \returns Nothing;
tgrosch 0:62b846b3988a 129 */
tgrosch 0:62b846b3988a 130 void loadFromFile(char *fileName);
tgrosch 0:62b846b3988a 131 #endif
tgrosch 0:62b846b3988a 132 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 133 /*!
tgrosch 0:62b846b3988a 134 * \brief Operator overload to store class contents to a file
tgrosch 0:62b846b3988a 135 * Casts all the class members for file storage
tgrosch 0:62b846b3988a 136 * \param[out] os; os is data stream to serialize data
tgrosch 0:62b846b3988a 137 * \param[in] data; data is pointer to the class to be serlialized and stored
tgrosch 0:62b846b3988a 138 * \returns std::ostream; Serialized std::ostream to be written to a file
tgrosch 0:62b846b3988a 139 */
tgrosch 0:62b846b3988a 140 friend std::ostream& operator<<(std::ostream& os, const frameData *data);
tgrosch 0:62b846b3988a 141 /*!
tgrosch 0:62b846b3988a 142 * \brief Operator overload to load class contents to from a file
tgrosch 0:62b846b3988a 143 * Retreives all the class members from a stored file
tgrosch 0:62b846b3988a 144 * \param[in] is; is input stream from where the data is loaded
tgrosch 0:62b846b3988a 145 * \param[out] data; data is pointer to the class to be restored
tgrosch 0:62b846b3988a 146 * \returns std::istream; Serialized Input stream loaded from file
tgrosch 0:62b846b3988a 147 */
tgrosch 0:62b846b3988a 148 friend std::istream& operator>>(std::istream& is, frameData *data);
tgrosch 0:62b846b3988a 149 #endif
tgrosch 0:62b846b3988a 150
tgrosch 0:62b846b3988a 151 };
tgrosch 0:62b846b3988a 152 }
tgrosch 0:62b846b3988a 153 #endif /* OPT3101FRAMEDATA_H_ */
tgrosch 0:62b846b3988a 154