vl53l1_api_strings.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * Copyright (c) 2017, STMicroelectronics - All Rights Reserved
  3. *
  4. * This file is part of VL53L1 Core and is dual licensed,
  5. * either 'STMicroelectronics
  6. * Proprietary license'
  7. * or 'BSD 3-clause "New" or "Revised" License' , at your option.
  8. *
  9. ********************************************************************************
  10. *
  11. * 'STMicroelectronics Proprietary license'
  12. *
  13. ********************************************************************************
  14. *
  15. * License terms: STMicroelectronics Proprietary in accordance with licensing
  16. * terms at www.st.com/sla0081
  17. *
  18. * STMicroelectronics confidential
  19. * Reproduction and Communication of this document is strictly prohibited unless
  20. * specifically authorized in writing by STMicroelectronics.
  21. *
  22. *
  23. ********************************************************************************
  24. *
  25. * Alternatively, VL53L1 Core may be distributed under the terms of
  26. * 'BSD 3-clause "New" or "Revised" License', in which case the following
  27. * provisions apply instead of the ones mentioned above :
  28. *
  29. ********************************************************************************
  30. *
  31. * License terms: BSD 3-clause "New" or "Revised" License.
  32. *
  33. * Redistribution and use in source and binary forms, with or without
  34. * modification, are permitted provided that the following conditions are met:
  35. *
  36. * 1. Redistributions of source code must retain the above copyright notice, this
  37. * list of conditions and the following disclaimer.
  38. *
  39. * 2. Redistributions in binary form must reproduce the above copyright notice,
  40. * this list of conditions and the following disclaimer in the documentation
  41. * and/or other materials provided with the distribution.
  42. *
  43. * 3. Neither the name of the copyright holder nor the names of its contributors
  44. * may be used to endorse or promote products derived from this software
  45. * without specific prior written permission.
  46. *
  47. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  48. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  50. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  51. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  52. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  53. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  54. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  55. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  56. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  57. *
  58. *
  59. ********************************************************************************
  60. *
  61. */
  62. /**
  63. * @file vl53l1_api_strings.c
  64. * @brief VL53L1 API functions for decoding error codes to a text string
  65. */
  66. #include "vl53l1_api_core.h"
  67. #include "vl53l1_api_strings.h"
  68. #include "vl53l1_error_codes.h"
  69. #include "vl53l1_error_strings.h"
  70. #define LOG_FUNCTION_START(fmt, ...) \
  71. _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__)
  72. #define LOG_FUNCTION_END(status, ...) \
  73. _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__)
  74. #define LOG_FUNCTION_END_FMT(status, fmt, ...) \
  75. _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, status, fmt, \
  76. ##__VA_ARGS__)
  77. VL53L1_Error VL53L1_get_range_status_string(
  78. uint8_t RangeStatus,
  79. char *pRangeStatusString)
  80. {
  81. VL53L1_Error status = VL53L1_ERROR_NONE;
  82. LOG_FUNCTION_START("");
  83. #ifdef VL53L1_USE_EMPTY_STRING
  84. VL53L1_COPYSTRING(pRangeStatusString, "");
  85. #else
  86. switch (RangeStatus) {
  87. case 0:
  88. VL53L1_COPYSTRING(pRangeStatusString,
  89. VL53L1_STRING_RANGESTATUS_RANGEVALID);
  90. break;
  91. case 1:
  92. VL53L1_COPYSTRING(pRangeStatusString,
  93. VL53L1_STRING_RANGESTATUS_SIGMA);
  94. break;
  95. case 2:
  96. VL53L1_COPYSTRING(pRangeStatusString,
  97. VL53L1_STRING_RANGESTATUS_SIGNAL);
  98. break;
  99. case 3:
  100. VL53L1_COPYSTRING(pRangeStatusString,
  101. VL53L1_STRING_RANGESTATUS_MINRANGE);
  102. break;
  103. case 4:
  104. VL53L1_COPYSTRING(pRangeStatusString,
  105. VL53L1_STRING_RANGESTATUS_PHASE);
  106. break;
  107. case 5:
  108. VL53L1_COPYSTRING(pRangeStatusString,
  109. VL53L1_STRING_RANGESTATUS_HW);
  110. break;
  111. default: /**/
  112. VL53L1_COPYSTRING(pRangeStatusString,
  113. VL53L1_STRING_RANGESTATUS_NONE);
  114. }
  115. #endif
  116. LOG_FUNCTION_END(status);
  117. return status;
  118. }
  119. VL53L1_Error VL53L1_get_pal_state_string(
  120. VL53L1_State PalStateCode,
  121. char *pPalStateString)
  122. {
  123. VL53L1_Error status = VL53L1_ERROR_NONE;
  124. LOG_FUNCTION_START("");
  125. #ifdef VL53L1_USE_EMPTY_STRING
  126. VL53L1_COPYSTRING(pPalStateString, "");
  127. #else
  128. switch (PalStateCode) {
  129. case VL53L1_STATE_POWERDOWN:
  130. VL53L1_COPYSTRING(pPalStateString,
  131. VL53L1_STRING_STATE_POWERDOWN);
  132. break;
  133. case VL53L1_STATE_WAIT_STATICINIT:
  134. VL53L1_COPYSTRING(pPalStateString,
  135. VL53L1_STRING_STATE_WAIT_STATICINIT);
  136. break;
  137. case VL53L1_STATE_STANDBY:
  138. VL53L1_COPYSTRING(pPalStateString,
  139. VL53L1_STRING_STATE_STANDBY);
  140. break;
  141. case VL53L1_STATE_IDLE:
  142. VL53L1_COPYSTRING(pPalStateString,
  143. VL53L1_STRING_STATE_IDLE);
  144. break;
  145. case VL53L1_STATE_RUNNING:
  146. VL53L1_COPYSTRING(pPalStateString,
  147. VL53L1_STRING_STATE_RUNNING);
  148. break;
  149. case VL53L1_STATE_RESET:
  150. VL53L1_COPYSTRING(pPalStateString,
  151. VL53L1_STRING_STATE_RESET);
  152. break;
  153. case VL53L1_STATE_UNKNOWN:
  154. VL53L1_COPYSTRING(pPalStateString,
  155. VL53L1_STRING_STATE_UNKNOWN);
  156. break;
  157. case VL53L1_STATE_ERROR:
  158. VL53L1_COPYSTRING(pPalStateString,
  159. VL53L1_STRING_STATE_ERROR);
  160. break;
  161. default:
  162. VL53L1_COPYSTRING(pPalStateString,
  163. VL53L1_STRING_STATE_UNKNOWN);
  164. }
  165. #endif
  166. LOG_FUNCTION_END(status);
  167. return status;
  168. }
  169. VL53L1_Error VL53L1_get_sequence_steps_info(
  170. VL53L1_SequenceStepId SequenceStepId,
  171. char *pSequenceStepsString)
  172. {
  173. VL53L1_Error Status = VL53L1_ERROR_NONE;
  174. LOG_FUNCTION_START("");
  175. #ifdef VL53L1_USE_EMPTY_STRING
  176. VL53L1_COPYSTRING(pSequenceStepsString, "");
  177. #else
  178. switch (SequenceStepId) {
  179. case VL53L1_SEQUENCESTEP_VHV:
  180. VL53L1_COPYSTRING(pSequenceStepsString,
  181. VL53L1_STRING_SEQUENCESTEP_VHV);
  182. break;
  183. case VL53L1_SEQUENCESTEP_PHASECAL:
  184. VL53L1_COPYSTRING(pSequenceStepsString,
  185. VL53L1_STRING_SEQUENCESTEP_PHASECAL);
  186. break;
  187. case VL53L1_SEQUENCESTEP_REFPHASE:
  188. VL53L1_COPYSTRING(pSequenceStepsString,
  189. VL53L1_STRING_SEQUENCESTEP_DSS1);
  190. break;
  191. case VL53L1_SEQUENCESTEP_DSS1:
  192. VL53L1_COPYSTRING(pSequenceStepsString,
  193. VL53L1_STRING_SEQUENCESTEP_DSS1);
  194. break;
  195. case VL53L1_SEQUENCESTEP_DSS2:
  196. VL53L1_COPYSTRING(pSequenceStepsString,
  197. VL53L1_STRING_SEQUENCESTEP_DSS2);
  198. break;
  199. case VL53L1_SEQUENCESTEP_MM1:
  200. VL53L1_COPYSTRING(pSequenceStepsString,
  201. VL53L1_STRING_SEQUENCESTEP_MM1);
  202. break;
  203. case VL53L1_SEQUENCESTEP_MM2:
  204. VL53L1_COPYSTRING(pSequenceStepsString,
  205. VL53L1_STRING_SEQUENCESTEP_MM2);
  206. break;
  207. case VL53L1_SEQUENCESTEP_RANGE:
  208. VL53L1_COPYSTRING(pSequenceStepsString,
  209. VL53L1_STRING_SEQUENCESTEP_RANGE);
  210. break;
  211. default:
  212. Status = VL53L1_ERROR_INVALID_PARAMS;
  213. }
  214. #endif
  215. LOG_FUNCTION_END(Status);
  216. return Status;
  217. }
  218. VL53L1_Error VL53L1_get_limit_check_info(uint16_t LimitCheckId,
  219. char *pLimitCheckString)
  220. {
  221. VL53L1_Error Status = VL53L1_ERROR_NONE;
  222. LOG_FUNCTION_START("");
  223. #ifdef VL53L1_USE_EMPTY_STRING
  224. VL53L1_COPYSTRING(pLimitCheckString, "");
  225. #else
  226. switch (LimitCheckId) {
  227. case VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE:
  228. VL53L1_COPYSTRING(pLimitCheckString,
  229. VL53L1_STRING_CHECKENABLE_SIGMA_FINAL_RANGE);
  230. break;
  231. case VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
  232. VL53L1_COPYSTRING(pLimitCheckString,
  233. VL53L1_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE);
  234. break;
  235. default:
  236. VL53L1_COPYSTRING(pLimitCheckString,
  237. VL53L1_STRING_UNKNOW_ERROR_CODE);
  238. }
  239. #endif
  240. LOG_FUNCTION_END(Status);
  241. return Status;
  242. }