Browse Source

Make M155 / M156 a bit more flexible

pull/1/head
Scott Lahteine 9 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() { inline void gcode_M155() {
// Set the target address // Set the target address
if (code_seen('A')) if (code_seen('A')) i2c.address(code_value_byte());
i2c.address(code_value_byte());
// Add a new byte to the buffer // Add a new byte to the buffer
else if (code_seen('B')) if (code_seen('B')) i2c.addbyte(code_value_byte());
i2c.addbyte(code_value_int());
// Flush the buffer to the bus // Flush the buffer to the bus
else if (code_seen('S')) i2c.send(); if (code_seen('S')) i2c.send();
// Reset and rewind the buffer // Reset and rewind the buffer
else if (code_seen('R')) i2c.reset(); 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> * Usage: M156 A<slave device address base 10> B<number of bytes>
*/ */
inline void gcode_M156() { inline void gcode_M156() {
uint8_t addr = code_seen('A') ? code_value_byte() : 0; if (code_seen('A')) i2c.address(code_value_byte());
int bytes = code_seen('B') ? code_value_int() : 1;
if (addr && bytes > 0 && bytes <= 32) { uint8_t bytes = code_seen('B') ? code_value_byte() : 1;
i2c.address(addr);
if (i2c.addr > 0 && bytes > 0 && bytes <= 32) {
i2c.reqbytes(bytes); i2c.reqbytes(bytes);
} }
else { else {

15
Marlin/twibus.h

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

Loading…
Cancel
Save