Skip to content

Commit e6ce431

Browse files
committed
Allow 0-7 sub-address
1 parent 47cea8a commit e6ce431

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Marlin/src/gcode/feature/adc/M3426.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@
3838
* M3426 I<byte-2 value in base 10> 0 or 1, invert reply
3939
*/
4040
void GcodeSuite::M3426() {
41-
uint8_t channel = parser.byteval('C', 1), // Select the channel 1 or 2
42-
gain = parser.byteval('G', 1),
43-
address = parser.byteval('A', 3);
44-
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');
4545

46-
if (channel <= 2 && (gain == 1 || gain == 2 || gain == 4 || gain == 8) && WITHIN(address, MCP3426_BASE_ADDR, MCP3426_BASE_ADDR + 7)) {
46+
if (address <= 7) address += MCP3426_BASE_ADDR;
47+
48+
if (WITHIN(channel, 1, 2) && (gain == 1 || gain == 2 || gain == 4 || gain == 8) && WITHIN(address, MCP3426_BASE_ADDR, MCP3426_BASE_ADDR + 7)) {
4749
int16_t result = mcp3426.ReadValue(channel, gain, address);
4850

4951
if (mcp3426.Error == false) {

0 commit comments

Comments
 (0)