File tree Expand file tree Collapse file tree 3 files changed +13
-11
lines changed Expand file tree Collapse file tree 3 files changed +13
-11
lines changed Original file line number Diff line number Diff line change 25
25
#include " platform/SingletonPtr.h"
26
26
#include " platform/PlatformMutex.h"
27
27
28
+ #include < cmath>
29
+
28
30
namespace mbed {
29
31
/* * \defgroup mbed-os-public Public API */
30
32
@@ -71,14 +73,14 @@ class AnalogIn {
71
73
*
72
74
* @param pinmap reference to structure which holds static pinmap.
73
75
*/
74
- AnalogIn (const PinMap &pinmap);
75
- AnalogIn (const PinMap &&) = delete ; // prevent passing of temporary objects
76
+ AnalogIn (const PinMap &pinmap, float vref = MBED_CONF_TARGET_DEFAULT_ADC_VREF );
77
+ AnalogIn (const PinMap &&, float vref = MBED_CONF_TARGET_DEFAULT_ADC_VREF ) = delete ; // prevent passing of temporary objects
76
78
77
79
/* * Create an AnalogIn, connected to the specified pin
78
80
*
79
81
* @param pin AnalogIn pin to connect to
80
82
*/
81
- AnalogIn (PinName pin);
83
+ AnalogIn (PinName pin, float vref = MBED_CONF_TARGET_DEFAULT_ADC_VREF );
82
84
83
85
/* * Read the input voltage, represented as a float in the range [0.0, 1.0]
84
86
*
@@ -161,7 +163,7 @@ class AnalogIn {
161
163
analogin_t _adc;
162
164
static SingletonPtr<PlatformMutex> _mutex;
163
165
164
- float vref ;
166
+ float _vref ;
165
167
166
168
#endif // !defined(DOXYGEN_ONLY)
167
169
Original file line number Diff line number Diff line change @@ -23,21 +23,21 @@ namespace mbed {
23
23
24
24
SingletonPtr<PlatformMutex> AnalogIn::_mutex;
25
25
26
- AnalogIn::AnalogIn (PinName pin) : vref(MBED_CONF_TARGET_DEFAULT_ADC_VREF)
26
+
27
+ AnalogIn::AnalogIn (PinName pin, float vref) : _vref(vref)
27
28
{
28
29
lock ();
29
30
analogin_init (&_adc, pin);
30
31
unlock ();
31
32
}
32
33
33
- AnalogIn::AnalogIn (const PinMap &pinmap) : vref(MBED_CONF_TARGET_DEFAULT_ADC_VREF )
34
+ AnalogIn::AnalogIn (const PinMap &pinmap, float vref ) : _vref(vref )
34
35
{
35
36
lock ();
36
37
analogin_init_direct (&_adc, &pinmap);
37
38
unlock ();
38
39
}
39
40
40
-
41
41
float AnalogIn::read ()
42
42
{
43
43
lock ();
@@ -56,17 +56,17 @@ unsigned short AnalogIn::read_u16()
56
56
57
57
float AnalogIn::read_voltage ()
58
58
{
59
- return (this ->read () * this ->vref );
59
+ return (this ->read () * this ->_vref );
60
60
}
61
61
62
62
void AnalogIn::set_reference_voltage (float vref)
63
63
{
64
- this ->vref = vref;
64
+ this ->_vref = vref;
65
65
}
66
66
67
67
float AnalogIn::get_reference_voltage (void )
68
68
{
69
- return this ->vref ;
69
+ return this ->_vref ;
70
70
}
71
71
72
72
} // namespace mbed
Original file line number Diff line number Diff line change 83
83
},
84
84
"default-adc-vref" : {
85
85
"help" : " Default reference voltage for ADC (float)" ,
86
- "value" : " 3.3f "
86
+ "value" : " NAN "
87
87
}
88
88
}
89
89
},
You can’t perform that action at this time.
0 commit comments