ST Expansion SW Team / VL53L1

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   X_NUCLEO_53L1CB

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers vl53l1_platform_log.c Source File

vl53l1_platform_log.c

00001 
00002 /*******************************************************************************
00003  This file is part of VL53L1 Platform
00004 
00005  Copyright (c) 2020, STMicroelectronics - All Rights Reserved
00006 
00007  License terms: BSD 3-clause "New" or "Revised" License.
00008 
00009  Redistribution and use in source and binary forms, with or without
00010  modification, are permitted provided that the following conditions are met:
00011 
00012  1. Redistributions of source code must retain the above copyright notice, this
00013  list of conditions and the following disclaimer.
00014 
00015  2. Redistributions in binary form must reproduce the above copyright notice,
00016  this list of conditions and the following disclaimer in the documentation
00017  and/or other materials provided with the distribution.
00018 
00019  3. Neither the name of the copyright holder nor the names of its contributors
00020  may be used to endorse or promote products derived from this software
00021  without specific prior written permission.
00022 
00023  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00026  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00027  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00028  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00029  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00031  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00032  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 
00037 
00038 
00039 #include <stdio.h>
00040 #include <string.h>
00041 #include <stdarg.h>
00042 //#include <malloc.h>
00043 
00044 #include "vl53l1_platform_log.h"
00045 #include "vl53l1_platform_user_config.h"
00046 
00047 #ifdef VL53L1_LOG_ENABLE
00048 
00049     char * _trace_filename = NULL;
00050     FILE *_tracefile = NULL;
00051 
00052     uint32_t _trace_level     = VL53L1_TRACE_LEVEL_WARNING;
00053     uint32_t _trace_modules   = VL53L1_TRACE_MODULE_NONE;
00054     uint32_t _trace_functions = VL53L1_TRACE_FUNCTION_ALL;
00055 
00056     int8_t VL53L1_trace_config(
00057         char *filename,
00058         uint32_t modules,
00059         uint32_t level,
00060         uint32_t functions)
00061     {
00062         int8_t status = 0;
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078         if (((filename != NULL) && (_tracefile == NULL)) && strcmp(filename,""))
00079         {
00080             _tracefile = fopen(filename, "w+");
00081 
00082 
00083 
00084             if ( _tracefile != NULL )
00085             {
00086                 _trace_filename = (char*)malloc((strlen(filename) + 1) * sizeof(char));
00087                 strcpy(_trace_filename, filename);
00088             }
00089             else
00090             {
00091                 printf("VL53L1_trace_config(): failed to open log file (%s)\n", filename);
00092                 status = 1;
00093             }
00094         }
00095 
00096         _trace_modules   = modules;
00097         _trace_level     = level;
00098         _trace_functions = functions;
00099 
00100         return status;
00101     }
00102 
00103     void VL53L1_trace_print_module_function(uint32_t module, uint32_t level, uint32_t function, const char *format, ...)
00104     {
00105         if ( ((level <=_trace_level) && ((module & _trace_modules) > 0))
00106             || ((function & _trace_functions) > 0) )
00107         {
00108             va_list arg_list;
00109             char message[VL53L1_MAX_STRING_LENGTH];
00110 
00111             va_start(arg_list, format);
00112             vsnprintf(message, VL53L1_MAX_STRING_LENGTH-1, format, arg_list);
00113             va_end(arg_list);
00114 
00115             if (_tracefile != NULL)
00116             {
00117                 fprintf(_tracefile, message);
00118             }
00119             else
00120             {
00121                 printf(message);
00122             }
00123 
00124 
00125 
00126 
00127 
00128         }
00129     }
00130 
00131 
00132     uint32_t VL53L1_get_trace_functions(void)
00133     {
00134         return _trace_functions;
00135     }
00136 
00137 
00138     void VL53L1_set_trace_functions(uint32_t function)
00139     {
00140         _trace_functions = function;
00141     }
00142 
00143 
00144     uint32_t VL53L1_clock(void)
00145     {
00146 
00147         uint32_t tick_count_ms = (uint32_t)clock();
00148         return tick_count_ms;
00149     }
00150 #endif
00151 
00152