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: X_NUCLEO_COMMON ST_INTERFACES
Dependents: VL53L1CB_noshield_1sensor_polls_auton VL53L1CB_noshield_1sensor_interrupt_auton X_NUCLEO_53L1A2
vl53l1_platform_log.c
00001 00002 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause 00003 /****************************************************************************** 00004 * Copyright (c) 2020, STMicroelectronics - All Rights Reserved 00005 00006 This file is part of VL53L1 and is dual licensed, 00007 either GPL-2.0+ 00008 or 'BSD 3-clause "New" or "Revised" License' , at your option. 00009 ****************************************************************************** 00010 */ 00011 00012 00013 00014 00015 #include <stdio.h> 00016 #include <string.h> 00017 #include <stdarg.h> 00018 00019 #include "vl53l1_platform_log.h" 00020 #include "vl53l1_platform_user_config.h" 00021 00022 #ifdef VL53L1_LOG_ENABLE 00023 00024 char * _trace_filename = NULL; 00025 FILE *_tracefile = NULL; 00026 00027 uint32_t _trace_level = VL53L1_TRACE_LEVEL_WARNING; 00028 uint32_t _trace_modules = VL53L1_TRACE_MODULE_NONE; 00029 uint32_t _trace_functions = VL53L1_TRACE_FUNCTION_ALL; 00030 00031 int8_t VL53L1_trace_config( 00032 char *filename, 00033 uint32_t modules, 00034 uint32_t level, 00035 uint32_t functions) 00036 { 00037 int8_t status = 0; 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 if (((filename != NULL) && (_tracefile == NULL)) && strcmp(filename,"")) 00054 { 00055 _tracefile = fopen(filename, "w+"); 00056 00057 00058 00059 if ( _tracefile != NULL ) 00060 { 00061 _trace_filename = (char*)malloc((strlen(filename) + 1) * sizeof(char)); 00062 strcpy(_trace_filename, filename); 00063 } 00064 else 00065 { 00066 printf("VL53L1_trace_config(): failed to open log file (%s)\n", filename); 00067 status = 1; 00068 } 00069 } 00070 00071 _trace_modules = modules; 00072 _trace_level = level; 00073 _trace_functions = functions; 00074 00075 return status; 00076 } 00077 00078 void VL53L1_trace_print_module_function(uint32_t module, uint32_t level, uint32_t function, const char *format, ...) 00079 { 00080 if ( ((level <=_trace_level) && ((module & _trace_modules) > 0)) 00081 || ((function & _trace_functions) > 0) ) 00082 { 00083 va_list arg_list; 00084 char message[VL53L1_MAX_STRING_LENGTH]; 00085 00086 va_start(arg_list, format); 00087 vsnprintf(message, VL53L1_MAX_STRING_LENGTH-1, format, arg_list); 00088 va_end(arg_list); 00089 00090 if (_tracefile != NULL) 00091 { 00092 fprintf(_tracefile, message); 00093 } 00094 else 00095 { 00096 printf(message); 00097 } 00098 00099 00100 00101 00102 00103 } 00104 } 00105 00106 00107 uint32_t VL53L1_get_trace_functions(void) 00108 { 00109 return _trace_functions; 00110 } 00111 00112 00113 void VL53L1_set_trace_functions(uint32_t function) 00114 { 00115 _trace_functions = function; 00116 } 00117 00118 00119 uint32_t VL53L1_clock(void) 00120 { 00121 00122 uint32_t tick_count_ms = (uint32_t)clock(); 00123 return tick_count_ms; 00124 } 00125 #endif 00126
Generated on Thu Jul 14 2022 10:14:48 by
1.7.2