Maxim Integrated / Mbed OS MAXREFDES220_HR_SPO2_MONITOR

Dependencies:   max32630fthr USBDevice

Fork of MAXREFDES220_HEART_RATE_MONITOR by Maxim Integrated

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SensorComm.h Source File

SensorComm.h

00001 /*******************************************************************************
00002  * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * Except as contained in this notice, the name of Maxim Integrated
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024  * Products, Inc. Branding Policy.
00025  *
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all
00030  * ownership rights.
00031  *******************************************************************************
00032  */
00033 
00034 #ifndef _SENSORCOMM_H_
00035 #define _SENSORCOMM_H_
00036 
00037 #include "mbed.h"
00038 #include <stdint.h>
00039 #include "MaximSensor.h"
00040 
00041 /**
00042  * @brief   SensorComm is Maxim Sensor Studio GUI command handler base class.
00043  * @details SensorComm includes base functions and data structures for to
00044  *  create new command handler classes. All command handler classes should
00045  *  implement this class.
00046  */
00047 class SensorComm
00048 {
00049 public:
00050 
00051     const static uint8_t kMaxRegisterInOneStruct = 4;
00052 
00053     // size of that struct is 20 bytes(checked)
00054     typedef struct{
00055         uint8_t reg_adresses[4];
00056         uint32_t reg_values[4];
00057     }Reg_Val_BLE;
00058 
00059     /* PUBLIC FUNCTION DECLARATIONS */
00060     /**
00061     * @brief    SensorComm constructor.
00062     *
00063     * @param[in]    sensorType Name of sensor (ie "ppg")
00064     * @param[in]    visible Whether this sensor should be visible to users in DeviceStudio
00065     */
00066     SensorComm(const char *type, bool visible);
00067 
00068     /**
00069     * @brief    SensorComm destructor.
00070     *
00071     */
00072     virtual ~SensorComm();
00073 
00074     /**
00075     * @brief    Initializer for SensorComm.
00076     *
00077     * @param[in]    s MaximSensor instance to handle sensor commands.
00078     */
00079     void comm_init(MaximSensor *s);
00080 
00081     /**
00082     * @brief    Get the type of the sensor
00083     *
00084     * @param[out]   char* to name of type (ie "ppg")
00085     */
00086     const char* get_type();
00087 
00088     /**
00089     * @brief    Get the maxim part name of the sensor
00090     *
00091     * @param[out]   char* to name (ie "max86140")
00092     */
00093     virtual const char* get_part_name();
00094 
00095     /**
00096     * @brief    Get the maxim algorithm version of the sensor
00097     *
00098     * @param[out]   char* to name (ie "max86140")
00099     */
00100     virtual const char* get_algo_ver();
00101 
00102     /**
00103     * @brief    Get the id and revision of the part
00104     *
00105     */
00106     int get_part_info(uint8_t *part_id, uint8_t *part_rev);
00107 
00108     /**
00109     * @brief    Returns whether the sensor should be visible to users in DeviceStudio
00110     */
00111     bool is_visible() { return vis; }
00112 
00113     /**
00114     * @brief    Get whether or not the sensor is enabled
00115     *
00116     * @param[out] true if the sensor is enabled
00117     */
00118     bool is_enabled();
00119 
00120     /**
00121     * @brief    Stop collecting data and disable sensor
00122     */
00123     virtual void stop();
00124 
00125     /**
00126     * @brief    Parses DeviceStudio commands.
00127     * @details  Parses and executes commands. Prints return code to i/o device.
00128     *
00129     * @param[in] cmd - Command to parse
00130     *
00131     * @returns true if sensor acted upon the command, false if command was unknown
00132     */
00133     virtual bool parse_command(const char* cmd);
00134 
00135     /**
00136     * @brief     Fill in buffer with sensor data
00137     *
00138     * @param[in]     buf Buffer to fill data into
00139     * @param[in]     size Maximum size of buffer
00140     * @param[out]   Number of bytes written to buffer
00141     */
00142     virtual int data_report_execute(char* buf, int size);
00143 
00144     int InsertRegValuesIntoBleQeueu(addr_val_pair *reg_values, uint8_t reg_count);
00145 
00146 protected:
00147 
00148     /* PROTECTED VARIABLES */
00149     Mutex comm_mutex;
00150     MaximSensor *sensor;
00151 
00152     int sensor_get_reg(char *ptr_ch, uint8_t *reg_addr, uint8_t *value);
00153     int sensor_set_reg(char *ptr_ch);
00154 
00155     volatile uint8_t data_report_mode;
00156     volatile uint8_t console_interface_exists;
00157 
00158     const char* sensor_type;
00159     bool vis;
00160     int sample_count;
00161 };
00162 
00163 #endif /* _SENSORCOMM_H_ */