summaryrefslogtreecommitdiff
path: root/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/sensors.c
blob: 7e0eae1c53f36ebe5d188169ea737fde42552915 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**************************************************************************//**
\file  sensors.h

\brief Implementation of sensors interface.

\author
    Atmel Corporation: http://www.atmel.com \n
    Support email: avr@atmel.com

  Copyright (c) 2008-2011, Atmel Corporation. All rights reserved.
  Licensed under Atmel's Limited License Agreement (BitCloudTM).

\internal
  History:
    12/05/08 A. Khromykh - Created
*******************************************************************************/
#if APP_DISABLE_BSP != 1

/******************************************************************************
                   Includes section
******************************************************************************/
#include <sensors.h>
#include <pwrCtrl.h>
#include <lm73.h>
#include <tsl2550.h>
#include <battery.h>

/******************************************************************************
                   Implementations section
******************************************************************************/
/***************************************************************************//**
\brief Opens temperature sensor.

\return
  BC_FAIL - sensor has been already open. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_OpenTemperatureSensor(void)
{
  result_t result;

  if (BC_SUCCESS == (result = openLm73()))
  {
#if BSP_MNZB_EVB_SUPPORT == 1
    bspOnPeriphery(SENSOR_TEMPERATURE);
#endif /* BSP_MNZB_EVB_SUPPORT */
  }
  return result;
}

/***************************************************************************//**
\brief Closes the temperature sensor.

\return
  BC_FAIL - if a hardware error has occured or
            there is uncompleted ReadData request. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_CloseTemperatureSensor(void)
{
  result_t result;

  if (BC_SUCCESS == (result = closeLm73()))
  {
#if BSP_MNZB_EVB_SUPPORT == 1
    bspOffPeriphery(SENSOR_TEMPERATURE);
#endif /* BSP_MNZB_EVB_SUPPORT */
  }
  return result;
}

/**************************************************************************//**
\brief Reads data from the temperature sensor.
\param[in]
    result - the result of the requested operation.
             true - operation finished successfully, false - some error has
             occured.
\param[in]
    data - sensor data.
\return
    BC_FAIL - previous request was not completed. \n
    BC_SUCCESS - otherwise.
******************************************************************************/
result_t BSP_ReadTemperatureData(void (*f)(bool result, int16_t data))
{
  return readLm73Data(f);
}

/***************************************************************************//**
\brief Opens the light sensor.
\return
  BC_FAIL - sensor has been already open. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_OpenLightSensor(void)
{
  result_t result;

  if (BC_SUCCESS == (result = openTsl2550()))
  {
#if BSP_MNZB_EVB_SUPPORT == 1
    bspOnPeriphery(SENSOR_LIGHT);
#endif /* BSP_MNZB_EVB_SUPPORT */
  }
  return result;
}

/***************************************************************************//**
\brief Closes the light sensor.
\return
  BC_FAIL - if a hardware error has occured or
         there is uncompleted ReadData request. \n
  BC_SUCCESS  - otherwise.
*******************************************************************************/
result_t BSP_CloseLightSensor(void)
{
  result_t result;

  if (BC_SUCCESS == (result = closeTsl2550()))
  {
#if BSP_MNZB_EVB_SUPPORT == 1
    bspOffPeriphery(SENSOR_LIGHT);
#endif /* BSP_MNZB_EVB_SUPPORT */
  }
  return result;
}

/**************************************************************************//**
\brief Reads data from the light sensor.
\param[in]
    result - the result of the requested operation.
             true - operation finished successfully, false - some error has
             occured.
\param[in]
    data - sensor data.
\return
    BC_FAIL - previous request was not completed. \n
    BC_SUCCESS - otherwise.
******************************************************************************/
result_t BSP_ReadLightData(void (*f)(bool result, int16_t data))
{
  return readTsl2550Data(f);
}

#if BSP_MNZB_EVB_SUPPORT == 1
/***************************************************************************//**
\brief Opens the battery sensor.
\return
  BC_FAIL - sensor has been already open. \n
  BC_SUCCESS - otherwise.
*******************************************************************************/
result_t BSP_OpenBatterySensor(void)
{
  result_t result;

  if (BC_SUCCESS == (result = openBattery()))
  {
    bspOnPeriphery(SENSOR_BATTERY);
  }
  return result;
}

/***************************************************************************//**
\brief Closes the battery sensor.
\return
  BC_FAIL - sensor was not opened. \n
  BC_SUCCESS  - otherwise.
*******************************************************************************/
result_t BSP_CloseBatterySensor(void)
{
  result_t result;

  if (BC_SUCCESS == (result = closeBattery()))
  {
    bspOffPeriphery(SENSOR_BATTERY);
  }
  return result;
}

/**************************************************************************//**
\brief Reads data from battery sensor.
\param[in]
    data - sensor data.
\return
    BC_FAIL - previous request was not completed, or sensor was not opened. \n
    BC_SUCCESS - otherwise.
******************************************************************************/
result_t BSP_ReadBatteryData(BspBatteryCb_t cb)
{
  return readBatteryData(cb);
}
#endif /* BSP_MNZB_EVB_SUPPORT */

#endif // APP_DISABLE_BSP != 1

//end of sensors.c