|
@@ -28,6 +28,8 @@
|
28
|
28
|
|
29
|
29
|
#include "../../../feature/adc/adc_mcp3426.h"
|
30
|
30
|
|
|
31
|
+#define MCP3426_BASE_ADDR (0b1101 << 3)
|
|
32
|
+
|
31
|
33
|
/**
|
32
|
34
|
* M3426: Read 16 bit (signed) value from I2C MCP3426 ADC device
|
33
|
35
|
*
|
|
@@ -36,12 +38,15 @@
|
36
|
38
|
* M3426 I<byte-2 value in base 10> 0 or 1, invert reply
|
37
|
39
|
*/
|
38
|
40
|
void GcodeSuite::M3426() {
|
39
|
|
- uint8_t channel = parser.byteval('C', 1), // Select the channel 1 or 2
|
40
|
|
- gain = parser.byteval('G', 1);
|
41
|
|
- const bool inverted = parser.byteval('I') == 1;
|
|
41
|
+ uint8_t channel = parser.byteval('C', 1), // Channel 1 or 2
|
|
42
|
+ gain = parser.byteval('G', 1), // Gain 1, 2, 4, or 8
|
|
43
|
+ address = parser.byteval('A', 3); // Address 0-7 (or 104-111)
|
|
44
|
+ const bool inverted = parser.boolval('I');
|
|
45
|
+
|
|
46
|
+ if (address <= 7) address += MCP3426_BASE_ADDR;
|
42
|
47
|
|
43
|
|
- if (channel <= 2 && (gain == 1 || gain == 2 || gain == 4 || gain == 8)) {
|
44
|
|
- int16_t result = mcp3426.ReadValue(channel, gain);
|
|
48
|
+ if (WITHIN(channel, 1, 2) && (gain == 1 || gain == 2 || gain == 4 || gain == 8) && WITHIN(address, MCP3426_BASE_ADDR, MCP3426_BASE_ADDR + 7)) {
|
|
49
|
+ int16_t result = mcp3426.ReadValue(channel, gain, address);
|
45
|
50
|
|
46
|
51
|
if (mcp3426.Error == false) {
|
47
|
52
|
if (inverted) {
|