Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit e3edfa7

Browse files
AnalogIn: change sensor type management
1 parent 7902817 commit e3edfa7

File tree

7 files changed

+21
-17
lines changed

7 files changed

+21
-17
lines changed

Diff for: docs/api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Class for the Analog IN connector of the Portenta Machine Control.
2424
--------------------------------|---------------------------------------------
2525
`public ` [`AnalogInClass`](#public-analoginclasspinname-ai0_pin--mc_ai_ai0_pin-pinname-ai1_pin--mc_ai_ai1_pin-pinname-ai2_pin--mc_ai_ai2_pin)`(PinName ai0_pin, PinName ai1_pin, PinName ai2_pin)` | Construct an Analog Input reader for the Portenta Machine Control.
2626
`public ` [`~AnalogInClass`](#public-analoginclass)`()` | Destruct the AnalogInClass object.
27-
`public bool` [`begin`](#public-bool-beginint-sensor_type-int-res_bits--16)`(int sensor_type, int res_bits)` | Initialize the analog reader, configure the sensor type and read resolution.
27+
`public bool` [`begin`](#public-bool-beginint-sensor_type-int-res_bits--16)`(SensorType sensor_type, int res_bits)` | Initialize the analog reader, configure the sensor type and read resolution.
2828
`public uint16_t` [`read`](#public-uint16_t-readint-channel)`(int channel)` | Read the sampled voltage from the selected channel.
2929

3030
# class `AnalogOutClass`

Diff for: examples/Analog_input/Analog_input_0_10V/Analog_input_0_10V.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void setup() {
2525
; // wait for serial port to connect.
2626
}
2727

28-
MachineControl_AnalogIn.begin(MCAI_SENSOR_0_10V);
28+
MachineControl_AnalogIn.begin(SensorType::V_0_10);
2929
}
3030

3131
void loop() {

Diff for: examples/Analog_input/Analog_input_4_20mA/Analog_input_4_20mA.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void setup() {
2626
; // wait for serial port to connect.
2727
}
2828

29-
MachineControl_AnalogIn.begin(MCAI_SENSOR_4_20MA);
29+
MachineControl_AnalogIn.begin(SensorType::MA_4_20);
3030
}
3131

3232
void loop() {

Diff for: examples/Analog_input/Analog_input_NTC/Analog_input_NTC.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void setup() {
2929
; // wait for serial port to connect.
3030
}
3131

32-
MachineControl_AnalogIn.begin(MCAI_SENSOR_NTC);
32+
MachineControl_AnalogIn.begin(SensorType::NTC);
3333
}
3434

3535
void loop() {

Diff for: library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ category=Communication
88
url=https://github.com/arduino-libraries/Arduino_MachineControl
99
architectures=mbed, mbed_portenta
1010
includes=Arduino_MachineControl.h
11-
depends=ArduinoRS485
11+
depends=ArduinoRS485, Arduino_CAN

Diff for: src/AnalogInClass.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ AnalogInClass::AnalogInClass(PinName ai0_pin, PinName ai1_pin, PinName ai2_pin)
4949
AnalogInClass::~AnalogInClass()
5050
{ }
5151

52-
bool AnalogInClass::begin(int sensor_type, int res_bits) {
52+
bool AnalogInClass::begin(SensorType sensor_type, int res_bits) {
5353
bool ret = true;
5454

5555
/* Set bit resolution of ADC */
5656
analogReadResolution(res_bits);
5757

5858
switch (sensor_type) {
59-
case MCAI_SENSOR_NTC:
59+
case SensorType::NTC:
6060
/* Enable a 100K resistor in series with the reference voltage.
6161
* The voltage sampled is the voltage division between the 100k resistor and the input resistor (NTC/PTC) */
6262
digitalWrite(CH0_IN1, LOW);
@@ -74,7 +74,7 @@ bool AnalogInClass::begin(int sensor_type, int res_bits) {
7474
digitalWrite(CH2_IN3, HIGH);
7575
digitalWrite(CH2_IN4, HIGH);
7676
break;
77-
case MCAI_SENSOR_0_10V:
77+
case SensorType::V_0_10:
7878
/* Configure the input resistor dividers to have a ratio of 0.28
7979
* (Maximum input voltage is 10V). */
8080
digitalWrite(CH0_IN1, HIGH);
@@ -92,7 +92,7 @@ bool AnalogInClass::begin(int sensor_type, int res_bits) {
9292
digitalWrite(CH2_IN3, LOW);
9393
digitalWrite(CH2_IN4, HIGH);
9494
break;
95-
case MCAI_SENSOR_4_20MA:
95+
case SensorType::MA_4_20:
9696
/* Enable a 120 ohm resistor to GND to convert the 4-20mA sensor currents to voltage.
9797
* Note: 24V are available from the carrier to power the 4-20mA sensors. */
9898
digitalWrite(CH0_IN1, HIGH);

Diff for: src/AnalogInClass.h

+12-8
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717

1818
/* Exported defines ----------------------------------------------------------*/
1919

20-
/** Analog Sensor type **/
21-
#define MCAI_SENSOR_NTC 1
22-
#define MCAI_SENSOR_0_10V 2
23-
#define MCAI_SENSOR_4_20MA 3
24-
20+
/**
21+
* @brief Enum class that represents different sensor types.
22+
*/
23+
enum class SensorType {
24+
NTC = 1,
25+
V_0_10 = 2,
26+
MA_4_20 = 3
27+
};
28+
2529
/* Class ----------------------------------------------------------------------*/
2630

2731
/**
@@ -49,11 +53,11 @@ class AnalogInClass {
4953
/**
5054
* @brief Initialize the analog reader, configure the sensor type and read resolution.
5155
*
52-
* @param sensor_type The sensor type (0-10V, 4-20mA or NTC)
56+
* @param sensor_type The sensor type (NTC, V_0_10 or MA_4_20)
5357
* @param res_bits Resolution in bits of the read analog value
54-
* @return true If the analog reader is successfully initialized, false Otherwise
58+
* @return true If the analog reader is successfully initialized, false otherwise
5559
*/
56-
bool begin(int sensor_type, int res_bits = 16);
60+
bool begin(SensorType sensor_type, int res_bits = 16);
5761

5862
/**
5963
* @brief Read the sampled voltage from the selected channel.

0 commit comments

Comments
 (0)