This repository has been archived on 2022-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
Marlin-Artillery-M600/Marlin/src/gcode/feature/i2c/M260_M261.h

71 lines
2.1 KiB
C
Raw Normal View History

/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* M260: Send data to a I2C slave device
*
* This is a PoC, the formating and arguments for the GCODE will
* change to be more compatible, the current proposal is:
*
* M260 A<slave device address base 10> ; Sets the I2C slave address the data will be sent to
*
* M260 B<byte-1 value in base 10>
* M260 B<byte-2 value in base 10>
* M260 B<byte-3 value in base 10>
*
* M260 S1 ; Send the buffered data and reset the buffer
* M260 R1 ; Reset the buffer without sending data
*
*/
void gcode_M260() {
// Set the target address
if (parser.seen('A')) i2c.address(parser.value_byte());
// Add a new byte to the buffer
if (parser.seen('B')) i2c.addbyte(parser.value_byte());
// Flush the buffer to the bus
if (parser.seen('S')) i2c.send();
// Reset and rewind the buffer
else if (parser.seen('R')) i2c.reset();
}
/**
* M261: Request X bytes from I2C slave device
*
* Usage: M261 A<slave device address base 10> B<number of bytes>
*/
void gcode_M261() {
if (parser.seen('A')) i2c.address(parser.value_byte());
uint8_t bytes = parser.byteval('B', 1);
if (i2c.addr && bytes && bytes <= TWIBUS_BUFFER_SIZE) {
i2c.relay(bytes);
}
else {
SERIAL_ERROR_START();
SERIAL_ERRORLN("Bad i2c request");
}
}