The VL53L1CB proximity sensor, based on ST’s FlightSense™, Time-of-Flight technology.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: VL53L1CB_noshield_1sensor_polls_auton VL53L1CB_noshield_1sensor_interrupt_auton X_NUCLEO_53L1A2
Based on VL53L1 library, this is a library for the VL53L1CB ToF chip.
src/vl53l1_platform_log.c@18:0696efe39d08, 2021-07-21 (annotated)
- Committer:
- lugandc
- Date:
- Wed Jul 21 17:06:38 2021 +0200
- Revision:
- 18:0696efe39d08
- Parent:
- 0:3ac96e360672
Cleanup i2c functions, removed all bad references to L1X
Cleanup VL53L1CB class:
- i2c device object is passed in a consistent way in MyDevice structure
- removed useless functions
Updated VL53L1CB component driver with bare driver release 6.6.7 content
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
charlesmn | 0:3ac96e360672 | 1 | |
lugandc | 18:0696efe39d08 | 2 | // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause |
lugandc | 18:0696efe39d08 | 3 | /****************************************************************************** |
lugandc | 18:0696efe39d08 | 4 | * Copyright (c) 2020, STMicroelectronics - All Rights Reserved |
charlesmn | 0:3ac96e360672 | 5 | |
lugandc | 18:0696efe39d08 | 6 | This file is part of VL53L1 and is dual licensed, |
lugandc | 18:0696efe39d08 | 7 | either GPL-2.0+ |
lugandc | 18:0696efe39d08 | 8 | or 'BSD 3-clause "New" or "Revised" License' , at your option. |
lugandc | 18:0696efe39d08 | 9 | ****************************************************************************** |
lugandc | 18:0696efe39d08 | 10 | */ |
charlesmn | 0:3ac96e360672 | 11 | |
charlesmn | 0:3ac96e360672 | 12 | |
charlesmn | 0:3ac96e360672 | 13 | |
charlesmn | 0:3ac96e360672 | 14 | |
charlesmn | 0:3ac96e360672 | 15 | #include <stdio.h> |
charlesmn | 0:3ac96e360672 | 16 | #include <string.h> |
charlesmn | 0:3ac96e360672 | 17 | #include <stdarg.h> |
charlesmn | 0:3ac96e360672 | 18 | |
charlesmn | 0:3ac96e360672 | 19 | #include "vl53l1_platform_log.h" |
charlesmn | 0:3ac96e360672 | 20 | #include "vl53l1_platform_user_config.h" |
charlesmn | 0:3ac96e360672 | 21 | |
charlesmn | 0:3ac96e360672 | 22 | #ifdef VL53L1_LOG_ENABLE |
charlesmn | 0:3ac96e360672 | 23 | |
charlesmn | 0:3ac96e360672 | 24 | char * _trace_filename = NULL; |
charlesmn | 0:3ac96e360672 | 25 | FILE *_tracefile = NULL; |
charlesmn | 0:3ac96e360672 | 26 | |
charlesmn | 0:3ac96e360672 | 27 | uint32_t _trace_level = VL53L1_TRACE_LEVEL_WARNING; |
charlesmn | 0:3ac96e360672 | 28 | uint32_t _trace_modules = VL53L1_TRACE_MODULE_NONE; |
charlesmn | 0:3ac96e360672 | 29 | uint32_t _trace_functions = VL53L1_TRACE_FUNCTION_ALL; |
charlesmn | 0:3ac96e360672 | 30 | |
charlesmn | 0:3ac96e360672 | 31 | int8_t VL53L1_trace_config( |
charlesmn | 0:3ac96e360672 | 32 | char *filename, |
charlesmn | 0:3ac96e360672 | 33 | uint32_t modules, |
charlesmn | 0:3ac96e360672 | 34 | uint32_t level, |
charlesmn | 0:3ac96e360672 | 35 | uint32_t functions) |
charlesmn | 0:3ac96e360672 | 36 | { |
charlesmn | 0:3ac96e360672 | 37 | int8_t status = 0; |
charlesmn | 0:3ac96e360672 | 38 | |
charlesmn | 0:3ac96e360672 | 39 | |
charlesmn | 0:3ac96e360672 | 40 | |
charlesmn | 0:3ac96e360672 | 41 | |
charlesmn | 0:3ac96e360672 | 42 | |
charlesmn | 0:3ac96e360672 | 43 | |
charlesmn | 0:3ac96e360672 | 44 | |
charlesmn | 0:3ac96e360672 | 45 | |
charlesmn | 0:3ac96e360672 | 46 | |
charlesmn | 0:3ac96e360672 | 47 | |
charlesmn | 0:3ac96e360672 | 48 | |
charlesmn | 0:3ac96e360672 | 49 | |
charlesmn | 0:3ac96e360672 | 50 | |
charlesmn | 0:3ac96e360672 | 51 | |
charlesmn | 0:3ac96e360672 | 52 | |
charlesmn | 0:3ac96e360672 | 53 | if (((filename != NULL) && (_tracefile == NULL)) && strcmp(filename,"")) |
charlesmn | 0:3ac96e360672 | 54 | { |
charlesmn | 0:3ac96e360672 | 55 | _tracefile = fopen(filename, "w+"); |
charlesmn | 0:3ac96e360672 | 56 | |
charlesmn | 0:3ac96e360672 | 57 | |
charlesmn | 0:3ac96e360672 | 58 | |
charlesmn | 0:3ac96e360672 | 59 | if ( _tracefile != NULL ) |
charlesmn | 0:3ac96e360672 | 60 | { |
charlesmn | 0:3ac96e360672 | 61 | _trace_filename = (char*)malloc((strlen(filename) + 1) * sizeof(char)); |
charlesmn | 0:3ac96e360672 | 62 | strcpy(_trace_filename, filename); |
charlesmn | 0:3ac96e360672 | 63 | } |
charlesmn | 0:3ac96e360672 | 64 | else |
charlesmn | 0:3ac96e360672 | 65 | { |
charlesmn | 0:3ac96e360672 | 66 | printf("VL53L1_trace_config(): failed to open log file (%s)\n", filename); |
charlesmn | 0:3ac96e360672 | 67 | status = 1; |
charlesmn | 0:3ac96e360672 | 68 | } |
charlesmn | 0:3ac96e360672 | 69 | } |
charlesmn | 0:3ac96e360672 | 70 | |
charlesmn | 0:3ac96e360672 | 71 | _trace_modules = modules; |
charlesmn | 0:3ac96e360672 | 72 | _trace_level = level; |
charlesmn | 0:3ac96e360672 | 73 | _trace_functions = functions; |
charlesmn | 0:3ac96e360672 | 74 | |
charlesmn | 0:3ac96e360672 | 75 | return status; |
charlesmn | 0:3ac96e360672 | 76 | } |
charlesmn | 0:3ac96e360672 | 77 | |
charlesmn | 0:3ac96e360672 | 78 | void VL53L1_trace_print_module_function(uint32_t module, uint32_t level, uint32_t function, const char *format, ...) |
charlesmn | 0:3ac96e360672 | 79 | { |
charlesmn | 0:3ac96e360672 | 80 | if ( ((level <=_trace_level) && ((module & _trace_modules) > 0)) |
charlesmn | 0:3ac96e360672 | 81 | || ((function & _trace_functions) > 0) ) |
charlesmn | 0:3ac96e360672 | 82 | { |
charlesmn | 0:3ac96e360672 | 83 | va_list arg_list; |
charlesmn | 0:3ac96e360672 | 84 | char message[VL53L1_MAX_STRING_LENGTH]; |
charlesmn | 0:3ac96e360672 | 85 | |
charlesmn | 0:3ac96e360672 | 86 | va_start(arg_list, format); |
charlesmn | 0:3ac96e360672 | 87 | vsnprintf(message, VL53L1_MAX_STRING_LENGTH-1, format, arg_list); |
charlesmn | 0:3ac96e360672 | 88 | va_end(arg_list); |
charlesmn | 0:3ac96e360672 | 89 | |
charlesmn | 0:3ac96e360672 | 90 | if (_tracefile != NULL) |
charlesmn | 0:3ac96e360672 | 91 | { |
charlesmn | 0:3ac96e360672 | 92 | fprintf(_tracefile, message); |
charlesmn | 0:3ac96e360672 | 93 | } |
charlesmn | 0:3ac96e360672 | 94 | else |
charlesmn | 0:3ac96e360672 | 95 | { |
charlesmn | 0:3ac96e360672 | 96 | printf(message); |
charlesmn | 0:3ac96e360672 | 97 | } |
charlesmn | 0:3ac96e360672 | 98 | |
charlesmn | 0:3ac96e360672 | 99 | |
charlesmn | 0:3ac96e360672 | 100 | |
charlesmn | 0:3ac96e360672 | 101 | |
charlesmn | 0:3ac96e360672 | 102 | |
charlesmn | 0:3ac96e360672 | 103 | } |
charlesmn | 0:3ac96e360672 | 104 | } |
charlesmn | 0:3ac96e360672 | 105 | |
charlesmn | 0:3ac96e360672 | 106 | |
charlesmn | 0:3ac96e360672 | 107 | uint32_t VL53L1_get_trace_functions(void) |
charlesmn | 0:3ac96e360672 | 108 | { |
charlesmn | 0:3ac96e360672 | 109 | return _trace_functions; |
charlesmn | 0:3ac96e360672 | 110 | } |
charlesmn | 0:3ac96e360672 | 111 | |
charlesmn | 0:3ac96e360672 | 112 | |
charlesmn | 0:3ac96e360672 | 113 | void VL53L1_set_trace_functions(uint32_t function) |
charlesmn | 0:3ac96e360672 | 114 | { |
charlesmn | 0:3ac96e360672 | 115 | _trace_functions = function; |
charlesmn | 0:3ac96e360672 | 116 | } |
charlesmn | 0:3ac96e360672 | 117 | |
charlesmn | 0:3ac96e360672 | 118 | |
charlesmn | 0:3ac96e360672 | 119 | uint32_t VL53L1_clock(void) |
charlesmn | 0:3ac96e360672 | 120 | { |
charlesmn | 0:3ac96e360672 | 121 | |
charlesmn | 0:3ac96e360672 | 122 | uint32_t tick_count_ms = (uint32_t)clock(); |
charlesmn | 0:3ac96e360672 | 123 | return tick_count_ms; |
charlesmn | 0:3ac96e360672 | 124 | } |
charlesmn | 0:3ac96e360672 | 125 | #endif |
charlesmn | 0:3ac96e360672 | 126 |