Browse Source

Make M155 / M156 a bit more flexible

pull/1/head
Scott Lahteine 8 years ago
parent
commit
dd75fca4d9
  1. 16
      Marlin/Marlin_main.cpp
  2. 15
      Marlin/twibus.h

16
Marlin/Marlin_main.cpp

@ -5259,15 +5259,13 @@ inline void gcode_M121() { endstops.enable_globally(false); }
*/
inline void gcode_M155() {
// Set the target address
if (code_seen('A'))
i2c.address(code_value_byte());
if (code_seen('A')) i2c.address(code_value_byte());
// Add a new byte to the buffer
else if (code_seen('B'))
i2c.addbyte(code_value_int());
if (code_seen('B')) i2c.addbyte(code_value_byte());
// Flush the buffer to the bus
else if (code_seen('S')) i2c.send();
if (code_seen('S')) i2c.send();
// Reset and rewind the buffer
else if (code_seen('R')) i2c.reset();
@ -5279,11 +5277,11 @@ inline void gcode_M121() { endstops.enable_globally(false); }
* Usage: M156 A<slave device address base 10> B<number of bytes>
*/
inline void gcode_M156() {
uint8_t addr = code_seen('A') ? code_value_byte() : 0;
int bytes = code_seen('B') ? code_value_int() : 1;
if (code_seen('A')) i2c.address(code_value_byte());
if (addr && bytes > 0 && bytes <= 32) {
i2c.address(addr);
uint8_t bytes = code_seen('B') ? code_value_byte() : 1;
if (i2c.addr > 0 && bytes > 0 && bytes <= 32) {
i2c.reqbytes(bytes);
}
else {

15
Marlin/twibus.h

@ -59,13 +59,6 @@ class TWIBus {
*/
const int timeout = 5;
/**
* @brief Target device address
* @description The target device address. Persists until changed.
*
*/
uint8_t addr = 0;
/**
* @brief Number of bytes on buffer
* @description Number of bytes in the buffer waiting to be flushed to the bus.
@ -76,10 +69,16 @@ class TWIBus {
* @brief Internal buffer
* @details A fixed buffer. TWI commands can be no longer than this.
*/
char buffer[30];
char buffer[32];
public:
/**
* @brief Target device address
* @description The target device address. Persists until changed.
*/
uint8_t addr = 0;
/**
* @brief Class constructor
* @details Initialize the TWI bus and clear the buffer

Loading…
Cancel
Save