Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / DiWheelDrive_1-2 / test / VCNL4020 / module_test_VCNL4020.c @ 96621a83

History | View | Annotate | Download (5.8 KB)

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

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
21
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
22
23
#include <module_test_VCNL4020.h>
24
#include <aos_test_VCNL4020.h>
25
#include <string.h>
26
27
/******************************************************************************/
28
/* LOCAL DEFINITIONS                                                          */
29
/******************************************************************************/
30
31
/******************************************************************************/
32
/* EXPORTED VARIABLES                                                         */
33
/******************************************************************************/
34
35
/******************************************************************************/
36
/* LOCAL TYPES                                                                */
37
/******************************************************************************/
38
39
/******************************************************************************/
40
/* LOCAL VARIABLES                                                            */
41
/******************************************************************************/
42
43
static aos_test_vcnl4020data_t _data = {
44
  /* driver       */ &moduleLldProximity,
45
  /* timeout      */ MICROSECONDS_PER_SECOND,
46 cda14729 Thomas Schöpping
  /* event source */ &aos.events.gpio,
47
  /* event flags  */ MODULE_OS_GPIOEVENTFLAG_IRINT,
48 4c72a54c Thomas Schöpping
};
49
50
static AOS_TEST(_test, "VCNL4020", "proximity sensor", moduleTestVcnl4020ShellCb, aosTestVcnl4020Func, &_data);
51
52
/******************************************************************************/
53
/* LOCAL FUNCTIONS                                                            */
54
/******************************************************************************/
55
56
static void _disableInterrupt(VCNL4020Driver* vcnl)
57
{
58
  uint8_t intstatus;
59
  vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, _data.timeout);
60
  vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, _data.timeout);
61
  if (intstatus) {
62
    vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, _data.timeout);
63
  }
64
  return;
65
}
66
67
/******************************************************************************/
68
/* EXPORTED FUNCTIONS                                                         */
69
/******************************************************************************/
70
71
int moduleTestVcnl4020ShellCb(BaseSequentialStream* stream, int argc, char* argv[], aos_testresult_t* result)
72
{
73
  enum {
74
    UNKNOWN,
75
    FL, FR, WL, WR,
76
  } sensor = UNKNOWN;
77
78
  // evaluate arguments
79
  if (argc == 2) {
80
    if (strcmp(argv[1], "--frontleft") == 0 || strcmp(argv[1], "-fl") == 0) {
81
      sensor = FL;
82
    } else if (strcmp(argv[1], "--frontright") == 0 || strcmp(argv[1], "-fr") == 0) {
83
      sensor = FR;
84
    } else if (strcmp(argv[1], "--wheelleft") == 0 || strcmp(argv[1], "-wl") == 0) {
85
      sensor = WL;
86
    } else if (strcmp(argv[1], "--wheelright") == 0 || strcmp(argv[1], "-wr") == 0) {
87
      sensor = WR;
88
    }
89
  }
90
91
  // handle valid sensor
92
  if (sensor != UNKNOWN) {
93
    aos_testresult_t res = {0, 0};
94
95
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, _data.timeout);
96
    _disableInterrupt(_data.vcnld);
97
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, _data.timeout);
98
    _disableInterrupt(_data.vcnld);
99
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, _data.timeout);
100
    _disableInterrupt(_data.vcnld);
101
    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, _data.timeout);
102
    _disableInterrupt(_data.vcnld);
103
    switch (sensor) {
104
      case FL:
105
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, _data.timeout);
106
        res = aosTestRun(stream, &_test, "front left");
107
        break;
108
      case FR:
109
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, _data.timeout);
110
        res = aosTestRun(stream, &_test, "front right");
111
        break;
112
      case WL:
113
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, _data.timeout);
114
        res = aosTestRun(stream, &_test, "left wheel");
115
        break;
116
      case WR:
117
        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, _data.timeout);
118
        res = aosTestRun(stream, &_test, "right wheel");
119
        break;
120
      default:
121
        break;
122
    }
123
    if (result != NULL) {
124
      *result = res;
125
    }
126
    return AOS_OK;
127
  }
128
  // handle invalid arguments
129
  else {
130
    // print help
131
    chprintf(stream, "Usage: %s OPTION\n", argv[0]);
132
    chprintf(stream, "Options:\n");
133
    chprintf(stream, "  --frontleft, -fl\n");
134
    chprintf(stream, "    Test front left proximity sensor.\n");
135
    chprintf(stream, "  --frontrigt, -fr\n");
136
    chprintf(stream, "    Test front right proximity sensor.\n");
137
    chprintf(stream, "  --wheelleft, -wl\n");
138
    chprintf(stream, "    Test left wheel proximity sensor.\n");
139
    chprintf(stream, "  --wheelright, -wr\n");
140
    chprintf(stream, "    Test right wheel proximity sensor.\n");
141
    if (result != NULL) {
142
      result->passed = 0;
143
      result->failed = 0;
144
    }
145
    return AOS_INVALIDARGUMENTS;
146
  }
147
}
148
149
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */