Statistics
| Branch: | Tag: | Revision:

amiro-os / test / periphery-lld / VL53L1X_v1 / aos_test_VL53L1X.c @ ded1ded7

History | View | Annotate | Download (4.397 KB)

1 849b383a galberding
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2020  Thomas Schöpping et al.
4

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU General Public License for more details.
14

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#include <amiroos.h>
20
#include <aos_test_VL53L1X.h>
21
22
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
23
24
/******************************************************************************/
25
/* LOCAL DEFINITIONS                                                          */
26
/******************************************************************************/
27
28
/******************************************************************************/
29
/* EXPORTED VARIABLES                                                         */
30
/******************************************************************************/
31
32
/******************************************************************************/
33
/* LOCAL TYPES                                                                */
34
/******************************************************************************/
35
36
/******************************************************************************/
37
/* LOCAL VARIABLES                                                            */
38
/******************************************************************************/
39
40
/******************************************************************************/
41
/* LOCAL FUNCTIONS                                                            */
42
/******************************************************************************/
43
44
/******************************************************************************/
45
/* EXPORTED FUNCTIONS                                                         */
46
/*****************************************************************************
47
*/
48
49
/**
50
 * @brief   LED test function.
51
 *
52
 * @param[in] stream  Stream for input/output.
53
 * @param[in] test    Test object.
54
 *
55
 * @return            Test result value.
56
 */
57
aos_testresult_t aosTestVL53L1XFunc(BaseSequentialStream* stream, const aos_test_t* test)
58
{
59 ded1ded7 Thomas Schöpping
  aosDbgCheck(test->data != NULL && ((aos_test_vl53l1xdata_t*)test->data)->vl53l1x != NULL);
60 849b383a galberding
61
  // local variables
62 ded1ded7 Thomas Schöpping
  aos_testresult_t result;
63 849b383a galberding
  int32_t status;
64 ded1ded7 Thomas Schöpping
  VL53L1_Error error;
65
66
  aosTestResultInit(&result);
67
68
  {
69
    chprintf(stream, "Checking XSHUT signal...\n");
70
    vl53l1x_lld_state_t device_state = VL53L1X_LLD_STATE_ON;
71
    status = vl53l1x_lld_getState(((aos_test_vl53l1xdata_t*)test->data)->vl53l1x, &device_state);
72
    if (status == APAL_STATUS_OK) {
73
      chprintf(stream, "\tXSHUT signal is %s.\n", (device_state == VL53L1X_LLD_STATE_ON) ? "on" : "off");
74
      aosTestPassed(stream, &result);
75
    } else {
76
      aosTestFailed(stream, &result);
77
    }
78
79
    if (device_state != VL53L1X_LLD_STATE_ON) {
80
      chprintf(stream, "Initilaizing device...\n");
81
      status = vl53l1x_lld_init(((aos_test_vl53l1xdata_t*)test->data)->vl53l1x);
82
      if (status == APAL_STATUS_OK) {
83
        aosTestPassed(stream, &result);
84
      } else {
85
        aosTestFailedMsg(stream, &result, "%d\t%u\n", status, i2cGetErrors(((aos_test_vl53l1xdata_t*)test->data)->vl53l1x->Interface.i2cd));
86
      }
87
    }
88 849b383a galberding
  }
89
90 ded1ded7 Thomas Schöpping
  {
91
    chprintf(stream, "Read device info...\n");
92
    VL53L1_DeviceInfo_t device_info;
93
    error = VL53L1_GetDeviceInfo(((aos_test_vl53l1xdata_t*)test->data)->vl53l1x, &device_info);
94
    if (error == VL53L1_ERROR_NONE) {
95
      chprintf(stream, "\tname:         %s\n", device_info.Name);
96
      chprintf(stream, "\ttype:         %s\n", device_info.Type);
97
      chprintf(stream, "\tproduct id:   %s\n", device_info.ProductId);
98
      chprintf(stream, "\tproduct tpye: %u\n", device_info.ProductType);
99
      chprintf(stream, "\trevision:     %u.%u\n", device_info.ProductRevisionMajor, device_info.ProductRevisionMinor);
100
      aosTestPassed(stream, &result);
101
    } else {
102
      aosTestFailedMsg(stream, &result, "%d", error);
103
    }
104 849b383a galberding
  }
105
106
  return result;
107
}
108
109
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */