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