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.
Dependencies: USBDevice max32630fthr
Fork of MAXREFDES220# by
SensorComm.cpp
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 #include <ctype.h> 00035 #include "SensorComm.h" 00036 #include "Peripherals.h" 00037 00038 SensorComm::SensorComm(const char *type, bool visible) 00039 { 00040 sensor = NULL; 00041 sensor_type = type; 00042 vis = visible; 00043 } 00044 00045 SensorComm::~SensorComm() 00046 { 00047 } 00048 00049 void SensorComm::comm_init(MaximSensor *s) 00050 { 00051 sensor = s; 00052 } 00053 00054 const char* SensorComm::get_type() 00055 { 00056 return sensor_type; 00057 } 00058 00059 const char* SensorComm::get_part_name() 00060 { 00061 if (sensor != NULL) 00062 { 00063 return sensor->get_sensor_part_name(); 00064 } 00065 else 00066 { 00067 return "unknown"; 00068 } 00069 } 00070 00071 int SensorComm::get_part_info(uint8_t *part_id, uint8_t *rev_id) 00072 { 00073 if (sensor != NULL) { 00074 return sensor->get_part_info(part_id, rev_id); 00075 } else { 00076 *part_id = 0xFF; 00077 *rev_id = 0xFF; 00078 return -1; 00079 } 00080 } 00081 00082 bool SensorComm::is_enabled() 00083 { 00084 return (data_report_mode != 0); 00085 } 00086 00087 int SensorComm::sensor_get_reg(char *ptr_ch, uint8_t *reg_addr, uint8_t *value) 00088 { 00089 int ret = EXIT_FAILURE; 00090 uint8_t num_found; 00091 int which_reg; 00092 *value = 0; 00093 00094 while (*ptr_ch) { 00095 if (isxdigit((int)*ptr_ch)) { 00096 num_found = (uint8_t)sscanf(ptr_ch, "%x", &which_reg); 00097 if (num_found == 1) { 00098 *reg_addr = which_reg; 00099 ret = sensor->readRegister(*reg_addr, value, 1); 00100 } 00101 break; 00102 } else { 00103 ptr_ch++; 00104 } 00105 } 00106 return ret; 00107 } 00108 00109 int SensorComm::sensor_set_reg(char *ptr_ch) 00110 { 00111 int ret = EXIT_FAILURE; 00112 uint8_t num_found; 00113 unsigned int reg_addr, value; 00114 char *ptr_char; 00115 00116 ptr_char = ptr_ch; 00117 while (*ptr_char) { 00118 if (isxdigit((int)*ptr_char)) { 00119 num_found = (uint8_t)sscanf(ptr_char, "%x %x", ®_addr, &value); 00120 if (num_found == 2) { 00121 ret = sensor->writeRegister(reg_addr, (uint8_t)value); 00122 } 00123 break; 00124 } else { 00125 ptr_char++; 00126 } 00127 } 00128 return ret; 00129 } 00130 00131 void SensorComm::stop() { } 00132 00133 bool SensorComm::parse_command(const char* cmd) { return false; } 00134 00135 int SensorComm::data_report_execute(char* buf, int size) { return 0; } 00136
Generated on Mon Jul 18 2022 23:37:28 by
